mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/ease/EASEFileUpdateDialog.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  * EaseFileUpdateDialog.java
2 26 Feb 07 jari 7  *
2 26 Feb 07 jari 8  * Created on January 19, 2005, 4:25 PM
2 26 Feb 07 jari 9  */
2 26 Feb 07 jari 10 package org.tigr.microarray.mev.cluster.gui.impl.ease;
2 26 Feb 07 jari 11
2 26 Feb 07 jari 12 import java.awt.Color;
2 26 Feb 07 jari 13 import java.awt.Dimension;
2 26 Feb 07 jari 14 import java.awt.GridBagLayout;
2 26 Feb 07 jari 15 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 16 import java.awt.Insets;
2 26 Feb 07 jari 17 import java.awt.Toolkit;
2 26 Feb 07 jari 18
2 26 Feb 07 jari 19 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 20 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 21
2 26 Feb 07 jari 22 import java.util.Hashtable;
2 26 Feb 07 jari 23 import java.util.Vector;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import javax.swing.JFrame;
2 26 Feb 07 jari 26 import javax.swing.JComboBox;
2 26 Feb 07 jari 27 import javax.swing.JLabel;
2 26 Feb 07 jari 28 import javax.swing.JOptionPane;
2 26 Feb 07 jari 29 import javax.swing.JPanel;
2 26 Feb 07 jari 30 import javax.swing.JTabbedPane;
2 26 Feb 07 jari 31
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 34 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow;
2 26 Feb 07 jari 35
2 26 Feb 07 jari 36 /**
2 26 Feb 07 jari 37  *
2 26 Feb 07 jari 38  * @author  braisted
2 26 Feb 07 jari 39  * 
2 26 Feb 07 jari 40  * Constructs controls to sepecify EASE file system to update
2 26 Feb 07 jari 41  * High level divisions are represneted on different tabs
2 26 Feb 07 jari 42  * On each tab there are two dropdonw menus.  One for upper level
2 26 Feb 07 jari 43  * folder, often species, and one to specify files
2 26 Feb 07 jari 44  * 
2 26 Feb 07 jari 45  * The constructor takes a Vector of Hashtables that have server information
2 26 Feb 07 jari 46  * but more importantly they contain content to popultate dialog controls
2 26 Feb 07 jari 47  */
2 26 Feb 07 jari 48 public class EASEFileUpdateDialog extends AlgorithmDialog {
2 26 Feb 07 jari 49
2 26 Feb 07 jari 50     private JTabbedPane pane;    
2 26 Feb 07 jari 51     private int result = JOptionPane.CANCEL_OPTION;        
2 26 Feb 07 jari 52     private Vector repositoryHashes;
2 26 Feb 07 jari 53
2 26 Feb 07 jari 54   
2 26 Feb 07 jari 55     public EASEFileUpdateDialog(JFrame parent, Vector repositoryPropertyHashes) {
2 26 Feb 07 jari 56         super(parent, "Ease File Update Selection", true);
2 26 Feb 07 jari 57         pane = new JTabbedPane();
2 26 Feb 07 jari 58         Listener listener = new Listener();
2 26 Feb 07 jari 59         //add tabbed panes
2 26 Feb 07 jari 60         addTabs(pane, repositoryPropertyHashes, listener); 
2 26 Feb 07 jari 61         addContent(pane);
2 26 Feb 07 jari 62         setActionListeners(listener);
2 26 Feb 07 jari 63         pack();
2 26 Feb 07 jari 64     }
2 26 Feb 07 jari 65     
2 26 Feb 07 jari 66     /**
2 26 Feb 07 jari 67      * Adds a tabbed pane for each HashTable in the propVector
2 26 Feb 07 jari 68      * 
2 26 Feb 07 jari 69      * @param pane Object to which panes should be added
2 26 Feb 07 jari 70      * @param propVector Vector of Hashtables (repository properties)
2 26 Feb 07 jari 71      * @param listener  Listener
2 26 Feb 07 jari 72      */
2 26 Feb 07 jari 73     public void addTabs(JTabbedPane pane, Vector propVector, Listener listener) {      
2 26 Feb 07 jari 74       int numTabs = propVector.size();
2 26 Feb 07 jari 75       
2 26 Feb 07 jari 76       for(int i = 0; i < numTabs; i++) {
2 26 Feb 07 jari 77         addNewTab(pane, i, (Hashtable)propVector.get(i), listener);
2 26 Feb 07 jari 78       }
2 26 Feb 07 jari 79     }
2 26 Feb 07 jari 80     
2 26 Feb 07 jari 81     
2 26 Feb 07 jari 82     /**
2 26 Feb 07 jari 83      * Extracts properties from the properties Hashtable to construct the tab
2 26 Feb 07 jari 84      * @param pane The tabbed pane to receive the tab
2 26 Feb 07 jari 85      * @param tabIndex the tab index
2 26 Feb 07 jari 86      * @param props Hashtable of properties
2 26 Feb 07 jari 87      * @param listener ActionListener for constructed controls
2 26 Feb 07 jari 88      */
2 26 Feb 07 jari 89     public void addNewTab(JTabbedPane pane, int tabIndex, Hashtable props, Listener listener) {
2 26 Feb 07 jari 90
2 26 Feb 07 jari 91       //label for the tab
2 26 Feb 07 jari 92       String tabLabel = (String)props.get("tab-label");
2 26 Feb 07 jari 93       //vector of level labels 
2 26 Feb 07 jari 94       String directoryLabel = (String)props.get("level-1-label");
2 26 Feb 07 jari 95       String fileLabel = (String)props.get("level-2-label");
2 26 Feb 07 jari 96       
2 26 Feb 07 jari 97       //vector of upper level menu items keys
2 26 Feb 07 jari 98       Vector mainKeys = (Vector)props.get("main-keys");
2 26 Feb 07 jari 99       
2 26 Feb 07 jari 100       Hashtable itemHash = (Hashtable)props.get("menu-hash");
2 26 Feb 07 jari 101       
2 26 Feb 07 jari 102       //list of all hashtables
2 26 Feb 07 jari 103       //repositoryHashes.add(itemHash);
2 26 Feb 07 jari 104       
2 26 Feb 07 jari 105       //box contains the directories
2 26 Feb 07 jari 106       JComboBox box1 = new JComboBox(mainKeys);
2 26 Feb 07 jari 107       //trigger to update lower list from hash of arrays or species
2 26 Feb 07 jari 108       box1.setActionCommand("upper-level-selection");
2 26 Feb 07 jari 109       box1.addActionListener(listener);
2 26 Feb 07 jari 110
2 26 Feb 07 jari 111       //box will contain files for a given drectory after update
2 26 Feb 07 jari 112       JComboBox box2 = new JComboBox();      
2 26 Feb 07 jari 113       //trigger just a new lower level selection
2 26 Feb 07 jari 114       box2.setActionCommand("lower-level-selection");
2 26 Feb 07 jari 115       box2.addActionListener(listener);
2 26 Feb 07 jari 116       
2 26 Feb 07 jari 117       //make a TabPanel given some labels, JComboBoxes, and a properties hash
2 26 Feb 07 jari 118       pane.addTab(tabLabel, new TabPanel(directoryLabel,box1,fileLabel,box2, itemHash, props));        
2 26 Feb 07 jari 119     }
2 26 Feb 07 jari 120     
2 26 Feb 07 jari 121     /**
2 26 Feb 07 jari 122      * Shows the dialog.
2 26 Feb 07 jari 123      */
2 26 Feb 07 jari 124     public int showModal() {
2 26 Feb 07 jari 125         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2 26 Feb 07 jari 126         setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2);
2 26 Feb 07 jari 127         show();
2 26 Feb 07 jari 128         return result;
2 26 Feb 07 jari 129     }
2 26 Feb 07 jari 130     
2 26 Feb 07 jari 131     
2 26 Feb 07 jari 132     
2 26 Feb 07 jari 133     private void resetControls() {
2 26 Feb 07 jari 134       //we can implement this but probably not needed
2 26 Feb 07 jari 135       //maybe switch to tab 0?
2 26 Feb 07 jari 136     }
2 26 Feb 07 jari 137
2 26 Feb 07 jari 138     /**
2 26 Feb 07 jari 139      * Returns the selected species (upper level or folder name)
2 26 Feb 07 jari 140      * @return species or folder names
2 26 Feb 07 jari 141      */
2 26 Feb 07 jari 142     public String getSpeciesName() {      
2 26 Feb 07 jari 143        TabPanel panel = (TabPanel) (pane.getSelectedComponent());
2 26 Feb 07 jari 144        return (String)panel.getBox1().getSelectedItem();
2 26 Feb 07 jari 145     }
2 26 Feb 07 jari 146
2 26 Feb 07 jari 147     /**
2 26 Feb 07 jari 148      * Returns the selected file name (these are usually specified by array)
2 26 Feb 07 jari 149      * @return array of file name
2 26 Feb 07 jari 150      */
2 26 Feb 07 jari 151     public String getArrayName() {
2 26 Feb 07 jari 152        TabPanel panel = (TabPanel) (pane.getSelectedComponent());
2 26 Feb 07 jari 153        return (String)panel.getBox2().getSelectedItem();
2 26 Feb 07 jari 154     }    
2 26 Feb 07 jari 155     
2 26 Feb 07 jari 156     /**
2 26 Feb 07 jari 157      * Returns the index of the desired repository
2 26 Feb 07 jari 158      * @return
2 26 Feb 07 jari 159      */
2 26 Feb 07 jari 160     public int getRepositoryIndex() {
2 26 Feb 07 jari 161       //pane's seletected tab index
2 26 Feb 07 jari 162       return pane.getSelectedIndex();
2 26 Feb 07 jari 163     }
2 26 Feb 07 jari 164     
2 26 Feb 07 jari 165     /**
2 26 Feb 07 jari 166      * Returns the properties for the seleted repository
2 26 Feb 07 jari 167      * @return repository properties for file retrieval
2 26 Feb 07 jari 168      */
2 26 Feb 07 jari 169     public Hashtable getRepositoryProperties() {
2 26 Feb 07 jari 170        TabPanel panel = (TabPanel) (pane.getSelectedComponent());
2 26 Feb 07 jari 171       return panel.getRepositoryProperties();
2 26 Feb 07 jari 172     }
2 26 Feb 07 jari 173     
2 26 Feb 07 jari 174     /**
2 26 Feb 07 jari 175      * This class holds the controls for one tab and a repository hash of
2 26 Feb 07 jari 176      * properties
2 26 Feb 07 jari 177      * 
2 26 Feb 07 jari 178      * @author braisted
2 26 Feb 07 jari 179      *
2 26 Feb 07 jari 180      * TODO To change the template for this generated type comment go to
2 26 Feb 07 jari 181      * Window - Preferences - Java - Code Style - Code Templates
2 26 Feb 07 jari 182      */
2 26 Feb 07 jari 183     private class TabPanel extends JPanel {
2 26 Feb 07 jari 184
2 26 Feb 07 jari 185       //directory and file lists
2 26 Feb 07 jari 186       private JComboBox box1;
2 26 Feb 07 jari 187       private JComboBox box2;
2 26 Feb 07 jari 188       //this gets updated by selection in box1
2 26 Feb 07 jari 189       private JLabel box2JLabel;
2 26 Feb 07 jari 190        // base text for box 2's label
2 26 Feb 07 jari 191       private String box2Label; 
2 26 Feb 07 jari 192       // updates box two's entries       
2 26 Feb 07 jari 193       private Hashtable box1ToBox2Hash;      
2 26 Feb 07 jari 194       //hashtable of repository properties       
2 26 Feb 07 jari 195       private Hashtable repositoryProperties;
2 26 Feb 07 jari 196       
2 26 Feb 07 jari 197       /**
2 26 Feb 07 jari 198        * Constructs a new TabPanel
2 26 Feb 07 jari 199        * @param box1Label label for box 1
2 26 Feb 07 jari 200        * @param b1 box 1
2 26 Feb 07 jari 201        * @param box2Label label for box 2
2 26 Feb 07 jari 202        * @param b2 box 2
2 26 Feb 07 jari 203        * @param menuHash hashtable to map directories in box 1 to a Vector of files
2 26 Feb 07 jari 204        *            to populate box 2
2 26 Feb 07 jari 205        * @param repProps  prepository properties for these files and tab
2 26 Feb 07 jari 206        */
2 26 Feb 07 jari 207       TabPanel(String box1Label, JComboBox b1, String box2Label, JComboBox b2, Hashtable menuHash, Hashtable repProps) {
2 26 Feb 07 jari 208           setLayout(new GridBagLayout());
2 26 Feb 07 jari 209           setBackground(Color.white);
2 26 Feb 07 jari 210
2 26 Feb 07 jari 211           box1 = b1;
2 26 Feb 07 jari 212           box2 = b2;
2 26 Feb 07 jari 213           box1ToBox2Hash = menuHash; 
2 26 Feb 07 jari 214           this.box2Label = box2Label;
2 26 Feb 07 jari 215           repositoryProperties = repProps;
2 26 Feb 07 jari 216           
2 26 Feb 07 jari 217           JLabel label = new JLabel(box1Label);
2 26 Feb 07 jari 218           add(label, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,0,5,0),0,0));
2 26 Feb 07 jari 219           add(box1, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,20,0),0,0));            
2 26 Feb 07 jari 220
2 26 Feb 07 jari 221           box2JLabel = new JLabel(box2Label);
2 26 Feb 07 jari 222
2 26 Feb 07 jari 223           add(box2JLabel, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,0),0,0));
2 26 Feb 07 jari 224           add(box2, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,20,0),0,0));                                
2 26 Feb 07 jari 225       
2 26 Feb 07 jari 226           updateBox2();
2 26 Feb 07 jari 227       }
2 26 Feb 07 jari 228       
2 26 Feb 07 jari 229       /**
2 26 Feb 07 jari 230        * Return the upper level selection (Directory)
2 26 Feb 07 jari 231        * @return selected directory
2 26 Feb 07 jari 232        */
2 26 Feb 07 jari 233       public JComboBox getBox1() {
2 26 Feb 07 jari 234         return box1;
2 26 Feb 07 jari 235       }
2 26 Feb 07 jari 236
2 26 Feb 07 jari 237       /**
2 26 Feb 07 jari 238        * Returns selected file
2 26 Feb 07 jari 239        * @return selected file
2 26 Feb 07 jari 240        */
2 26 Feb 07 jari 241       public JComboBox getBox2() {
2 26 Feb 07 jari 242         return box2;
2 26 Feb 07 jari 243       }
2 26 Feb 07 jari 244
2 26 Feb 07 jari 245       /**
2 26 Feb 07 jari 246        * Repository props for the selection
2 26 Feb 07 jari 247        * @return props 
2 26 Feb 07 jari 248        */
2 26 Feb 07 jari 249       public Hashtable getRepositoryProperties() {
2 26 Feb 07 jari 250         return repositoryProperties;
2 26 Feb 07 jari 251       }
2 26 Feb 07 jari 252       
2 26 Feb 07 jari 253       /**
2 26 Feb 07 jari 254        * Updates file box base on directory box selection
2 26 Feb 07 jari 255        */
2 26 Feb 07 jari 256       public void updateBox2() {
2 26 Feb 07 jari 257            box2.removeAllItems();
2 26 Feb 07 jari 258         String key = (String)box1.getSelectedItem();        
2 26 Feb 07 jari 259         Vector box2Items = (Vector)(this.box1ToBox2Hash.get(key));
2 26 Feb 07 jari 260         for(int i = 0; i < box2Items.size(); i++)
2 26 Feb 07 jari 261                 box2.addItem(box2Items.elementAt(i));
2 26 Feb 07 jari 262         box2JLabel.setText(box2Label+" "+key);
2 26 Feb 07 jari 263       }
2 26 Feb 07 jari 264     }
2 26 Feb 07 jari 265     
2 26 Feb 07 jari 266     
2 26 Feb 07 jari 267         /**
2 26 Feb 07 jari 268      * The class to listen to the dialog events.
2 26 Feb 07 jari 269      */
2 26 Feb 07 jari 270     private class Listener extends DialogListener {
2 26 Feb 07 jari 271         
2 26 Feb 07 jari 272         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 273             Object source = e.getSource();
2 26 Feb 07 jari 274             String command = e.getActionCommand();
2 26 Feb 07 jari 275             if(command.equals("upper-level-selection")) {
2 26 Feb 07 jari 276               //get source
2 26 Feb 07 jari 277               TabPanel panel = (TabPanel) (pane.getSelectedComponent());
2 26 Feb 07 jari 278               panel.updateBox2();
2 26 Feb 07 jari 279             } else if(command.equals("lower-level-selection")) {
2 26 Feb 07 jari 280               //no need to act on this at this time
2 26 Feb 07 jari 281             } else if (source == okButton) {
2 26 Feb 07 jari 282                 result = JOptionPane.OK_OPTION;
2 26 Feb 07 jari 283                 dispose();
2 26 Feb 07 jari 284             } else if (source == cancelButton) {
2 26 Feb 07 jari 285                 result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 286                 dispose();
2 26 Feb 07 jari 287             } else if (source == resetButton) {
2 26 Feb 07 jari 288                 resetControls();
2 26 Feb 07 jari 289             } else if (source == infoButton){
2 26 Feb 07 jari 290                 HelpWindow hw = new HelpWindow(EASEFileUpdateDialog.this, "EASE File Update Dialog");
2 26 Feb 07 jari 291                 if(hw.getWindowContent()){
2 26 Feb 07 jari 292                     hw.setSize(450,650);
2 26 Feb 07 jari 293                     hw.setLocation();
2 26 Feb 07 jari 294                     hw.show();
2 26 Feb 07 jari 295                 }
2 26 Feb 07 jari 296                 else {
2 26 Feb 07 jari 297                     hw.setVisible(false);
2 26 Feb 07 jari 298                     hw.dispose();
2 26 Feb 07 jari 299                 }                    
2 26 Feb 07 jari 300             }            
2 26 Feb 07 jari 301         }
2 26 Feb 07 jari 302         
2 26 Feb 07 jari 303         public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 304             result = JOptionPane.CLOSED_OPTION;
2 26 Feb 07 jari 305             dispose();
2 26 Feb 07 jari 306         }
2 26 Feb 07 jari 307     }
2 26 Feb 07 jari 308 }