mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/helpers/ExperimentClusterCentroidsViewer.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: ExperimentClusterCentroidsViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.10 $
2 26 Feb 07 jari 8  * $Date: 2006/05/02 16:56:57 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.gui.helpers;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Font;
2 26 Feb 07 jari 15 import java.awt.Color;
2 26 Feb 07 jari 16 import java.awt.Graphics;
2 26 Feb 07 jari 17 import java.awt.Rectangle;
2 26 Feb 07 jari 18 import java.awt.Graphics2D;
2 26 Feb 07 jari 19 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 20 import java.beans.Expression;
2 26 Feb 07 jari 21
2 26 Feb 07 jari 22 import javax.swing.JPanel;
2 26 Feb 07 jari 23 import javax.swing.JComponent;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31
2 26 Feb 07 jari 32 public class ExperimentClusterCentroidsViewer extends JPanel implements IViewer {
2 26 Feb 07 jari 33     private int exptID = 0;
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     /** Wrapped experiment cluster centroid viewer */
2 26 Feb 07 jari 36     protected ExperimentClusterCentroidViewer centroidViewer;
2 26 Feb 07 jari 37     
2 26 Feb 07 jari 38     /**
2 26 Feb 07 jari 39      * Constructs a <code>ExperimentClusterCentroidsViewer</code> for specified experiment
2 26 Feb 07 jari 40      * and clusters.
2 26 Feb 07 jari 41      */
2 26 Feb 07 jari 42     public ExperimentClusterCentroidsViewer(Experiment experiment, int[][] clusters) {
2 26 Feb 07 jari 43         this.centroidViewer = new ExperimentClusterCentroidViewer(experiment, clusters);
2 26 Feb 07 jari 44         this.exptID = experiment.getId();
2 26 Feb 07 jari 45         setBackground(Color.white);
2 26 Feb 07 jari 46         setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 47     }
2 26 Feb 07 jari 48     
2 26 Feb 07 jari 49     /**
2 26 Feb 07 jari 50      * Constructs a <code>CentroidsViewer</code> for specified experiment
2 26 Feb 07 jari 51      * and clusters.
2 26 Feb 07 jari 52      */
2 26 Feb 07 jari 53     public ExperimentClusterCentroidsViewer(ExperimentClusterCentroidViewer cv) {
2 26 Feb 07 jari 54         this.centroidViewer = cv;
2 26 Feb 07 jari 55         setBackground(Color.white);
2 26 Feb 07 jari 56         setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 57     } 
2 26 Feb 07 jari 58     //EH begin state-saving additions
2 26 Feb 07 jari 59     public Expression getExpression(){
2 26 Feb 07 jari 60       return new Expression(this, this.getClass(), "new",
2 26 Feb 07 jari 61         new Object[]{centroidViewer});  
2 26 Feb 07 jari 62   
2 26 Feb 07 jari 63     }
2 26 Feb 07 jari 64     /*
2 26 Feb 07 jari 65     copy-paste this constructor into descendent classes
2 26 Feb 07 jari 66     /**
2 26 Feb 07 jari 67      * @inheritDoc
2 26 Feb 07 jari 68      *
2 26 Feb 07 jari 69     public ExperimentClusterCentroidsViewer(ExperimentClusterCentroidViewer cv) {
2 26 Feb 07 jari 70       super(cv);
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     */
2 26 Feb 07 jari 73
2 26 Feb 07 jari 74     /* (non-Javadoc)
2 26 Feb 07 jari 75    * @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperiment(org.tigr.microarray.mev.cluster.gui.Experiment)
2 26 Feb 07 jari 76    */
2 26 Feb 07 jari 77   public void setExperiment(Experiment e) {
2 26 Feb 07 jari 78     this.centroidViewer.setExperimentID(e.getId());
2 26 Feb 07 jari 79     this.centroidViewer.setExperiment(e);
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81   }
2 26 Feb 07 jari 82
2 26 Feb 07 jari 83   /* (non-Javadoc)
2 26 Feb 07 jari 84    * @see org.tigr.microarray.mev.cluster.gui.IViewer#getExperimentID()
2 26 Feb 07 jari 85    */
2 26 Feb 07 jari 86   public int getExperimentID() {
2 26 Feb 07 jari 87     return this.exptID;
2 26 Feb 07 jari 88   }
2 26 Feb 07 jari 89
2 26 Feb 07 jari 90   /* (non-Javadoc)
2 26 Feb 07 jari 91    * @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperimentID(int)
2 26 Feb 07 jari 92    */
2 26 Feb 07 jari 93   public void setExperimentID(int id) {
2 26 Feb 07 jari 94     this.exptID = id;
2 26 Feb 07 jari 95     
2 26 Feb 07 jari 96   }
2 26 Feb 07 jari 97     //EH end state-saving additions
2 26 Feb 07 jari 98     
2 26 Feb 07 jari 99     /**
2 26 Feb 07 jari 100      * Returns component to be inserted into the framework scroll pane.
2 26 Feb 07 jari 101      */
2 26 Feb 07 jari 102     public JComponent getContentComponent() {
2 26 Feb 07 jari 103         return this;
2 26 Feb 07 jari 104     }
2 26 Feb 07 jari 105     
2 26 Feb 07 jari 106     /**
2 26 Feb 07 jari 107      * There is no a header.
2 26 Feb 07 jari 108      * @return null
2 26 Feb 07 jari 109      */
2 26 Feb 07 jari 110     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 111         return null;
2 26 Feb 07 jari 112     }
2 26 Feb 07 jari 113     
2 26 Feb 07 jari 114     /**
2 26 Feb 07 jari 115      * Updates data, drawing mode and some attributes of the wrapped viewer.
2 26 Feb 07 jari 116      */
2 26 Feb 07 jari 117     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 118         this.centroidViewer.setData(framework.getData());
2 26 Feb 07 jari 119         this.centroidViewer.setMode(((Integer)framework.getUserObject()).intValue());
2 26 Feb 07 jari 120         this.centroidViewer.setAntiAliasing(framework.getDisplayMenu().isAntiAliasing());
2 26 Feb 07 jari 121         this.centroidViewer.onSelected(framework);
2 26 Feb 07 jari 122     }
2 26 Feb 07 jari 123     
2 26 Feb 07 jari 124     /**
2 26 Feb 07 jari 125      * Updates data of the wrapped viewer.
2 26 Feb 07 jari 126      */
2 26 Feb 07 jari 127     public void onDataChanged(IData data) {
2 26 Feb 07 jari 128         this.centroidViewer.setData(data);
2 26 Feb 07 jari 129     }
2 26 Feb 07 jari 130     
2 26 Feb 07 jari 131     /**
2 26 Feb 07 jari 132      * Sets mean values to the wrapped viewer.
2 26 Feb 07 jari 133      */
2 26 Feb 07 jari 134     public void setMeans(float[][] means) {
2 26 Feb 07 jari 135         this.centroidViewer.setMeans(means);
2 26 Feb 07 jari 136     }
2 26 Feb 07 jari 137     
2 26 Feb 07 jari 138     /**
2 26 Feb 07 jari 139      * Sets variances values to the wrapped viewer.
2 26 Feb 07 jari 140      */
2 26 Feb 07 jari 141     public void setVariances(float[][] variances) {
2 26 Feb 07 jari 142         this.centroidViewer.setVariances(variances);
2 26 Feb 07 jari 143     }
2 26 Feb 07 jari 144     
2 26 Feb 07 jari 145     /**
2 26 Feb 07 jari 146      * Sets codes to the wrapped viewer.
2 26 Feb 07 jari 147      */
2 26 Feb 07 jari 148     public void setCodes(float[][] codes) {
2 26 Feb 07 jari 149         this.centroidViewer.setCodes(codes);
2 26 Feb 07 jari 150     }
2 26 Feb 07 jari 151     
2 26 Feb 07 jari 152     /**
2 26 Feb 07 jari 153      * Returns the experiment.
2 26 Feb 07 jari 154      */
2 26 Feb 07 jari 155     public Experiment getExperiment() {
2 26 Feb 07 jari 156         return this.centroidViewer.getExperiment();
2 26 Feb 07 jari 157     }
2 26 Feb 07 jari 158     
2 26 Feb 07 jari 159     /**
2 26 Feb 07 jari 160      * Returns the data.
2 26 Feb 07 jari 161      */
2 26 Feb 07 jari 162     protected IData getData() {
2 26 Feb 07 jari 163         return this.centroidViewer.getData();
2 26 Feb 07 jari 164     }
2 26 Feb 07 jari 165     
2 26 Feb 07 jari 166     /**
2 26 Feb 07 jari 167      * Returns clusters.
2 26 Feb 07 jari 168      */
2 26 Feb 07 jari 169     public int[][] getClusters() {
2 26 Feb 07 jari 170         return this.centroidViewer.getClusters();
2 26 Feb 07 jari 171     }
2 26 Feb 07 jari 172     
2 26 Feb 07 jari 173     /**
2 26 Feb 07 jari 174      * Updates some attributes of the wrapped viewer.
2 26 Feb 07 jari 175      */
2 26 Feb 07 jari 176     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 177         this.centroidViewer.onMenuChanged(menu);
2 26 Feb 07 jari 178     }
2 26 Feb 07 jari 179     
2 26 Feb 07 jari 180     public void onDeselected() {}
2 26 Feb 07 jari 181     public void onClosed() {}
2 26 Feb 07 jari 182     
2 26 Feb 07 jari 183     /**
2 26 Feb 07 jari 184      * @return null
2 26 Feb 07 jari 185      */
2 26 Feb 07 jari 186     public BufferedImage getImage() {
2 26 Feb 07 jari 187         return null;
2 26 Feb 07 jari 188     }
2 26 Feb 07 jari 189     
2 26 Feb 07 jari 190     /**
2 26 Feb 07 jari 191      * Paints centroid charts into specified graphics.
2 26 Feb 07 jari 192      */
2 26 Feb 07 jari 193     public void paint(Graphics g) {
2 26 Feb 07 jari 194         super.paint(g);
2 26 Feb 07 jari 195         
2 26 Feb 07 jari 196         final int gap = 10;
2 26 Feb 07 jari 197         final int imagesX = (int)Math.ceil(Math.sqrt(getClusters().length));
2 26 Feb 07 jari 198         final int imagesY = (int)Math.ceil((float)getClusters().length/(float)imagesX);
2 26 Feb 07 jari 199         
2 26 Feb 07 jari 200         final float stepX = (float)(getWidth()-gap)/(float)imagesX;
2 26 Feb 07 jari 201         final float stepY = (float)(getHeight()-gap)/(float)imagesY;
2 26 Feb 07 jari 202         Rectangle rect = new Rectangle();
2 26 Feb 07 jari 203         int cluster;
2 26 Feb 07 jari 204         for (int y=0; y<imagesY; y++) {
2 26 Feb 07 jari 205             for (int x=0; x<imagesX; x++) {
2 26 Feb 07 jari 206                 cluster = y*imagesX+x;
2 26 Feb 07 jari 207                 if (cluster >= getClusters().length) {
2 26 Feb 07 jari 208                     break;
2 26 Feb 07 jari 209                 }
2 26 Feb 07 jari 210                 this.centroidViewer.setClusterIndex(cluster);
2 26 Feb 07 jari 211                 rect.setBounds((int)Math.round(gap+x*stepX), (int)Math.round(gap+y*stepY), (int)Math.round(stepX-gap), (int)Math.round(stepY-gap));
2 26 Feb 07 jari 212                 this.centroidViewer.paint((Graphics2D)g, rect, false);
2 26 Feb 07 jari 213             }
2 26 Feb 07 jari 214         }
2 26 Feb 07 jari 215     }
2 26 Feb 07 jari 216     
2 26 Feb 07 jari 217     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 218      */
2 26 Feb 07 jari 219     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 220         return null;
2 26 Feb 07 jari 221     }
2 26 Feb 07 jari 222     
2 26 Feb 07 jari 223     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 224      * posibly null
2 26 Feb 07 jari 225      */
2 26 Feb 07 jari 226     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 227         return null;
2 26 Feb 07 jari 228     }
2 26 Feb 07 jari 229     
2 26 Feb 07 jari 230     /** Returns int value indicating viewer type
2 26 Feb 07 jari 231      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 232      */
2 26 Feb 07 jari 233     public int getViewerType() {
2 26 Feb 07 jari 234         return org.tigr.microarray.mev.cluster.clusterUtil.Cluster.EXPERIMENT_CLUSTER;
2 26 Feb 07 jari 235     }
2 26 Feb 07 jari 236     
2 26 Feb 07 jari 237 }
2 26 Feb 07 jari 238