mev-4.0.01/source/org/tigr/microarray/mev/cluster/clusterUtil/ClusterTable.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: ClusterTable.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.11 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:49:52 $
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.clusterUtil;
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.Component;
2 26 Feb 07 jari 17 import java.awt.Dimension;
2 26 Feb 07 jari 18 import java.awt.Font;
2 26 Feb 07 jari 19 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 20 import java.awt.GridBagLayout;
2 26 Feb 07 jari 21 import java.awt.Insets;
2 26 Feb 07 jari 22 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 23 import java.awt.event.ActionListener;
2 26 Feb 07 jari 24 import java.awt.event.MouseEvent;
2 26 Feb 07 jari 25 import java.awt.event.MouseListener;
2 26 Feb 07 jari 26 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 27 import java.beans.Expression;
2 26 Feb 07 jari 28 import java.util.Arrays;
2 26 Feb 07 jari 29 import java.util.Vector;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31 import javax.swing.ButtonGroup;
2 26 Feb 07 jari 32 import javax.swing.JCheckBox;
2 26 Feb 07 jari 33 import javax.swing.JCheckBoxMenuItem;
2 26 Feb 07 jari 34 import javax.swing.JColorChooser;
2 26 Feb 07 jari 35 import javax.swing.JComponent;
2 26 Feb 07 jari 36 import javax.swing.JLabel;
2 26 Feb 07 jari 37 import javax.swing.JMenu;
2 26 Feb 07 jari 38 import javax.swing.JMenuItem;
2 26 Feb 07 jari 39 import javax.swing.JOptionPane;
2 26 Feb 07 jari 40 import javax.swing.JPanel;
2 26 Feb 07 jari 41 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 42 import javax.swing.JRadioButtonMenuItem;
2 26 Feb 07 jari 43 import javax.swing.JScrollPane;
2 26 Feb 07 jari 44 import javax.swing.JTable;
2 26 Feb 07 jari 45 import javax.swing.JTextArea;
2 26 Feb 07 jari 46 import javax.swing.ListSelectionModel;
2 26 Feb 07 jari 47 import javax.swing.event.CellEditorListener;
2 26 Feb 07 jari 48 import javax.swing.event.EventListenerList;
2 26 Feb 07 jari 49 import javax.swing.event.TableModelEvent;
2 26 Feb 07 jari 50 import javax.swing.event.TableModelListener;
2 26 Feb 07 jari 51 import javax.swing.table.AbstractTableModel;
2 26 Feb 07 jari 52 import javax.swing.table.TableCellRenderer;
2 26 Feb 07 jari 53 import javax.swing.table.TableColumn;
2 26 Feb 07 jari 54 import javax.swing.tree.DefaultMutableTreeNode;
2 26 Feb 07 jari 55
2 26 Feb 07 jari 56 import org.tigr.microarray.mev.cluster.gui.Experiment;
2 26 Feb 07 jari 57 import org.tigr.microarray.mev.cluster.gui.IData;
2 26 Feb 07 jari 58 import org.tigr.microarray.mev.cluster.gui.IDisplayMenu;
2 26 Feb 07 jari 59 import org.tigr.microarray.mev.cluster.gui.IFramework;
2 26 Feb 07 jari 60 import org.tigr.microarray.mev.cluster.gui.IViewer;
2 26 Feb 07 jari 61 import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory;
2 26 Feb 07 jari 62
2 26 Feb 07 jari 63 public class ClusterTable extends JPanel implements IViewer {
2 26 Feb 07 jari 64     
2 26 Feb 07 jari 65     private JTable table;
2 26 Feb 07 jari 66     private JPopupMenu menu;
2 26 Feb 07 jari 67     private JScrollPane pane;
2 26 Feb 07 jari 68     private ClusterRepository repository;
2 26 Feb 07 jari 69     private ClusterTableModel model;
2 26 Feb 07 jari 70     private IFramework framework;
2 26 Feb 07 jari 71     private boolean geneClusterTable;
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     /** Creates new ClusterTablePanel */
2 26 Feb 07 jari 74     public ClusterTable(ClusterRepository rep, IFramework framework) {
2 26 Feb 07 jari 75         super(new GridBagLayout());
2 26 Feb 07 jari 76         this.framework = framework;
2 26 Feb 07 jari 77         this.repository = rep;
2 26 Feb 07 jari 78         this.geneClusterTable = rep.isGeneClusterRepository();
2 26 Feb 07 jari 79         setBackground(Color.white);
2 26 Feb 07 jari 80         MenuListener menuListener = new MenuListener();
2 26 Feb 07 jari 81         initializeTable();
2 26 Feb 07 jari 82         initializeMenu(menuListener);
2 26 Feb 07 jari 83     }
2 26 Feb 07 jari 84     
2 26 Feb 07 jari 85     
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     private void initializeTable(){
2 26 Feb 07 jari 88         
2 26 Feb 07 jari 89         Cluster cluster;
2 26 Feb 07 jari 90         ClusterList list;
2 26 Feb 07 jari 91         JLabel colorLabel;
2 26 Feb 07 jari 92         JTextArea remarksTextArea;
2 26 Feb 07 jari 93         
2 26 Feb 07 jari 94         Vector headerVector = new Vector();
2 26 Feb 07 jari 95         headerVector.add("Serial #");
2 26 Feb 07 jari 96         headerVector.add("Source");
2 26 Feb 07 jari 97         headerVector.add("Algorithm Node");
2 26 Feb 07 jari 98         headerVector.add("Cluster Node");
2 26 Feb 07 jari 99         headerVector.add("Cluster Label");
2 26 Feb 07 jari 100         headerVector.add("Remarks");
2 26 Feb 07 jari 101         headerVector.add("Size");
2 26 Feb 07 jari 102         headerVector.add("Color");
2 26 Feb 07 jari 103         headerVector.add("Show Color");
2 26 Feb 07 jari 104         
2 26 Feb 07 jari 105         Vector dataVector = new Vector();
2 26 Feb 07 jari 106         
2 26 Feb 07 jari 107         int row = 0;
2 26 Feb 07 jari 108         for(int i = 0; i < repository.size(); i++){
2 26 Feb 07 jari 109             list = repository.getClusterList(i);
2 26 Feb 07 jari 110             for(int j = 0; j < list.size(); j++){
2 26 Feb 07 jari 111                 cluster = list.getClusterAt(j);
2 26 Feb 07 jari 112                 dataVector.add(new JLabel(String.valueOf(cluster.getSerialNumber())));
2 26 Feb 07 jari 113                 dataVector.add(new JLabel(String.valueOf(cluster.getSource())));
2 26 Feb 07 jari 114                 dataVector.add(new JLabel(String.valueOf(cluster.getAlgorithmName())));
2 26 Feb 07 jari 115                 dataVector.add(new JLabel(String.valueOf(cluster.getClusterID())));
2 26 Feb 07 jari 116                 dataVector.add(cluster.getClusterLabel());
2 26 Feb 07 jari 117                 dataVector.add(cluster.getClusterDescription());
2 26 Feb 07 jari 118                 dataVector.add(new JLabel(String.valueOf(cluster.getSize())));
2 26 Feb 07 jari 119                 dataVector.add(cluster.getClusterColor());
2 26 Feb 07 jari 120                 dataVector.add(new Boolean(cluster.showColor()));
2 26 Feb 07 jari 121                 row++;
2 26 Feb 07 jari 122             }
2 26 Feb 07 jari 123         }
2 26 Feb 07 jari 124         model = new ClusterTableModel(headerVector, dataVector);
2 26 Feb 07 jari 125         table = new JTable(model);
2 26 Feb 07 jari 126         ClusterCellRenderer renderer = new ClusterCellRenderer();
2 26 Feb 07 jari 127         table.setDefaultRenderer(Color.class, renderer);
2 26 Feb 07 jari 128         table.setDefaultRenderer(JLabel.class, renderer);
2 26 Feb 07 jari 129       //  table.setDefaultRenderer(Boolean.class, new javax.swing.table.DefaultTableCellRenderer());
2 26 Feb 07 jari 130         table.setPreferredScrollableViewportSize(new Dimension(450, 175));
2 26 Feb 07 jari 131         table.addMouseListener(new TableListener());
2 26 Feb 07 jari 132         table.setBackground(Color.white);
2 26 Feb 07 jari 133         table.setRowHeight(table.getRowHeight() + 10);
2 26 Feb 07 jari 134         
2 26 Feb 07 jari 135         table.setRowSelectionAllowed(true);
2 26 Feb 07 jari 136         table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
2 26 Feb 07 jari 137         
2 26 Feb 07 jari 138         setInitialColumnWidths();
2 26 Feb 07 jari 139         
2 26 Feb 07 jari 140         model.addTableModelListener(new TableListener());
2 26 Feb 07 jari 141         table.setRowHeight(30);
2 26 Feb 07 jari 142         pane = new JScrollPane(table);
2 26 Feb 07 jari 143         pane.setBackground(Color.white);
2 26 Feb 07 jari 144         
2 26 Feb 07 jari 145         add(pane, new GridBagConstraints(0,0,0,0,1.0,1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0));
2 26 Feb 07 jari 146         validate();
2 26 Feb 07 jari 147     }
2 26 Feb 07 jari 148     
2 26 Feb 07 jari 149     /**
2 26 Feb 07 jari 150      * @param row Removes a row from the table
2 26 Feb 07 jari 151      */
2 26 Feb 07 jari 152     public void removeRow(int row){
2 26 Feb 07 jari 153         model.removeRow(row);
2 26 Feb 07 jari 154     }
2 26 Feb 07 jari 155     
2 26 Feb 07 jari 156     /**
2 26 Feb 07 jari 157      *  Adds a cluster to the table
2 26 Feb 07 jari 158      */
2 26 Feb 07 jari 159     public void addCluster(Cluster cluster){
2 26 Feb 07 jari 160         Vector dataVector = new Vector();
2 26 Feb 07 jari 161         
2 26 Feb 07 jari 162         dataVector.add(new JLabel(String.valueOf(cluster.getSerialNumber())));
2 26 Feb 07 jari 163         dataVector.add(new JLabel(String.valueOf(cluster.getSource())));
2 26 Feb 07 jari 164         dataVector.add(new JLabel(String.valueOf(cluster.getAlgorithmName())));
2 26 Feb 07 jari 165         dataVector.add(new JLabel(String.valueOf(cluster.getClusterID())));
2 26 Feb 07 jari 166         dataVector.add(cluster.getClusterLabel());
2 26 Feb 07 jari 167         JLabel lab = new JLabel();
2 26 Feb 07 jari 168         
2 26 Feb 07 jari 169         dataVector.add(cluster.getClusterDescription());
2 26 Feb 07 jari 170         dataVector.add(new JLabel(String.valueOf(cluster.getSize())));
2 26 Feb 07 jari 171         dataVector.add(cluster.getClusterColor());
2 26 Feb 07 jari 172         dataVector.add(new Boolean(cluster.showColor()));
2 26 Feb 07 jari 173         
2 26 Feb 07 jari 174         model.addRow(dataVector);
2 26 Feb 07 jari 175     }
2 26 Feb 07 jari 176     
2 26 Feb 07 jari 177     private void initializeMenu(MenuListener listener){
2 26 Feb 07 jari 178         JMenuItem item;
2 26 Feb 07 jari 179         this.menu = new JPopupMenu();
2 26 Feb 07 jari 180         
2 26 Feb 07 jari 181         item = new JMenuItem("Modify Attributes", GUIFactory.getIcon("empty16.gif"));
2 26 Feb 07 jari 182         item.setActionCommand("modify-command");
2 26 Feb 07 jari 183         item.addActionListener(listener);
2 26 Feb 07 jari 184         menu.add(item);
2 26 Feb 07 jari 185         menu.addSeparator();
2 26 Feb 07 jari 186         
2 26 Feb 07 jari 187         menu.add(initializeOpenMenu(listener));
2 26 Feb 07 jari 188         menu.addSeparator();
2 26 Feb 07 jari 189         
2 26 Feb 07 jari 190         this.menu.add( initializeClusterOperationsMenu(listener) );
2 26 Feb 07 jari 191         this.menu.addSeparator();
2 26 Feb 07 jari 192         
2 26 Feb 07 jari 193         this.menu.add( initializeSortMenu(listener) );
2 26 Feb 07 jari 194         this.menu.addSeparator();
2 26 Feb 07 jari 195         
2 26 Feb 07 jari 196         this.menu.add( initializeHideMenu(listener) );
2 26 Feb 07 jari 197         this.menu.addSeparator();
2 26 Feb 07 jari 198         
2 26 Feb 07 jari 199         item = new JMenuItem("Delete Selected", GUIFactory.getIcon("delete16.gif"));
2 26 Feb 07 jari 200         item.setActionCommand("delete-command");
2 26 Feb 07 jari 201         item.addActionListener(listener);
2 26 Feb 07 jari 202         this.menu.add(item);
2 26 Feb 07 jari 203         
2 26 Feb 07 jari 204         item = new JMenuItem("Delete All", GUIFactory.getIcon("delete16.gif"));
2 26 Feb 07 jari 205         item.setActionCommand("delete-all-command");
2 26 Feb 07 jari 206         item.addActionListener(listener);
2 26 Feb 07 jari 207         this.menu.add(item);
2 26 Feb 07 jari 208         this.menu.addSeparator();
2 26 Feb 07 jari 209         
2 26 Feb 07 jari 210         item = new JMenuItem("Save Cluster", GUIFactory.getIcon("save16.gif"));
2 26 Feb 07 jari 211         item.setActionCommand("save-cluster-command");
2 26 Feb 07 jari 212         item.addActionListener(listener);
2 26 Feb 07 jari 213         this.menu.add(item);
2 26 Feb 07 jari 214         
2 26 Feb 07 jari 215         this.menu.addSeparator();
2 26 Feb 07 jari 216         
2 26 Feb 07 jari 217         if(repository.isGeneClusterRepository()) {
2 26 Feb 07 jari 218             item = new JMenuItem("Import Gene List", GUIFactory.getIcon("empty.gif"));
2 26 Feb 07 jari 219         } else {
2 26 Feb 07 jari 220             item = new JMenuItem("Import Experiment List", GUIFactory.getIcon("empty.gif"));
2 26 Feb 07 jari 221         }
2 26 Feb 07 jari 222         item.setActionCommand("import-list-command");
2 26 Feb 07 jari 223         item.addActionListener(listener);
2 26 Feb 07 jari 224         this.menu.add(item);
2 26 Feb 07 jari 225         
2 26 Feb 07 jari 226         if(repository.isGeneClusterRepository()) {
2 26 Feb 07 jari 227             menu.addSeparator();
2 26 Feb 07 jari 228             
2 26 Feb 07 jari 229             item = new JMenuItem("Submit Gene List (External Repository)", GUIFactory.getIcon("empty.gif"));
2 26 Feb 07 jari 230             item.setActionCommand("submit-list-command");
2 26 Feb 07 jari 231             item.addActionListener(listener);
2 26 Feb 07 jari 232             this.menu.add(item);
2 26 Feb 07 jari 233         }
2 26 Feb 07 jari 234     }
2 26 Feb 07 jari 235     
2 26 Feb 07 jari 236     private JMenu initializeModifyMenu(MenuListener listener){
2 26 Feb 07 jari 237         JMenu menu = new JMenu("Modify Cluster");
2 26 Feb 07 jari 238         JMenuItem item;
2 26 Feb 07 jari 239         
2 26 Feb 07 jari 240         item = new JMenuItem("Modify Attributes");
2 26 Feb 07 jari 241         item.setActionCommand("modify-command");
2 26 Feb 07 jari 242         item.addActionListener(listener);
2 26 Feb 07 jari 243         menu.add(item);
2 26 Feb 07 jari 244         menu.addSeparator();
2 26 Feb 07 jari 245         
2 26 Feb 07 jari 246         item = new JMenuItem("Modify Membership");
2 26 Feb 07 jari 247         item.setActionCommand("modify-membership-command");
2 26 Feb 07 jari 248         item.addActionListener(listener);
2 26 Feb 07 jari 249         menu.add(item);
2 26 Feb 07 jari 250         
2 26 Feb 07 jari 251         
2 26 Feb 07 jari 252         return menu;
2 26 Feb 07 jari 253     }
2 26 Feb 07 jari 254     
2 26 Feb 07 jari 255     private JMenu initializeOpenMenu(MenuListener listener){
2 26 Feb 07 jari 256         JMenu menu = new JMenu("Open/Launch");
2 26 Feb 07 jari 257         menu.setIcon(GUIFactory.getIcon("open_launch.gif"));
2 26 Feb 07 jari 258         JMenuItem item;
2 26 Feb 07 jari 259         
2 26 Feb 07 jari 260         item = new JMenuItem("Open Cluster Viewer", GUIFactory.getIcon("Open16.gif"));
2 26 Feb 07 jari 261         item.setActionCommand("go-to-origin-command");
2 26 Feb 07 jari 262         item.addActionListener(listener);
2 26 Feb 07 jari 263         menu.add(item);
2 26 Feb 07 jari 264         menu.addSeparator();
2 26 Feb 07 jari 265         
2 26 Feb 07 jari 266         item = new JMenuItem("Launch MeV Session", GUIFactory.getIcon("launch_new_mav.gif"));
2 26 Feb 07 jari 267         item.setActionCommand("launch-new-command");
2 26 Feb 07 jari 268         item.addActionListener(listener);
2 26 Feb 07 jari 269         menu.add(item);
2 26 Feb 07 jari 270         
2 26 Feb 07 jari 271         return menu;
2 26 Feb 07 jari 272     }
2 26 Feb 07 jari 273     
2 26 Feb 07 jari 274     
2 26 Feb 07 jari 275     private JMenu initializeHideMenu(MenuListener listener){
2 26 Feb 07 jari 276         JMenu menu = new JMenu("Hide Columns");
2 26 Feb 07 jari 277         menu.setIcon(GUIFactory.getIcon("empty16.gif"));
2 26 Feb 07 jari 278         JCheckBoxMenuItem item;
2 26 Feb 07 jari 279         
2 26 Feb 07 jari 280         for(int i = 0; i < model.getColumnCount(); i++){
2 26 Feb 07 jari 281             item = new JCheckBoxMenuItem(model.getColumnName(i));
2 26 Feb 07 jari 282             item.setActionCommand("hide-command");
2 26 Feb 07 jari 283             item.setSelected(false);
2 26 Feb 07 jari 284             item.addActionListener(listener);
2 26 Feb 07 jari 285             menu.add(item);
2 26 Feb 07 jari 286         }
2 26 Feb 07 jari 287         menu.addSeparator();
2 26 Feb 07 jari 288         JMenuItem showAll = new JMenuItem("Show All");
2 26 Feb 07 jari 289         showAll.setActionCommand("show-all-command");
2 26 Feb 07 jari 290         showAll.addActionListener(listener);
2 26 Feb 07 jari 291         menu.add(showAll);
2 26 Feb 07 jari 292         return menu;
2 26 Feb 07 jari 293     }
2 26 Feb 07 jari 294     
2 26 Feb 07 jari 295     private JMenu initializeSortMenu(MenuListener listener){
2 26 Feb 07 jari 296         JMenu menu = new JMenu("Sort");
2 26 Feb 07 jari 297         menu.setIcon(GUIFactory.getIcon("empty16.gif"));
2 26 Feb 07 jari 298         JRadioButtonMenuItem item;
2 26 Feb 07 jari 299         ButtonGroup bg = new ButtonGroup();
2 26 Feb 07 jari 300         for(int i = 0; i < model.getColumnCount() - 1; i++){
2 26 Feb 07 jari 301             item = new JRadioButtonMenuItem(model.getColumnName(i));
2 26 Feb 07 jari 302             item.setActionCommand("sort-command");
2 26 Feb 07 jari 303             if((model.getColumnName(i)).equals("Serial #"))
2 26 Feb 07 jari 304                 item.setSelected(true);
2 26 Feb 07 jari 305             else
2 26 Feb 07 jari 306                 item.setSelected(false);
2 26 Feb 07 jari 307             bg.add(item);
2 26 Feb 07 jari 308             item.addActionListener(listener);
2 26 Feb 07 jari 309             menu.add(item);
2 26 Feb 07 jari 310         }
2 26 Feb 07 jari 311         return menu;
2 26 Feb 07 jari 312     }
2 26 Feb 07 jari 313     
2 26 Feb 07 jari 314     private JMenu initializeClusterOperationsMenu(MenuListener listener){
2 26 Feb 07 jari 315         JMenu menu = new JMenu("Cluster Operations");
2 26 Feb 07 jari 316         menu.setIcon(GUIFactory.getIcon("cluster_operations.gif"));
2 26 Feb 07 jari 317         JMenuItem item;
2 26 Feb 07 jari 318         ButtonGroup bg = new ButtonGroup();
2 26 Feb 07 jari 319         for(int i = 0; i < 3; i++){
2 26 Feb 07 jari 320             item = new JMenuItem();
2 26 Feb 07 jari 321             if(i == 0){
2 26 Feb 07 jari 322                 item.setText("Intersection");
2 26 Feb 07 jari 323                 item.setIcon(GUIFactory.getIcon("intersection.gif"));
2 26 Feb 07 jari 324             } else if(i == 1){
2 26 Feb 07 jari 325                 item.setText("Union");
2 26 Feb 07 jari 326                 item.setIcon(GUIFactory.getIcon("union.gif"));
2 26 Feb 07 jari 327             } else if(i == 2){
2 26 Feb 07 jari 328                 item.setText("XOR");
2 26 Feb 07 jari 329                 item.setIcon(GUIFactory.getIcon("xor.gif"));
2 26 Feb 07 jari 330             }
2 26 Feb 07 jari 331             item.setActionCommand("cluster-operations-command");
2 26 Feb 07 jari 332             bg.add(item);
2 26 Feb 07 jari 333             item.addActionListener(listener);
2 26 Feb 07 jari 334             menu.add(item);
2 26 Feb 07 jari 335         }
2 26 Feb 07 jari 336         return menu;
2 26 Feb 07 jari 337     }
2 26 Feb 07 jari 338     
2 26 Feb 07 jari 339     private void setInitialColumnWidths(){
2 26 Feb 07 jari 340         String [] columnNames = model.getColumnNames();
2 26 Feb 07 jari 341         for(int i = 0; i < columnNames.length; i++){
2 26 Feb 07 jari 342             setColumnWidth(columnNames[i]);
2 26 Feb 07 jari 343         }
2 26 Feb 07 jari 344     }
2 26 Feb 07 jari 345     
2 26 Feb 07 jari 346     
2 26 Feb 07 jari 347     private void setColumnWidth(String headerName){
2 26 Feb 07 jari 348         TableColumn column;
2 26 Feb 07 jari 349         int width = 10;
2 26 Feb 07 jari 350         if(headerName.equals("Serial #")){
2 26 Feb 07 jari 351             column = table.getColumn(headerName);
2 26 Feb 07 jari 352             width = 50;
2 26 Feb 07 jari 353             column.setWidth(width);
2 26 Feb 07 jari 354             column.setMaxWidth(width);
2 26 Feb 07 jari 355             column.setMinWidth(width);
2 26 Feb 07 jari 356             column.setPreferredWidth(width);
2 26 Feb 07 jari 357         } else if(headerName.equals("Source")){
2 26 Feb 07 jari 358             column = table.getColumn(headerName);
2 26 Feb 07 jari 359             width = 100;
2 26 Feb 07 jari 360             column.setWidth(width);
2 26 Feb 07 jari 361             column.setPreferredWidth(width);
2 26 Feb 07 jari 362         } else if(headerName.equals("Color")){
2 26 Feb 07 jari 363             column = table.getColumn(headerName);
2 26 Feb 07 jari 364             width = 60;
2 26 Feb 07 jari 365             column.setWidth(width);
2 26 Feb 07 jari 366             column.setPreferredWidth(width);
2 26 Feb 07 jari 367         } else if(headerName.equals("Size")){
2 26 Feb 07 jari 368             column = table.getColumn(headerName);
2 26 Feb 07 jari 369             width = 50;
2 26 Feb 07 jari 370             column.setWidth(width);
2 26 Feb 07 jari 371             column.setMaxWidth(width);
2 26 Feb 07 jari 372             column.setMinWidth(width);
2 26 Feb 07 jari 373             column.setPreferredWidth(width);
2 26 Feb 07 jari 374         }
2 26 Feb 07 jari 375     }
2 26 Feb 07 jari 376     
2 26 Feb 07 jari 377     public class ClusterTableModel extends AbstractTableModel{
2 26 Feb 07 jari 378         
2 26 Feb 07 jari 379         private String [] columnNames;
2 26 Feb 07 jari 380         private Object [][] rowData;
2 26 Feb 07 jari 381         private Row [] rows;
2 26 Feb 07 jari 382         private int colToSort = 0;
2 26 Feb 07 jari 383         
2 26 Feb 07 jari 384         
2 26 Feb 07 jari 385         public ClusterTableModel(Vector columnNames, Vector rowData){
2 26 Feb 07 jari 386             initializeHeader(columnNames);
2 26 Feb 07 jari 387             initializeData(rowData);
2 26 Feb 07 jari 388             rows = new Row[this.rowData.length];
2 26 Feb 07 jari 389             for(int i = 0; i < rows.length; i++){
2 26 Feb 07 jari 390                 rows[i] = new Row();
2 26 Feb 07 jari 391                 rows[i].index = i;
2 26 Feb 07 jari 392             }
2 26 Feb 07 jari 393         }
2 26 Feb 07 jari 394         
2 26 Feb 07 jari 395         private void initializeHeader(Vector headerNames){
2 26 Feb 07 jari 396             columnNames = new String[headerNames.size()];
2 26 Feb 07 jari 397             for(int i = 0; i < headerNames.size(); i++){
2 26 Feb 07 jari 398                 columnNames[i] = (String)headerNames.elementAt(i);
2 26 Feb 07 jari 399             }
2 26 Feb 07 jari 400         }
2 26 Feb 07 jari 401         
2 26 Feb 07 jari 402         private void initializeData(Vector data){
2 26 Feb 07 jari 403             int cnt = 0;
2 26 Feb 07 jari 404             rowData = new Object[(int)(data.size()/columnNames.length)][columnNames.length];
2 26 Feb 07 jari 405             while(cnt < data.size()){
2 26 Feb 07 jari 406                 for(int j = 0; j < columnNames.length; j++){
2 26 Feb 07 jari 407                     rowData[(int)(cnt/columnNames.length)][j] = data.elementAt(cnt);
2 26 Feb 07 jari 408                     cnt++;
2 26 Feb 07 jari 409                 }
2 26 Feb 07 jari 410             }
2 26 Feb 07 jari 411         }
2 26 Feb 07 jari 412         
2 26 Feb 07 jari 413         
2 26 Feb 07 jari 414         public String getColumnName(int col) {
2 26 Feb 07 jari 415             return columnNames[col];
2 26 Feb 07 jari 416         }
2 26 Feb 07 jari 417         
2 26 Feb 07 jari 418         public int getRowCount() { return rowData.length; }
2 26 Feb 07 jari 419         
2 26 Feb 07 jari 420         public int getColumnCount() { return columnNames.length; }
2 26 Feb 07 jari 421         
2 26 Feb 07 jari 422         public Object getValueAt(int row, int col) {
2 26 Feb 07 jari 423             return rowData[rows[row].index][col];
2 26 Feb 07 jari 424         }
2 26 Feb 07 jari 425         
2 26 Feb 07 jari 426         public boolean isCellEditable(int row, int col) {
2 26 Feb 07 jari 427             return (col == 7 || col == 8);
2 26 Feb 07 jari 428         }
2 26 Feb 07 jari 429         
2 26 Feb 07 jari 430         public void setValueAt(Object value, int row, int col) {
2 26 Feb 07 jari 431             rowData[rows[row].index][col] = value;
2 26 Feb 07 jari 432             this.fireTableChanged(new TableModelEvent(this, row, row, col));
2 26 Feb 07 jari 433         }
2 26 Feb 07 jari 434         
2 26 Feb 07 jari 435         public Class getColumnClass(int col){
2 26 Feb 07 jari 436             if(col == 7) return Color.class;
2 26 Feb 07 jari 437             if(col == 4 || col == 5) return String.class;
2 26 Feb 07 jari 438             if(col == 8) return Boolean.class;
2 26 Feb 07 jari 439             else return JLabel.class;
2 26 Feb 07 jari 440         }
2 26 Feb 07 jari 441         
2 26 Feb 07 jari 442         public int getClusterSerialNumber( int row ){
2 26 Feb 07 jari 443             if(isLegalRow(row)){
2 26 Feb 07 jari 444                 return (Integer.parseInt(((JLabel)(getValueAt(row, 0))).getText()));
2 26 Feb 07 jari 445             }
2 26 Feb 07 jari 446             return -1;
2 26 Feb 07 jari 447         }
2 26 Feb 07 jari 448         
2 26 Feb 07 jari 449         public boolean isLegalRow(int row){
2 26 Feb 07 jari 450             return (row > -1 && row < getRowCount());
2 26 Feb 07 jari 451         }
2 26 Feb 07 jari 452         
2 26 Feb 07 jari 453         public boolean isLegalColumn(int col){
2 26 Feb 07 jari 454             return (col > -1 && col < getColumnCount());
2 26 Feb 07 jari 455         }
2 26 Feb 07 jari 456         
2 26 Feb 07 jari 457         /** Sorts table rows based on column index.
2 26 Feb 07 jari 458          * @param c Column to use as sort key when sorting columns
2 26 Feb 07 jari 459          */
2 26 Feb 07 jari 460         public void sort(int c){
2 26 Feb 07 jari 461             colToSort = c;
2 26 Feb 07 jari 462             Arrays.sort(rows);
2 26 Feb 07 jari 463             table.repaint();
2 26 Feb 07 jari 464         }
2 26 Feb 07 jari 465         
2 26 Feb 07 jari 466         /** Sorts table rows by column header key.
2 26 Feb 07 jari 467          * @param key <CODE>String</CODE> key to identify sort column.
2 26 Feb 07 jari 468          */
2 26 Feb 07 jari 469         public void sortBy(String key){
2 26 Feb 07 jari 470             int col = getColumnIndex(key);
2 26 Feb 07 jari 471             
2 26 Feb 07 jari 472             if(col >= 0){
2 26 Feb 07 jari 473                 sort(col);
2 26 Feb 07 jari 474                 colToSort = col;
2 26 Feb 07 jari 475             }
2 26 Feb 07 jari 476         }
2 26 Feb 07 jari 477         
2 26 Feb 07 jari 478         private int getColumnIndex(String key){
2 26 Feb 07 jari 479             for(int i = 0; i < columnNames.length; i++){
2 26 Feb 07 jari 480                 if(columnNames[i] == key)
2 26 Feb 07 jari 481                     return i;
2 26 Feb 07 jari 482             }
2 26 Feb 07 jari 483             return 0;
2 26 Feb 07 jari 484         }
2 26 Feb 07 jari 485         
2 26 Feb 07 jari 486         public String [] getColumnNames(){ return this.columnNames; }
2 26 Feb 07 jari 487         
2 26 Feb 07 jari 488         public void hide(String columnName){
2 26 Feb 07 jari 489             table.removeColumn(table.getColumn(columnName));
2 26 Feb 07 jari 490         }
2 26 Feb 07 jari 491         
2 26 Feb 07 jari 492         public void addColumn(String columnName){
2 26 Feb 07 jari 493             table.addColumn( new TableColumn(getColumnIndex(columnName)));
2 26 Feb 07 jari 494             moveColumnFromEnd(getColumnIndex(columnName));
2 26 Feb 07 jari 495         }
2 26 Feb 07 jari 496         
2 26 Feb 07 jari 497         public void addRow(Vector data){
2 26 Feb 07 jari 498             Object [][] newData = new Object[rowData.length+1][columnNames.length];
2 26 Feb 07 jari 499             
2 26 Feb 07 jari 500             for(int i = 0; i < rowData.length; i++){
2 26 Feb 07 jari 501                 for(int j = 0; j < rowData[i].length; j++){
2 26 Feb 07 jari 502                     newData[i][j] = rowData[i][j];
2 26 Feb 07 jari 503                 }
2 26 Feb 07 jari 504             }
2 26 Feb 07 jari 505             for(int i = 0; i < this.columnNames.length; i++){
2 26 Feb 07 jari 506                 newData[newData.length -1][i] = data.elementAt(i);
2 26 Feb 07 jari 507             }
2 26 Feb 07 jari 508             rowData = newData;
2 26 Feb 07 jari 509             
2 26 Feb 07 jari 510             Row [] newRows = new Row[this.rowData.length];
2 26 Feb 07 jari 511             
2 26 Feb 07 jari 512             for(int i = 0; i < rows.length; i++){
2 26 Feb 07 jari 513                 newRows[i] = rows[i];
2 26 Feb 07 jari 514             }
2 26 Feb 07 jari 515             newRows[newRows.length-1] = new Row();
2 26 Feb 07 jari 516             newRows[newRows.length-1].index = newRows.length-1;
2 26 Feb 07 jari 517             rows = newRows;
2 26 Feb 07 jari 518             this.fireTableRowsInserted(rows.length-1, rows.length-1);
2 26 Feb 07 jari 519         }
2 26 Feb 07 jari 520         
2 26 Feb 07 jari 521         public void removeRow(int tableRow){
2 26 Feb 07 jari 522             int row = rows[tableRow].index;
2 26 Feb 07 jari 523             Object [][] newData = new Object[rowData.length-1][rowData[0].length];
2 26 Feb 07 jari 524             int currRow = -1;
2 26 Feb 07 jari 525             for(int i = 0; i < rowData.length; i++){
2 26 Feb 07 jari 526                 if(i != row){
2 26 Feb 07 jari 527                     currRow++;
2 26 Feb 07 jari 528                     for(int j = 0; j < rowData[i].length; j++){
2 26 Feb 07 jari 529                         newData[currRow][j] = rowData[i][j];
2 26 Feb 07 jari 530                     }
2 26 Feb 07 jari 531                 }
2 26 Feb 07 jari 532             }
2 26 Feb 07 jari 533             rowData = newData;
2 26 Feb 07 jari 534             Row [] newRows = new Row[this.rowData.length];
2 26 Feb 07 jari 535             currRow = -1;
2 26 Feb 07 jari 536             for(int i = 0; i < rows.length; i++){
2 26 Feb 07 jari 537                 if(i != row){
2 26 Feb 07 jari 538                     currRow++;
2 26 Feb 07 jari 539                     newRows[currRow] = rows[i];
2 26 Feb 07 jari 540                     newRows[currRow].index = currRow;
2 26 Feb 07 jari 541                 }
2 26 Feb 07 jari 542             }
2 26 Feb 07 jari 543             rows = newRows;
2 26 Feb 07 jari 544             this.fireTableRowsDeleted(row,row);
2 26 Feb 07 jari 545         }
2 26 Feb 07 jari 546         
2 26 Feb 07 jari 547         public void removeAllRows(){
2 26 Feb 07 jari 548             int numRows = rows.length;
2 26 Feb 07 jari 549             rowData = new Object[0][0];
2 26 Feb 07 jari 550             rows = new Row[0];
2 26 Feb 07 jari 551             this.fireTableRowsDeleted(0, numRows);
2 26 Feb 07 jari 552         }
2 26 Feb 07 jari 553         
2 26 Feb 07 jari 554         private void moveColumnFromEnd(int finalLocation){
2 26 Feb 07 jari 555             for(int i = table.getColumnCount()-1; i > finalLocation; i--)
2 26 Feb 07 jari 556                 table.moveColumn(i-1,i);
2 26 Feb 07 jari 557         }
2 26 Feb 07 jari 558         
2 26 Feb 07 jari 559         public int getSerialNumber(int row){
2 26 Feb 07 jari 560             JLabel serialLabel = (JLabel)(rowData[rows[row].index][0]);
2 26 Feb 07 jari 561             return Integer.parseInt(serialLabel.getText());
2 26 Feb 07 jari 562         }
2 26 Feb 07 jari 563         
2 26 Feb 07 jari 564         public void setClusterColor(int tableRow, Color clusterColor){
2 26 Feb 07 jari 565             int row = rows[tableRow].index;
2 26 Feb 07 jari 566             int col = this.getColumnIndex("Color");
2 26 Feb 07 jari 567             setValueAt(clusterColor, row, col);
2 26 Feb 07 jari 568             this.fireTableCellUpdated(tableRow, col);
2 26 Feb 07 jari 569         }
2 26 Feb 07 jari 570         
2 26 Feb 07 jari 571         public void setClusterLabel(int tableRow, String clusterLabel){
2 26 Feb 07 jari 572             int row = rows[tableRow].index;
2 26 Feb 07 jari 573             int col = this.getColumnIndex("Cluster Label");
2 26 Feb 07 jari 574             setValueAt(clusterLabel, row, col);
2 26 Feb 07 jari 575             this.fireTableCellUpdated(tableRow, col);
2 26 Feb 07 jari 576         }
2 26 Feb 07 jari 577         
2 26 Feb 07 jari 578         public void setClusterDescription(int tableRow, String clusterDescription){
2 26 Feb 07 jari 579             int row = rows[tableRow].index;
2 26 Feb 07 jari 580             int col = this.getColumnIndex("Remarks");
2 26 Feb 07 jari 581             setValueAt(clusterDescription, row, col);
2 26 Feb 07 jari 582             this.fireTableCellUpdated(tableRow, col);
2 26 Feb 07 jari 583         }
2 26 Feb 07 jari 584         
2 26 Feb 07 jari 585         
2 26 Feb 07 jari 586         private class Row implements Comparable{
2 26 Feb 07 jari 587             public int index;
2 26 Feb 07 jari 588             private String myString, otherString;
2 26 Feb 07 jari 589             
2 26 Feb 07 jari 590             public int compareTo(Object other){
2 26 Feb 07 jari 591                 Row otherRow = (Row)other;
2 26 Feb 07 jari 592                 Object myObject = rowData[index][colToSort];
2 26 Feb 07 jari 593                 Object otherObject = rowData[otherRow.index][colToSort];
2 26 Feb 07 jari 594                 if(model.getColumnName(colToSort).equals("Serial #") ||
2 26 Feb 07 jari 595                 model.getColumnName(colToSort).equals("Size")){
2 26 Feb 07 jari 596                     Integer i;
2 26 Feb 07 jari 597                     i = new Integer(((JLabel)rowData[index][colToSort]).getText());
2 26 Feb 07 jari 598                     return i.compareTo(new Integer(((JLabel)(otherObject)).getText()));
2 26 Feb 07 jari 599                 }
2 26 Feb 07 jari 600                 if( myObject instanceof Comparable )
2 26 Feb 07 jari 601                     return ((Comparable)myObject).compareTo(otherObject);
2 26 Feb 07 jari 602                 if(myObject instanceof JLabel){
2 26 Feb 07 jari 603                     myString = ((JLabel)(myObject)).getText();
2 26 Feb 07 jari 604                     otherString = ((JLabel)(otherObject)).getText();
2 26 Feb 07 jari 605                     return myString.compareTo(otherString);
2 26 Feb 07 jari 606                 }
2 26 Feb 07 jari 607                 else return index - otherRow.index;
2 26 Feb 07 jari 608             }
2 26 Feb 07 jari 609         }
2 26 Feb 07 jari 610     }
2 26 Feb 07 jari 611     
2 26 Feb 07 jari 612     
2 26 Feb 07 jari 613     public class ClusterCellRenderer implements TableCellRenderer{
2 26 Feb 07 jari 614         
2 26 Feb 07 jari 615         private JPanel colorPanel = new JPanel();
2 26 Feb 07 jari 616         private JLabel label;
2 26 Feb 07 jari 617         private JTextArea textArea;
2 26 Feb 07 jari 618         
2 26 Feb 07 jari 619         public ClusterCellRenderer(){
2 26 Feb 07 jari 620             
2 26 Feb 07 jari 621         }
2 26 Feb 07 jari 622         
2 26 Feb 07 jari 623         public Component getTableCellRendererComponent(JTable jTable, Object obj, boolean param, boolean param3, int row, int col) {
2 26 Feb 07 jari 624             if(obj instanceof Color){
2 26 Feb 07 jari 625                 colorPanel.setBackground((Color)obj);
2 26 Feb 07 jari 626                 return colorPanel;
2 26 Feb 07 jari 627             } else if(obj instanceof JLabel){
2 26 Feb 07 jari 628                 label = (JLabel)obj;
2 26 Feb 07 jari 629                 label.setOpaque(true);
2 26 Feb 07 jari 630                 label.setFont(new Font("Arial", Font.PLAIN, 12));
2 26 Feb 07 jari 631                 label.setBackground(new Color(225, 225, 225));
2 26 Feb 07 jari 632                 label.setForeground(Color.black);
2 26 Feb 07 jari 633                 label.setHorizontalAlignment(JLabel.CENTER);
2 26 Feb 07 jari 634                 if(table.isRowSelected(row))
2 26 Feb 07 jari 635                     label.setBackground(table.getSelectionBackground());
2 26 Feb 07 jari 636                 return label;
2 26 Feb 07 jari 637             } else if(obj instanceof JTextArea){
2 26 Feb 07 jari 638                 textArea = (JTextArea)obj;
2 26 Feb 07 jari 639                 if(table.isRowSelected(row))
2 26 Feb 07 jari 640                     textArea.setBackground(table.getSelectionBackground());
2 26 Feb 07 jari 641                 return textArea;
2 26 Feb 07 jari 642             } else if(obj instanceof Boolean) {
2 26 Feb 07 jari 643                 System.out.println("Handle Boolean");
2 26 Feb 07 jari 644                 JCheckBox box = new JCheckBox();
2 26 Feb 07 jari 645                 box.setBackground(Color.white);
2 26 Feb 07 jari 646                 box.setHorizontalAlignment(JCheckBox.CENTER);
2 26 Feb 07 jari 647                 box.setSelected(((Boolean)obj).booleanValue());
2 26 Feb 07 jari 648                 return box;
2 26 Feb 07 jari 649             }
2 26 Feb 07 jari 650             colorPanel.setBackground(Color.white);
2 26 Feb 07 jari 651             return colorPanel;
2 26 Feb 07 jari 652         }
2 26 Feb 07 jari 653     }
2 26 Feb 07 jari 654     
2 26 Feb 07 jari 655     
2 26 Feb 07 jari 656     
2 26 Feb 07 jari 657     public class TableListener implements TableModelListener, MouseListener{
2 26 Feb 07 jari 658         
2 26 Feb 07 jari 659         public TableListener(){
2 26 Feb 07 jari 660             super();
2 26 Feb 07 jari 661         }
2 26 Feb 07 jari 662         
2 26 Feb 07 jari 663         public void tableChanged(TableModelEvent tableModelEvent) {
2 26 Feb 07 jari 664         }
2 26 Feb 07 jari 665         
2 26 Feb 07 jari 666         public void mouseExited(MouseEvent mouseEvent) {
2 26 Feb 07 jari 667         }
2 26 Feb 07 jari 668         
2 26 Feb 07 jari 669         public void mouseReleased(MouseEvent mouseEvent) {
2 26 Feb 07 jari 670             if(!mouseEvent.isPopupTrigger()){
2 26 Feb 07 jari 671                 int col = table.getSelectedColumn();
2 26 Feb 07 jari 672                 int row = table.getSelectedRow();
2 26 Feb 07 jari 673                 if(!model.isLegalRow(row) || !model.isLegalColumn(col))
2 26 Feb 07 jari 674                     return;
2 26 Feb 07 jari 675                 if(table.getColumnClass(col) == Color.class)
2 26 Feb 07 jari 676                     modifyColor(row, col);
2 26 Feb 07 jari 677                 else if(table.getColumnClass(col) == Boolean.class)
2 26 Feb 07 jari 678                     modifyShowColor(row, col);
2 26 Feb 07 jari 679             } else {
2 26 Feb 07 jari 680                 if(mouseEvent.isPopupTrigger()){
2 26 Feb 07 jari 681                     int menuSize = menu.getComponentCount();
2 26 Feb 07 jari 682                     int selectionSize = table.getSelectedRowCount();
2 26 Feb 07 jari 683                     int [] selectedRows = table.getSelectedRows();
2 26 Feb 07 jari 684                     if(selectionSize < 1)
2 26 Feb 07 jari 685                         return;
2 26 Feb 07 jari 686                     enableAllMenuItems();
2 26 Feb 07 jari 687                     Component component;
2 26 Feb 07 jari 688                     JMenuItem item;
2 26 Feb 07 jari 689                     JMenu aMenu;
2 26 Feb 07 jari 690                     String menuString;
2 26 Feb 07 jari 691                     for(int i = 0; i < menuSize; i++){
2 26 Feb 07 jari 692                         component = menu.getComponent(i);
2 26 Feb 07 jari 693                         if(component instanceof JMenuItem){
2 26 Feb 07 jari 694                             item = (JMenuItem)component;
2 26 Feb 07 jari 695                             menuString = item.getText();
2 26 Feb 07 jari 696                             if(selectionSize != 1 && menuString.equals("Modify Attributes"))
2 26 Feb 07 jari 697                                 component.setEnabled(false);
2 26 Feb 07 jari 698                             if( selectionSize != 1 && menuString.equals("Save Cluster"))
2 26 Feb 07 jari 699                                 component.setEnabled(false);
2 26 Feb 07 jari 700                             if(selectionSize < 2 && menuString.equals("Cluster Operations"))
2 26 Feb 07 jari 701                                 component.setEnabled(false);
2 26 Feb 07 jari 702                             if(selectionSize != 1 &&  menuString.equals("Modify Cluster"))
2 26 Feb 07 jari 703                                 component.setEnabled(false);
2 26 Feb 07 jari 704                             if(selectionSize != 1 && menuString.equals("Open/Launch")){
2 26 Feb 07 jari 705                                 ((JMenu)item).getMenuComponent(0).setEnabled(false);
2 26 Feb 07 jari 706                             } else if(menuString.equals("Open/Launch") && !(repository.getCluster(model.getSerialNumber(selectedRows[0])).getSource().equals("Algorithm"))) {
2 26 Feb 07 jari 707                                 ((JMenu)item).getMenuComponent(0).setEnabled(false);
2 26 Feb 07 jari 708                             }
2 26 Feb 07 jari 709                             
2 26 Feb 07 jari 710                         } else if(component instanceof JMenu){
2 26 Feb 07 jari 711                             aMenu = (JMenu)component;
2 26 Feb 07 jari 712                             menuString = aMenu.getText();
2 26 Feb 07 jari 713                             if(selectionSize != 1 && ( menuString.equals("Modify Cluster") || menuString.equals("Open/Launch")))
2 26 Feb 07 jari 714                                 aMenu.setEnabled(false);
2 26 Feb 07 jari 715                             else if(menuString.equals("Open/Lanuch") && !(repository.getCluster(model.getSerialNumber(selectedRows[0])).getSource().equals("Algorithm"))) {
2 26 Feb 07 jari 716                                 aMenu.getMenuComponent(1).setEnabled(false);
2 26 Feb 07 jari 717                             } else
2 26 Feb 07 jari 718                                 aMenu.setEnabled(true);
2 26 Feb 07 jari 719                         }
2 26 Feb 07 jari 720                     }
2 26 Feb 07 jari 721                     menu.show(table, mouseEvent.getX(), mouseEvent.getY());
2 26 Feb 07 jari 722                 }
2 26 Feb 07 jari 723             }
2 26 Feb 07 jari 724             
2 26 Feb 07 jari 725         }
2 26 Feb 07 jari 726         
2 26 Feb 07 jari 727         public void mousePressed(MouseEvent mouseEvent) {
2 26 Feb 07 jari 728             String command;
2 26 Feb 07 jari 729             Component component;
2 26 Feb 07 jari 730             if(mouseEvent.isPopupTrigger()){
2 26 Feb 07 jari 731                 int menuSize = menu.getComponentCount();
2 26 Feb 07 jari 732                 int selectionSize = table.getSelectedRowCount();
2 26 Feb 07 jari 733                 int [] selectedRows = table.getSelectedRows();
2 26 Feb 07 jari 734                 if(selectionSize < 1)
2 26 Feb 07 jari 735                     return;
2 26 Feb 07 jari 736                 enableAllMenuItems();
2 26 Feb 07 jari 737                 JMenuItem item;
2 26 Feb 07 jari 738                 JMenu aMenu;
2 26 Feb 07 jari 739                 String menuString;
2 26 Feb 07 jari 740                 for(int i = 0; i < menuSize; i++){
2 26 Feb 07 jari 741                     component = menu.getComponent(i);
2 26 Feb 07 jari 742                     if(component instanceof JMenuItem){
2 26 Feb 07 jari 743                         item = (JMenuItem)component;
2 26 Feb 07 jari 744                         menuString = item.getText();
2 26 Feb 07 jari 745                         if( selectionSize != 1 && menuString.equals("Modify Attributes"))
2 26 Feb 07 jari 746                             component.setEnabled(false);
2 26 Feb 07 jari 747                         if( selectionSize != 1 && menuString.equals("Save Cluster"))
2 26 Feb 07 jari 748                             component.setEnabled(false);
2 26 Feb 07 jari 749                         if(selectionSize < 2 && menuString.equals("Cluster Operations"))
2 26 Feb 07 jari 750                             component.setEnabled(false);
2 26 Feb 07 jari 751                         if(selectionSize != 1 &&  menuString.equals("Modify Cluster"))
2 26 Feb 07 jari 752                             component.setEnabled(false);
2 26 Feb 07 jari 753                         if(selectionSize != 1 && menuString.equals("Open/Launch")){
2 26 Feb 07 jari 754                             ((JMenu)item).getMenuComponent(0).setEnabled(false);
2 26 Feb 07 jari 755                         } else if(menuString.equals("Open/Launch") && !(repository.getCluster(model.getSerialNumber(selectedRows[0])).getSource().equals("Algorithm"))) {
2 26 Feb 07 jari 756                             ((JMenu)item).getMenuComponent(0).setEnabled(false);
2 26 Feb 07 jari 757                         }
2 26 Feb 07 jari 758                         
2 26 Feb 07 jari 759                     } else if(component instanceof JMenu){
2 26 Feb 07 jari 760                         aMenu = (JMenu)component;
2 26 Feb 07 jari 761                         menuString = aMenu.getText();
2 26 Feb 07 jari 762                         if(selectionSize != 1 && ( menuString.equals("Modify Cluster") || menuString.equals("Open/Launch")))
2 26 Feb 07 jari 763                             aMenu.setEnabled(false);
2 26 Feb 07 jari 764                         else if(menuString.equals("Open/Lanuch") && !(repository.getCluster(model.getSerialNumber(selectedRows[0])).getSource().equals("Algorithm"))) {
2 26 Feb 07 jari 765                             aMenu.getMenuComponent(1).setEnabled(false);
2 26 Feb 07 jari 766                         } else
2 26 Feb 07 jari 767                             aMenu.setEnabled(true);
2 26 Feb 07 jari 768                     }
2 26 Feb 07 jari 769                 }
2 26 Feb 07 jari 770                 menu.show(table, mouseEvent.getX(), mouseEvent.getY());
2 26 Feb 07 jari 771             }
2 26 Feb 07 jari 772         }
2 26 Feb 07 jari 773         
2 26 Feb 07 jari 774         public void mouseClicked(MouseEvent mouseEvent) {
2 26 Feb 07 jari 775         }
2 26 Feb 07 jari 776         
2 26 Feb 07 jari 777         public void mouseEntered(MouseEvent mouseEvent) {
2 26 Feb 07 jari 778         }
2 26 Feb 07 jari 779     }
2 26 Feb 07 jari 780     
2 26 Feb 07 jari 781     public class ClusterCellEditor implements javax.swing.table.TableCellEditor{
2 26 Feb 07 jari 782         
2 26 Feb 07 jari 783         JTextArea textArea;
2 26 Feb 07 jari 784         javax.swing.event.EventListenerList list = new EventListenerList();
2 26 Feb 07 jari 785         
2 26 Feb 07 jari 786         public ClusterCellEditor(JTextArea ta){
2 26 Feb 07 jari 787             textArea = ta;
2 26 Feb 07 jari 788         }
2 26 Feb 07 jari 789         
2 26 Feb 07 jari 790         public void addCellEditorListener(CellEditorListener cellEditorListener) {
2 26 Feb 07 jari 791             list.add(CellEditorListener.class, cellEditorListener);
2 26 Feb 07 jari 792         }
2 26 Feb 07 jari 793         
2 26 Feb 07 jari 794         public java.awt.Component getTableCellEditorComponent(javax.swing.JTable jTable, java.lang.Object obj, boolean param, int param3, int param4) {
2 26 Feb 07 jari 795             if(obj instanceof JTextArea){
2 26 Feb 07 jari 796                 textArea.setText(((JTextArea)obj).getText());
2 26 Feb 07 jari 797                 textArea.selectAll();
2 26 Feb 07 jari 798                 textArea.setCaretPosition(0);
2 26 Feb 07 jari 799                 return textArea;
2 26 Feb 07 jari 800             }
2 26 Feb 07 jari 801             else
2 26 Feb 07 jari 802                 return (Component)obj;
2 26 Feb 07 jari 803         }
2 26 Feb 07 jari 804         
2 26 Feb 07 jari 805         public void cancelCellEditing() {
2 26 Feb 07 jari 806             textArea = null;
2 26 Feb 07 jari 807         }
2 26 Feb 07 jari 808         
2 26 Feb 07 jari 809         public boolean isCellEditable(java.util.EventObject eventObject) {
2 26 Feb 07 jari 810             return true;
2 26 Feb 07 jari 811         }
2 26 Feb 07 jari 812         
2 26 Feb 07 jari 813         public void removeCellEditorListener(javax.swing.event.CellEditorListener cellEditorListener) {
2 26 Feb 07 jari 814         }
2 26 Feb 07 jari 815         
2 26 Feb 07 jari 816         public java.lang.Object getCellEditorValue() {
2 26 Feb 07 jari 817             return textArea;
2 26 Feb 07 jari 818         }
2 26 Feb 07 jari 819         
2 26 Feb 07 jari 820         public boolean stopCellEditing() {
2 26 Feb 07 jari 821             if(textArea != null)
2 26 Feb 07 jari 822                 (repository.getCluster(model.getClusterSerialNumber(table.getSelectedRow()))).setClusterDescription(textArea.getText());
2 26 Feb 07 jari 823             return true;
2 26 Feb 07 jari 824         }
2 26 Feb 07 jari 825         
2 26 Feb 07 jari 826         public boolean shouldSelectCell(java.util.EventObject eventObject) {
2 26 Feb 07 jari 827             return true;
2 26 Feb 07 jari 828         }
2 26 Feb 07 jari 829         
2 26 Feb 07 jari 830     }
2 26 Feb 07 jari 831     
2 26 Feb 07 jari 832     
2 26 Feb 07 jari 833     
2 26 Feb 07 jari 834     public class MenuListener implements ActionListener{
2 26 Feb 07 jari 835         
2 26 Feb 07 jari 836         public void actionPerformed(ActionEvent actionEvent) {
2 26 Feb 07 jari 837             String command = actionEvent.getActionCommand();
2 26 Feb 07 jari 838             String key;
2 26 Feb 07 jari 839             if(command.equals("hide-command")) {
2 26 Feb 07 jari 840                 if( ((JCheckBoxMenuItem)actionEvent.getSource()).isSelected())
2 26 Feb 07 jari 841                     model.hide(((JCheckBoxMenuItem)actionEvent.getSource()).getText());
2 26 Feb 07 jari 842                 else
2 26 Feb 07 jari 843                     model.addColumn(((JCheckBoxMenuItem)actionEvent.getSource()).getText());
2 26 Feb 07 jari 844             } else if(command.equals("show-all-command")) {
2 26 Feb 07 jari 845                 showAllColumns();
2 26 Feb 07 jari 846             } else if(command.equals("sort-command")) {
2 26 Feb 07 jari 847                 model.sortBy(((JRadioButtonMenuItem)actionEvent.getSource()).getText());
2 26 Feb 07 jari 848             } else if(command.equals("modify-command")) {
2 26 Feb 07 jari 849                 modifyClusterAttributes();
2 26 Feb 07 jari 850             } else if(command.equals("modify-membership-command")) {
2 26 Feb 07 jari 851                 
2 26 Feb 07 jari 852             } else if(command.equals("go-to-origin-command")) {
2 26 Feb 07 jari 853                 openClusterNode();
2 26 Feb 07 jari 854             } else if(command.equals("launch-new-command")) {
2 26 Feb 07 jari 855                 launchNewMevSession();
2 26 Feb 07 jari 856             } else if(command.equals("cluster-operations-command")) {
2 26 Feb 07 jari 857                 performClusterOperation(((JMenuItem)(actionEvent.getSource())).getText());
2 26 Feb 07 jari 858             } else if(command.equals("delete-command")) {
2 26 Feb 07 jari 859                 deleteSelectedRows();
2 26 Feb 07 jari 860             } else if(command.equals("delete-all-command")) {
2 26 Feb 07 jari 861                 deleteAllRows();
2 26 Feb 07 jari 862             } else if(command.equals("save-cluster-command")){
2 26 Feb 07 jari 863                 saveCluster();
2 26 Feb 07 jari 864             } else if(command.equals("import-list-command")){
2 26 Feb 07 jari 865                 Cluster newCluster = repository.createClusterFromList();
2 26 Feb 07 jari 866                 if(newCluster != null)
2 26 Feb 07 jari 867                     addCluster(newCluster);
2 26 Feb 07 jari 868             } else if(command.equals("submit-list-command")) {
2 26 Feb 07 jari 869                 submitCluster();
2 26 Feb 07 jari 870             }
2 26 Feb 07 jari 871         }
2 26 Feb 07 jari 872     }
2 26 Feb 07 jari 873     
2 26 Feb 07 jari 874     /**
2 26 Feb 07 jari 875      * Invoked by the framework when this viewer was deselected.
2 26 Feb 07 jari 876      */
2 26 Feb 07 jari 877     public void onDeselected() {
2 26 Feb 07 jari 878     }
2 26 Feb 07 jari 879     
2 26 Feb 07 jari 880     /**
2 26 Feb 07 jari 881      * Invoked by the framework when data is changed,
2 26 Feb 07 jari 882      * if this viewer is selected.
2 26 Feb 07 jari 883      * @see IData
2 26 Feb 07 jari 884      */
2 26 Feb 07 jari 885     public void onDataChanged(IData data) {
2 26 Feb 07 jari 886         repaint();
2 26 Feb 07 jari 887     }
2 26 Feb 07 jari 888     
2 26 Feb 07 jari 889     /**
2 26 Feb 07 jari 890      * Invoked when the framework is going to be closed.
2 26 Feb 07 jari 891      */
2 26 Feb 07 jari 892     public void onClosed() {
2 26 Feb 07 jari 893     }
2 26 Feb 07 jari 894     
2 26 Feb 07 jari 895     /**
2 26 Feb 07 jari 896      * Returns a component to be inserted into scroll pane view port.
2 26 Feb 07 jari 897      */
2 26 Feb 07 jari 898     public JComponent getContentComponent() {
2 26 Feb 07 jari 899         return table;
2 26 Feb 07 jari 900     }
2 26 Feb 07 jari 901     
2 26 Feb 07 jari 902     /**
2 26 Feb 07 jari 903      * Invoked by the framework to save or to print viewer image.
2 26 Feb 07 jari 904      */
2 26 Feb 07 jari 905     public BufferedImage getImage() {
2 26 Feb 07 jari 906         return null;
2 26 Feb 07 jari 907     }
2 26 Feb 07 jari 908     
2 26 Feb 07 jari 909     /**
2 26 Feb 07 jari 910      * Invoked by the framework when this viewer is selected.
2 26 Feb 07 jari 911      */
2 26 Feb 07 jari 912     public void onSelected(IFramework framework) {
2 26 Feb 07 jari 913         this.table.getSelectionModel().setSelectionInterval(0,0);
2 26 Feb 07 jari 914         repaint();
2 26 Feb 07 jari 915     }
2 26 Feb 07 jari 916     
2 26 Feb 07 jari 917     /**
2 26 Feb 07 jari 918      * Invoked by the framework when display menu is changed,
2 26 Feb 07 jari 919      * if this viewer is selected.
2 26 Feb 07 jari 920      * @see IDisplayMenu
2 26 Feb 07 jari 921      */
2 26 Feb 07 jari 922     public void onMenuChanged(IDisplayMenu menu) {
2 26 Feb 07 jari 923     }
2 26 Feb 07 jari 924     
2 26 Feb 07 jari 925     /**
2 26 Feb 07 jari 926      * Returns a component to be inserted into scroll pane header.
2 26 Feb 07 jari 927      */
2 26 Feb 07 jari 928     public JComponent getHeaderComponent() {
2 26 Feb 07 jari 929         return table.getTableHeader();
2 26 Feb 07 jari 930     }
2 26 Feb 07 jari 931     
2 26 Feb 07 jari 932     /**
2 26 Feb 07 jari 933      * Updates the cluster table to reflect a change in the repository
2 26 Feb 07 jari 934      */
2 26 Feb 07 jari 935     public void onRepositoryChanged(ClusterRepository cr){
2 26 Feb 07 jari 936         this.repository = cr;
2 26 Feb 07 jari 937         initializeTable();
2 26 Feb 07 jari 938         imposeHideMenu();
2 26 Feb 07 jari 939         this.validate();
2 26 Feb 07 jari 940         model.sortBy("Serial #");
2 26 Feb 07 jari 941         model.fireTableDataChanged();
2 26 Feb 07 jari 942         model.fireTableChanged(new TableModelEvent(model));
2 26 Feb 07 jari 943     }
2 26 Feb 07 jari 944     
2 26 Feb 07 jari 945     private void imposeHideMenu(){
2 26 Feb 07 jari 946         Component component;
2 26 Feb 07 jari 947         JMenu hideMenu = (JMenu)(menu.getComponent(8));
2 26 Feb 07 jari 948         
2 26 Feb 07 jari 949         JMenuItem item;
2 26 Feb 07 jari 950         for(int i = 0; i < hideMenu.getMenuComponentCount(); i++){
2 26 Feb 07 jari 951             component = (Component)(hideMenu.getMenuComponent(i));
2 26 Feb 07 jari 952             
2 26 Feb 07 jari 953             if(component instanceof JMenuItem){
2 26 Feb 07 jari 954                 item = (JMenuItem)component;
2 26 Feb 07 jari 955                 if(item.isSelected()){
2 26 Feb 07 jari 956                     model.hide(item.getText());
2 26 Feb 07 jari 957                 }
2 26 Feb 07 jari 958             }
2 26 Feb 07 jari 959         }
2 26 Feb 07 jari 960     }
2 26 Feb 07 jari 961     
2 26 Feb 07 jari 962     private void resetSortMenu(){
2 26 Feb 07 jari 963         Component component;
2 26 Feb 07 jari 964         JMenu sortMenu = (JMenu)(menu.getComponent(6));
2 26 Feb 07 jari 965         
2 26 Feb 07 jari 966         JMenuItem item;
2 26 Feb 07 jari 967         for(int i = 0; i < sortMenu.getMenuComponentCount(); i++){
2 26 Feb 07 jari 968             component = (Component)(sortMenu.getMenuComponent(i));
2 26 Feb 07 jari 969             
2 26 Feb 07 jari 970             if(component instanceof JMenuItem){
2 26 Feb 07 jari 971                 item = (JMenuItem)component;
2 26 Feb 07 jari 972                 if(i == 0){
2 26 Feb 07 jari 973                     model.sortBy(item.getText());
2 26 Feb 07 jari 974                 }
2 26 Feb 07 jari 975                 else{
2 26 Feb 07 jari 976                     item.setSelected(false);
2 26 Feb 07 jari 977                 }
2 26 Feb 07 jari 978             }
2 26 Feb 07 jari 979         }
2 26 Feb 07 jari 980     }
2 26 Feb 07 jari 981     
2 26 Feb 07 jari 982     private void enableAllMenuItems(){
2 26 Feb 07 jari 983         int n = this.menu.getComponentCount();
2 26 Feb 07 jari 984         int m;
2 26 Feb 07 jari 985         for(int i = 0 ; i < n; i++){
2 26 Feb 07 jari 986             if(menu.getComponent(i) instanceof JMenuItem){
2 26 Feb 07 jari 987                 menu.getComponent(i).setEnabled(true);
2 26 Feb 07 jari 988                 m = 0;
2 26 Feb 07 jari 989                 m = ((JMenuItem)(menu.getComponent(i))).getComponentCount();
2 26 Feb 07 jari 990                 if( (((JMenuItem)menu.getComponent(i)).getText()).equals("Open/Launch") )
2 26 Feb 07 jari 991                     ((JMenu)menu.getComponent(i)).getMenuComponent(0).setEnabled(true);
2 26 Feb 07 jari 992                 for(int j = 0; j < m; j++){
2 26 Feb 07 jari 993                     ((JMenuItem)((JMenuItem)menu.getComponent(i)).getComponent(m)).setEnabled(true);
2 26 Feb 07 jari 994                 }
2 26 Feb 07 jari 995             }
2 26 Feb 07 jari 996         }
2 26 Feb 07 jari 997     }
2 26 Feb 07 jari 998     
2 26 Feb 07 jari 999     private Cluster [] getSelectedClusters(){
2 26 Feb 07 jari 1000         int [] rows = table.getSelectedRows();
2 26 Feb 07 jari 1001         Cluster [] clusters = new Cluster[rows.length];
2 26 Feb 07 jari 1002         Cluster cluster;
2 26 Feb 07 jari 1003         for(int i = 0; i < clusters.length; i++){
2 26 Feb 07 jari 1004             clusters[i] = repository.getCluster(model.getClusterSerialNumber(rows[i]));
2 26 Feb 07 jari 1005         }
2 26 Feb 07 jari 1006         return clusters;
2 26 Feb 07 jari 1007     }
2 26 Feb 07 jari 1008     
2 26 Feb 07 jari 1009     private void modifyColor(int row, int col){
2 26 Feb 07 jari 1010         Color color = (Color)(table.getValueAt(row, col));       
2 26 Feb 07 jari 1011         color = JColorChooser.showDialog(ClusterTable.this, "Reassign Color", color);
2 26 Feb 07 jari 1012         if(color != null){
2 26 Feb 07 jari 1013             table.setValueAt(color, row, col);
2 26 Feb 07 jari 1014             repository.updateClusterColor(model.getClusterSerialNumber(row), color);
2 26 Feb 07 jari 1015         }
2 26 Feb 07 jari 1016     }
2 26 Feb 07 jari 1017     
2 26 Feb 07 jari 1018     private void modifyShowColor(int row, int col) {
2 26 Feb 07 jari 1019         Cluster [] clusters = this.getSelectedClusters();
2 26 Feb 07 jari 1020         
2 26 Feb 07 jari 1021         if(clusters.length == 0)
2 26 Feb 07 jari 1022             return;
2 26 Feb 07 jari 1023         
2 26 Feb 07 jari 1024         Boolean bool = (Boolean)(this.model.getValueAt(row, col));
2 26 Feb 07 jari 1025
2 26 Feb 07 jari 1026         clusters[0].enableShowColor(bool.booleanValue());
2 26 Feb 07 jari 1027         model.setValueAt( clusters[0].getClusterColor(),row, col-1);
2 26 Feb 07 jari 1028       //  initializeTable();        
2 26 Feb 07 jari 1029         model.fireTableDataChanged();
2 26 Feb 07 jari 1030         model.fireTableChanged(new TableModelEvent(model));
2 26 Feb 07 jari 1031         this.table.repaint();
2 26 Feb 07 jari 1032         repaint();
2 26 Feb 07 jari 1033     }
2 26 Feb 07 jari 1034     
2 26 Feb 07 jari 1035     private void launchNewMevSession(){
2 26 Feb 07 jari 1036         Cluster [] clusters = getSelectedClusters();
2 26 Feb 07 jari 1037         ClusterWorker worker = new ClusterWorker(repository);
2 26 Feb 07 jari 1038         int [] indices = worker.getUniqueIndices(clusters);
2 26 Feb 07 jari 1039         String [] clusterLabels = worker.getClusterLabels(clusters);
2 26 Feb 07 jari 1040         if(clusterLabels.length == 1)
2 26 Feb 07 jari 1041             if(this.geneClusterTable)
2 26 Feb 07 jari 1042                 framework.launchNewMAV(indices, worker.getMinExperiment(clusters), ("Cluster: "+clusterLabels[0]), Cluster.GENE_CLUSTER);
2 26 Feb 07 jari 1043             else
2 26 Feb 07 jari 1044                 framework.launchNewMAV(indices, worker.getMinExperiment(clusters), ("Cluster: "+clusterLabels[0]), Cluster.EXPERIMENT_CLUSTER);
2 26 Feb 07 jari 1045         else if(clusterLabels.length > 1){
2 26 Feb 07 jari 1046             String labelString = "";
2 26 Feb 07 jari 1047             labelString = "Clusters: ";
2 26 Feb 07 jari 1048             for(int i = 0; i < clusterLabels.length-1; i++){
2 26 Feb 07 jari 1049                 labelString += clusterLabels[i] + " : ";
2 26 Feb 07 jari 1050             }
2 26 Feb 07 jari 1051             labelString += clusterLabels[clusterLabels.length-1];
2 26 Feb 07 jari 1052             if(this.geneClusterTable)
2 26 Feb 07 jari 1053                 framework.launchNewMAV(indices, worker.getMinExperiment(clusters), ("Cluster: "+clusterLabels[0]), Cluster.GENE_CLUSTER);
2 26 Feb 07 jari 1054             else
2 26 Feb 07 jari 1055                 framework.launchNewMAV(indices, worker.getMinExperiment(clusters), ("Cluster: "+clusterLabels[0]), Cluster.EXPERIMENT_CLUSTER);
2 26 Feb 07 jari 1056         }
2 26 Feb 07 jari 1057     }
2 26 Feb 07 jari 1058     
2 26 Feb 07 jari 1059     private void openClusterNode(){
2 26 Feb 07 jari 1060         int row = table.getSelectedRow();
2 26 Feb 07 jari 1061         Cluster cluster = repository.getCluster(model.getClusterSerialNumber(row));
2 26 Feb 07 jari 1062         if( !(cluster.getSource()).equals("Algorithm") ){
2 26 Feb 07 jari 1063             return;
2 26 Feb 07 jari 1064         }
2 26 Feb 07 jari 1065         
2 26 Feb 07 jari 1066         DefaultMutableTreeNode node = cluster.getNode();
2 26 Feb 07 jari 1067         
2 26 Feb 07 jari 1068         if(node == null){  // no node, probably cluster loaded from saved object, set node if found
2 26 Feb 07 jari 1069    /*         node = this.framework.findNode(cluster.getAlgorithmName(), cluster.getClusterID());
2 26 Feb 07 jari 1070             if( node != null){
2 26 Feb 07 jari 1071                 cluster.setNode(node);
2 26 Feb 07 jari 1072                 framework.setTreeNode(node);
2 26 Feb 07 jari 1073             }
2 26 Feb 07 jari 1074     **/
2 26 Feb 07 jari 1075             Object userObject = cluster.getUserObject();
2 26 Feb 07 jari 1076             if(userObject != null) {
2 26 Feb 07 jari 1077                 node = framework.getNode(userObject);
2 26 Feb 07 jari 1078                 if( node != null) {
2 26 Feb 07 jari 1079                     cluster.setNode(node);
2 26 Feb 07 jari 1080                     framework.setTreeNode(node);
2 26 Feb 07 jari 1081                 }
2 26 Feb 07 jari 1082             }
2 26 Feb 07 jari 1083         } else {
2 26 Feb 07 jari 1084             framework.setTreeNode(node);
2 26 Feb 07 jari 1085         }
2 26 Feb 07 jari 1086     }
2 26 Feb 07 jari 1087     
2 26 Feb 07 jari 1088     private void modifyClusterAttributes(){
2 26 Feb 07 jari 1089         int row = table.getSelectedRow();
2 26 Feb 07 jari 1090         if(model.isLegalRow(row)){
2 26 Feb 07 jari 1091             Cluster cluster = repository.getCluster(model.getClusterSerialNumber(row));
2 26 Feb 07 jari 1092             ClusterAttributesDialog dialog = new ClusterAttributesDialog("Modify Cluster Attributes", cluster.getAlgorithmName(), cluster.getClusterID(),
2 26 Feb 07 jari 1093             cluster.getClusterLabel(), cluster.getClusterDescription(), cluster.getClusterColor());
2 26 Feb 07 jari 1094             if(dialog.showModal() != JOptionPane.OK_OPTION){
2 26 Feb 07 jari 1095                 return;
2 26 Feb 07 jari 1096             }
2 26 Feb 07 jari 1097             
2 26 Feb 07 jari 1098             Color clusterColor = dialog.getColor();
2 26 Feb 07 jari 1099             String clusterLabel = dialog.getLabel();
2 26 Feb 07 jari 1100             String clusterDescription = dialog.getDescription();
2 26 Feb 07 jari 1101             
2 26 Feb 07 jari 1102             cluster.setClusterColor(clusterColor);
2 26 Feb 07 jari 1103             cluster.setClusterLabel(clusterLabel);
2 26 Feb 07 jari 1104             cluster.setClusterDescription(clusterDescription);
2 26 Feb 07 jari 1105             
2 26 Feb 07 jari 1106             model.setClusterColor(row, clusterColor);
2 26 Feb 07 jari 1107             model.setClusterLabel(row, clusterLabel);
2 26 Feb 07 jari 1108             model.setClusterDescription(row, clusterDescription);
2 26 Feb 07 jari 1109             model.fireTableDataChanged();
2 26 Feb 07 jari 1110         }
2 26 Feb 07 jari 1111     }
2 26 Feb 07 jari 1112     
2 26 Feb 07 jari 1113     private void showAllColumns(){
2 26 Feb 07 jari 1114         Component component;
2 26 Feb 07 jari 1115         JMenu hideMenu = (JMenu)(menu.getComponent(8));
2 26 Feb 07 jari 1116         JMenuItem item;
2 26 Feb 07 jari 1117         for(int i = 0; i < hideMenu.getMenuComponentCount(); i++){
2 26 Feb 07 jari 1118             component = (Component)(hideMenu.getMenuComponent(i));
2 26 Feb 07 jari 1119             if(component instanceof JMenuItem){
2 26 Feb 07 jari 1120                 item = (JMenuItem)component;
2 26 Feb 07 jari 1121                 if(item.isSelected()){
2 26 Feb 07 jari 1122                     model.addColumn(item.getText());
2 26 Feb 07 jari 1123                     item.setSelected(false);
2 26 Feb 07 jari 1124                 }
2 26 Feb 07 jari 1125             }
2 26 Feb 07 jari 1126         }
2 26 Feb 07 jari 1127     }
2 26 Feb 07 jari 1128     
2 26 Feb 07 jari 1129     private void performClusterOperation(String clusterOp){
2 26 Feb 07 jari 1130         Cluster [] clusters = getSelectedClusters();
2 26 Feb 07 jari 1131         if(clusters.length < 2)
2 26 Feb 07 jari 1132             return;
2 26 Feb 07 jari 1133         ClusterWorker worker = new ClusterWorker(repository);
2 26 Feb 07 jari 1134         Cluster result = null;
2 26 Feb 07 jari 1135         if(clusterOp.equals("Intersection"))
2 26 Feb 07 jari 1136             result = worker.intersection(clusters);
2 26 Feb 07 jari 1137         else if(clusterOp.equals("Union"))
2 26 Feb 07 jari 1138             result = worker.union(clusters);
2 26 Feb 07 jari 1139         else if(clusterOp.equals("XOR"))
2 26 Feb 07 jari 1140             result = worker.xor(clusters);
2 26 Feb 07 jari 1141         if(result != null){
2 26 Feb 07 jari 1142             repository.addCluster(repository.getClusterOperationsList(), result);
2 26 Feb 07 jari 1143             addCluster(result);
2 26 Feb 07 jari 1144         }
2 26 Feb 07 jari 1145         if(result != null)
2 26 Feb 07 jari 1146             this.framework.addHistory("Cluster Operation: "+result.getAlgorithmName());
2 26 Feb 07 jari 1147     }
2 26 Feb 07 jari 1148     
2 26 Feb 07 jari 1149     private void deleteSelectedRows(){
2 26 Feb 07 jari 1150         int [] rows = table.getSelectedRows();
2 26 Feb 07 jari 1151         for(int i = 0; i < rows.length; i++){
2 26 Feb 07 jari 1152             if(model.isLegalRow(rows[i]-i)){
2 26 Feb 07 jari 1153                 repository.removeCluster(model.getSerialNumber(rows[i]-i));
2 26 Feb 07 jari 1154                 model.removeRow(rows[i]-i);
2 26 Feb 07 jari 1155             }
2 26 Feb 07 jari 1156         }
2 26 Feb 07 jari 1157         if(rows.length > 0)
2 26 Feb 07 jari 1158             model.fireTableDataChanged();
2 26 Feb 07 jari 1159         //try this
2 26 Feb 07 jari 1160         this.onRepositoryChanged(this.repository);
2 26 Feb 07 jari 1161     }
2 26 Feb 07 jari 1162     
2 26 Feb 07 jari 1163     private void deleteAllRows(){
2 26 Feb 07 jari 1164         int result = JOptionPane.showConfirmDialog(ClusterTable.this, "Are you sure that you want to delete all clusters in the repository?",
2 26 Feb 07 jari 1165         "Delete All Clusters", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
2 26 Feb 07 jari 1166         if( result == JOptionPane.YES_OPTION){
2 26 Feb 07 jari 1167             model.removeAllRows();
2 26 Feb 07 jari 1168             repository.clearClusterLists();
2 26 Feb 07 jari 1169         }
2 26 Feb 07 jari 1170     }
2 26 Feb 07 jari 1171     
2 26 Feb 07 jari 1172     /**
2 26 Feb 07 jari 1173      *  Removes all clusters from view and clears the repository
2 26 Feb 07 jari 1174      */
2 26 Feb 07 jari 1175     public void deleteAllClusters(){
2 26 Feb 07 jari 1176         model.removeAllRows();
2 26 Feb 07 jari 1177         repository.clearClusterLists();
2 26 Feb 07 jari 1178     }
2 26 Feb 07 jari 1179     
2 26 Feb 07 jari 1180     private void saveCluster(){
2 26 Feb 07 jari 1181         Cluster [] clusters = getSelectedClusters();
2 26 Feb 07 jari 1182         if(clusters.length != 1){
2 26 Feb 07 jari 1183             JOptionPane.showMessageDialog(framework.getFrame(), "One row must be selected to indicate the cluster to save.", "Save Error", JOptionPane.WARNING_MESSAGE);
2 26 Feb 07 jari 1184             return;
2 26 Feb 07 jari 1185         }
2 26 Feb 07 jari 1186         repository.saveCluster(clusters[0].getSerialNumber());
2 26 Feb 07 jari 1187     }
2 26 Feb 07 jari 1188     
2 26 Feb 07 jari 1189     private void submitCluster() {
2 26 Feb 07 jari 1190         Cluster [] clusters = getSelectedClusters();
2 26 Feb 07 jari 1191         if(clusters != null && clusters.length > 0)
2 26 Feb 07 jari 1192             this.repository.submitCluster(clusters[0]);
2 26 Feb 07 jari 1193     }
2 26 Feb 07 jari 1194     
2 26 Feb 07 jari 1195     /** Returns a component to be inserted into the scroll pane row header
2 26 Feb 07 jari 1196      */
2 26 Feb 07 jari 1197     public JComponent getRowHeaderComponent() {
2 26 Feb 07 jari 1198         return null;
2 26 Feb 07 jari 1199     }
2 26 Feb 07 jari 1200     
2 26 Feb 07 jari 1201     /** Returns the corner component corresponding to the indicated corner,
2 26 Feb 07 jari 1202      * posibly null
2 26 Feb 07 jari 1203      */
2 26 Feb 07 jari 1204     public JComponent getCornerComponent(int cornerIndex) {
2 26 Feb 07 jari 1205         return null;
2 26 Feb 07 jari 1206     }
2 26 Feb 07 jari 1207     
2 26 Feb 07 jari 1208     public int[][] getClusters() {
2 26 Feb 07 jari 1209         return null;
2 26 Feb 07 jari 1210     }
2 26 Feb 07 jari 1211     
2 26 Feb 07 jari 1212     /**
2 26 Feb 07 jari 1213      * Implemented to satisfy the IViewer interface - returns null because
2 26 Feb 07 jari 1214      * there is no associated Experiment.
2 26 Feb 07 jari 1215      */
2 26 Feb 07 jari 1216     public Experiment getExperiment() {
2 26 Feb 07 jari 1217         return null;
2 26 Feb 07 jari 1218     }
2 26 Feb 07 jari 1219     
2 26 Feb 07 jari 1220     /** Returns int value indicating viewer type
2 26 Feb 07 jari 1221      * Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified
2 26 Feb 07 jari 1222      */
2 26 Feb 07 jari 1223     public int getViewerType() {
2 26 Feb 07 jari 1224         return -1;
2 26 Feb 07 jari 1225     }
2 26 Feb 07 jari 1226     /**
2 26 Feb 07 jari 1227      * Implemented to satisfy the IViewer interface. Does nothing because 
2 26 Feb 07 jari 1228      * ClusterTable has no Experiment object associated with it.
2 26 Feb 07 jari 1229      */
2 26 Feb 07 jari 1230     public void setExperimentID(int i){}
2 26 Feb 07 jari 1231     
2 26 Feb 07 jari 1232     /**
2 26 Feb 07 jari 1233      * Implemented to satisfy the IViewer interface - always returns 0
2 26 Feb 07 jari 1234      * because ClusterTable has no Experiment object associated with it.
2 26 Feb 07 jari 1235      */
2 26 Feb 07 jari 1236     public int getExperimentID(){return 0;}
2 26 Feb 07 jari 1237     /**
2 26 Feb 07 jari 1238      * Implemented to satisfy the IViewer interface - does nothing.
2 26 Feb 07 jari 1239      */
2 26 Feb 07 jari 1240     public void setExperiment(Experiment e){}
2 26 Feb 07 jari 1241
2 26 Feb 07 jari 1242
2 26 Feb 07 jari 1243
2 26 Feb 07 jari 1244   /* (non-Javadoc)
2 26 Feb 07 jari 1245    * @see org.tigr.microarray.mev.cluster.gui.IViewer#getExpression()
2 26 Feb 07 jari 1246    */
2 26 Feb 07 jari 1247   public Expression getExpression() {
2 26 Feb 07 jari 1248     // TODO Auto-generated method stub
2 26 Feb 07 jari 1249     return null;
2 26 Feb 07 jari 1250   }
2 26 Feb 07 jari 1251 }