mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/sota/SOTAExperimentViewer.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: SOTAExperimentViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.9 $
2 26 Feb 07 jari 8  * $Date: 2006/05/02 16:57:35 $
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.sota;
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.Dimension;
2 26 Feb 07 jari 17 import java.awt.Frame;
2 26 Feb 07 jari 18 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 19 import java.awt.GridBagLayout;
2 26 Feb 07 jari 20 import java.awt.Insets;
2 26 Feb 07 jari 21 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 22 import java.awt.event.ActionListener;
2 26 Feb 07 jari 23 import java.awt.event.MouseAdapter;
2 26 Feb 07 jari 24 import java.awt.event.MouseEvent;
2 26 Feb 07 jari 25 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 26 import java.beans.Expression;
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28 import javax.swing.JColorChooser;
2 26 Feb 07 jari 29 import javax.swing.JComponent;
2 26 Feb 07 jari 30 import javax.swing.JMenuItem;
2 26 Feb 07 jari 31 import javax.swing.JOptionPane;
2 26 Feb 07 jari 32 import javax.swing.JPanel;
2 26 Feb 07 jari 33 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 34 import javax.swing.border.LineBorder;
2 26 Feb 07 jari 35
2 26 Feb 07 jari 36 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 37 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 38 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 39 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 40 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 41 import org.tigr.microarray.mev.cluster.gui.helpers.CentroidExperimentHeader;
2 26 Feb 07 jari 42 import org.tigr.microarray.mev.cluster.gui.helpers.CentroidViewer;
2 26 Feb 07 jari 43 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterHeader;
2 26 Feb 07 jari 44 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterViewer;
2 26 Feb 07 jari 45 import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentViewer;
2 26 Feb 07 jari 46 import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory;
2 26 Feb 07 jari 47 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 48
2 26 Feb 07 jari 49 /**
2 26 Feb 07 jari 50  * Class to display expression images with a <code>CentroidExperimentHeader</code>
2 26 Feb 07 jari 51  * and cluster information.
2 26 Feb 07 jari 52  */
2 26 Feb 07 jari 53 public class SOTAExperimentViewer extends ExperimentViewer implements IViewer {
2 26 Feb 07 jari 54     
2 26 Feb 07 jari 55     protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd";
2 26 Feb 07 jari 56     private static final String SET_DEF_COLOR_CMD = "set-def-color-cmd";
2 26 Feb 07 jari 57     private static final String SAVE_CLUSTER_CMD = "save-cluster-cmd";
2 26 Feb 07 jari 58     private static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd";
2 26 Feb 07 jari 59     protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd";
2 26 Feb 07 jari 60     
2 26 Feb 07 jari 61     private JPopupMenu popup;
2 26 Feb 07 jari 62     
2 26 Feb 07 jari 63     //panel components
2 26 Feb 07 jari 64     private IViewer expViewer;
2 26 Feb 07 jari 65     private JComponent header;
2 26 Feb 07 jari 66     private InfoPanel infoPanel;
2 26 Feb 07 jari 67     private JPanel viewPanel;
2 26 Feb 07 jari 68     
2 26 Feb 07 jari 69     //data matricies and parameters
2 26 Feb 07 jari 70     private int [][] clusters;
2 26 Feb 07 jari 71     private FloatMatrix clusterDivFM;
2 26 Feb 07 jari 72     private FloatMatrix centroidDataFM;
2 26 Feb 07 jari 73     private int numberOfCells;
2 26 Feb 07 jari 74     private float factor;
2 26 Feb 07 jari 75     private int function;
2 26 Feb 07 jari 76     private boolean geneClusterViewer = true;
2 26 Feb 07 jari 77     private boolean useDoubleGradient = true;
2 26 Feb 07 jari 78     private FloatMatrix codes;
2 26 Feb 07 jari 79     private SOTATreeData sotaTreeData;
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81     /**
2 26 Feb 07 jari 82      * Constructs a <code>SOTAExperimentViewer</code> with specified
2 26 Feb 07 jari 83      * experiment, clusters (gene indices) and codes (centroid data)
2 26 Feb 07 jari 84      * SOTAExperimentViewers created with this constructor always display gene clusters
2 26 Feb 07 jari 85      */
2 26 Feb 07 jari 86     public SOTAExperimentViewer(Experiment experiment, int[][] clusters, FloatMatrix codes, FloatMatrix clusterDiv, SOTATreeData sotaTreeData) {
2 26 Feb 07 jari 87         setLayout(new GridBagLayout());
2 26 Feb 07 jari 88         Listener listener = new Listener();
2 26 Feb 07 jari 89         this.codes = codes;
2 26 Feb 07 jari 90         this.popup = createJPopupMenu(listener);
2 26 Feb 07 jari 91         this.clusters = clusters;
2 26 Feb 07 jari 92         this.clusterDivFM = clusterDiv;
2 26 Feb 07 jari 93         this.numberOfCells = 0;
2 26 Feb 07 jari 94         this.exptID = experiment.getId();
2 26 Feb 07 jari 95         if(this.clusterDivFM != null)
2 26 Feb 07 jari 96             this.numberOfCells = clusterDivFM.getRowDimension();
2 26 Feb 07 jari 97         this.centroidDataFM = codes;
2 26 Feb 07 jari 98         this.sotaTreeData = sotaTreeData;
2 26 Feb 07 jari 99         this.factor = sotaTreeData.factor;  //from SOTA, factor sets polarity of 'displayed' distances in viewer based on metric
2 26 Feb 07 jari 100         this.function = sotaTreeData.function; //distance metric
2 26 Feb 07 jari 101         this.expViewer = new ExperimentViewer(experiment, clusters);
2 26 Feb 07 jari 102         this.expViewer.getContentComponent().addMouseListener(listener);
2 26 Feb 07 jari 103         setInsets(new Insets(0,0,0,0));
2 26 Feb 07 jari 104         this.header = new CentroidExperimentHeader(this.expViewer.getHeaderComponent(), codes, clusters,"SOTA Centroid Vector");
2 26 Feb 07 jari 105         ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(((ExperimentViewer)expViewer).getNegColorImage(), ((ExperimentViewer)expViewer).getPosColorImage());
2 26 Feb 07 jari 106         this.infoPanel = new InfoPanel();
2 26 Feb 07 jari 107         this.infoPanel.addMouseListener(listener);
2 26 Feb 07 jari 108         ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(((ExperimentViewer)expViewer).getNegColorImage(), ((ExperimentViewer)expViewer).getPosColorImage());
2 26 Feb 07 jari 109         ((CentroidExperimentHeader)this.header).setMissingColor(((ExperimentViewer)expViewer).getMissingColor());
2 26 Feb 07 jari 110         ((CentroidExperimentHeader)this.header).addMouseListener(listener);
2 26 Feb 07 jari 111         viewPanel = new JPanel();
2 26 Feb 07 jari 112         viewPanel.setLayout(new GridBagLayout());
2 26 Feb 07 jari 113         viewPanel.add(((JComponent)expViewer), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 114         viewPanel.add(infoPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 115         add(viewPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 116     }
2 26 Feb 07 jari 117     public SOTAExperimentViewer(Experiment experiment, int[][] clusters, FloatMatrix codes, FloatMatrix clusterDiv, SOTATreeData sotaTreeData, Boolean clusterGenes) {
2 26 Feb 07 jari 118       this(experiment, clusters, codes, clusterDiv, sotaTreeData, clusterGenes.booleanValue());
2 26 Feb 07 jari 119     }   
2 26 Feb 07 jari 120     /**
2 26 Feb 07 jari 121      * Constructs a <code>SOTAExperimentViewer</code> with specified
2 26 Feb 07 jari 122      * experiment, clusters (gene indices) and codes (centroid data)
2 26 Feb 07 jari 123      */
2 26 Feb 07 jari 124     public SOTAExperimentViewer(Experiment experiment, int[][] clusters, FloatMatrix codes, FloatMatrix clusterDiv, SOTATreeData sotaTreeData, boolean clusterGenes) {
2 26 Feb 07 jari 125         setLayout(new GridBagLayout());
2 26 Feb 07 jari 126       this.codes = codes;
2 26 Feb 07 jari 127         this.geneClusterViewer = clusterGenes;
2 26 Feb 07 jari 128         this.exptID = experiment.getId();
2 26 Feb 07 jari 129         Listener listener = new Listener();
2 26 Feb 07 jari 130         this.popup = createJPopupMenu(listener);
2 26 Feb 07 jari 131         this.clusters = clusters;
2 26 Feb 07 jari 132         this.clusterDivFM = clusterDiv;
2 26 Feb 07 jari 133         this.numberOfCells = 0;
2 26 Feb 07 jari 134         if(this.clusterDivFM != null)
2 26 Feb 07 jari 135             this.numberOfCells = clusterDivFM.getRowDimension();
2 26 Feb 07 jari 136         this.centroidDataFM = codes;
2 26 Feb 07 jari 137         this.sotaTreeData = sotaTreeData;
2 26 Feb 07 jari 138         this.factor = sotaTreeData.factor;  //from SOTA, factor sets polarity of 'displayed' distances in viewer based on metric
2 26 Feb 07 jari 139         this.function = sotaTreeData.function; //distance metric
2 26 Feb 07 jari 140         if(!clusterGenes){
2 26 Feb 07 jari 141             this.expViewer = new ExperimentClusterViewer(experiment, clusters, "Sota Centroid Vector", codes.getArrayCopy());
2 26 Feb 07 jari 142             this.header = (ExperimentClusterHeader)(expViewer.getHeaderComponent());
2 26 Feb 07 jari 143         } else {
2 26 Feb 07 jari 144             this.expViewer = new ExperimentViewer(experiment, clusters);
2 26 Feb 07 jari 145             this.header = new CentroidExperimentHeader(expViewer.getHeaderComponent(), codes, this.clusters, "SOTA Centroid Vector");
2 26 Feb 07 jari 146         }
2 26 Feb 07 jari 147         this.expViewer.getContentComponent().addMouseListener(listener);
2 26 Feb 07 jari 148         this.infoPanel = new InfoPanel();
2 26 Feb 07 jari 149         this.infoPanel.addMouseListener(listener);
2 26 Feb 07 jari 150         setInsets(new Insets(0,0,0,0));
2 26 Feb 07 jari 151         viewPanel = new JPanel();
2 26 Feb 07 jari 152         viewPanel.setLayout(new GridBagLayout());
2 26 Feb 07 jari 153         viewPanel.add(((JComponent)expViewer), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 154         viewPanel.add(infoPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 155         add(viewPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 156     }
2 26 Feb 07 jari 157     
2 26 Feb 07 jari 158     public Expression getExpression(){
2 26 Feb 07 jari 159       return new Expression(this, this.getClass(), "new",
2 26 Feb 07 jari 160 //(Experiment experiment, int[][] clusters, FloatMatrix codes, FloatMatrix clusterDiv, SOTATreeData sotaTreeData, boolean clusterGenes) {
2 26 Feb 07 jari 161           new Object[]{this.expViewer.getExperiment(), this.clusters, this.codes, this.clusterDivFM, this.sotaTreeData, new Boolean(this.geneClusterViewer)});
2 26 Feb 07 jari 162 //          new Object[]{this.expViewer, new Float(this.factor), 
2 26 Feb 07 jari 163  //         new Integer(this.function), new Integer(this.numberOfCells), 
2 26 Feb 07 jari 164 //        new Boolean(this.geneClusterViewer), new Boolean(this.useDoubleGradient), 
2 26 Feb 07 jari 165 //        this.clusterDivFM, this.centroidDataFM, this.clusters, 
2 26 Feb 07 jari 166 //        this.getHeaderComponent(), this.getInsets(), new Integer(this.exptID), 
2 26 Feb 07 jari 167 //        this.codes, this.viewPanel});  
2 26 Feb 07 jari 168   }
2 26 Feb 07 jari 169     public SOTAExperimentViewer(IViewer exptViewer, Float factor, Integer function,
2 26 Feb 07 jari 170         Integer numberOfCells, Boolean geneClusterViewer, Boolean useDoubleGradient, 
2 26 Feb 07 jari 171       FloatMatrix clusterDivFM, FloatMatrix centroidDataFM, int[][] clusters, 
2 26 Feb 07 jari 172       JComponent header, 
2 26 Feb 07 jari 173       Insets insets, Integer exptID, FloatMatrix codes, JPanel viewPanel) {
2 26 Feb 07 jari 174       setLayout(new GridBagLayout());
2 26 Feb 07 jari 175
2 26 Feb 07 jari 176       this.expViewer = exptViewer;
2 26 Feb 07 jari 177         this.factor = factor.floatValue();
2 26 Feb 07 jari 178         this.function = function.intValue();
2 26 Feb 07 jari 179         this.numberOfCells = numberOfCells.intValue();
2 26 Feb 07 jari 180         this.geneClusterViewer = geneClusterViewer.booleanValue();
2 26 Feb 07 jari 181         this.useDoubleGradient = useDoubleGradient.booleanValue();
2 26 Feb 07 jari 182         this.clusterDivFM = clusterDivFM;
2 26 Feb 07 jari 183         this.centroidDataFM = centroidDataFM;
2 26 Feb 07 jari 184       this.clusters = clusters;
2 26 Feb 07 jari 185       this.header = header;
2 26 Feb 07 jari 186       setInsets(insets);
2 26 Feb 07 jari 187       this.exptID = exptID.intValue();
2 26 Feb 07 jari 188       this.codes = codes;
2 26 Feb 07 jari 189       this.viewPanel = viewPanel;
2 26 Feb 07 jari 190     }
2 26 Feb 07 jari 191     public void setExperiment(Experiment e) {
2 26 Feb 07 jari 192       super.setExperiment(e);
2 26 Feb 07 jari 193         expViewer.setExperiment(e);
2 26 Feb 07 jari 194         Listener listener = new Listener();
2 26 Feb 07 jari 195         this.expViewer.getContentComponent().addMouseListener(listener);
2 26 Feb 07 jari 196         this.infoPanel = new InfoPanel();
2 26 Feb 07 jari 197         this.infoPanel.addMouseListener(listener);
2 26 Feb 07 jari 198       this.header.addMouseListener(listener);
2 26 Feb 07 jari 199         this.popup = createJPopupMenu(listener);
2 26 Feb 07 jari 200         if(!geneClusterViewer){ //Experiment clusters (expViewer is an ExperimentClusterViewer)
2 26 Feb 07 jari 201            this.header = (ExperimentClusterHeader)(expViewer.getHeaderComponent());
2 26 Feb 07 jari 202            ((ExperimentClusterHeader)header).setExperiment(e);
2 26 Feb 07 jari 203         } else { // gene clusters
2 26 Feb 07 jari 204             this.header = new CentroidExperimentHeader(expViewer.getHeaderComponent(), codes, this.clusters, "SOTA Centroid Vector");
2 26 Feb 07 jari 205             ((CentroidExperimentHeader)header).setExperiment(e);
2 26 Feb 07 jari 206             ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(((ExperimentViewer)expViewer).getNegColorImage(), ((ExperimentViewer)expViewer).getPosColorImage());
2 26 Feb 07 jari 207             ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(((ExperimentViewer)expViewer).getNegColorImage(), ((ExperimentViewer)expViewer).getPosColorImage());
2 26 Feb 07 jari 208           ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(((ExperimentViewer)expViewer).getNegColorImage(), ((ExperimentViewer)expViewer).getPosColorImage());
2 26 Feb 07 jari 209           ((CentroidExperimentHeader)this.header).setMissingColor(((ExperimentViewer)expViewer).getMissingColor());
2 26 Feb 07 jari 210       }
2 26 Feb 07 jari 211         viewPanel.add(((JComponent)expViewer), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 212         viewPanel.add(infoPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 213         add(viewPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 214     }
2 26 Feb 07 jari 215     
2 26 Feb 07 jari 216     
2 26 Feb 07 jari 217     /**
2 26 Feb 07 jari 218      *  Adds components to viewer
2 26 Feb 07 jari 219      */
2 26 Feb 07 jari 220     private void addComponents(JComponent header, ExperimentViewer expImageViewer, InfoPanel info){
2 26 Feb 07 jari 221         add(expImageViewer, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 222         add(info,  new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
2 26 Feb 07 jari 223     }
2 26 Feb 07 jari 224     
2 26 Feb 07 jari 225     /**
2 26 Feb 07 jari 226      * Returns the header component.
2 26 Feb 07 jari 227      */
2 26 Feb 07 jari 228     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 229         return header;
2 26 Feb 07 jari 230     }
2 26 Feb 07 jari 231     
2 26 Feb 07 jari 232     /**
2 26 Feb 07 jari 233      * Returns the wrapped experiment viewer.
2 26 Feb 07 jari 234      */
2 26 Feb 07 jari 235     public JComponent getContentComponent() {
2 26 Feb 07 jari 236         return this;
2 26 Feb 07 jari 237     }
2 26 Feb 07 jari 238     
2 26 Feb 07 jari 239     public BufferedImage getImage() {
2 26 Feb 07 jari 240         return expViewer.getImage();
2 26 Feb 07 jari 241     }
2 26 Feb 07 jari 242     
2 26 Feb 07 jari 243     /**
2 26 Feb 07 jari 244      * Updates header and contents attributes when the viewer is selected.
2 26 Feb 07 jari 245      */
2 26 Feb 07 jari 246     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 247         if(this.geneClusterViewer)
2 26 Feb 07 jari 248             ((ExperimentViewer) expViewer).onSelected(framework);
2 26 Feb 07 jari 249         else
2 26 Feb 07 jari 250             ((ExperimentClusterViewer) expViewer).onSelected(framework);
2 26 Feb 07 jari 251         Integer userObject = ((Integer)framework.getUserObject());
2 26 Feb 07 jari 252         infoPanel.setCurrentCluster(userObject == null ? 0 : userObject.intValue());
2 26 Feb 07 jari 253         infoPanel.onSelected();
2 26 Feb 07 jari 254         IDisplayMenu menu = framework.getDisplayMenu();
2 26 Feb 07 jari 255         useDoubleGradient = menu.getUseDoubleGradient();
2 26 Feb 07 jari 256         if(geneClusterViewer){                        
2 26 Feb 07 jari 257             ((CentroidExperimentHeader)this.header).setCurrentCluster(userObject == null ? 0 : userObject.intValue());
2 26 Feb 07 jari 258             ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(menu.getNegativeGradientImage(), menu.getPositiveGradientImage());
2 26 Feb 07 jari 259             ((CentroidExperimentHeader)this.header).setValues(menu.getMinRatioScale(), menu.getMidRatioValue(), menu.getMaxRatioScale());
2 26 Feb 07 jari 260             ((CentroidExperimentHeader)this.header).setAntiAliasing(menu.isAntiAliasing());            
2 26 Feb 07 jari 261             ((CentroidExperimentHeader)this.header).setDrawBorders(menu.isDrawingBorder());
2 26 Feb 07 jari 262             ((CentroidExperimentHeader)this.header).updateSize(menu.getElementSize());
2 26 Feb 07 jari 263             ((CentroidExperimentHeader)this.header).setUseDoubleGradient(useDoubleGradient);
2 26 Feb 07 jari 264             int height = ((CentroidExperimentHeader)this.header).getCurrHeight();
2 26 Feb 07 jari 265             this.header.setSize(getContentWidth(), height);
2 26 Feb 07 jari 266             this.header.setPreferredSize(new Dimension(getContentWidth(), height));
2 26 Feb 07 jari 267         }
2 26 Feb 07 jari 268         else{
2 26 Feb 07 jari 269             ((ExperimentClusterHeader)(this.header)).updateSizes(getContentWidth(), menu.getElementSize().width);
2 26 Feb 07 jari 270             ((ExperimentClusterHeader)(this.header)).setUseDoubleGradient(useDoubleGradient);        
2 26 Feb 07 jari 271             ((ExperimentClusterHeader)this.header).setValues(menu.getMinRatioScale(), menu.getMidRatioValue(), menu.getMaxRatioScale());
2 26 Feb 07 jari 272         }
2 26 Feb 07 jari 273         repaint();
2 26 Feb 07 jari 274     }
2 26 Feb 07 jari 275     
2 26 Feb 07 jari 276     
2 26 Feb 07 jari 277     public int getContentWidth(){
2 26 Feb 07 jari 278         int width;
2 26 Feb 07 jari 279         if(this.geneClusterViewer)
2 26 Feb 07 jari 280             width = ((ExperimentViewer)this.expViewer).getContentWidth();
2 26 Feb 07 jari 281         else
2 26 Feb 07 jari 282             width = ((ExperimentClusterViewer)this.expViewer).getContentWidth();
2 26 Feb 07 jari 283         width += this.infoPanel.INFO_PANEL_WIDTH;
2 26 Feb 07 jari 284         return width;
2 26 Feb 07 jari 285     }
2 26 Feb 07 jari 286     
2 26 Feb 07 jari 287     
2 26 Feb 07 jari 288     /**
2 26 Feb 07 jari 289      * Updates experiment data.
2 26 Feb 07 jari 290      */
2 26 Feb 07 jari 291     public void onDataChanged(IData data) {
2 26 Feb 07 jari 292         expViewer.onDataChanged(data);
2 26 Feb 07 jari 293     }
2 26 Feb 07 jari 294     
2 26 Feb 07 jari 295     /**
2 26 Feb 07 jari 296      * Updates header and contents attributes when the display menu is changed.
2 26 Feb 07 jari 297      */
2 26 Feb 07 jari 298     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 299         
2 26 Feb 07 jari 300         if(this.geneClusterViewer)
2 26 Feb 07 jari 301             ((ExperimentViewer) expViewer).onMenuChanged(menu);
2 26 Feb 07 jari 302         else
2 26 Feb 07 jari 303             ((ExperimentClusterViewer) expViewer).onMenuChanged(menu);
2 26 Feb 07 jari 304         
2 26 Feb 07 jari 305         useDoubleGradient = menu.getUseDoubleGradient();
2 26 Feb 07 jari 306         if(geneClusterViewer){
2 26 Feb 07 jari 307             ((CentroidExperimentHeader)this.header).setNegAndPosColorImages(menu.getNegativeGradientImage(), menu.getPositiveGradientImage());
2 26 Feb 07 jari 308             ((CentroidExperimentHeader)this.header).setValues(Math.abs(menu.getMaxRatioScale()), -Math.abs(menu.getMinRatioScale()));
2 26 Feb 07 jari 309             ((CentroidExperimentHeader)this.header).setAntiAliasing(menu.isAntiAliasing());
2 26 Feb 07 jari 310             ((CentroidExperimentHeader)this.header).setDrawBorders(menu.isDrawingBorder());
2 26 Feb 07 jari 311             ((CentroidExperimentHeader)this.header).updateSize(menu.getElementSize());
2 26 Feb 07 jari 312             ((CentroidExperimentHeader)this.header).setUseDoubleGradient(useDoubleGradient);
2 26 Feb 07 jari 313             this.header.setSize(getContentWidth(), this.header.getHeight());
2 26 Feb 07 jari 314             this.header.setPreferredSize(new Dimension(getContentWidth(), this.header.getHeight()));
2 26 Feb 07 jari 315         }
2 26 Feb 07 jari 316         else {
2 26 Feb 07 jari 317             ((ExperimentClusterHeader)(this.header)).updateSizes(getContentWidth(), menu.getElementSize().width);
2 26 Feb 07 jari 318             ((ExperimentClusterHeader)(this.header)).setUseDoubleGradient(useDoubleGradient);
2 26 Feb 07 jari 319         }
2 26 Feb 07 jari 320         repaint();
2 26 Feb 07 jari 321     }
2 26 Feb 07 jari 322     
2 26 Feb 07 jari 323     public void onDeselected() {}
2 26 Feb 07 jari 324     public void onClosed() {}
2 26 Feb 07 jari 325     
2 26 Feb 07 jari 326     /**
2 26 Feb 07 jari 327      * Creates a popup menu.
2 26 Feb 07 jari 328      */
2 26 Feb 07 jari 329     private JPopupMenu createJPopupMenu(Listener listener) {
2 26 Feb 07 jari 330         JPopupMenu popup = new JPopupMenu();
2 26 Feb 07 jari 331         addMenuItems(popup, listener);
2 26 Feb 07 jari 332         return popup;
2 26 Feb 07 jari 333     }
2 26 Feb 07 jari 334     
2 26 Feb 07 jari 335     protected void addMenuItems(JPopupMenu menu, ActionListener listener) {
2 26 Feb 07 jari 336         JMenuItem menuItem;
2 26 Feb 07 jari 337         menuItem = new JMenuItem("Store cluster", GUIFactory.getIcon("new16.gif"));
2 26 Feb 07 jari 338         menuItem.setActionCommand(STORE_CLUSTER_CMD);
2 26 Feb 07 jari 339         menuItem.addActionListener(listener);
2 26 Feb 07 jari 340         menu.add(menuItem);
2 26 Feb 07 jari 341         
2 26 Feb 07 jari 342         menu.addSeparator();
2 26 Feb 07 jari 343         
2 26 Feb 07 jari 344         menuItem = new JMenuItem("Launch new session", GUIFactory.getIcon("analysis16.gif"));
2 26 Feb 07 jari 345         menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD);
2 26 Feb 07 jari 346         menuItem.addActionListener(listener);
2 26 Feb 07 jari 347         menu.add(menuItem);
2 26 Feb 07 jari 348         
2 26 Feb 07 jari 349         menu.addSeparator();
2 26 Feb 07 jari 350         
2 26 Feb 07 jari 351         menuItem = new JMenuItem("Delete public cluster", GUIFactory.getIcon("delete16.gif"));
2 26 Feb 07 jari 352         menuItem.setActionCommand(SET_DEF_COLOR_CMD);
2 26 Feb 07 jari 353         menuItem.addActionListener(listener);
2 26 Feb 07 jari 354         menu.add(menuItem);
2 26 Feb 07 jari 355         
2 26 Feb 07 jari 356         menu.addSeparator();
2 26 Feb 07 jari 357         
2 26 Feb 07 jari 358         menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif"));
2 26 Feb 07 jari 359         menuItem.setActionCommand(SAVE_CLUSTER_CMD);
2 26 Feb 07 jari 360         menuItem.addActionListener(listener);
2 26 Feb 07 jari 361         menu.add(menuItem);
2 26 Feb 07 jari 362         
2 26 Feb 07 jari 363         menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif"));
2 26 Feb 07 jari 364         menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD);
2 26 Feb 07 jari 365         menuItem.addActionListener(listener);
2 26 Feb 07 jari 366         menu.add(menuItem);
2 26 Feb 07 jari 367     }
2 26 Feb 07 jari 368     
2 26 Feb 07 jari 369     /**
2 26 Feb 07 jari 370      * Saves clusters.
2 26 Feb 07 jari 371      */
2 26 Feb 07 jari 372     private void onSaveClusters() {
2 26 Feb 07 jari 373         Frame frame = JOptionPane.getFrameForComponent(getContentComponent());
2 26 Feb 07 jari 374         try {
2 26 Feb 07 jari 375             if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 376                 ((ExperimentViewer)expViewer).saveClusters(frame);
2 26 Feb 07 jari 377             else
2 26 Feb 07 jari 378                 ((ExperimentClusterViewer)expViewer).saveClusters(frame);
2 26 Feb 07 jari 379         } catch (Exception e) {
2 26 Feb 07 jari 380             JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE);
2 26 Feb 07 jari 381             e.printStackTrace();
2 26 Feb 07 jari 382         }
2 26 Feb 07 jari 383     }
2 26 Feb 07 jari 384     
2 26 Feb 07 jari 385     /**
2 26 Feb 07 jari 386      * Save the viewer cluster.
2 26 Feb 07 jari 387      */
2 26 Feb 07 jari 388     private void onSaveCluster() {
2 26 Feb 07 jari 389         Frame frame = JOptionPane.getFrameForComponent(getContentComponent());
2 26 Feb 07 jari 390         try {
2 26 Feb 07 jari 391             if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 392                 ((ExperimentViewer)expViewer).saveCluster(frame);
2 26 Feb 07 jari 393             else{
2 26 Feb 07 jari 394                 ((ExperimentClusterViewer)expViewer).saveCluster(frame);
2 26 Feb 07 jari 395             }
2 26 Feb 07 jari 396         } catch (Exception e) {
2 26 Feb 07 jari 397             JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE);
2 26 Feb 07 jari 398             e.printStackTrace();
2 26 Feb 07 jari 399         }
2 26 Feb 07 jari 400     }
2 26 Feb 07 jari 401     
2 26 Feb 07 jari 402     /**
2 26 Feb 07 jari 403      * Sets a public color.
2 26 Feb 07 jari 404      */
2 26 Feb 07 jari 405     private void onSetColor() {
2 26 Feb 07 jari 406         Frame frame = JOptionPane.getFrameForComponent(getContentComponent());
2 26 Feb 07 jari 407         Color newColor = JColorChooser.showDialog(frame, "Choose color", CentroidViewer.DEF_CLUSTER_COLOR);
2 26 Feb 07 jari 408         if (newColor != null) {
2 26 Feb 07 jari 409             if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 410                 ((ExperimentViewer)expViewer).setClusterColor(newColor);
2 26 Feb 07 jari 411             else
2 26 Feb 07 jari 412                 ((ExperimentClusterViewer)expViewer).setClusterColor(newColor);
2 26 Feb 07 jari 413         }
2 26 Feb 07 jari 414     }
2 26 Feb 07 jari 415     
2 26 Feb 07 jari 416     /**
2 26 Feb 07 jari 417      * Sets public color for the current cluster.
2 26 Feb 07 jari 418      */
2 26 Feb 07 jari 419     public void setClusterColor(Color color) {
2 26 Feb 07 jari 420         if(color ==null){  //indicates removal of cluster
2 26 Feb 07 jari 421             if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 422                 ((ExperimentViewer)expViewer).setClusterColor(null);
2 26 Feb 07 jari 423             else
2 26 Feb 07 jari 424                 ((ExperimentClusterViewer)expViewer).setClusterColor(null);
2 26 Feb 07 jari 425         }
2 26 Feb 07 jari 426     }
2 26 Feb 07 jari 427     
2 26 Feb 07 jari 428     /**
2 26 Feb 07 jari 429      * Launches a new session
2 26 Feb 07 jari 430      */
2 26 Feb 07 jari 431     public void launchNewSession(){
2 26 Feb 07 jari 432         if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 433             ((ExperimentViewer)expViewer).launchNewSession();
2 26 Feb 07 jari 434         else
2 26 Feb 07 jari 435             ((ExperimentClusterViewer)expViewer).launchNewSession();
2 26 Feb 07 jari 436     }
2 26 Feb 07 jari 437     
2 26 Feb 07 jari 438     /**
2 26 Feb 07 jari 439      *  Sets cluster color
2 26 Feb 07 jari 440      */
2 26 Feb 07 jari 441     public void storeCluster(){
2 26 Feb 07 jari 442         if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 443             ((ExperimentViewer)expViewer).storeCluster();
2 26 Feb 07 jari 444         else
2 26 Feb 07 jari 445             ((ExperimentClusterViewer)expViewer).storeCluster();
2 26 Feb 07 jari 446     }
2 26 Feb 07 jari 447     
2 26 Feb 07 jari 448     /**
2 26 Feb 07 jari 449      * Removes a public color.
2 26 Feb 07 jari 450      */
2 26 Feb 07 jari 451     private void onSetDefaultColor() {
2 26 Feb 07 jari 452         if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 453             ((ExperimentViewer)expViewer).setClusterColor(null);
2 26 Feb 07 jari 454         else
2 26 Feb 07 jari 455             ((ExperimentClusterViewer)expViewer).setClusterColor(null);
2 26 Feb 07 jari 456     }
2 26 Feb 07 jari 457     
2 26 Feb 07 jari 458     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 459      */
2 26 Feb 07 jari 460     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 461         return null;
2 26 Feb 07 jari 462     }
2 26 Feb 07 jari 463     
2 26 Feb 07 jari 464     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 465      * posibly null
2 26 Feb 07 jari 466      */
2 26 Feb 07 jari 467     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 468         return null;
2 26 Feb 07 jari 469     }
2 26 Feb 07 jari 470     
2 26 Feb 07 jari 471     /** Returns the viewer's clusters or null
2 26 Feb 07 jari 472      */
2 26 Feb 07 jari 473     public int[][] getClusters() {
2 26 Feb 07 jari 474         return this.expViewer.getClusters();
2 26 Feb 07 jari 475     }    
2 26 Feb 07 jari 476     
2 26 Feb 07 jari 477     /**  Returns the viewer's experiment or null
2 26 Feb 07 jari 478      */
2 26 Feb 07 jari 479     public Experiment getExperiment() {
2 26 Feb 07 jari 480         return this.expViewer.getExperiment();
2 26 Feb 07 jari 481     }
2 26 Feb 07 jari 482     
2 26 Feb 07 jari 483     /** Returns int value indicating viewer type
2 26 Feb 07 jari 484      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 485      */
2 26 Feb 07 jari 486     public int getViewerType() {       
2 26 Feb 07 jari 487         return this.expViewer.getViewerType();
2 26 Feb 07 jari 488     }    
2 26 Feb 07 jari 489     
2 26 Feb 07 jari 490     /**
2 26 Feb 07 jari 491      * The class to listen to mouse and action events.
2 26 Feb 07 jari 492      */
2 26 Feb 07 jari 493     private class Listener extends MouseAdapter implements ActionListener {
2 26 Feb 07 jari 494         
2 26 Feb 07 jari 495         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 496             String command = e.getActionCommand();
2 26 Feb 07 jari 497             if (command.equals(SAVE_CLUSTER_CMD)) {
2 26 Feb 07 jari 498                 onSaveCluster();
2 26 Feb 07 jari 499             } else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) {
2 26 Feb 07 jari 500                 onSaveClusters();
2 26 Feb 07 jari 501             } else if (command.equals(SET_DEF_COLOR_CMD)) {
2 26 Feb 07 jari 502                 onSetDefaultColor();
2 26 Feb 07 jari 503             } else if (command.equals(STORE_CLUSTER_CMD)) {
2 26 Feb 07 jari 504                 storeCluster();
2 26 Feb 07 jari 505             } else if(command.equals(LAUNCH_NEW_SESSION_CMD)){
2 26 Feb 07 jari 506                 launchNewSession();
2 26 Feb 07 jari 507             }
2 26 Feb 07 jari 508         }
2 26 Feb 07 jari 509         
2 26 Feb 07 jari 510         public void mouseReleased(MouseEvent event) {
2 26 Feb 07 jari 511             maybeShowPopup(event);
2 26 Feb 07 jari 512         }
2 26 Feb 07 jari 513         
2 26 Feb 07 jari 514         private void maybeShowPopup(MouseEvent e) {
2 26 Feb 07 jari 515             int [] cluster = null;
2 26 Feb 07 jari 516             if(expViewer instanceof ExperimentViewer)
2 26 Feb 07 jari 517                 cluster = ((ExperimentViewer)expViewer).getCluster();
2 26 Feb 07 jari 518             else
2 26 Feb 07 jari 519                 cluster = ((ExperimentClusterViewer)expViewer).getCluster();
2 26 Feb 07 jari 520             
2 26 Feb 07 jari 521             if (!e.isPopupTrigger() || cluster == null || cluster.length == 0) {
2 26 Feb 07 jari 522                 return;
2 26 Feb 07 jari 523             }
2 26 Feb 07 jari 524             popup.show(e.getComponent(), e.getX(), e.getY());
2 26 Feb 07 jari 525         }
2 26 Feb 07 jari 526     }
2 26 Feb 07 jari 527     
2 26 Feb 07 jari 528     /**
2 26 Feb 07 jari 529      * Displays information about the currently displayed cluster
2 26 Feb 07 jari 530      *
2 26 Feb 07 jari 531      */
2 26 Feb 07 jari 532     private class InfoPanel extends JPanel {
2 26 Feb 07 jari 533         
2 26 Feb 07 jari 534         private int currCluster;
2 26 Feb 07 jari 535         public int INFO_PANEL_WIDTH = 300;
2 26 Feb 07 jari 536         
2 26 Feb 07 jari 537         private javax.swing.JSplitPane jSplitPane1;
2 26 Feb 07 jari 538         private javax.swing.JScrollPane viewerPane;
2 26 Feb 07 jari 539         private javax.swing.JPanel infoPanel;
2 26 Feb 07 jari 540         private javax.swing.JLabel jLabel10;
2 26 Feb 07 jari 541         private javax.swing.JLabel jLabel11;
2 26 Feb 07 jari 542         private javax.swing.JLabel jLabel12;
2 26 Feb 07 jari 543         private javax.swing.JLabel jLabel13;
2 26 Feb 07 jari 544         private javax.swing.JLabel jLabel14;
2 26 Feb 07 jari 545         private javax.swing.JLabel jLabel15;
2 26 Feb 07 jari 546         private javax.swing.JLabel jLabel16;
2 26 Feb 07 jari 547         private javax.swing.JLabel jLabel17;
2 26 Feb 07 jari 548         private javax.swing.JLabel c1Label;
2 26 Feb 07 jari 549         private javax.swing.JLabel c1PopLabel;
2 26 Feb 07 jari 550         private javax.swing.JLabel c1DivLabel;
2 26 Feb 07 jari 551         private javax.swing.JLabel distLabel;
2 26 Feb 07 jari 552         private javax.swing.JLabel c2Label;
2 26 Feb 07 jari 553         private javax.swing.JLabel c2DivLabel;
2 26 Feb 07 jari 554         private javax.swing.JLabel c2PopLabel;
2 26 Feb 07 jari 555     private SOTAInfoStats infoStats = new SOTAInfoStats();
2 26 Feb 07 jari 556         
2 26 Feb 07 jari 557         /**
2 26 Feb 07 jari 558          * Constructs a new InfoPanel.
2 26 Feb 07 jari 559          *
2 26 Feb 07 jari 560          */
2 26 Feb 07 jari 561         private InfoPanel(){
2 26 Feb 07 jari 562             initComponents();
2 26 Feb 07 jari 563             currCluster = 0;
2 26 Feb 07 jari 564             
2 26 Feb 07 jari 565             this.setSize(INFO_PANEL_WIDTH , 350);
2 26 Feb 07 jari 566             this.setPreferredSize( new Dimension(INFO_PANEL_WIDTH , 350));
2 26 Feb 07 jari 567             this.setVisible(true);
2 26 Feb 07 jari 568             this.setBackground(java.awt.Color.white);
2 26 Feb 07 jari 569             super.setBackground(java.awt.Color.white);
2 26 Feb 07 jari 570         }
2 26 Feb 07 jari 571         
2 26 Feb 07 jari 572         private void initComponents() {
2 26 Feb 07 jari 573             
2 26 Feb 07 jari 574           
2 26 Feb 07 jari 575             jLabel10 = new javax.swing.JLabel();
2 26 Feb 07 jari 576             jLabel11 = new javax.swing.JLabel();
2 26 Feb 07 jari 577             jLabel12 = new javax.swing.JLabel();
2 26 Feb 07 jari 578             jLabel13 = new javax.swing.JLabel();
2 26 Feb 07 jari 579             jLabel14 = new javax.swing.JLabel();
2 26 Feb 07 jari 580             jLabel15 = new javax.swing.JLabel();
2 26 Feb 07 jari 581             jLabel16 = new javax.swing.JLabel();
2 26 Feb 07 jari 582             jLabel17 = new javax.swing.JLabel();
2 26 Feb 07 jari 583             c1Label = new javax.swing.JLabel();
2 26 Feb 07 jari 584             c1PopLabel = new javax.swing.JLabel();
2 26 Feb 07 jari 585             c1DivLabel = new javax.swing.JLabel();
2 26 Feb 07 jari 586             distLabel = new javax.swing.JLabel();
2 26 Feb 07 jari 587             c2Label = new javax.swing.JLabel();
2 26 Feb 07 jari 588             c2DivLabel = new javax.swing.JLabel();
2 26 Feb 07 jari 589             c2PopLabel = new javax.swing.JLabel();
2 26 Feb 07 jari 590             
2 26 Feb 07 jari 591             setBackground(Color.white);
2 26 Feb 07 jari 592             this.setLayout(null);
2 26 Feb 07 jari 593             
2 26 Feb 07 jari 594             this.setBackground(java.awt.Color.white);
2 26 Feb 07 jari 595             super.setBackground(java.awt.Color.white);
2 26 Feb 07 jari 596             this.setBorder(new LineBorder(Color.black, 1));
2 26 Feb 07 jari 597             
2 26 Feb 07 jari 598             setAlignmentY(1.0F);
2 26 Feb 07 jari 599             setAlignmentX(1.0F);
2 26 Feb 07 jari 600             setOpaque(false);
2 26 Feb 07 jari 601             jLabel10.setText("Cluster ID#:");
2 26 Feb 07 jari 602             jLabel10.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 603             add(jLabel10);
2 26 Feb 07 jari 604             jLabel10.setBounds(20, 30, 65, 17);
2 26 Feb 07 jari 605             
2 26 Feb 07 jari 606             jLabel11.setText("Cluster Population:");
2 26 Feb 07 jari 607             jLabel11.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 608             add(jLabel11);
2 26 Feb 07 jari 609             jLabel11.setBounds(20, 60, 107, 17);
2 26 Feb 07 jari 610             
2 26 Feb 07 jari 611             jLabel12.setText("Cluster Diversity:");
2 26 Feb 07 jari 612             jLabel12.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 613             add(jLabel12);
2 26 Feb 07 jari 614             jLabel12.setBounds(20, 90, 96, 17);
2 26 Feb 07 jari 615             
2 26 Feb 07 jari 616             jLabel13.setText("Distance to");
2 26 Feb 07 jari 617             jLabel13.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 618             add(jLabel13);
2 26 Feb 07 jari 619             jLabel13.setBounds(20, 130, 64, 17);
2 26 Feb 07 jari 620             
2 26 Feb 07 jari 621             jLabel14.setText("Closest Neighbor:");
2 26 Feb 07 jari 622             jLabel14.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 623             add(jLabel14);
2 26 Feb 07 jari 624             jLabel14.setBounds(20, 150, 100, 17);
2 26 Feb 07 jari 625             
2 26 Feb 07 jari 626             jLabel15.setText("Neighbor ID#:");
2 26 Feb 07 jari 627             jLabel15.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 628             add(jLabel15);
2 26 Feb 07 jari 629             jLabel15.setBounds(20, 190, 75, 17);
2 26 Feb 07 jari 630             
2 26 Feb 07 jari 631             jLabel16.setText("Neighbor Population:");
2 26 Feb 07 jari 632             jLabel16.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 633             add(jLabel16);
2 26 Feb 07 jari 634             jLabel16.setBounds(20, 220, 117, 17);
2 26 Feb 07 jari 635             
2 26 Feb 07 jari 636             jLabel17.setText("Neighbor Diversity:");
2 26 Feb 07 jari 637             jLabel17.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 638             add(jLabel17);
2 26 Feb 07 jari 639             jLabel17.setBounds(20, 250, 106, 17);
2 26 Feb 07 jari 640             
2 26 Feb 07 jari 641             c1Label.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 642             add(c1Label);
2 26 Feb 07 jari 643             c1Label.setBounds(150, 30, 70, 20);
2 26 Feb 07 jari 644             
2 26 Feb 07 jari 645             c1PopLabel.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 646             add(c1PopLabel);
2 26 Feb 07 jari 647             c1PopLabel.setBounds(150, 60, 70, 20);
2 26 Feb 07 jari 648             
2 26 Feb 07 jari 649             c1DivLabel.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 650             add(c1DivLabel);
2 26 Feb 07 jari 651             c1DivLabel.setBounds(150, 90, 110, 20);
2 26 Feb 07 jari 652             
2 26 Feb 07 jari 653             distLabel.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 654             add(distLabel);
2 26 Feb 07 jari 655             distLabel.setBounds(150, 150, 110, 20);
2 26 Feb 07 jari 656             
2 26 Feb 07 jari 657             c2Label.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 658             add(c2Label);
2 26 Feb 07 jari 659             c2Label.setBounds(150, 190, 70, 20);
2 26 Feb 07 jari 660             
2 26 Feb 07 jari 661             c2DivLabel.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 662             add(c2DivLabel);
2 26 Feb 07 jari 663             c2DivLabel.setBounds(150, 250, 110, 20);
2 26 Feb 07 jari 664             
2 26 Feb 07 jari 665             c2PopLabel.setForeground(java.awt.Color.black);
2 26 Feb 07 jari 666             add(c2PopLabel);
2 26 Feb 07 jari 667             c2PopLabel.setBounds(150, 220, 70, 20);
2 26 Feb 07 jari 668         }
2 26 Feb 07 jari 669         
2 26 Feb 07 jari 670         /**
2 26 Feb 07 jari 671          * Sets viewable data into panel
2 26 Feb 07 jari 672          * EH changed this method to take the bean SOTAInfoPanel instead of a long list of parameters
2 26 Feb 07 jari 673          */
2 26 Feb 07 jari 674          private void setData1(SOTAInfoStats infoStats) {
2 26 Feb 07 jari 675           this.infoStats = infoStats;
2 26 Feb 07 jari 676           this.c1Label.setText(String.valueOf(infoStats.getC1()+1));
2 26 Feb 07 jari 677             this.c1PopLabel.setText(String.valueOf(infoStats.getClusterPop1()));
2 26 Feb 07 jari 678             this.c1DivLabel.setText(String.valueOf(infoStats.getDiv1()));
2 26 Feb 07 jari 679             this.distLabel.setText(String.valueOf(infoStats.getDist()*factor));  //factor sets polarity based on distance metric
2 26 Feb 07 jari 680             this.c2Label.setText(String.valueOf(infoStats.getC2()+1));
2 26 Feb 07 jari 681             this.c2PopLabel.setText(String.valueOf(infoStats.getClusterPop2()));
2 26 Feb 07 jari 682             this.c2DivLabel.setText(String.valueOf(infoStats.getDiv2()));
2 26 Feb 07 jari 683            
2 26 Feb 07 jari 684             repaint();
2 26 Feb 07 jari 685         }
2 26 Feb 07 jari 686         
2 26 Feb 07 jari 687         /**
2 26 Feb 07 jari 688          * Clears data entries
2 26 Feb 07 jari 689          */
2 26 Feb 07 jari 690         private void clearData(int clusterNum){
2 26 Feb 07 jari 691             this.c1Label.setText(String.valueOf(clusterNum+1));
2 26 Feb 07 jari 692             this.c1PopLabel.setText("");
2 26 Feb 07 jari 693             this.c1DivLabel.setText("");
2 26 Feb 07 jari 694             this.distLabel.setText("");
2 26 Feb 07 jari 695             this.c2Label.setText("");
2 26 Feb 07 jari 696             this.c2PopLabel.setText("");
2 26 Feb 07 jari 697             this.c2DivLabel.setText("");
2 26 Feb 07 jari 698             repaint();
2 26 Feb 07 jari 699         }
2 26 Feb 07 jari 700         
2 26 Feb 07 jari 701         /**
2 26 Feb 07 jari 702          * Returns index of closest neighbor
2 26 Feb 07 jari 703          */
2 26 Feb 07 jari 704         private int getClosestCentroid(int centroidNum){
2 26 Feb 07 jari 705             
2 26 Feb 07 jari 706             float minDist = Float.POSITIVE_INFINITY;
2 26 Feb 07 jari 707             float currDist;
2 26 Feb 07 jari 708             int closestCentroid = centroidNum;
2 26 Feb 07 jari 709             for(int i = 0; i < numberOfCells ;i++){
2 26 Feb 07 jari 710                 currDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidDataFM,
2 26 Feb 07 jari 711                 null, centroidNum, i, function, (float)1.0, false);
2 26 Feb 07 jari 712                 
2 26 Feb 07 jari 713                 if(currDist < minDist && i != centroidNum){
2 26 Feb 07 jari 714                     minDist = currDist;
2 26 Feb 07 jari 715                     closestCentroid = i;
2 26 Feb 07 jari 716                 }
2 26 Feb 07 jari 717             }
2 26 Feb 07 jari 718             return closestCentroid;
2 26 Feb 07 jari 719         }
2 26 Feb 07 jari 720         
2 26 Feb 07 jari 721         /**
2 26 Feb 07 jari 722          *  sets the cluster index (and associated data) to display
2 26 Feb 07 jari 723          */
2 26 Feb 07 jari 724         public void setCurrentCluster(int clusterIndex){
2 26 Feb 07 jari 725             currCluster = clusterIndex;
2 26 Feb 07 jari 726         }
2 26 Feb 07 jari 727         
2 26 Feb 07 jari 728         
2 26 Feb 07 jari 729         /**
2 26 Feb 07 jari 730          *  Triggers preparation to display data on current cluster
2 26 Feb 07 jari 731          */
2 26 Feb 07 jari 732         public void onSelected(){
2 26 Feb 07 jari 733             float neighborDist;
2 26 Feb 07 jari 734             int neighbor = getClosestCentroid(currCluster);
2 26 Feb 07 jari 735             
2 26 Feb 07 jari 736             if(neighbor == currCluster) return;
2 26 Feb 07 jari 737             
2 26 Feb 07 jari 738             neighborDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidDataFM,
2 26 Feb 07 jari 739             null, currCluster, neighbor, function, (float)1.0, false);
2 26 Feb 07 jari 740             
2 26 Feb 07 jari 741             if(neighborDist == Float.POSITIVE_INFINITY || neighborDist == 0 || neighbor >= numberOfCells || clusterDivFM == null || clusters[currCluster].length <=0)
2 26 Feb 07 jari 742                 clearData(currCluster);
2 26 Feb 07 jari 743             else {
2 26 Feb 07 jari 744               //int c1, int clusterPop1, float div1, float dist, int c2, int clusterPop2, float div2){
2 26 Feb 07 jari 745               infoStats.setC1(currCluster);
2 26 Feb 07 jari 746               infoStats.setClusterPop1(clusters[currCluster].length);
2 26 Feb 07 jari 747               infoStats.setDiv1(clusterDivFM.get(currCluster, 0));
2 26 Feb 07 jari 748               infoStats.setDist(neighborDist);
2 26 Feb 07 jari 749               infoStats.setC2(neighbor);
2 26 Feb 07 jari 750               infoStats.setClusterPop2(clusters[neighbor].length);
2 26 Feb 07 jari 751               infoStats.setDiv2(clusterDivFM.get(neighbor, 0));
2 26 Feb 07 jari 752               setData1(infoStats);
2 26 Feb 07 jari 753             }
2 26 Feb 07 jari 754         }
2 26 Feb 07 jari 755     }
2 26 Feb 07 jari 756 }
2 26 Feb 07 jari 757
2 26 Feb 07 jari 758
2 26 Feb 07 jari 759