mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/coa/COADummyViewer.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2005, 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  * COADummyViewer.java
2 26 Feb 07 jari 7  *
2 26 Feb 07 jari 8  * Created on December 15, 2004, 2:07 PM
2 26 Feb 07 jari 9  */
2 26 Feb 07 jari 10
2 26 Feb 07 jari 11 package org.tigr.microarray.mev.cluster.gui.impl.coa;
2 26 Feb 07 jari 12
2 26 Feb 07 jari 13 import java.awt.Component;
2 26 Feb 07 jari 14 import java.awt.Frame;
2 26 Feb 07 jari 15 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 16 import java.awt.event.ActionListener;
2 26 Feb 07 jari 17 import java.awt.event.MouseAdapter;
2 26 Feb 07 jari 18 import java.awt.event.MouseEvent;
2 26 Feb 07 jari 19 import java.beans.Expression;
2 26 Feb 07 jari 20
2 26 Feb 07 jari 21 import javax.swing.JFrame;
2 26 Feb 07 jari 22 import javax.swing.JMenuItem;
2 26 Feb 07 jari 23 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 24 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 25
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 27 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 28 import org.tigr.microarray.mev.cluster.gui.LeafInfo;
2 26 Feb 07 jari 29 import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter;
2 26 Feb 07 jari 30 import org.tigr.util.FloatMatrix;
2 26 Feb 07 jari 31 /**
2 26 Feb 07 jari 32  *
2 26 Feb 07 jari 33  * @author  nbhagaba
2 26 Feb 07 jari 34  */
2 26 Feb 07 jari 35 public class COADummyViewer extends ViewerAdapter {
2 26 Feb 07 jari 36     
2 26 Feb 07 jari 37     private static final String ADD_NEW_3D_CMD = "add-new-3d-cmd";
2 26 Feb 07 jari 38     private static final String ADD_NEW_2D_CMD = "add-new-2d-cmd";    
2 26 Feb 07 jari 39     private JPopupMenu popup;
2 26 Feb 07 jari 40     private IFramework framework;    
2 26 Feb 07 jari 41     private FloatMatrix geneUMatrix, exptUMatrix;
2 26 Feb 07 jari 42     private Experiment experiment;    
2 26 Feb 07 jari 43     
2 26 Feb 07 jari 44     /** Creates a new instance of COADummyViewer */
2 26 Feb 07 jari 45     public COADummyViewer(FloatMatrix geneUMatrix, FloatMatrix exptUMatrix) {
2 26 Feb 07 jari 46         //no effect this.experiment = experiment;        
2 26 Feb 07 jari 47         this.geneUMatrix = geneUMatrix;
2 26 Feb 07 jari 48         this.exptUMatrix = exptUMatrix;
2 26 Feb 07 jari 49         popup = createJPopupMenu();        
2 26 Feb 07 jari 50     }
2 26 Feb 07 jari 51     /**
2 26 Feb 07 jari 52      * @inheritDoc
2 26 Feb 07 jari 53      */
2 26 Feb 07 jari 54     public Expression getExpression(){
2 26 Feb 07 jari 55       return new Expression(this, this.getClass(), "new", 
2 26 Feb 07 jari 56           new Object[]{geneUMatrix, exptUMatrix});
2 26 Feb 07 jari 57     }    
2 26 Feb 07 jari 58     
2 26 Feb 07 jari 59     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 60         this.framework = framework;        
2 26 Feb 07 jari 61         //In case it is viewed after serialization
2 26 Feb 07 jari 62         if(popup == null){
2 26 Feb 07 jari 63             popup = createJPopupMenu(); 
2 26 Feb 07 jari 64             DefaultMutableTreeNode node = framework.getCurrentNode();
2 26 Feb 07 jari 65             if(node != null){
2 26 Feb 07 jari 66                 if(node.getUserObject() instanceof LeafInfo){
2 26 Feb 07 jari 67                     LeafInfo leafInfo = (LeafInfo) node.getUserObject();
2 26 Feb 07 jari 68                     leafInfo.setPopupMenu(this.popup);
2 26 Feb 07 jari 69                 }
2 26 Feb 07 jari 70             }
2 26 Feb 07 jari 71         }          
2 26 Feb 07 jari 72     }
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74    /**
2 26 Feb 07 jari 75      * Returns the viewer popup menu.
2 26 Feb 07 jari 76      */
2 26 Feb 07 jari 77     public JPopupMenu getJPopupMenu() {
2 26 Feb 07 jari 78         return popup;
2 26 Feb 07 jari 79     }
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81     /**
2 26 Feb 07 jari 82      * Creates the viewer popup menu.
2 26 Feb 07 jari 83      */
2 26 Feb 07 jari 84     private JPopupMenu createJPopupMenu() {
2 26 Feb 07 jari 85         JPopupMenu popup = new JPopupMenu();
2 26 Feb 07 jari 86         addMenuItems(popup);
2 26 Feb 07 jari 87         return popup;
2 26 Feb 07 jari 88     }    
2 26 Feb 07 jari 89     
2 26 Feb 07 jari 90  
2 26 Feb 07 jari 91     private void addMenuItems(JPopupMenu menu) {  
2 26 Feb 07 jari 92         Listener listener = new Listener();
2 26 Feb 07 jari 93         
2 26 Feb 07 jari 94         JMenuItem menuItem;
2 26 Feb 07 jari 95         menuItem = new JMenuItem("Add new 3-axis projections");
2 26 Feb 07 jari 96         menuItem.setActionCommand("add-new-3d-cmd");
2 26 Feb 07 jari 97         menuItem.addActionListener(listener);
2 26 Feb 07 jari 98         menu.add(menuItem);
2 26 Feb 07 jari 99                 
2 26 Feb 07 jari 100         menuItem = new JMenuItem("Add new 2-axis projections");
2 26 Feb 07 jari 101         menuItem.setActionCommand("add-new-2d-cmd");
2 26 Feb 07 jari 102         menuItem.addActionListener(listener);        
2 26 Feb 07 jari 103         menu.add(menuItem);    
2 26 Feb 07 jari 104     }
2 26 Feb 07 jari 105     
2 26 Feb 07 jari 106     /**
2 26 Feb 07 jari 107      * Returns a menu item by specified action command.
2 26 Feb 07 jari 108      */
2 26 Feb 07 jari 109     private JMenuItem getJMenuItem(String command) {
2 26 Feb 07 jari 110         JMenuItem item;
2 26 Feb 07 jari 111         Component[] components = popup.getComponents();
2 26 Feb 07 jari 112         for (int i=0; i<components.length; i++) {
2 26 Feb 07 jari 113             if (components[i] instanceof JMenuItem) {
2 26 Feb 07 jari 114                 if (((JMenuItem)components[i]).getActionCommand().equals(command))
2 26 Feb 07 jari 115                     return(JMenuItem)components[i];
2 26 Feb 07 jari 116             }
2 26 Feb 07 jari 117         }
2 26 Feb 07 jari 118         return null;
2 26 Feb 07 jari 119     }     
2 26 Feb 07 jari 120     
2 26 Feb 07 jari 121    private void add2DViewNode(DefaultMutableTreeNode node, Experiment experiment, int xAxis, int yAxis, int zAxis) {
2 26 Feb 07 jari 122        COA2DViewer geneViewer, exptViewer, bothViewer;
2 26 Feb 07 jari 123        DefaultMutableTreeNode genes = new DefaultMutableTreeNode("2D views - genes");
2 26 Feb 07 jari 124        DefaultMutableTreeNode expts = new DefaultMutableTreeNode("2D views - expts");
2 26 Feb 07 jari 125        DefaultMutableTreeNode both = new DefaultMutableTreeNode("2D views - both");
2 26 Feb 07 jari 126        
2 26 Feb 07 jari 127        COA2DViewer coaxy = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, xAxis, yAxis);
2 26 Feb 07 jari 128        COA2DViewer coayz = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, yAxis, zAxis);
2 26 Feb 07 jari 129        COA2DViewer coaxz = new COA2DViewer(experiment, geneUMatrix, COAGUI.GENES, xAxis, zAxis);
2 26 Feb 07 jari 130        
2 26 Feb 07 jari 131        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), coaxy, coaxy.getJPopupMenu())));
2 26 Feb 07 jari 132        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), coayz, coayz.getJPopupMenu())));
2 26 Feb 07 jari 133        genes.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), coaxz, coaxz.getJPopupMenu())));
2 26 Feb 07 jari 134        
2 26 Feb 07 jari 135        COA2DViewer coaExptsxy = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, xAxis, yAxis);
2 26 Feb 07 jari 136        COA2DViewer coaExptsyz = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, yAxis, zAxis);
2 26 Feb 07 jari 137        COA2DViewer coaExptsxz = new COA2DViewer(experiment, exptUMatrix, COAGUI.EXPTS, xAxis, zAxis);
2 26 Feb 07 jari 138        
2 26 Feb 07 jari 139        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), coaExptsxy, coaExptsxy.getJPopupMenu())));    
2 26 Feb 07 jari 140        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), coaExptsyz, coaExptsyz.getJPopupMenu()))); 
2 26 Feb 07 jari 141        expts.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), coaExptsxz, coaExptsxz.getJPopupMenu()))); 
2 26 Feb 07 jari 142        
2 26 Feb 07 jari 143        COA2DViewer bothxy = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, xAxis, yAxis);
2 26 Feb 07 jari 144        COA2DViewer bothyz = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, yAxis, zAxis);
2 26 Feb 07 jari 145        COA2DViewer bothxz = new COA2DViewer(experiment, geneUMatrix, exptUMatrix, COAGUI.BOTH, xAxis, zAxis);
2 26 Feb 07 jari 146        
2 26 Feb 07 jari 147        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (yAxis + 1), bothxy, bothxy.getJPopupMenu())));
2 26 Feb 07 jari 148        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (yAxis + 1) + ", " + (zAxis + 1), bothyz, bothyz.getJPopupMenu())));       
2 26 Feb 07 jari 149        both.add(new DefaultMutableTreeNode(new LeafInfo("" + (xAxis + 1) + ", " + (zAxis + 1), bothxz, bothxz.getJPopupMenu())));    
2 26 Feb 07 jari 150        
2 26 Feb 07 jari 151        node.add(genes);
2 26 Feb 07 jari 152        node.add(expts);
2 26 Feb 07 jari 153        node.add(both);
2 26 Feb 07 jari 154    }   
2 26 Feb 07 jari 155    
2 26 Feb 07 jari 156    private void add3DViewNode(Frame frame, DefaultMutableTreeNode node, Experiment experiment, int xAxis, int yAxis, int zAxis) {
2 26 Feb 07 jari 157        COA3DViewer coa3DGeneViewer, coa3DExptViewer, coa3DBothViewer;
2 26 Feb 07 jari 158        coa3DGeneViewer = new COA3DViewer(frame, geneUMatrix, experiment, COAGUI.GENES, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 159        coa3DExptViewer = new COA3DViewer(frame, exptUMatrix, experiment, COAGUI.EXPTS, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 160        coa3DBothViewer = new COA3DViewer(frame, geneUMatrix, exptUMatrix, experiment, COAGUI.BOTH, xAxis, yAxis, zAxis);
2 26 Feb 07 jari 161        
2 26 Feb 07 jari 162        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - genes", coa3DGeneViewer, coa3DGeneViewer.getJPopupMenu())));
2 26 Feb 07 jari 163        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - expts", coa3DExptViewer, coa3DExptViewer.getJPopupMenu())));
2 26 Feb 07 jari 164        node.add(new DefaultMutableTreeNode(new LeafInfo("3D view - both", coa3DBothViewer, coa3DBothViewer.getJPopupMenu())));
2 26 Feb 07 jari 165    }      
2 26 Feb 07 jari 166     
2 26 Feb 07 jari 167    public void addNew3DNode() {
2 26 Feb 07 jari 168         
2 26 Feb 07 jari 169        COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog((JFrame)framework.getFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 170        //COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog(new JFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 171         pd.setVisible(true);      
2 26 Feb 07 jari 172         if (!pd.isOkPressed()) {
2 26 Feb 07 jari 173             return;
2 26 Feb 07 jari 174         } else {
2 26 Feb 07 jari 175             int selectedX = pd.getXAxis();
2 26 Feb 07 jari 176             int selectedY = pd.getYAxis();
2 26 Feb 07 jari 177             int selectedZ = pd.getZAxis();
2 26 Feb 07 jari 178             
2 26 Feb 07 jari 179             DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("Components " + (selectedX + 1) + ", " + (selectedY + 1) + ", " + (selectedZ + 1));
2 26 Feb 07 jari 180             DefaultMutableTreeNode threeDNode = new DefaultMutableTreeNode("3D Views");
2 26 Feb 07 jari 181             add3DViewNode(framework.getFrame(), threeDNode, framework.getData().getExperiment(), selectedX, selectedY, selectedZ);
2 26 Feb 07 jari 182             //add3DViewNode(new JFrame(), newNode, framework.getData().getExperiment(), selectedX, selectedY, selectedZ);
2 26 Feb 07 jari 183             DefaultMutableTreeNode twoDNode = new DefaultMutableTreeNode("2D Views");
2 26 Feb 07 jari 184             add2DViewNode(twoDNode, framework.getData().getExperiment(), selectedX, selectedY, selectedZ);
2 26 Feb 07 jari 185             newNode.add(threeDNode);
2 26 Feb 07 jari 186             newNode.add(twoDNode);   
2 26 Feb 07 jari 187             framework.addNode(framework.getCurrentNode(), newNode);
2 26 Feb 07 jari 188         }        
2 26 Feb 07 jari 189    }
2 26 Feb 07 jari 190    
2 26 Feb 07 jari 191    public void addNew2DNode() {
2 26 Feb 07 jari 192         COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog((JFrame)framework.getFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 193        //COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog(new JFrame(), true, geneUMatrix.getColumnDimension());
2 26 Feb 07 jari 194         pd.setZBoxInvisible(true);
2 26 Feb 07 jari 195         pd.setVisible(true);  
2 26 Feb 07 jari 196         if (!pd.isOkPressed()) {
2 26 Feb 07 jari 197             return;
2 26 Feb 07 jari 198         } else {
2 26 Feb 07 jari 199             int selectedX = pd.getXAxis();
2 26 Feb 07 jari 200             int selectedY = pd.getYAxis();  
2 26 Feb 07 jari 201             
2 26 Feb 07 jari 202             DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("Components " + (selectedX + 1) + ", " + (selectedY + 1));   
2 26 Feb 07 jari 203             COA2DViewer coaGenexy = new COA2DViewer(framework.getData().getExperiment(), geneUMatrix, COAGUI.GENES, selectedX, selectedY);
2 26 Feb 07 jari 204             COA2DViewer coaExptxy = new COA2DViewer(framework.getData().getExperiment(), exptUMatrix, COAGUI.EXPTS, selectedX, selectedY);
2 26 Feb 07 jari 205             COA2DViewer coaBothxy = new COA2DViewer(framework.getData().getExperiment(), geneUMatrix, exptUMatrix, COAGUI.BOTH, selectedX, selectedY);
2 26 Feb 07 jari 206             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Genes", coaGenexy, coaGenexy.getJPopupMenu())));
2 26 Feb 07 jari 207             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Expts", coaExptxy, coaExptxy.getJPopupMenu())));
2 26 Feb 07 jari 208             newNode.add(new DefaultMutableTreeNode(new LeafInfo("Both", coaBothxy, coaBothxy.getJPopupMenu())));
2 26 Feb 07 jari 209             framework.addNode(framework.getCurrentNode(), newNode);
2 26 Feb 07 jari 210             //add2DViewNode(newNode, );
2 26 Feb 07 jari 211         }
2 26 Feb 07 jari 212    }    
2 26 Feb 07 jari 213     
2 26 Feb 07 jari 214     
2 26 Feb 07 jari 215     /**
2 26 Feb 07 jari 216      * The class to listen to dialog and algorithm events.
2 26 Feb 07 jari 217      */
2 26 Feb 07 jari 218     private class Listener extends MouseAdapter implements ActionListener {
2 26 Feb 07 jari 219         
2 26 Feb 07 jari 220         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 221             String command = e.getActionCommand();
2 26 Feb 07 jari 222             if (command.equals("add-new-3d-cmd")) {
2 26 Feb 07 jari 223                 addNew3DNode();
2 26 Feb 07 jari 224             } else if (command.equals("add-new-2d-cmd")) {
2 26 Feb 07 jari 225                 addNew2DNode();
2 26 Feb 07 jari 226             }
2 26 Feb 07 jari 227         }
2 26 Feb 07 jari 228         
2 26 Feb 07 jari 229   public void mouseReleased(MouseEvent event) {
2 26 Feb 07 jari 230       maybeShowPopup(event);
2 26 Feb 07 jari 231   }
2 26 Feb 07 jari 232   
2 26 Feb 07 jari 233   public void mousePressed(MouseEvent event) {
2 26 Feb 07 jari 234       maybeShowPopup(event);
2 26 Feb 07 jari 235   }
2 26 Feb 07 jari 236   
2 26 Feb 07 jari 237   private void maybeShowPopup(MouseEvent e) {
2 26 Feb 07 jari 238             //System.out.println("maybeShowPopup");
2 26 Feb 07 jari 239       //if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) {
2 26 Feb 07 jari 240            if (!e.isPopupTrigger()) { 
2 26 Feb 07 jari 241     return;
2 26 Feb 07 jari 242       }
2 26 Feb 07 jari 243       popup.show(e.getComponent(), e.getX(), e.getY());
2 26 Feb 07 jari 244   }          
2 26 Feb 07 jari 245         
2 26 Feb 07 jari 246     } 
2 26 Feb 07 jari 247     
2 26 Feb 07 jari 248 }