mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/helpers/CentroidViewer.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: CentroidViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.9 $
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.Rectangle;
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.FontMetrics;
2 26 Feb 07 jari 20 import java.awt.RenderingHints;
2 26 Feb 07 jari 21 import java.awt.event.ActionListener;
2 26 Feb 07 jari 22 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 23 import java.beans.Expression;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import javax.swing.JMenuItem;
2 26 Feb 07 jari 26 import javax.swing.JPanel;
2 26 Feb 07 jari 27 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 28 import javax.swing.JComponent;
2 26 Feb 07 jari 29
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 34 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 35 import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory;
2 26 Feb 07 jari 36
2 26 Feb 07 jari 37 import org.tigr.microarray.mev.cluster.clusterUtil.*;
2 26 Feb 07 jari 38
2 26 Feb 07 jari 39
2 26 Feb 07 jari 40 public class CentroidViewer extends JPanel implements IViewer {
2 26 Feb 07 jari 41     
2 26 Feb 07 jari 42     public static final Color DEF_CLUSTER_COLOR = Color.lightGray;
2 26 Feb 07 jari 43     protected static final Color bColor = new Color(0, 0, 128);
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     //menu options
2 26 Feb 07 jari 46     protected JMenuItem setOverallMaxMenuItem;
2 26 Feb 07 jari 47     protected JMenuItem setClusterMaxMenuItem;
2 26 Feb 07 jari 48     protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd";
2 26 Feb 07 jari 49     protected static final String SET_DEF_COLOR_CMD = "set-def-color-cmd";
2 26 Feb 07 jari 50     protected static final String SAVE_CLUSTER_CMD = "save-cluster-cmd";
2 26 Feb 07 jari 51     protected static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd";
2 26 Feb 07 jari 52     protected static final String SET_Y_TO_EXPERIMENT_MAX_CMD = "set-y-to-exp-max-cmd";
2 26 Feb 07 jari 53     protected static final String SET_Y_TO_CLUSTER_MAX_CMD = "set-y-to-cluster-max-cmd";
2 26 Feb 07 jari 54     protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd";   
2 26 Feb 07 jari 55     protected static final String TOGGLE_REF_LINE_CMD = "toggle-ref-line-cmd";   
2 26 Feb 07 jari 56         
2 26 Feb 07 jari 57     protected Color centroidColor = Color.magenta;
2 26 Feb 07 jari 58     
2 26 Feb 07 jari 59     protected Experiment experiment;
2 26 Feb 07 jari 60     protected IFramework framework;
2 26 Feb 07 jari 61     protected IData data;
2 26 Feb 07 jari 62     protected int clusterIndex;
2 26 Feb 07 jari 63     protected int[][] clusters;
2 26 Feb 07 jari 64     protected float maxYValue;           //current max y range set for graph, from y = 0
2 26 Feb 07 jari 65     protected float maxClusterValue;     //max abs. value in current cluster
2 26 Feb 07 jari 66     protected float maxExperimentValue;  //max abs. value in all clusters
2 26 Feb 07 jari 67     protected boolean gradientToggle = true;
2 26 Feb 07 jari 68     
2 26 Feb 07 jari 69     protected int yRangeOption;
2 26 Feb 07 jari 70     public static int USE_EXPERIMENT_MAX = 0;
2 26 Feb 07 jari 71     public static int USE_CLUSTER_MAX = 1;
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     protected boolean drawValues = true;
2 26 Feb 07 jari 74     protected boolean drawVariances = true;
2 26 Feb 07 jari 75     protected boolean drawCodes = true;
2 26 Feb 07 jari 76     private boolean drawMarks = true;
2 26 Feb 07 jari 77     protected boolean isAntiAliasing = false;
2 26 Feb 07 jari 78     protected boolean gradientColors;
2 26 Feb 07 jari 79     protected float[][] means;
2 26 Feb 07 jari 80     protected float[][] variances;
2 26 Feb 07 jari 81     protected float[][] codes;
2 26 Feb 07 jari 82     protected float minValue, maxValue, midValue = 0.0f;
2 26 Feb 07 jari 83     public static Color missingColor = new Color(128, 128, 128);
2 26 Feb 07 jari 84     public static BufferedImage posColorImage; // = createGradientImage(Color.black, Color.red);
2 26 Feb 07 jari 85     public static BufferedImage negColorImage; // = createGradientImage(Color.green, Color.black);
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     public boolean useDoubleGradient = true;
2 26 Feb 07 jari 88     
2 26 Feb 07 jari 89     protected boolean drawReferenceBlock = false;
2 26 Feb 07 jari 90     protected int xref = 0;
2 26 Feb 07 jari 91     protected int yref = 0;
2 26 Feb 07 jari 92     protected int currExpRefLine;
2 26 Feb 07 jari 93     protected boolean showRefLine = false;
2 26 Feb 07 jari 94     private int exptID = 0;
2 26 Feb 07 jari 95     
2 26 Feb 07 jari 96     public CentroidViewer() { }
2 26 Feb 07 jari 97     
2 26 Feb 07 jari 98     /**
2 26 Feb 07 jari 99      * This constructor is used by XMLEncoder/Decoder to store and retreive a 
2 26 Feb 07 jari 100      * CentroidViewer object to/from and xml file.  This constructor must 
2 26 Feb 07 jari 101      * always exist, with its current method signature, for purposes of 
2 26 Feb 07 jari 102      * backwards-compatability in loading old save-files from MeV versions 
2 26 Feb 07 jari 103      * of v3.2 and later.  
2 26 Feb 07 jari 104      * @param experiment TODO
2 26 Feb 07 jari 105      * @param clusters
2 26 Feb 07 jari 106      * @param variances
2 26 Feb 07 jari 107      * @param means
2 26 Feb 07 jari 108      * @param codes
2 26 Feb 07 jari 109      */
2 26 Feb 07 jari 110     public CentroidViewer(Experiment experiment, int[][] clusters, float[][] variances, float[][] means, float[][] codes) {
2 26 Feb 07 jari 111       this.experiment = experiment;
2 26 Feb 07 jari 112       this.clusters = clusters;
2 26 Feb 07 jari 113       this.setVariances(variances);
2 26 Feb 07 jari 114       this.setMeans(means);
2 26 Feb 07 jari 115       this.setCodes(codes);
2 26 Feb 07 jari 116         setBackground(Color.white);
2 26 Feb 07 jari 117         setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 118         this.maxExperimentValue = experiment.getMaxAbsValue();
2 26 Feb 07 jari 119         this.yRangeOption = CentroidViewer.USE_EXPERIMENT_MAX;
2 26 Feb 07 jari 120         this.addMouseMotionListener(new GraphListener()); 
2 26 Feb 07 jari 121     }
2 26 Feb 07 jari 122     //TODO EH testing
2 26 Feb 07 jari 123     public Expression getExpression(){
2 26 Feb 07 jari 124       return new Expression(this, this.getClass(), "new",
2 26 Feb 07 jari 125         new Object[]{experiment, clusters, variances, means, codes});
2 26 Feb 07 jari 126     }
2 26 Feb 07 jari 127     /*
2 26 Feb 07 jari 128     copy-paste this constructor into each descendent class
2 26 Feb 07 jari 129     /**
2 26 Feb 07 jari 130      * @inheritDoc
2 26 Feb 07 jari 131      *
2 26 Feb 07 jari 132     public CentroidViewer(int[][] clusters, float[][] variances, float[][] means, float[][] codes, Integer id) {
2 26 Feb 07 jari 133       super(clusters, variances, means, codes, id);
2 26 Feb 07 jari 134     }
2 26 Feb 07 jari 135      */
2 26 Feb 07 jari 136     
2 26 Feb 07 jari 137
2 26 Feb 07 jari 138     
2 26 Feb 07 jari 139     /**
2 26 Feb 07 jari 140      * Constructs a <code>CentroidViewer</code> for specified
2 26 Feb 07 jari 141      * experiment and clusters.
2 26 Feb 07 jari 142      *
2 26 Feb 07 jari 143      * @param experiment the data of an experiment.
2 26 Feb 07 jari 144      * @param clusters the array of clusters.
2 26 Feb 07 jari 145      */
2 26 Feb 07 jari 146     public CentroidViewer(Experiment experiment, int[][] clusters) {
2 26 Feb 07 jari 147         if (experiment == null) {
2 26 Feb 07 jari 148             throw new IllegalArgumentException("experiment == null");
2 26 Feb 07 jari 149         }
2 26 Feb 07 jari 150         this.experiment = experiment;
2 26 Feb 07 jari 151         this.exptID = experiment.getId();
2 26 Feb 07 jari 152         this.clusters = clusters;
2 26 Feb 07 jari 153         setBackground(Color.white);
2 26 Feb 07 jari 154         setFont(new Font("monospaced", Font.BOLD, 10));
2 26 Feb 07 jari 155         this.maxExperimentValue = experiment.getMaxAbsValue();
2 26 Feb 07 jari 156         this.yRangeOption = CentroidViewer.USE_EXPERIMENT_MAX;
2 26 Feb 07 jari 157         this.addMouseMotionListener(new GraphListener());        
2 26 Feb 07 jari 158     }
2 26 Feb 07 jari 159     
2 26 Feb 07 jari 160     //EH begin state-saving additions
2 26 Feb 07 jari 161     public void setExperiment(Experiment e){
2 26 Feb 07 jari 162       this.experiment = e;
2 26 Feb 07 jari 163       this.exptID = e.getId();
2 26 Feb 07 jari 164         this.maxExperimentValue = experiment.getMaxAbsValue();
2 26 Feb 07 jari 165         }
2 26 Feb 07 jari 166     
2 26 Feb 07 jari 167   /* (non-Javadoc)
2 26 Feb 07 jari 168    * @see org.tigr.microarray.mev.cluster.gui.IViewer#getExperimentId()
2 26 Feb 07 jari 169    */
2 26 Feb 07 jari 170   public int getExperimentID() {
2 26 Feb 07 jari 171     return this.exptID;
2 26 Feb 07 jari 172     }
2 26 Feb 07 jari 173   /* (non-Javadoc)
2 26 Feb 07 jari 174    * @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperimentId(int)
2 26 Feb 07 jari 175    */
2 26 Feb 07 jari 176   public void setExperimentID(int id) {
2 26 Feb 07 jari 177     this.exptID = id;
2 26 Feb 07 jari 178     
2 26 Feb 07 jari 179     }
2 26 Feb 07 jari 180   //EH end state-saving additions
2 26 Feb 07 jari 181     
2 26 Feb 07 jari 182     /**
2 26 Feb 07 jari 183      * Sets means values.
2 26 Feb 07 jari 184      */
2 26 Feb 07 jari 185     public void setMeans(float[][] means) {
2 26 Feb 07 jari 186         this.means = means;
2 26 Feb 07 jari 187     }
2 26 Feb 07 jari 188     
2 26 Feb 07 jari 189     public void toggleGradient() {
2 26 Feb 07 jari 190         this.gradientToggle = !this.gradientToggle;
2 26 Feb 07 jari 191     }
2 26 Feb 07 jari 192     
2 26 Feb 07 jari 193     /**
2 26 Feb 07 jari 194      * Sets variances values.
2 26 Feb 07 jari 195      */
2 26 Feb 07 jari 196     public void setVariances(float[][] variances) {
2 26 Feb 07 jari 197         this.variances = variances;
2 26 Feb 07 jari 198     }
2 26 Feb 07 jari 199     
2 26 Feb 07 jari 200     /**
2 26 Feb 07 jari 201      * Sets codes.
2 26 Feb 07 jari 202      */
2 26 Feb 07 jari 203     public void setCodes(float[][] codes) {
2 26 Feb 07 jari 204         this.codes = codes;
2 26 Feb 07 jari 205     }
2 26 Feb 07 jari 206     
2 26 Feb 07 jari 207     /**
2 26 Feb 07 jari 208      * Sets the draw marks attribute.
2 26 Feb 07 jari 209      */
2 26 Feb 07 jari 210     public void setDrawMarks(boolean draw) {
2 26 Feb 07 jari 211         this.drawMarks = draw;
2 26 Feb 07 jari 212     }
2 26 Feb 07 jari 213     
2 26 Feb 07 jari 214     /**
2 26 Feb 07 jari 215      * Sets the draw variances attribute.
2 26 Feb 07 jari 216      */
2 26 Feb 07 jari 217     public void setDrawVariances(boolean draw) {
2 26 Feb 07 jari 218         this.drawVariances = draw;
2 26 Feb 07 jari 219     }
2 26 Feb 07 jari 220     
2 26 Feb 07 jari 221     /**
2 26 Feb 07 jari 222      * Sets the draw values attribute.
2 26 Feb 07 jari 223      */
2 26 Feb 07 jari 224     public void setDrawValues(boolean draw) {
2 26 Feb 07 jari 225         this.drawValues = draw;
2 26 Feb 07 jari 226     }
2 26 Feb 07 jari 227     
2 26 Feb 07 jari 228     /**
2 26 Feb 07 jari 229      * Sets the draw codes attribute.
2 26 Feb 07 jari 230      */
2 26 Feb 07 jari 231     public void setDrawCodes(boolean draw) {
2 26 Feb 07 jari 232         this.drawCodes = draw;
2 26 Feb 07 jari 233     }
2 26 Feb 07 jari 234     
2 26 Feb 07 jari 235     /**
2 26 Feb 07 jari 236      * Sets the anti-aliasing attribute.
2 26 Feb 07 jari 237      */
2 26 Feb 07 jari 238     public void setAntiAliasing(boolean value) {
2 26 Feb 07 jari 239         this.isAntiAliasing = value;
2 26 Feb 07 jari 240     }
2 26 Feb 07 jari 241     
2 26 Feb 07 jari 242     /**
2 26 Feb 07 jari 243      * Updates data, mode and some the viewer attributes.
2 26 Feb 07 jari 244      */
2 26 Feb 07 jari 245     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 246         this.framework = framework;
2 26 Feb 07 jari 247         setData(framework.getData());
2 26 Feb 07 jari 248         setAntiAliasing(framework.getDisplayMenu().isAntiAliasing());
2 26 Feb 07 jari 249         Object userObject = framework.getUserObject();
2 26 Feb 07 jari 250         if (userObject instanceof CentroidUserObject) {
2 26 Feb 07 jari 251             setClusterIndex(((CentroidUserObject)userObject).getClusterIndex());
2 26 Feb 07 jari 252             setMode(((CentroidUserObject)userObject).getMode());
2 26 Feb 07 jari 253         } else {
2 26 Feb 07 jari 254             //  setClusterIndex(((Integer)userObject).intValue());
2 26 Feb 07 jari 255             setMode(((Integer)userObject).intValue());
2 26 Feb 07 jari 256         }
2 26 Feb 07 jari 257         updateValues(getCluster());
2 26 Feb 07 jari 258         this.maxValue = framework.getDisplayMenu().getMaxRatioScale();
2 26 Feb 07 jari 259         this.minValue = framework.getDisplayMenu().getMinRatioScale();
2 26 Feb 07 jari 260         this.midValue = framework.getDisplayMenu().getMidRatioValue();
2 26 Feb 07 jari 261         CentroidViewer.posColorImage = framework.getDisplayMenu().getPositiveGradientImage();
2 26 Feb 07 jari 262         CentroidViewer.negColorImage = framework.getDisplayMenu().getNegativeGradientImage();
2 26 Feb 07 jari 263         useDoubleGradient = framework.getDisplayMenu().getUseDoubleGradient();
2 26 Feb 07 jari 264         this.setGradient(framework.getDisplayMenu().getColorGradientState());
2 26 Feb 07 jari 265         // repaint put in in case onSelected called by refreshCurrentViewer() method
2 26 Feb 07 jari 266         repaint();
2 26 Feb 07 jari 267     }
2 26 Feb 07 jari 268     
2 26 Feb 07 jari 269     /**
2 26 Feb 07 jari 270      * Determines whether any clusters are set
2 26 Feb 07 jari 271      */
2 26 Feb 07 jari 272     public boolean checkGradient() {
2 26 Feb 07 jari 273         boolean temp = true;
2 26 Feb 07 jari 274         for (int i = 0; i<clusters.length; i++) {
2 26 Feb 07 jari 275             for (int j = 0; j<clusters[i].length; j++) {
2 26 Feb 07 jari 276                 try {
2 26 Feb 07 jari 277                     if (this.data.getProbeColor(this.experiment.getGeneIndexMappedToData(clusters[i][j])) != null) {
2 26 Feb 07 jari 278                         temp = false;
2 26 Feb 07 jari 279                     }
2 26 Feb 07 jari 280                 } catch (Exception e) {
2 26 Feb 07 jari 281                 }
2 26 Feb 07 jari 282             }
2 26 Feb 07 jari 283         }
2 26 Feb 07 jari 284         return temp;
2 26 Feb 07 jari 285     }
2 26 Feb 07 jari 286     
2 26 Feb 07 jari 287     
2 26 Feb 07 jari 288     public void setGradient(boolean g) {
2 26 Feb 07 jari 289         this.gradientColors = g;
2 26 Feb 07 jari 290         this.gradientToggle = g;
2 26 Feb 07 jari 291     }
2 26 Feb 07 jari 292     
2 26 Feb 07 jari 293     /**
2 26 Feb 07 jari 294      * Calculates color for passed value.
2 26 Feb 07 jari 295      */
2 26 Feb 07 jari 296     private Color getColor(float value) {
2 26 Feb 07 jari 297         if (Float.isNaN(value)) {
2 26 Feb 07 jari 298             return missingColor;
2 26 Feb 07 jari 299         }
2 26 Feb 07 jari 300         
2 26 Feb 07 jari 301         float maximum;
2 26 Feb 07 jari 302         int colorIndex, rgb;
2 26 Feb 07 jari 303         
2 26 Feb 07 jari 304         if(useDoubleGradient) {
2 26 Feb 07 jari 305           maximum = value < midValue ? this.minValue : this.maxValue;
2 26 Feb 07 jari 306       colorIndex = (int) (255 * (value-midValue) / (maximum - midValue));
2 26 Feb 07 jari 307       colorIndex = colorIndex > 255 ? 255 : colorIndex;
2 26 Feb 07 jari 308       rgb = value < midValue ? negColorImage.getRGB(255 - colorIndex, 0)
2 26 Feb 07 jari 309           : posColorImage.getRGB(colorIndex, 0);
2 26 Feb 07 jari 310         } else {
2 26 Feb 07 jari 311           float span = this.maxValue - this.minValue;
2 26 Feb 07 jari 312           if(value <= minValue)
2 26 Feb 07 jari 313             colorIndex = 0;
2 26 Feb 07 jari 314           else if(value >= maxValue)
2 26 Feb 07 jari 315             colorIndex = 255;
2 26 Feb 07 jari 316           else
2 26 Feb 07 jari 317             colorIndex = (int)(((value - this.minValue)/span) * 255);
2 26 Feb 07 jari 318            
2 26 Feb 07 jari 319           rgb = posColorImage.getRGB(colorIndex,0);
2 26 Feb 07 jari 320         }
2 26 Feb 07 jari 321         return new Color(rgb);
2 26 Feb 07 jari 322     }
2 26 Feb 07 jari 323     
2 26 Feb 07 jari 324     
2 26 Feb 07 jari 325     /**
2 26 Feb 07 jari 326      * Sets data.
2 26 Feb 07 jari 327      */
2 26 Feb 07 jari 328     public void setData(IData data) {
2 26 Feb 07 jari 329         this.data = data;
2 26 Feb 07 jari 330     }
2 26 Feb 07 jari 331     
2 26 Feb 07 jari 332     /**
2 26 Feb 07 jari 333      * Sets a cluster index.
2 26 Feb 07 jari 334      */
2 26 Feb 07 jari 335     public void setClusterIndex(int clusterIndex) {
2 26 Feb 07 jari 336         this.clusterIndex = clusterIndex;
2 26 Feb 07 jari 337         updateValues(getCluster());
2 26 Feb 07 jari 338     }
2 26 Feb 07 jari 339     
2 26 Feb 07 jari 340     /**
2 26 Feb 07 jari 341      * Returns a current cluster.
2 26 Feb 07 jari 342      */
2 26 Feb 07 jari 343     public int[] getCluster() {
2 26 Feb 07 jari 344         return this.clusters[this.clusterIndex];
2 26 Feb 07 jari 345     }
2 26 Feb 07 jari 346     
2 26 Feb 07 jari 347     /**
2 26 Feb 07 jari 348      * Returns all clusters.
2 26 Feb 07 jari 349      */
2 26 Feb 07 jari 350     public int[][] getClusters() {
2 26 Feb 07 jari 351         return clusters;
2 26 Feb 07 jari 352     }
2 26 Feb 07 jari 353     
2 26 Feb 07 jari 354     /**
2 26 Feb 07 jari 355      * Returns index of a gene in the current cluster.
2 26 Feb 07 jari 356      */
2 26 Feb 07 jari 357     protected int getProbe(int row) {
2 26 Feb 07 jari 358         return this.clusters[this.clusterIndex][row];
2 26 Feb 07 jari 359     }
2 26 Feb 07 jari 360     
2 26 Feb 07 jari 361     /**
2 26 Feb 07 jari 362      * Sets the viewer mode.
2 26 Feb 07 jari 363      */
2 26 Feb 07 jari 364     public void setMode(int mode) {
2 26 Feb 07 jari 365         switch (mode) {
2 26 Feb 07 jari 366             case CentroidUserObject.VARIANCES_MODE:
2 26 Feb 07 jari 367                 setDrawVariances(true);
2 26 Feb 07 jari 368                 setDrawValues(false);
2 26 Feb 07 jari 369                 break;
2 26 Feb 07 jari 370             case CentroidUserObject.VALUES_MODE:
2 26 Feb 07 jari 371                 setDrawVariances(false);
2 26 Feb 07 jari 372                 setDrawValues(true);
2 26 Feb 07 jari 373                 break;
2 26 Feb 07 jari 374         }
2 26 Feb 07 jari 375     }
2 26 Feb 07 jari 376     
2 26 Feb 07 jari 377     /**
2 26 Feb 07 jari 378      * Updates max value.
2 26 Feb 07 jari 379      */
2 26 Feb 07 jari 380     private void updateValues(int[] cluster) {
2 26 Feb 07 jari 381         this.maxClusterValue = calculateMaxValue(cluster);
2 26 Feb 07 jari 382     }
2 26 Feb 07 jari 383     
2 26 Feb 07 jari 384     /**
2 26 Feb 07 jari 385      * Sets public color for the current cluster.
2 26 Feb 07 jari 386      */
2 26 Feb 07 jari 387     public void setClusterColor(Color color) {
2 26 Feb 07 jari 388         if(color ==null){  //indicates removal of cluster
2 26 Feb 07 jari 389             framework.removeCluster(getArrayMappedToData(), experiment, ClusterRepository.GENE_CLUSTER);
2 26 Feb 07 jari 390         }
2 26 Feb 07 jari 391     }
2 26 Feb 07 jari 392     
2 26 Feb 07 jari 393     /**
2 26 Feb 07 jari 394      *  Sets cluster color
2 26 Feb 07 jari 395      */
2 26 Feb 07 jari 396     public void storeCluster(){
2 26 Feb 07 jari 397         framework.storeCluster(getArrayMappedToData(), experiment, ClusterRepository.GENE_CLUSTER);       
2 26 Feb 07 jari 398         onDataChanged(this.data);
2 26 Feb 07 jari 399     }
2 26 Feb 07 jari 400     
2 26 Feb 07 jari 401     /**
2 26 Feb 07 jari 402      * Launches a new <code>MultipleExperimentViewer</code> containing the current cluster
2 26 Feb 07 jari 403      */
2 26 Feb 07 jari 404     public void launchNewSession(){
2 26 Feb 07 jari 405         framework.launchNewMAV(getArrayMappedToData(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.GENE_CLUSTER);
2 26 Feb 07 jari 406     }
2 26 Feb 07 jari 407     
2 26 Feb 07 jari 408     
2 26 Feb 07 jari 409     private int [] getArrayMappedToData(){
2 26 Feb 07 jari 410         int [] clusterIndices = getCluster();
2 26 Feb 07 jari 411         if(clusterIndices == null || clusterIndices.length < 1)
2 26 Feb 07 jari 412             return clusterIndices;
2 26 Feb 07 jari 413         
2 26 Feb 07 jari 414         int [] dataIndices = new int [clusterIndices.length];
2 26 Feb 07 jari 415         for(int i = 0; i < clusterIndices.length; i++){
2 26 Feb 07 jari 416             dataIndices[i] = this.experiment.getGeneIndexMappedToData(clusterIndices[i]);
2 26 Feb 07 jari 417         }
2 26 Feb 07 jari 418         return dataIndices;
2 26 Feb 07 jari 419     }
2 26 Feb 07 jari 420     
2 26 Feb 07 jari 421     
2 26 Feb 07 jari 422     /**
2 26 Feb 07 jari 423      * Sets Y range scaling option
2 26 Feb 07 jari 424      */
2 26 Feb 07 jari 425     public void setYRangeOption(int option){
2 26 Feb 07 jari 426         if(option != CentroidViewer.USE_EXPERIMENT_MAX && option != CentroidViewer.USE_CLUSTER_MAX)
2 26 Feb 07 jari 427             this.yRangeOption = USE_EXPERIMENT_MAX;
2 26 Feb 07 jari 428         else
2 26 Feb 07 jari 429             yRangeOption = option;
2 26 Feb 07 jari 430     }
2 26 Feb 07 jari 431     
2 26 Feb 07 jari 432     
2 26 Feb 07 jari 433     /**
2 26 Feb 07 jari 434      * Returns the experiment data (ratio values).
2 26 Feb 07 jari 435      */
2 26 Feb 07 jari 436     public Experiment getExperiment() {
2 26 Feb 07 jari 437         return experiment;
2 26 Feb 07 jari 438     }
2 26 Feb 07 jari 439     
2 26 Feb 07 jari 440     /**
2 26 Feb 07 jari 441      * Returns data values.
2 26 Feb 07 jari 442      */
2 26 Feb 07 jari 443     public IData getData() {
2 26 Feb 07 jari 444         return data;
2 26 Feb 07 jari 445     }
2 26 Feb 07 jari 446     
2 26 Feb 07 jari 447     /**
2 26 Feb 07 jari 448      * Returns component to be displayed in the framework scroll pane.
2 26 Feb 07 jari 449      */
2 26 Feb 07 jari 450     public JComponent getContentComponent() {
2 26 Feb 07 jari 451         return this;
2 26 Feb 07 jari 452     }
2 26 Feb 07 jari 453     
2 26 Feb 07 jari 454     /**
2 26 Feb 07 jari 455      * Paints chart into specified graphics.
2 26 Feb 07 jari 456      */
2 26 Feb 07 jari 457     public void paint(Graphics g) {
2 26 Feb 07 jari 458         FontMetrics metrics = g.getFontMetrics();
2 26 Feb 07 jari 459         Rectangle rect = new Rectangle(40, 20, getWidth()-80, getHeight() - 40 - getNamesWidth(metrics));
2 26 Feb 07 jari 460         paint((Graphics2D)g, rect, true);
2 26 Feb 07 jari 461     }
2 26 Feb 07 jari 462     
2 26 Feb 07 jari 463     public void subPaint(Graphics2D g, Rectangle rect, boolean drawMarks) {
2 26 Feb 07 jari 464         super.paint(g);
2 26 Feb 07 jari 465     }
2 26 Feb 07 jari 466     
2 26 Feb 07 jari 467     /**
2 26 Feb 07 jari 468      * Paints chart into specified graphics and with specified bounds.
2 26 Feb 07 jari 469      */
2 26 Feb 07 jari 470     public void paint(Graphics2D g, Rectangle rect, boolean drawMarks) {
2 26 Feb 07 jari 471         super.paint(g);
2 26 Feb 07 jari 472         if (isAntiAliasing) {
2 26 Feb 07 jari 473             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
2 26 Feb 07 jari 474             g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
2 26 Feb 07 jari 475         }
2 26 Feb 07 jari 476         
2 26 Feb 07 jari 477         final int left = rect.x;
2 26 Feb 07 jari 478         final int top = rect.y;
2 26 Feb 07 jari 479         final int width  = rect.width;
2 26 Feb 07 jari 480         final int height = rect.height;
2 26 Feb 07 jari 481         
2 26 Feb 07 jari 482         if (width < 5 || height < 5) {
2 26 Feb 07 jari 483             return;
2 26 Feb 07 jari 484         }
2 26 Feb 07 jari 485   //      if (gradientToggle) {
2 26 Feb 07 jari 486   //          setGradient(checkGradient());
2 26 Feb 07 jari 487   //      } else {
2 26 Feb 07 jari 488   //          setGradient(false);
2 26 Feb 07 jari 489    //     }
2 26 Feb 07 jari 490         final int zeroValue = top + (int)Math.round(height/2f);
2 26 Feb 07 jari 491         final int numberOfSamples  = experiment.getNumberOfSamples();
2 26 Feb 07 jari 492         
2 26 Feb 07 jari 493         //do this outside paint once menu is set up
2 26 Feb 07 jari 494         if(this.yRangeOption == CentroidViewer.USE_EXPERIMENT_MAX)
2 26 Feb 07 jari 495             maxYValue = this.maxExperimentValue;
2 26 Feb 07 jari 496         else if(this.yRangeOption == CentroidViewer.USE_CLUSTER_MAX)
2 26 Feb 07 jari 497             maxYValue = this.maxClusterValue;
2 26 Feb 07 jari 498         
2 26 Feb 07 jari 499         if (maxYValue == 0.0f) {
2 26 Feb 07 jari 500             maxYValue = 1.0f;
2 26 Feb 07 jari 501         }
2 26 Feb 07 jari 502         
2 26 Feb 07 jari 503         final float factor = height/(2f*maxYValue);
2 26 Feb 07 jari 504         final float stepX  = width/(float)(numberOfSamples-1);
2 26 Feb 07 jari 505         final int   stepsY = (int)maxYValue+1;
2 26 Feb 07 jari 506         if (this.drawVariances) {
2 26 Feb 07 jari 507             // draw variances
2 26 Feb 07 jari 508             g.setColor(bColor);
2 26 Feb 07 jari 509             for (int i=0; i<numberOfSamples; i++) {
2 26 Feb 07 jari 510                 if(Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.variances[this.clusterIndex][i]) || (this.variances[this.clusterIndex][i] < 0.0f)) {
2 26 Feb 07 jari 511                     continue;
2 26 Feb 07 jari 512                 }
2 26 Feb 07 jari 513                 g.drawLine(left+(int)Math.round(i*stepX)  , zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor),
2 26 Feb 07 jari 514                 left+(int)Math.round(i*stepX)  , zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor));
2 26 Feb 07 jari 515                 g.drawLine(left+(int)Math.round(i*stepX)-3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor),
2 26 Feb 07 jari 516                 left+(int)Math.round(i*stepX)+3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]-this.variances[this.clusterIndex][i])*factor));
2 26 Feb 07 jari 517                 g.drawLine(left+(int)Math.round(i*stepX)-3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor),
2 26 Feb 07 jari 518                 left+(int)Math.round(i*stepX)+3, zeroValue - (int)Math.round((this.means[this.clusterIndex][i]+this.variances[this.clusterIndex][i])*factor));
2 26 Feb 07 jari 519             }
2 26 Feb 07 jari 520         }
2 26 Feb 07 jari 521         if (this.drawValues) {
2 26 Feb 07 jari 522             // draw values
2 26 Feb 07 jari 523             boolean coloredClusters = false;
2 26 Feb 07 jari 524             float fValue, sValue, yInterval, lineHeight;
2 26 Feb 07 jari 525             Color color = null;
2 26 Feb 07 jari 526             float maxLineHeight = (maxExperimentValue*factor) / 20;  //maxExperimentValue is an expression value - not a coordinate length
2 26 Feb 07 jari 527             int R=0, G=0, B = 0, intervalNumber;
2 26 Feb 07 jari 528             
2 26 Feb 07 jari 529             for (int sample=0; sample<numberOfSamples-1; sample++) {
2 26 Feb 07 jari 530                 for (int probe=0; probe<getCluster().length; probe++) {
2 26 Feb 07 jari 531                     fValue = this.experiment.get(getProbe(probe), sample);
2 26 Feb 07 jari 532                     sValue = this.experiment.get(getProbe(probe), sample+1);
2 26 Feb 07 jari 533                     if (Float.isNaN(fValue) || Float.isNaN(sValue)) {
2 26 Feb 07 jari 534                         continue;
2 26 Feb 07 jari 535                     }
2 26 Feb 07 jari 536                     if(!gradientColors) {
2 26 Feb 07 jari 537                         color = this.data.getProbeColor(this.experiment.getGeneIndexMappedToData(getProbe(probe)));
2 26 Feb 07 jari 538                         color = color == null ? DEF_CLUSTER_COLOR : color;
2 26 Feb 07 jari 539                         g.setColor(color);
2 26 Feb 07 jari 540                         g.drawLine(left+(int)Math.round(sample*stepX), zeroValue - (int)Math.round(fValue*factor),
2 26 Feb 07 jari 541                         left+(int)Math.round((sample+1)*stepX), zeroValue - (int)Math.round(sValue*factor));
2 26 Feb 07 jari 542                     } else {
2 26 Feb 07 jari 543                         lineHeight = (sValue - fValue)*factor;
2 26 Feb 07 jari 544                         if (Math.abs(lineHeight) > maxLineHeight) {
2 26 Feb 07 jari 545                             intervalNumber = Math.abs((int)(lineHeight / maxLineHeight));
2 26 Feb 07 jari 546                         } else {
2 26 Feb 07 jari 547                             intervalNumber = 1;
2 26 Feb 07 jari 548                         }
2 26 Feb 07 jari 549                         yInterval = lineHeight/intervalNumber;
2 26 Feb 07 jari 550                         for(int i=0; i<intervalNumber; i++) {
2 26 Feb 07 jari 551                             g.setColor(getColor(fValue + (float)(i)*yInterval/factor));
2 26 Feb 07 jari 552                             g.drawLine(left+(int)Math.round(sample*stepX + ((float)i/intervalNumber)*stepX), zeroValue - (int)Math.round(fValue*factor + (float)i*yInterval),
2 26 Feb 07 jari 553                             left+(int)Math.round((sample)*stepX + (((float)i+1)/intervalNumber)*stepX), zeroValue - (int)Math.round(fValue*factor + ((float)i+1)*yInterval));
2 26 Feb 07 jari 554                         }
2 26 Feb 07 jari 555                     }
2 26 Feb 07 jari 556                 }
2 26 Feb 07 jari 557             }
2 26 Feb 07 jari 558         }
2 26 Feb 07 jari 559         if (this.drawCodes && this.codes != null && clusters[clusterIndex].length > 0) {
2 26 Feb 07 jari 560             g.setColor(Color.blue);
2 26 Feb 07 jari 561             for (int i=0; i<numberOfSamples-1; i++) {
2 26 Feb 07 jari 562                 g.drawLine(left+(int)Math.round(i*stepX), zeroValue-(int)Math.round(this.codes[this.clusterIndex][i]*factor), left+(int)Math.round((i+1)*stepX), zeroValue-(int)Math.round(this.codes[this.clusterIndex][i+1]*factor));
2 26 Feb 07 jari 563             }
2 26 Feb 07 jari 564         }
2 26 Feb 07 jari 565         
2 26 Feb 07 jari 566         // draw zero line
2 26 Feb 07 jari 567         g.setColor(Color.black);
2 26 Feb 07 jari 568         g.drawLine(left, zeroValue, left+width, zeroValue);
2 26 Feb 07 jari 569         // draw magenta line
2 26 Feb 07 jari 570         if (getCluster() != null && getCluster().length > 0) {
2 26 Feb 07 jari 571             g.setColor(centroidColor);
2 26 Feb 07 jari 572             for (int i=0; i<numberOfSamples-1; i++) {
2 26 Feb 07 jari 573                 if (Float.isNaN(this.means[this.clusterIndex][i]) || Float.isNaN(this.means[this.clusterIndex][i+1])) {
2 26 Feb 07 jari 574                     continue;
2 26 Feb 07 jari 575                 }
2 26 Feb 07 jari 576                 g.drawLine(left+(int)Math.round(i*stepX), zeroValue-(int)Math.round(this.means[this.clusterIndex][i]*factor), left+(int)Math.round((i+1)*stepX), zeroValue-(int)Math.round(this.means[this.clusterIndex][i+1]*factor));
2 26 Feb 07 jari 577             }
2 26 Feb 07 jari 578         }
2 26 Feb 07 jari 579         // draw rectangle
2 26 Feb 07 jari 580         g.setColor(Color.black);
2 26 Feb 07 jari 581         g.drawRect(left, top, width, height);
2 26 Feb 07 jari 582         // draw X items
2 26 Feb 07 jari 583         for (int i=1; i<numberOfSamples-1; i++) {
2 26 Feb 07 jari 584             g.drawLine(left+(int)Math.round(i*stepX), top+height-5, left+(int)Math.round(i*stepX), top+height);
2 26 Feb 07 jari 585             g.drawLine(left+(int)Math.round(i*stepX), top, left+(int)Math.round(i*stepX), top+5);
2 26 Feb 07 jari 586         }
2 26 Feb 07 jari 587         //draw Y items
2 26 Feb 07 jari 588         for (int i=1; i<stepsY; i++) {
2 26 Feb 07 jari 589             g.drawLine(left, zeroValue-(int)Math.round(i*factor), left+5, zeroValue-(int)Math.round(i*factor));
2 26 Feb 07 jari 590             g.drawLine(left, zeroValue+(int)Math.round(i*factor), left+5, zeroValue+(int)Math.round(i*factor));
2 26 Feb 07 jari 591         }
2 26 Feb 07 jari 592         // draw genes info
2 26 Feb 07 jari 593         g.setColor(bColor);
2 26 Feb 07 jari 594         if (drawMarks) {
2 26 Feb 07 jari 595             FontMetrics metrics = g.getFontMetrics();
2 26 Feb 07 jari 596             String str;
2 26 Feb 07 jari 597             int strWidth;
2 26 Feb 07 jari 598             //draw Y digits
2 26 Feb 07 jari 599             for (int i=1; i<stepsY; i++) {
2 26 Feb 07 jari 600                 str = String.valueOf(i);
2 26 Feb 07 jari 601                 strWidth = metrics.stringWidth(str);
2 26 Feb 07 jari 602                 g.drawString(str, left-10-strWidth, zeroValue+5-(int)Math.round(i*factor));
2 26 Feb 07 jari 603                 str = String.valueOf(-i);
2 26 Feb 07 jari 604                 strWidth = metrics.stringWidth(str);
2 26 Feb 07 jari 605                 g.drawString(str, left-10-strWidth, zeroValue+5+(int)Math.round(i*factor));
2 26 Feb 07 jari 606             }
2 26 Feb 07 jari 607             // draw X samples names
2 26 Feb 07 jari 608             g.rotate(-Math.PI/2.0);
2 26 Feb 07 jari 609             final int max_name_width = getNamesWidth(metrics);
2 26 Feb 07 jari 610             for (int i=0; i<numberOfSamples; i++) {
2 26 Feb 07 jari 611                 g.drawString(data.getSampleName(experiment.getSampleIndex(i)), -height-top-10-max_name_width, left+(int)Math.round(i*stepX)+3);
2 26 Feb 07 jari 612             }
2 26 Feb 07 jari 613             g.rotate(Math.PI/2.0);
2 26 Feb 07 jari 614         }
2 26 Feb 07 jari 615         if (getCluster() != null && getCluster().length > 0 && this.drawVariances) {
2 26 Feb 07 jari 616             // draw points
2 26 Feb 07 jari 617             g.setColor(bColor);
2 26 Feb 07 jari 618             for (int i=0; i<numberOfSamples; i++) {
2 26 Feb 07 jari 619                 if (Float.isNaN(this.means[this.clusterIndex][i])) {
2 26 Feb 07 jari 620                     continue;
2 26 Feb 07 jari 621                 }
2 26 Feb 07 jari 622                 g.fillOval(left+(int)Math.round(i*stepX)-3, zeroValue-(int)Math.round(this.means[this.clusterIndex][i]*factor)-3, 6, 6);
2 26 Feb 07 jari 623             }
2 26 Feb 07 jari 624         }
2 26 Feb 07 jari 625         if(this.showRefLine && this.drawReferenceBlock){          
2 26 Feb 07 jari 626            java.awt.Composite initComposite = g.getComposite();
2 26 Feb 07 jari 627            g.setComposite(java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.3f));
2 26 Feb 07 jari 628            g.setColor(Color.yellow);
2 26 Feb 07 jari 629            g.fillRect(xref-3, 20, 7, height); 
2 26 Feb 07 jari 630            g.setComposite(initComposite);
2 26 Feb 07 jari 631            g.setColor(Color.blue);
2 26 Feb 07 jari 632            g.drawLine(xref, 20, xref, height+20);
2 26 Feb 07 jari 633            framework.setStatusText("Sample= "+data.getSampleName(experiment.getSampleIndex(currExpRefLine))+",   mean = "+ this.means[this.clusterIndex][currExpRefLine]+",   sd = "+ this.variances[this.clusterIndex][currExpRefLine]);
2 26 Feb 07 jari 634         }
2 26 Feb 07 jari 635         g.setColor(bColor);
2 26 Feb 07 jari 636         if (getCluster() == null || getCluster().length == 0) {
2 26 Feb 07 jari 637             g.drawString("No Genes", left+10, top+20);
2 26 Feb 07 jari 638         } else {
2 26 Feb 07 jari 639             g.drawString(getCluster().length+" Genes", left+10, top+20);
2 26 Feb 07 jari 640         }
2 26 Feb 07 jari 641     }
2 26 Feb 07 jari 642     
2 26 Feb 07 jari 643     /**
2 26 Feb 07 jari 644      * @return null
2 26 Feb 07 jari 645      */
2 26 Feb 07 jari 646     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 647         return null;
2 26 Feb 07 jari 648     }
2 26 Feb 07 jari 649     
2 26 Feb 07 jari 650     /**
2 26 Feb 07 jari 651      * Updates the viewer data.
2 26 Feb 07 jari 652      */
2 26 Feb 07 jari 653     public void onDataChanged(IData data) {
2 26 Feb 07 jari 654         setData(data);
2 26 Feb 07 jari 655     }
2 26 Feb 07 jari 656     
2 26 Feb 07 jari 657     /**
2 26 Feb 07 jari 658      * Updates some viewer attributes.
2 26 Feb 07 jari 659      */
2 26 Feb 07 jari 660     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 661         setAntiAliasing(menu.isAntiAliasing());
2 26 Feb 07 jari 662         this.maxValue = menu.getMaxRatioScale();
2 26 Feb 07 jari 663         this.minValue = menu.getMinRatioScale();
2 26 Feb 07 jari 664         this.midValue = menu.getMidRatioValue();
2 26 Feb 07 jari 665         CentroidViewer.posColorImage = menu.getPositiveGradientImage();
2 26 Feb 07 jari 666         CentroidViewer.negColorImage = menu.getNegativeGradientImage();
2 26 Feb 07 jari 667         this.setGradient(menu.getColorGradientState());
2 26 Feb 07 jari 668         useDoubleGradient = menu.getUseDoubleGradient();
2 26 Feb 07 jari 669         repaint();
2 26 Feb 07 jari 670     }
2 26 Feb 07 jari 671     
2 26 Feb 07 jari 672     public void onDeselected() {}
2 26 Feb 07 jari 673     public void onClosed() {}
2 26 Feb 07 jari 674     
2 26 Feb 07 jari 675     /**
2 26 Feb 07 jari 676      * @return null
2 26 Feb 07 jari 677      */
2 26 Feb 07 jari 678     public BufferedImage getImage() {
2 26 Feb 07 jari 679         return null;
2 26 Feb 07 jari 680     }
2 26 Feb 07 jari 681     
2 26 Feb 07 jari 682     /**
2 26 Feb 07 jari 683      * Calculate experiment max value for scale purpose.
2 26 Feb 07 jari 684      */
2 26 Feb 07 jari 685     private float calculateMaxValue(int[] probes) {
2 26 Feb 07 jari 686         float max = 0f;
2 26 Feb 07 jari 687         float value;
2 26 Feb 07 jari 688         final int samples = experiment.getNumberOfSamples();
2 26 Feb 07 jari 689         for (int sample=0; sample<samples; sample++) {
2 26 Feb 07 jari 690             for (int probe=0; probe<probes.length; probe++) {
2 26 Feb 07 jari 691                 value = experiment.get(probes[probe], sample);
2 26 Feb 07 jari 692                 if (!Float.isNaN(value)) {
2 26 Feb 07 jari 693                     max = Math.max(max, Math.abs(value));
2 26 Feb 07 jari 694                 }
2 26 Feb 07 jari 695             }
2 26 Feb 07 jari 696         }
2 26 Feb 07 jari 697         return max;
2 26 Feb 07 jari 698     }
2 26 Feb 07 jari 699     
2 26 Feb 07 jari 700     /**
2 26 Feb 07 jari 701      * Returns max width of experiment names.
2 26 Feb 07 jari 702      */
2 26 Feb 07 jari 703     protected int getNamesWidth(FontMetrics metrics) {
2 26 Feb 07 jari 704         int maxWidth = 0;
2 26 Feb 07 jari 705         for (int i=0; i<experiment.getNumberOfSamples(); i++) {
2 26 Feb 07 jari 706             maxWidth = Math.max(maxWidth, metrics.stringWidth(data.getSampleName(experiment.getSampleIndex(i))));
2 26 Feb 07 jari 707         }
2 26 Feb 07 jari 708         return maxWidth;
2 26 Feb 07 jari 709     }
2 26 Feb 07 jari 710     
2 26 Feb 07 jari 711         /**
2 26 Feb 07 jari 712      * Adds viewer specific menu items.
2 26 Feb 07 jari 713      */
2 26 Feb 07 jari 714     protected void addMenuItems(JPopupMenu menu, ActionListener listener) {
2 26 Feb 07 jari 715         JMenuItem menuItem;
2 26 Feb 07 jari 716         menuItem = new JMenuItem("Store cluster", GUIFactory.getIcon("new16.gif"));
2 26 Feb 07 jari 717         menuItem.setActionCommand(STORE_CLUSTER_CMD);
2 26 Feb 07 jari 718         menuItem.addActionListener(listener);
2 26 Feb 07 jari 719         menu.add(menuItem);
2 26 Feb 07 jari 720         
2 26 Feb 07 jari 721         menu.addSeparator();
2 26 Feb 07 jari 722         
2 26 Feb 07 jari 723         menuItem = new JMenuItem("Launch new session", GUIFactory.getIcon("launch_new_mav.gif"));
2 26 Feb 07 jari 724         menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD);
2 26 Feb 07 jari 725         menuItem.addActionListener(listener);
2 26 Feb 07 jari 726         menu.add(menuItem);       
2 26 Feb 07 jari 727         
2 26 Feb 07 jari 728         menu.addSeparator();
2 26 Feb 07 jari 729         
2 26 Feb 07 jari 730         menuItem = new JMenuItem("Delete public cluster", GUIFactory.getIcon("delete16.gif"));
2 26 Feb 07 jari 731         menuItem.setActionCommand(SET_DEF_COLOR_CMD);
2 26 Feb 07 jari 732         menuItem.addActionListener(listener);
2 26 Feb 07 jari 733         menu.add(menuItem);
2 26 Feb 07 jari 734         
2 26 Feb 07 jari 735         menu.addSeparator();
2 26 Feb 07 jari 736         
2 26 Feb 07 jari 737         menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif"));
2 26 Feb 07 jari 738         menuItem.setActionCommand(SAVE_CLUSTER_CMD);
2 26 Feb 07 jari 739         menuItem.addActionListener(listener);
2 26 Feb 07 jari 740         menu.add(menuItem);
2 26 Feb 07 jari 741         
2 26 Feb 07 jari 742         menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif"));
2 26 Feb 07 jari 743         menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD);
2 26 Feb 07 jari 744         menuItem.addActionListener(listener);
2 26 Feb 07 jari 745         menu.add(menuItem);
2 26 Feb 07 jari 746         
2 26 Feb 07 jari 747         menu.addSeparator();
2 26 Feb 07 jari 748         
2 26 Feb 07 jari 749         setOverallMaxMenuItem = new JMenuItem("Set Y to overall max...", GUIFactory.getIcon("Y_range_expand.gif"));
2 26 Feb 07 jari 750         setOverallMaxMenuItem.setActionCommand(SET_Y_TO_EXPERIMENT_MAX_CMD);
2 26 Feb 07 jari 751         setOverallMaxMenuItem.addActionListener(listener);
2 26 Feb 07 jari 752         setOverallMaxMenuItem.setEnabled(false);
2 26 Feb 07 jari 753         menu.add(setOverallMaxMenuItem);
2 26 Feb 07 jari 754         
2 26 Feb 07 jari 755         setClusterMaxMenuItem = new JMenuItem("Set Y to cluster max...", GUIFactory.getIcon("Y_range_expand.gif"));
2 26 Feb 07 jari 756         setClusterMaxMenuItem.setActionCommand(SET_Y_TO_CLUSTER_MAX_CMD);
2 26 Feb 07 jari 757         setClusterMaxMenuItem.addActionListener(listener);
2 26 Feb 07 jari 758         menu.add(setClusterMaxMenuItem);
2 26 Feb 07 jari 759         
2 26 Feb 07 jari 760         menu.addSeparator();
2 26 Feb 07 jari 761
2 26 Feb 07 jari 762         menuItem = new JMenuItem("Toggle reference line...");
2 26 Feb 07 jari 763         menuItem.setActionCommand(TOGGLE_REF_LINE_CMD);
2 26 Feb 07 jari 764         menuItem.addActionListener(listener);
2 26 Feb 07 jari 765         menu.add(menuItem);
2 26 Feb 07 jari 766         
2 26 Feb 07 jari 767     }
2 26 Feb 07 jari 768     
2 26 Feb 07 jari 769     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 770      */
2 26 Feb 07 jari 771     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 772         return null;
2 26 Feb 07 jari 773     }    
2 26 Feb 07 jari 774     
2 26 Feb 07 jari 775     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 776      * posibly null
2 26 Feb 07 jari 777      */
2 26 Feb 07 jari 778     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 779         return null;
2 26 Feb 07 jari 780     }
2 26 Feb 07 jari 781     
2 26 Feb 07 jari 782     /** Returns int value indicating viewer type
2 26 Feb 07 jari 783      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 784      */
2 26 Feb 07 jari 785     public int getViewerType() {
2 26 Feb 07 jari 786         return Cluster.GENE_CLUSTER;
2 26 Feb 07 jari 787     }
2 26 Feb 07 jari 788     
2 26 Feb 07 jari 789     /**
2 26 Feb 07 jari 790      * Handles mouse event in viewer
2 26 Feb 07 jari 791      */
2 26 Feb 07 jari 792     public class GraphListener extends java.awt.event.MouseAdapter implements java.awt.event.MouseMotionListener{
2 26 Feb 07 jari 793         int x = 0, y = 0;
2 26 Feb 07 jari 794         
2 26 Feb 07 jari 795         public void mouseDragged(java.awt.event.MouseEvent mouseEvent) {
2 26 Feb 07 jari 796             
2 26 Feb 07 jari 797         }
2 26 Feb 07 jari 798         
2 26 Feb 07 jari 799         public void mouseMoved(java.awt.event.MouseEvent me) {
2 26 Feb 07 jari 800             if(!showRefLine){
2 26 Feb 07 jari 801                 framework.setStatusText("TIGR MultiExperiment Viewer");
2 26 Feb 07 jari 802                 return;
2 26 Feb 07 jari 803             }
2 26 Feb 07 jari 804             int newX = me.getX();            
2 26 Feb 07 jari 805             int newY = me.getY();
2 26 Feb 07 jari 806             
2 26 Feb 07 jari 807             int numberOfSamples  = experiment.getNumberOfSamples();
2 26 Feb 07 jari 808             if(newX < 40 || newX > getWidth()- 40 || numberOfSamples <= 1){
2 26 Feb 07 jari 809                 drawReferenceBlock = false;
2 26 Feb 07 jari 810                 framework.setStatusText("TIGR MultiExperiment Viewer");
2 26 Feb 07 jari 811                 repaint();
2 26 Feb 07 jari 812                 return;
2 26 Feb 07 jari 813             }
2 26 Feb 07 jari 814             drawReferenceBlock = true;           
2 26 Feb 07 jari 815             currExpRefLine = Math.round((numberOfSamples - 1) * ((newX-40f)/(getWidth()-80f)));
2 26 Feb 07 jari 816             xref = newX;
2 26 Feb 07 jari 817             yref = newY;
2 26 Feb 07 jari 818             repaint();        
2 26 Feb 07 jari 819         }
2 26 Feb 07 jari 820     } 
2 26 Feb 07 jari 821 }