mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/ptm/PTMExperimentSubCentroidsViewer.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: PTMExperimentSubCentroidsViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.8 $
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 PTMExperimentSubCentroidsViewer 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 PTMExperimentCentroidViewer 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 PTMExperimentSubCentroidsViewer(Experiment experiment, int[][] clusters, Vector templateVector, String[] auxTitles, Object[][] auxData) {
2 26 Feb 07 jari 46     //  super(experiment, clusters);
2 26 Feb 07 jari 47     //this.templateVector = templateVector;
2 26 Feb 07 jari 48     this.centroidViewer = new PTMExperimentCentroidViewer(experiment, clusters, templateVector, auxTitles, auxData);
2 26 Feb 07 jari 49     setBackground(Color.white);
2 26 Feb 07 jari 50     setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 51     }
2 26 Feb 07 jari 52     
2 26 Feb 07 jari 53     public PTMExperimentSubCentroidsViewer(PTMExperimentCentroidViewer 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     public Expression getExpression(){
2 26 Feb 07 jari 59       return new Expression(this, this.getClass(), "new", 
2 26 Feb 07 jari 60           new Object[]{this.centroidViewer});
2 26 Feb 07 jari 61     }
2 26 Feb 07 jari 62     
2 26 Feb 07 jari 63     public int getExperimentID(){return centroidViewer.getExperimentID();}
2 26 Feb 07 jari 64     public void setExperimentID(int id){centroidViewer.setExperimentID(id);}
2 26 Feb 07 jari 65     public void setExperiment(Experiment e){centroidViewer.setExperiment(e);}
2 26 Feb 07 jari 66     
2 26 Feb 07 jari 67     /**
2 26 Feb 07 jari 68      * Returns component to be inserted into the framework scroll pane.
2 26 Feb 07 jari 69      */
2 26 Feb 07 jari 70     public JComponent getContentComponent() {
2 26 Feb 07 jari 71   return this;
2 26 Feb 07 jari 72     }
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 75      */
2 26 Feb 07 jari 76     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 77         return null;
2 26 Feb 07 jari 78     }
2 26 Feb 07 jari 79     
2 26 Feb 07 jari 80     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 81      * posibly null
2 26 Feb 07 jari 82      */
2 26 Feb 07 jari 83     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 84         return null;
2 26 Feb 07 jari 85     }    
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     /**
2 26 Feb 07 jari 88      * There is no a header.
2 26 Feb 07 jari 89      * @return null
2 26 Feb 07 jari 90      */
2 26 Feb 07 jari 91     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 92   return null;
2 26 Feb 07 jari 93     }
2 26 Feb 07 jari 94     
2 26 Feb 07 jari 95     
2 26 Feb 07 jari 96     /**
2 26 Feb 07 jari 97      * Updates data, drawing mode and some attributes of the wrapped viewer.
2 26 Feb 07 jari 98      */
2 26 Feb 07 jari 99     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 100   this.centroidViewer.setData(framework.getData());
2 26 Feb 07 jari 101   this.centroidViewer.setMode(((Integer)framework.getUserObject()).intValue());
2 26 Feb 07 jari 102   this.centroidViewer.setAntiAliasing(framework.getDisplayMenu().isAntiAliasing());
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 of the wrapped viewer.
2 26 Feb 07 jari 107      */
2 26 Feb 07 jari 108     public void onDataChanged(IData data) {
2 26 Feb 07 jari 109   this.centroidViewer.setData(data);
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 mean values to the wrapped viewer.
2 26 Feb 07 jari 114      */
2 26 Feb 07 jari 115     public void setMeans(float[][] means) {
2 26 Feb 07 jari 116   this.centroidViewer.setMeans(means);
2 26 Feb 07 jari 117     }
2 26 Feb 07 jari 118     
2 26 Feb 07 jari 119     /**
2 26 Feb 07 jari 120      * Sets variances values to the wrapped viewer.
2 26 Feb 07 jari 121      */
2 26 Feb 07 jari 122     public void setVariances(float[][] variances) {
2 26 Feb 07 jari 123   this.centroidViewer.setVariances(variances);
2 26 Feb 07 jari 124     }
2 26 Feb 07 jari 125     
2 26 Feb 07 jari 126     /**
2 26 Feb 07 jari 127      * Sets codes to the wrapped viewer.
2 26 Feb 07 jari 128      */
2 26 Feb 07 jari 129     public void setCodes(float[][] codes) {
2 26 Feb 07 jari 130   this.centroidViewer.setCodes(codes);
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 the experiment.
2 26 Feb 07 jari 135      */
2 26 Feb 07 jari 136     public Experiment getExperiment() {
2 26 Feb 07 jari 137   return this.centroidViewer.getExperiment();
2 26 Feb 07 jari 138     }
2 26 Feb 07 jari 139     
2 26 Feb 07 jari 140     /**
2 26 Feb 07 jari 141      * Returns the data.
2 26 Feb 07 jari 142      */
2 26 Feb 07 jari 143     protected IData getData() {
2 26 Feb 07 jari 144   return this.centroidViewer.getData();
2 26 Feb 07 jari 145     }
2 26 Feb 07 jari 146     
2 26 Feb 07 jari 147     /**
2 26 Feb 07 jari 148      * Returns clusters.
2 26 Feb 07 jari 149      */
2 26 Feb 07 jari 150     public int[][] getClusters() {
2 26 Feb 07 jari 151   return this.centroidViewer.getClusters();
2 26 Feb 07 jari 152     }
2 26 Feb 07 jari 153     
2 26 Feb 07 jari 154     /**
2 26 Feb 07 jari 155      * Updates some attributes of the wrapped viewer.
2 26 Feb 07 jari 156      */
2 26 Feb 07 jari 157     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 158   this.centroidViewer.onMenuChanged(menu);
2 26 Feb 07 jari 159     }
2 26 Feb 07 jari 160     
2 26 Feb 07 jari 161     public void onDeselected() {}
2 26 Feb 07 jari 162     public void onClosed() {}
2 26 Feb 07 jari 163     
2 26 Feb 07 jari 164     /**
2 26 Feb 07 jari 165      * @return null
2 26 Feb 07 jari 166      */
2 26 Feb 07 jari 167     public BufferedImage getImage() {
2 26 Feb 07 jari 168   return null;
2 26 Feb 07 jari 169     }
2 26 Feb 07 jari 170     
2 26 Feb 07 jari 171     /**
2 26 Feb 07 jari 172      * Paints centroid charts into specified graphics.
2 26 Feb 07 jari 173      */
2 26 Feb 07 jari 174     public void paint(Graphics g) {
2 26 Feb 07 jari 175   super.paint(g);
2 26 Feb 07 jari 176   
2 26 Feb 07 jari 177   final int gap = 10;
2 26 Feb 07 jari 178   final int imagesX = (int)Math.ceil(Math.sqrt(getClusters().length));
2 26 Feb 07 jari 179   final int imagesY = (int)Math.ceil((float)getClusters().length/(float)imagesX);
2 26 Feb 07 jari 180   
2 26 Feb 07 jari 181   final float stepX = (float)(getWidth()-gap)/(float)imagesX;
2 26 Feb 07 jari 182   final float stepY = (float)(getHeight()-gap)/(float)imagesY;
2 26 Feb 07 jari 183   Rectangle rect = new Rectangle();
2 26 Feb 07 jari 184   int cluster;
2 26 Feb 07 jari 185   for (int y=0; y<imagesY; y++) {
2 26 Feb 07 jari 186       for (int x=0; x<imagesX; x++) {
2 26 Feb 07 jari 187     cluster = y*imagesX+x;
2 26 Feb 07 jari 188     if (cluster >= getClusters().length) {
2 26 Feb 07 jari 189         break;
2 26 Feb 07 jari 190     }
2 26 Feb 07 jari 191     this.centroidViewer.setClusterIndex(cluster);
2 26 Feb 07 jari 192     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 193     this.centroidViewer.paint((Graphics2D)g, rect, false);
2 26 Feb 07 jari 194       }
2 26 Feb 07 jari 195   }
2 26 Feb 07 jari 196     }
2 26 Feb 07 jari 197     
2 26 Feb 07 jari 198     /** Returns int value indicating viewer type
2 26 Feb 07 jari 199      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 200      */
2 26 Feb 07 jari 201     public int getViewerType() {
2 26 Feb 07 jari 202         return this.centroidViewer.getViewerType();
2 26 Feb 07 jari 203     }    
2 26 Feb 07 jari 204     
2 26 Feb 07 jari 205 }