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