mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/ptm/PTMSubCentroidsViewer.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, 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: PTMSubCentroidsViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.7 $
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
2 26 Feb 07 jari 13 package org.tigr.microarray.mev.cluster.gui.impl.ptm;
2 26 Feb 07 jari 14
2 26 Feb 07 jari 15 import java.awt.Color;
2 26 Feb 07 jari 16 import java.awt.Font;
2 26 Feb 07 jari 17 import java.awt.Graphics;
2 26 Feb 07 jari 18 import java.awt.Graphics2D;
2 26 Feb 07 jari 19 import java.awt.Rectangle;
2 26 Feb 07 jari 20 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 21 import java.beans.Expression;
2 26 Feb 07 jari 22 import java.util.Vector;
2 26 Feb 07 jari 23
2 26 Feb 07 jari 24 import javax.swing.JComponent;
2 26 Feb 07 jari 25 import javax.swing.JPanel;
2 26 Feb 07 jari 26
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.IData;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33 /**
2 26 Feb 07 jari 34  *
2 26 Feb 07 jari 35  * @author  nbhagaba
2 26 Feb 07 jari 36  * @version
2 26 Feb 07 jari 37  */
2 26 Feb 07 jari 38 public class PTMSubCentroidsViewer  extends JPanel implements IViewer {
2 26 Feb 07 jari 39     
2 26 Feb 07 jari 40     //Vector templateVector;
2 26 Feb 07 jari 41     protected PTMSubCentroidViewer centroidViewer;
2 26 Feb 07 jari 42     
2 26 Feb 07 jari 43     
2 26 Feb 07 jari 44     /** Creates new PTMSubCentroidsViewer */
2 26 Feb 07 jari 45     public PTMSubCentroidsViewer(Experiment experiment, int[][] clusters, Vector templateVector) {
2 26 Feb 07 jari 46     this.centroidViewer = new PTMSubCentroidViewer(experiment, clusters, templateVector);
2 26 Feb 07 jari 47     setBackground(Color.white);
2 26 Feb 07 jari 48     setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 49     }
2 26 Feb 07 jari 50     
2 26 Feb 07 jari 51     public PTMSubCentroidsViewer(PTMSubCentroidViewer cv){
2 26 Feb 07 jari 52       this.centroidViewer = cv;
2 26 Feb 07 jari 53     setBackground(Color.white);
2 26 Feb 07 jari 54     setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 55     }
2 26 Feb 07 jari 56     public Expression getExpression(){
2 26 Feb 07 jari 57       return new Expression(this, this.getClass(), "new", 
2 26 Feb 07 jari 58           new Object[]{this.centroidViewer});
2 26 Feb 07 jari 59     }
2 26 Feb 07 jari 60     
2 26 Feb 07 jari 61    
2 26 Feb 07 jari 62     public void setExperiment(Experiment e){centroidViewer.setExperiment(e);}
2 26 Feb 07 jari 63     public void setExperimentID(int i){centroidViewer.setExperimentID(i);}
2 26 Feb 07 jari 64     public int getExperimentID(){return centroidViewer.getExperimentID();}
2 26 Feb 07 jari 65     
2 26 Feb 07 jari 66     /**
2 26 Feb 07 jari 67      * Returns component to be inserted into the framework scroll pane.
2 26 Feb 07 jari 68      */
2 26 Feb 07 jari 69     public JComponent getContentComponent() {
2 26 Feb 07 jari 70   return this;
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     /**
2 26 Feb 07 jari 74      * There is no a header.
2 26 Feb 07 jari 75      * @return null
2 26 Feb 07 jari 76      */
2 26 Feb 07 jari 77     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 78   return null;
2 26 Feb 07 jari 79     }
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81     
2 26 Feb 07 jari 82     /**
2 26 Feb 07 jari 83      * Updates data, drawing mode and some attributes of the wrapped viewer.
2 26 Feb 07 jari 84      */
2 26 Feb 07 jari 85     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 86   this.centroidViewer.setData(framework.getData());
2 26 Feb 07 jari 87   this.centroidViewer.setMode(((Integer)framework.getUserObject()).intValue());
2 26 Feb 07 jari 88   this.centroidViewer.setAntiAliasing(framework.getDisplayMenu().isAntiAliasing());
2 26 Feb 07 jari 89     }
2 26 Feb 07 jari 90     
2 26 Feb 07 jari 91     /**
2 26 Feb 07 jari 92      * Updates data of the wrapped viewer.
2 26 Feb 07 jari 93      */
2 26 Feb 07 jari 94     public void onDataChanged(IData data) {
2 26 Feb 07 jari 95   this.centroidViewer.setData(data);
2 26 Feb 07 jari 96     }
2 26 Feb 07 jari 97     
2 26 Feb 07 jari 98     /**
2 26 Feb 07 jari 99      * Sets mean values to the wrapped viewer.
2 26 Feb 07 jari 100      */
2 26 Feb 07 jari 101     public void setMeans(float[][] means) {
2 26 Feb 07 jari 102   this.centroidViewer.setMeans(means);
2 26 Feb 07 jari 103     }
2 26 Feb 07 jari 104     
2 26 Feb 07 jari 105     /**
2 26 Feb 07 jari 106      * Sets variances values to the wrapped viewer.
2 26 Feb 07 jari 107      */
2 26 Feb 07 jari 108     public void setVariances(float[][] variances) {
2 26 Feb 07 jari 109   this.centroidViewer.setVariances(variances);
2 26 Feb 07 jari 110     }
2 26 Feb 07 jari 111     
2 26 Feb 07 jari 112     /**
2 26 Feb 07 jari 113      * Sets codes to the wrapped viewer.
2 26 Feb 07 jari 114      */
2 26 Feb 07 jari 115     public void setCodes(float[][] codes) {
2 26 Feb 07 jari 116   this.centroidViewer.setCodes(codes);
2 26 Feb 07 jari 117     }
2 26 Feb 07 jari 118     
2 26 Feb 07 jari 119     /**
2 26 Feb 07 jari 120      * Returns the experiment.
2 26 Feb 07 jari 121      */
2 26 Feb 07 jari 122     public Experiment getExperiment() {
2 26 Feb 07 jari 123   return this.centroidViewer.getExperiment();
2 26 Feb 07 jari 124     }
2 26 Feb 07 jari 125     
2 26 Feb 07 jari 126     /**
2 26 Feb 07 jari 127      * Returns the data.
2 26 Feb 07 jari 128      */
2 26 Feb 07 jari 129     protected IData getData() {
2 26 Feb 07 jari 130   return this.centroidViewer.getData();
2 26 Feb 07 jari 131     }
2 26 Feb 07 jari 132     
2 26 Feb 07 jari 133     /**
2 26 Feb 07 jari 134      * Returns clusters.
2 26 Feb 07 jari 135      */
2 26 Feb 07 jari 136     public int[][] getClusters() {
2 26 Feb 07 jari 137   return this.centroidViewer.getClusters();
2 26 Feb 07 jari 138     }
2 26 Feb 07 jari 139     
2 26 Feb 07 jari 140     /**
2 26 Feb 07 jari 141      * Updates some attributes of the wrapped viewer.
2 26 Feb 07 jari 142      */
2 26 Feb 07 jari 143     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 144   this.centroidViewer.onMenuChanged(menu);
2 26 Feb 07 jari 145     }
2 26 Feb 07 jari 146     
2 26 Feb 07 jari 147     public void onDeselected() {}
2 26 Feb 07 jari 148     public void onClosed() {}
2 26 Feb 07 jari 149     
2 26 Feb 07 jari 150     /**
2 26 Feb 07 jari 151      * @return null
2 26 Feb 07 jari 152      */
2 26 Feb 07 jari 153     public BufferedImage getImage() {
2 26 Feb 07 jari 154   return null;
2 26 Feb 07 jari 155     }
2 26 Feb 07 jari 156     
2 26 Feb 07 jari 157     /**
2 26 Feb 07 jari 158      * Paints centroid charts into specified graphics.
2 26 Feb 07 jari 159      */
2 26 Feb 07 jari 160     public void paint(Graphics g) {
2 26 Feb 07 jari 161   super.paint(g);
2 26 Feb 07 jari 162   
2 26 Feb 07 jari 163   final int gap = 10;
2 26 Feb 07 jari 164   final int imagesX = (int)Math.ceil(Math.sqrt(getClusters().length));
2 26 Feb 07 jari 165   final int imagesY = (int)Math.ceil((float)getClusters().length/(float)imagesX);
2 26 Feb 07 jari 166   
2 26 Feb 07 jari 167   final float stepX = (float)(getWidth()-gap)/(float)imagesX;
2 26 Feb 07 jari 168   final float stepY = (float)(getHeight()-gap)/(float)imagesY;
2 26 Feb 07 jari 169   Rectangle rect = new Rectangle();
2 26 Feb 07 jari 170   int cluster;
2 26 Feb 07 jari 171   for (int y=0; y<imagesY; y++) {
2 26 Feb 07 jari 172       for (int x=0; x<imagesX; x++) {
2 26 Feb 07 jari 173     cluster = y*imagesX+x;
2 26 Feb 07 jari 174     if (cluster >= getClusters().length) {
2 26 Feb 07 jari 175         break;
2 26 Feb 07 jari 176     }
2 26 Feb 07 jari 177     this.centroidViewer.setClusterIndex(cluster);
2 26 Feb 07 jari 178     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 179     this.centroidViewer.paint((Graphics2D)g, rect, false);
2 26 Feb 07 jari 180       }
2 26 Feb 07 jari 181   }
2 26 Feb 07 jari 182     }
2 26 Feb 07 jari 183     
2 26 Feb 07 jari 184     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 185      */
2 26 Feb 07 jari 186     public JComponent getRowHeaderComponent() {
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     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 191      * posibly null
2 26 Feb 07 jari 192      */
2 26 Feb 07 jari 193     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 194         return null;
2 26 Feb 07 jari 195     }
2 26 Feb 07 jari 196     
2 26 Feb 07 jari 197     /** Returns int value indicating viewer type
2 26 Feb 07 jari 198      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 199      */
2 26 Feb 07 jari 200     public int getViewerType() {
2 26 Feb 07 jari 201         return centroidViewer.getViewerType();
2 26 Feb 07 jari 202     }
2 26 Feb 07 jari 203     
2 26 Feb 07 jari 204 }