mev-4.0.01/source/org/tigr/microarray/mev/GeneAnnotationImportDialog.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2  * GeneAnnotationImportDialog.java
2 26 Feb 07 jari 3  *
2 26 Feb 07 jari 4  * Created on February 3, 2005, 4:54 PM
2 26 Feb 07 jari 5  */
2 26 Feb 07 jari 6
2 26 Feb 07 jari 7 package org.tigr.microarray.mev;
2 26 Feb 07 jari 8
2 26 Feb 07 jari 9 import java.awt.Color;
2 26 Feb 07 jari 10 import java.awt.Dimension;
2 26 Feb 07 jari 11 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 12 import java.awt.GridBagLayout;
2 26 Feb 07 jari 13 import java.awt.Insets;
2 26 Feb 07 jari 14 import java.awt.Toolkit;
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.WindowEvent;
2 26 Feb 07 jari 18 import java.util.Vector;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 import javax.swing.BorderFactory;
2 26 Feb 07 jari 21 import javax.swing.JButton;
2 26 Feb 07 jari 22 import javax.swing.JCheckBox;
2 26 Feb 07 jari 23 import javax.swing.JComboBox;
2 26 Feb 07 jari 24 import javax.swing.JFrame;
2 26 Feb 07 jari 25 import javax.swing.JLabel;
2 26 Feb 07 jari 26 import javax.swing.JOptionPane;
2 26 Feb 07 jari 27 import javax.swing.JPanel;
2 26 Feb 07 jari 28 import javax.swing.JScrollPane;
2 26 Feb 07 jari 29
2 26 Feb 07 jari 30 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog;
2 26 Feb 07 jari 31 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow;
2 26 Feb 07 jari 34
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 public class GeneAnnotationImportDialog extends AlgorithmDialog {
2 26 Feb 07 jari 41     
2 26 Feb 07 jari 42     private JComboBox dataKeyBox, annFileKeyBox;
2 26 Feb 07 jari 43     private String [] dataAnnKeys;
2 26 Feb 07 jari 44     private String [] annFileKeys;
2 26 Feb 07 jari 45     
2 26 Feb 07 jari 46     private ColumnNamesPanel fieldSelectionPanel;
2 26 Feb 07 jari 47     
2 26 Feb 07 jari 48     private int result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 49     
2 26 Feb 07 jari 50     /** Creates a new instance of GeneAnnotationImportDialog */
2 26 Feb 07 jari 51     public GeneAnnotationImportDialog(JFrame frame, String [] dataAnnKeys, String [] annFileKeys) {
2 26 Feb 07 jari 52         super(frame, "Append Gene Annotation", true);
2 26 Feb 07 jari 53         
2 26 Feb 07 jari 54         this.dataAnnKeys = dataAnnKeys;
2 26 Feb 07 jari 55         this.annFileKeys = annFileKeys;
2 26 Feb 07 jari 56
2 26 Feb 07 jari 57         JLabel dataKeyLabel = new JLabel("Gene Identifier (from current data):");
2 26 Feb 07 jari 58         dataKeyBox = new JComboBox(dataAnnKeys);
2 26 Feb 07 jari 59         
2 26 Feb 07 jari 60         JLabel fileKeyLabel = new JLabel("Corresponding Gene Identifier from Input File:");        
2 26 Feb 07 jari 61         annFileKeyBox = new JComboBox(annFileKeys);
2 26 Feb 07 jari 62         
2 26 Feb 07 jari 63         String text = "<html><body>Note: The Gene identifiers from the loaded data and the input annoation<br>";
2 26 Feb 07 jari 64         text += "file should correspond to the same annoation type.   These identifiers<br>";
2 26 Feb 07 jari 65         text += "are used to map annotation in the file to the proper genes loaded in MeV.</html>";
2 26 Feb 07 jari 66         
2 26 Feb 07 jari 67         JLabel explanationLabel = new JLabel(text);
2 26 Feb 07 jari 68
2 26 Feb 07 jari 69         fieldSelectionPanel = new ColumnNamesPanel(annFileKeys);
2 26 Feb 07 jari 70         
2 26 Feb 07 jari 71         ParameterPanel panel = new ParameterPanel("Annotation Key Selection");
2 26 Feb 07 jari 72         panel.setLayout(new GridBagLayout());
2 26 Feb 07 jari 73         
2 26 Feb 07 jari 74         panel.add(dataKeyLabel, new GridBagConstraints(0,0,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,10,0,10),0,0));
2 26 Feb 07 jari 75         panel.add(dataKeyBox, new GridBagConstraints(0,1,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,10,0,10),0,0));
2 26 Feb 07 jari 76         panel.add(fileKeyLabel, new GridBagConstraints(0,2,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(25,10,0,10),0,0));
2 26 Feb 07 jari 77         panel.add(annFileKeyBox, new GridBagConstraints(0,3,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,10,20,10),0,0));        
2 26 Feb 07 jari 78         panel.add(explanationLabel, new GridBagConstraints(0,4,1,1,1,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,10,20,10),0,0));        
2 26 Feb 07 jari 79         //panel.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0,5,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,0,20,0),0,0));        
2 26 Feb 07 jari 80         panel.add(fieldSelectionPanel, new GridBagConstraints(0,5,1,1,0,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,0,20,0),0,0));        
2 26 Feb 07 jari 81         
2 26 Feb 07 jari 82         setActionListeners(new Listener());
2 26 Feb 07 jari 83         addContent(panel);
2 26 Feb 07 jari 84         pack();
2 26 Feb 07 jari 85     }
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     /**
2 26 Feb 07 jari 88      * Shows the dialog.
2 26 Feb 07 jari 89      */
2 26 Feb 07 jari 90     public int showModal() {
2 26 Feb 07 jari 91         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2 26 Feb 07 jari 92         setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2);
2 26 Feb 07 jari 93         show();
2 26 Feb 07 jari 94         return result;
2 26 Feb 07 jari 95     }
2 26 Feb 07 jari 96     
2 26 Feb 07 jari 97     /** Returns the annotation key to identify genes in the annotation file
2 26 Feb 07 jari 98      */
2 26 Feb 07 jari 99     public String getFileAnnotationKey() {
2 26 Feb 07 jari 100         return (String)this.annFileKeyBox.getSelectedItem();
2 26 Feb 07 jari 101     }
2 26 Feb 07 jari 102     
2 26 Feb 07 jari 103     /** Returns the annotation key to identify genes in the loaded data
2 26 Feb 07 jari 104      */
2 26 Feb 07 jari 105     public String getDataAnnotationKey() {
2 26 Feb 07 jari 106         return (String)this.dataKeyBox.getSelectedItem();
2 26 Feb 07 jari 107     }
2 26 Feb 07 jari 108
2 26 Feb 07 jari 109     /** Resets the controls to the initial state
2 26 Feb 07 jari 110      */
2 26 Feb 07 jari 111     private void resetControls() {
2 26 Feb 07 jari 112         this.dataKeyBox.setSelectedIndex(0);
2 26 Feb 07 jari 113         this.annFileKeyBox.setSelectedIndex(0);
2 26 Feb 07 jari 114         this.fieldSelectionPanel.resetControls();
2 26 Feb 07 jari 115     }
2 26 Feb 07 jari 116     
2 26 Feb 07 jari 117     public String [] getSelectedAnnotationFields() {
2 26 Feb 07 jari 118         return fieldSelectionPanel.getSelectedColNames();
2 26 Feb 07 jari 119     }
2 26 Feb 07 jari 120     
2 26 Feb 07 jari 121     /**
2 26 Feb 07 jari 122      * The class to listen to the dialog and check boxes items events.
2 26 Feb 07 jari 123      */
2 26 Feb 07 jari 124     private class Listener extends DialogListener {
2 26 Feb 07 jari 125         
2 26 Feb 07 jari 126         public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 127             String command = e.getActionCommand();
2 26 Feb 07 jari 128             if (command.equals("ok-command")) {
2 26 Feb 07 jari 129                 if(getSelectedAnnotationFields().length < 1) {
2 26 Feb 07 jari 130                     JOptionPane.showMessageDialog(GeneAnnotationImportDialog.this, "You must select at least one annotation field to import.", "Empty Annotation Field Selection", JOptionPane.ERROR_MESSAGE);
2 26 Feb 07 jari 131                     return;   
2 26 Feb 07 jari 132                 }
2 26 Feb 07 jari 133                 result = JOptionPane.OK_OPTION;
2 26 Feb 07 jari 134                 dispose();
2 26 Feb 07 jari 135             } else if (command.equals("cancel-command")) {
2 26 Feb 07 jari 136                 result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 137                 dispose();
2 26 Feb 07 jari 138             }
2 26 Feb 07 jari 139             else if (command.equals("reset-command")){
2 26 Feb 07 jari 140                 resetControls();
2 26 Feb 07 jari 141                 result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 142                 return;
2 26 Feb 07 jari 143             }
2 26 Feb 07 jari 144             else if (command.equals("info-command")){
2 26 Feb 07 jari 145                 HelpWindow hw = new HelpWindow(GeneAnnotationImportDialog.this, "Gene Annotation Import");
2 26 Feb 07 jari 146                 result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 147                 if(hw.getWindowContent()){
2 26 Feb 07 jari 148                     hw.setSize(600,650);
2 26 Feb 07 jari 149                     hw.setLocation();
2 26 Feb 07 jari 150                     hw.show();
2 26 Feb 07 jari 151                     return;
2 26 Feb 07 jari 152                 }
2 26 Feb 07 jari 153                 else {
2 26 Feb 07 jari 154                     hw.setVisible(false);
2 26 Feb 07 jari 155                     hw.dispose();
2 26 Feb 07 jari 156                     return;
2 26 Feb 07 jari 157                 }
2 26 Feb 07 jari 158             }
2 26 Feb 07 jari 159             dispose();
2 26 Feb 07 jari 160         }
2 26 Feb 07 jari 161         
2 26 Feb 07 jari 162         public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 163             result = JOptionPane.CLOSED_OPTION;
2 26 Feb 07 jari 164             dispose();
2 26 Feb 07 jari 165         }
2 26 Feb 07 jari 166     }    
2 26 Feb 07 jari 167
2 26 Feb 07 jari 168     
2 26 Feb 07 jari 169     private class ColumnNamesPanel extends JPanel {
2 26 Feb 07 jari 170         
2 26 Feb 07 jari 171         JCheckBox[] columnNameBoxes;
2 26 Feb 07 jari 172         
2 26 Feb 07 jari 173         JButton selectAllButton, clearAllButton;
2 26 Feb 07 jari 174         
2 26 Feb 07 jari 175         ColumnNamesPanel(String [] columnHeaders) {
2 26 Feb 07 jari 176     
2 26 Feb 07 jari 177             setLayout(new GridBagLayout());
2 26 Feb 07 jari 178             setBorder(BorderFactory.createTitledBorder("Select Annotation Fields to Append"));
2 26 Feb 07 jari 179             this.setBackground(Color.white);
2 26 Feb 07 jari 180             
2 26 Feb 07 jari 181             columnNameBoxes = new JCheckBox[columnHeaders.length];
2 26 Feb 07 jari 182             boolean selected = true;
2 26 Feb 07 jari 183             for (int i= 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 184                 if(columnHeaders[i].equals("UID") || columnHeaders[i].equals("R") || columnHeaders[i].equals("C"))
2 26 Feb 07 jari 185                     selected = false;
2 26 Feb 07 jari 186                 else
2 26 Feb 07 jari 187                     selected = true;
2 26 Feb 07 jari 188                 
2 26 Feb 07 jari 189                 columnNameBoxes[i] = new JCheckBox(columnHeaders[i], selected);
2 26 Feb 07 jari 190                 columnNameBoxes[i].setOpaque(false);
2 26 Feb 07 jari 191                 columnNameBoxes[i].setFocusPainted(false);
2 26 Feb 07 jari 192             }
2 26 Feb 07 jari 193             
2 26 Feb 07 jari 194             JPanel checkBoxPanel = createCheckBoxPanel();
2 26 Feb 07 jari 195             JScrollPane scroll = new JScrollPane(checkBoxPanel);
2 26 Feb 07 jari 196             scroll.setPreferredSize(new Dimension(450, 150));
2 26 Feb 07 jari 197             
2 26 Feb 07 jari 198             JButton selectAllButton = new JButton("Select All");
2 26 Feb 07 jari 199             JButton clearAllButton = new JButton("Clear All");
2 26 Feb 07 jari 200             
2 26 Feb 07 jari 201             selectAllButton.addActionListener(new ActionListener() {
2 26 Feb 07 jari 202                 public void actionPerformed(ActionEvent evt) {
2 26 Feb 07 jari 203                     for (int i = 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 204                         columnNameBoxes[i].setSelected(true);
2 26 Feb 07 jari 205                     }
2 26 Feb 07 jari 206                 }
2 26 Feb 07 jari 207             });
2 26 Feb 07 jari 208             
2 26 Feb 07 jari 209             clearAllButton.addActionListener(new ActionListener() {
2 26 Feb 07 jari 210                 public void actionPerformed(ActionEvent evt) {
2 26 Feb 07 jari 211                     for (int i = 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 212                         columnNameBoxes[i].setSelected(false);
2 26 Feb 07 jari 213                     }
2 26 Feb 07 jari 214                 }
2 26 Feb 07 jari 215             });    
2 26 Feb 07 jari 216             add(selectAllButton, new GridBagConstraints(0,0,1,1,50,10, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(5,10,5,0),0,0));       
2 26 Feb 07 jari 217             add(scroll, new GridBagConstraints(0,1,2,1,100,90, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,5,5,5),0,0));            
2 26 Feb 07 jari 218         }
2 26 Feb 07 jari 219         
2 26 Feb 07 jari 220         private JPanel createCheckBoxPanel() {
2 26 Feb 07 jari 221             JPanel panel1 = new JPanel();
2 26 Feb 07 jari 222             panel1.setBackground(Color.white);
2 26 Feb 07 jari 223             panel1.setLayout(new GridBagLayout());    
2 26 Feb 07 jari 224             for (int i = 0; i < columnNameBoxes.length; i++) {    
2 26 Feb 07 jari 225                 panel1.add(columnNameBoxes[i], new GridBagConstraints(0,i,1,1,100,0,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,5,0,0), 0, 0));
2 26 Feb 07 jari 226             }
2 26 Feb 07 jari 227             return panel1;
2 26 Feb 07 jari 228         }
2 26 Feb 07 jari 229         
2 26 Feb 07 jari 230         public int[] getSelectedCols() {
2 26 Feb 07 jari 231             Vector selColsVector = new Vector();
2 26 Feb 07 jari 232             for (int i = 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 233                 if (columnNameBoxes[i].isSelected()) {
2 26 Feb 07 jari 234                     selColsVector.add(new Integer(i + 1));
2 26 Feb 07 jari 235                 }                
2 26 Feb 07 jari 236             }
2 26 Feb 07 jari 237             
2 26 Feb 07 jari 238             int[] selCols = new int[selColsVector.size()];
2 26 Feb 07 jari 239             for (int i = 0; i < selCols.length; i++) {
2 26 Feb 07 jari 240                 selCols[i] = ((Integer)(selColsVector.get(i))).intValue();
2 26 Feb 07 jari 241             }
2 26 Feb 07 jari 242             
2 26 Feb 07 jari 243             return selCols;
2 26 Feb 07 jari 244         }
2 26 Feb 07 jari 245         
2 26 Feb 07 jari 246         public String[] getSelectedColNames() {
2 26 Feb 07 jari 247             Vector selColNamesVector = new Vector();
2 26 Feb 07 jari 248             for (int i = 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 249                 if (columnNameBoxes[i].isSelected()) {
2 26 Feb 07 jari 250                     selColNamesVector.add(columnNameBoxes[i].getText());
2 26 Feb 07 jari 251                 }                
2 26 Feb 07 jari 252             }    
2 26 Feb 07 jari 253             
2 26 Feb 07 jari 254             String[] selColNames = new String[selColNamesVector.size()];
2 26 Feb 07 jari 255             for (int i = 0; i < selColNames.length; i++) {
2 26 Feb 07 jari 256                 selColNames[i] = (String)(selColNamesVector.get(i));
2 26 Feb 07 jari 257             }
2 26 Feb 07 jari 258             
2 26 Feb 07 jari 259             return selColNames;
2 26 Feb 07 jari 260         }
2 26 Feb 07 jari 261         
2 26 Feb 07 jari 262         public void resetControls() {
2 26 Feb 07 jari 263             boolean selected = true;
2 26 Feb 07 jari 264             for (int i= 0; i < columnNameBoxes.length; i++) {
2 26 Feb 07 jari 265                 if(columnNameBoxes[i].getText().equals("UID") || columnNameBoxes[i].getText().equals("R") || columnNameBoxes[i].getText().equals("C"))
2 26 Feb 07 jari 266                     selected = false;
2 26 Feb 07 jari 267                 else
2 26 Feb 07 jari 268                     selected = true;
2 26 Feb 07 jari 269                 
2 26 Feb 07 jari 270                 columnNameBoxes[i].setSelected(selected);            }   
2 26 Feb 07 jari 271         }        
2 26 Feb 07 jari 272     }    
2 26 Feb 07 jari 273     
2 26 Feb 07 jari 274     
2 26 Feb 07 jari 275     public static void main(String [] args) {
2 26 Feb 07 jari 276         String [] s1 = new String[3];
2 26 Feb 07 jari 277         String [] s2 = new String[5];
2 26 Feb 07 jari 278         
2 26 Feb 07 jari 279         s1[0] = "UID";
2 26 Feb 07 jari 280         s1[1] = "GB";
2 26 Feb 07 jari 281         s1[2] = "TC";
2 26 Feb 07 jari 282
2 26 Feb 07 jari 283         s2[0] = "UID";
2 26 Feb 07 jari 284         s2[1] = "R";
2 26 Feb 07 jari 285         s2[2] = "C";
2 26 Feb 07 jari 286         s2[3] = "Tigr TC";
2 26 Feb 07 jari 287         s2[4] = "GenBank";
2 26 Feb 07 jari 288         
2 26 Feb 07 jari 289         GeneAnnotationImportDialog dialog = new GeneAnnotationImportDialog(new JFrame(), s1, s2);
2 26 Feb 07 jari 290         dialog.showModal();
2 26 Feb 07 jari 291         System.exit(0);
2 26 Feb 07 jari 292     }
2 26 Feb 07 jari 293     
2 26 Feb 07 jari 294     
2 26 Feb 07 jari 295     
2 26 Feb 07 jari 296 }