mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/usc/USCClassDialog.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 package org.tigr.microarray.mev.cluster.gui.impl.usc;
2 26 Feb 07 jari 2 import java.awt.BorderLayout;
2 26 Feb 07 jari 3 import java.awt.Color;
2 26 Feb 07 jari 4 import java.awt.Component;
2 26 Feb 07 jari 5 import java.awt.Dimension;
2 26 Feb 07 jari 6 import java.awt.Frame;
2 26 Feb 07 jari 7 import java.awt.Toolkit;
2 26 Feb 07 jari 8 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 9 import java.awt.event.ItemEvent;
2 26 Feb 07 jari 10 import java.awt.event.ItemListener;
2 26 Feb 07 jari 11 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 12 import java.util.Vector;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import javax.swing.BorderFactory;
2 26 Feb 07 jari 15 import javax.swing.Box;
2 26 Feb 07 jari 16 import javax.swing.BoxLayout;
2 26 Feb 07 jari 17 import javax.swing.ButtonGroup;
2 26 Feb 07 jari 18 import javax.swing.JCheckBox;
2 26 Feb 07 jari 19 import javax.swing.JFrame;
2 26 Feb 07 jari 20 import javax.swing.JLabel;
2 26 Feb 07 jari 21 import javax.swing.JOptionPane;
2 26 Feb 07 jari 22 import javax.swing.JPanel;
2 26 Feb 07 jari 23 import javax.swing.JRadioButton;
2 26 Feb 07 jari 24 import javax.swing.JScrollPane;
2 26 Feb 07 jari 25 import javax.swing.JSpinner;
2 26 Feb 07 jari 26 import javax.swing.JTextField;
2 26 Feb 07 jari 27 import javax.swing.SpinnerNumberModel;
2 26 Feb 07 jari 28 import javax.swing.SpringLayout;
2 26 Feb 07 jari 29 import javax.swing.event.ChangeEvent;
2 26 Feb 07 jari 30 import javax.swing.event.ChangeListener;
2 26 Feb 07 jari 31
2 26 Feb 07 jari 32 import org.tigr.microarray.mev.r.ClassAssigner;
2 26 Feb 07 jari 33 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog;
2 26 Feb 07 jari 34 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener;
2 26 Feb 07 jari 35 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow;
2 26 Feb 07 jari 36
2 26 Feb 07 jari 37 /*
2 26 Feb 07 jari 38  * Created on Nov 22, 2004
2 26 Feb 07 jari 39  */
2 26 Feb 07 jari 40
2 26 Feb 07 jari 41 /**
2 26 Feb 07 jari 42  * This is the 1st Dialog Box that should be displayed.  It allows a user to decide to 
2 26 Feb 07 jari 43  * either train the algorithm using a set of training data or to load the training results 
2 26 Feb 07 jari 44  * from a file.
2 26 Feb 07 jari 45  * @author vu
2 26 Feb 07 jari 46  */
2 26 Feb 07 jari 47 public class USCClassDialog extends AlgorithmDialog {
2 26 Feb 07 jari 48   //Static ints
2 26 Feb 07 jari 49   static int TRAIN_THEN_CLASSIFY = 0;
2 26 Feb 07 jari 50   static int CLASSIFY_FROM_FILE = 1;
2 26 Feb 07 jari 51   
2 26 Feb 07 jari 52   private int result;
2 26 Feb 07 jari 53   
2 26 Feb 07 jari 54   private JPanel mainPanel;            //
2 26 Feb 07 jari 55   private JPanel radioPanel;            //Radio buttons
2 26 Feb 07 jari 56   private JPanel labelPanel;            //
2 26 Feb 07 jari 57   private JPanel fieldPanel;              //JTextFields
2 26 Feb 07 jari 58   private JPanel textPanel;              //JLabels for JTextFields
2 26 Feb 07 jari 59   private JPanel paramPanel;            //Advanced Parameters
2 26 Feb 07 jari 60   
2 26 Feb 07 jari 61   private JRadioButton trainClassify;    //train then classify
2 26 Feb 07 jari 62   private JRadioButton fileClassify;      //use a file to classify
2 26 Feb 07 jari 63   
2 26 Feb 07 jari 64   private JSpinner numClasses;        //
2 26 Feb 07 jari 65   private Vector vField;                //Vector of JTextFields for Class Labels
2 26 Feb 07 jari 66   private Vector vLabel;                //Vector of JLabels of Class Labels
2 26 Feb 07 jari 67   
2 26 Feb 07 jari 68   private JCheckBox advActive;        //
2 26 Feb 07 jari 69   //private JButton advDeactive;          //
2 26 Feb 07 jari 70   
2 26 Feb 07 jari 71   private JSpinner numFolds;            //# Cross Validation fold
2 26 Feb 07 jari 72   private JSpinner numBins;            //Number of deltas
2 26 Feb 07 jari 73   private JSpinner deltaMax;            //Maximum delta
2 26 Feb 07 jari 74   private JSpinner numXVal;            //# Cross Validation runs
2 26 Feb 07 jari 75   private JTextField corrLo;              //
2 26 Feb 07 jari 76   private JTextField corrHi;              //
2 26 Feb 07 jari 77   private JTextField corrStep;          //
2 26 Feb 07 jari 78   
2 26 Feb 07 jari 79   private Dimension dField;            //
2 26 Feb 07 jari 80   private Dimension dLabel;            //
2 26 Feb 07 jari 81
2 26 Feb 07 jari 82   private JLabel numLabel;              //
2 26 Feb 07 jari 83   private JLabel foldLabel;              //
2 26 Feb 07 jari 84   private JLabel xValLabel;              //
2 26 Feb 07 jari 85   private JLabel binLabel;              //
2 26 Feb 07 jari 86   private JLabel deltaLabel;            //
2 26 Feb 07 jari 87   private JLabel loLabel;                //
2 26 Feb 07 jari 88   private JLabel hiLabel;                //
2 26 Feb 07 jari 89   private JLabel stepLabel;              //
2 26 Feb 07 jari 90   
2 26 Feb 07 jari 91   
2 26 Feb 07 jari 92   
2 26 Feb 07 jari 93   /**
2 26 Feb 07 jari 94    * @param parent
2 26 Feb 07 jari 95    */
2 26 Feb 07 jari 96   public USCClassDialog( Frame parent ) {
2 26 Feb 07 jari 97     super( ( JFrame ) parent, "USC: Uncorrelated Shrunken Centroid", true );
2 26 Feb 07 jari 98     this.setSize( 350, 525 );
2 26 Feb 07 jari 99     //this.setSize( 350, 415 );
2 26 Feb 07 jari 100     
2 26 Feb 07 jari 101     //
2 26 Feb 07 jari 102     this.dLabel = new Dimension( 55, 20 );
2 26 Feb 07 jari 103     this.dField = new Dimension( 140, 20 );
2 26 Feb 07 jari 104     Dimension dSpin = new Dimension( 45, 20 );
2 26 Feb 07 jari 105     Dimension dButton = new Dimension( 140, 20 );
2 26 Feb 07 jari 106     
2 26 Feb 07 jari 107     //the mainPanel is the big one that will be placed in the AlgorithmDialog
2 26 Feb 07 jari 108     this.mainPanel = new JPanel();
2 26 Feb 07 jari 109     
2 26 Feb 07 jari 110     //need Listeners for the JCheckBox and JSpinner and the Dialog itself
2 26 Feb 07 jari 111     SpinListener sl = new SpinListener();
2 26 Feb 07 jari 112     ButtonListener bl = new ButtonListener();
2 26 Feb 07 jari 113     Listener listener = new Listener();
2 26 Feb 07 jari 114     super.addWindowListener(listener);
2 26 Feb 07 jari 115     super.setActionListeners(listener);
2 26 Feb 07 jari 116     
2 26 Feb 07 jari 117     //create the sub panels
2 26 Feb 07 jari 118     this.createRadioPanel( bl, dSpin );
2 26 Feb 07 jari 119     this.createLabelPanel( sl, 2 );
2 26 Feb 07 jari 120     this.createParamPanel( bl, dSpin );
2 26 Feb 07 jari 121     
2 26 Feb 07 jari 122     //add the sub panels to mainPanel
2 26 Feb 07 jari 123     this.mainPanel.setLayout( new BorderLayout() );
2 26 Feb 07 jari 124     this.mainPanel.add( this.radioPanel, BorderLayout.WEST );
2 26 Feb 07 jari 125     this.mainPanel.add( this.paramPanel, BorderLayout.EAST );
2 26 Feb 07 jari 126     this.mainPanel.add( this.labelPanel, BorderLayout.NORTH );
2 26 Feb 07 jari 127     
2 26 Feb 07 jari 128     //add mainPanel to AlgorithmDialog
2 26 Feb 07 jari 129     JScrollPane scrollPane = new JScrollPane( this.mainPanel );
2 26 Feb 07 jari 130     this.addContent( scrollPane );
2 26 Feb 07 jari 131   }//end constructor
2 26 Feb 07 jari 132   
2 26 Feb 07 jari 133   
2 26 Feb 07 jari 134   public static void main( String[] args ) {
2 26 Feb 07 jari 135     System.out.println( "invoked by main()" );
2 26 Feb 07 jari 136     
2 26 Feb 07 jari 137     USCClassDialog d = new USCClassDialog( new JFrame() );
2 26 Feb 07 jari 138     d.showModal();
2 26 Feb 07 jari 139   }
2 26 Feb 07 jari 140   
2 26 Feb 07 jari 141   
2 26 Feb 07 jari 142   /**
2 26 Feb 07 jari 143    * Creates the JPanel containing the JRadioButton group that allows the user to 
2 26 Feb 07 jari 144    * choose whether they'd like to train data using a training set or using a trained 
2 26 Feb 07 jari 145    * file to use to classify their data
2 26 Feb 07 jari 146    * @param dSpin
2 26 Feb 07 jari 147    */
2 26 Feb 07 jari 148   private void createRadioPanel( ButtonListener bl, Dimension dSpin ) {
2 26 Feb 07 jari 149     this.radioPanel = new JPanel();
2 26 Feb 07 jari 150     BoxLayout box = new BoxLayout( this.radioPanel, BoxLayout.Y_AXIS );
2 26 Feb 07 jari 151     this.radioPanel.setLayout( box );
2 26 Feb 07 jari 152     this.radioPanel.setBorder( BorderFactory.createTitledBorder("Analysis Mode"));
2 26 Feb 07 jari 153     
2 26 Feb 07 jari 154     //create radio buttons and group them
2 26 Feb 07 jari 155     this.trainClassify = new JRadioButton( "Train & Classify" );
2 26 Feb 07 jari 156     this.trainClassify.setSelected( true );
2 26 Feb 07 jari 157     this.trainClassify.addItemListener( bl );
2 26 Feb 07 jari 158     this.fileClassify = new JRadioButton( "Classify from File" );
2 26 Feb 07 jari 159     this.fileClassify.setSelected( false );
2 26 Feb 07 jari 160     this.fileClassify.addItemListener( bl );
2 26 Feb 07 jari 161     ButtonGroup group = new ButtonGroup();
2 26 Feb 07 jari 162     group.add( this.trainClassify );
2 26 Feb 07 jari 163     group.add( this.fileClassify );
2 26 Feb 07 jari 164     
2 26 Feb 07 jari 165     this.radioPanel.add(Box.createVerticalGlue());
2 26 Feb 07 jari 166     this.radioPanel.add( this.trainClassify );
2 26 Feb 07 jari 167     this.radioPanel.add( this.fileClassify );
2 26 Feb 07 jari 168     this.radioPanel.add(Box.createVerticalGlue());
2 26 Feb 07 jari 169   }//end createRadioPanel()
2 26 Feb 07 jari 170   
2 26 Feb 07 jari 171   
2 26 Feb 07 jari 172   /**
2 26 Feb 07 jari 173    * Creates the JPanel containing the JSpinner for # of Classes and the corresponding 
2 26 Feb 07 jari 174    * number of JTextFields and their JLabels for the user to enter the class labels
2 26 Feb 07 jari 175    * @param dField  Dimension of the JTextFields
2 26 Feb 07 jari 176    * @param dText    Dimension of the JLabels
2 26 Feb 07 jari 177    * @param kount    Default number of classes
2 26 Feb 07 jari 178    */
2 26 Feb 07 jari 179   private void createLabelPanel( SpinListener sl, int kount ) {
2 26 Feb 07 jari 180     this.vField = new Vector();
2 26 Feb 07 jari 181     this.vLabel = new Vector();
2 26 Feb 07 jari 182     
2 26 Feb 07 jari 183     this.labelPanel = new JPanel( new BorderLayout() );
2 26 Feb 07 jari 184     this.labelPanel.setBorder( BorderFactory.createTitledBorder( "Enter all Class Labels") );
2 26 Feb 07 jari 185     
2 26 Feb 07 jari 186     //JSpinner, the class labels and the labels for class labels should go on labelPanel
2 26 Feb 07 jari 187     this.fieldPanel = new JPanel();
2 26 Feb 07 jari 188     BoxLayout fieldBoxLayout = new BoxLayout( this.fieldPanel, BoxLayout.Y_AXIS );
2 26 Feb 07 jari 189     this.fieldPanel.setLayout( fieldBoxLayout );
2 26 Feb 07 jari 190     
2 26 Feb 07 jari 191     this.textPanel = new JPanel();
2 26 Feb 07 jari 192     BoxLayout textBoxLayout = new BoxLayout( this.textPanel, BoxLayout.Y_AXIS );
2 26 Feb 07 jari 193     this.textPanel.setLayout( textBoxLayout );
2 26 Feb 07 jari 194     
2 26 Feb 07 jari 195     JPanel centerPanel = new JPanel();
2 26 Feb 07 jari 196     centerPanel.add( this.textPanel );
2 26 Feb 07 jari 197     centerPanel.add( this.fieldPanel );
2 26 Feb 07 jari 198     
2 26 Feb 07 jari 199     for( int i = 0; i < kount; i ++ ) {
2 26 Feb 07 jari 200       JLabel label = new JLabel( "Label " + ( i + 1 ) );
2 26 Feb 07 jari 201       label.setMaximumSize( this.dLabel );
2 26 Feb 07 jari 202       label.setMinimumSize( this.dLabel );
2 26 Feb 07 jari 203       label.setPreferredSize( this.dLabel );
2 26 Feb 07 jari 204       
2 26 Feb 07 jari 205       JTextField field = new JTextField();
2 26 Feb 07 jari 206       field.setMaximumSize( this.dField );
2 26 Feb 07 jari 207       field.setMinimumSize( this.dField );
2 26 Feb 07 jari 208       field.setPreferredSize( this.dField );
2 26 Feb 07 jari 209       
2 26 Feb 07 jari 210       textPanel.add( label );
2 26 Feb 07 jari 211       fieldPanel.add( field );
2 26 Feb 07 jari 212       
2 26 Feb 07 jari 213       this.vLabel.add( label );
2 26 Feb 07 jari 214       this.vField.add( field );
2 26 Feb 07 jari 215     }
2 26 Feb 07 jari 216     
2 26 Feb 07 jari 217     //create a sub JPanel for JSpinner
2 26 Feb 07 jari 218     JPanel spinPanel = new JPanel();
2 26 Feb 07 jari 219     
2 26 Feb 07 jari 220     //create JSpinner for # of classes
2 26 Feb 07 jari 221     SpinnerNumberModel model = new SpinnerNumberModel( kount, 2, 50, 1 );
2 26 Feb 07 jari 222     this.numClasses = new JSpinner( model );
2 26 Feb 07 jari 223     this.numClasses.setMaximumSize( this.dLabel );
2 26 Feb 07 jari 224     this.numLabel = new JLabel( "# of Classes" );
2 26 Feb 07 jari 225     spinPanel.add( this.numLabel );
2 26 Feb 07 jari 226     spinPanel.add( this.numClasses );
2 26 Feb 07 jari 227     this.numClasses.addChangeListener( sl );
2 26 Feb 07 jari 228     
2 26 Feb 07 jari 229     this.labelPanel.add( spinPanel, BorderLayout.NORTH );
2 26 Feb 07 jari 230     this.labelPanel.add( centerPanel, BorderLayout.CENTER );
2 26 Feb 07 jari 231   }//end createLabelPanel()
2 26 Feb 07 jari 232   
2 26 Feb 07 jari 233   
2 26 Feb 07 jari 234   /**
2 26 Feb 07 jari 235    * Creates the JPanel containing all the Advanced options.  By default, they will 
2 26 Feb 07 jari 236    * be instantiated with default values and disabled.  If the user would like to change 
2 26 Feb 07 jari 237    * any values, they will have to click on the advActive JCheckBox to enable the 
2 26 Feb 07 jari 238    * parameters.
2 26 Feb 07 jari 239    * @param cl  ItemListener
2 26 Feb 07 jari 240    * @param d    Dimension of the JSpinners and JTextFields
2 26 Feb 07 jari 241    */
2 26 Feb 07 jari 242   private void createParamPanel( ButtonListener cl, Dimension d ) {
2 26 Feb 07 jari 243     this.paramPanel = new JPanel( new SpringLayout() );
2 26 Feb 07 jari 244     this.paramPanel.setBorder( BorderFactory.createTitledBorder("Advanced Parameters"));
2 26 Feb 07 jari 245     //BoxLayout bl = new BoxLayout( this.paramPanel, BoxLayout.Y_AXIS );
2 26 Feb 07 jari 246     //this.paramPanel.setLayout( bl );
2 26 Feb 07 jari 247     
2 26 Feb 07 jari 248     this.advActive = new JCheckBox( "Advanced" );
2 26 Feb 07 jari 249     this.advActive.addItemListener( cl );
2 26 Feb 07 jari 250     JLabel advLabel = new JLabel( " " );
2 26 Feb 07 jari 251     
2 26 Feb 07 jari 252     SpinnerNumberModel numClassModel = ( SpinnerNumberModel ) this.numClasses.getModel();
2 26 Feb 07 jari 253     int numClasses = numClassModel.getNumber().intValue();
2 26 Feb 07 jari 254     int defaultFold = 3;
2 26 Feb 07 jari 255     int defaultXVal = 5;
2 26 Feb 07 jari 256     
2 26 Feb 07 jari 257     SpinnerNumberModel foldModel = new SpinnerNumberModel( defaultFold, 1, 100, 1 );
2 26 Feb 07 jari 258     this.numFolds = new JSpinner( foldModel );
2 26 Feb 07 jari 259     this.numFolds.setMaximumSize( d );
2 26 Feb 07 jari 260     this.numFolds.setMinimumSize( d );
2 26 Feb 07 jari 261     this.numFolds.setPreferredSize( d );
2 26 Feb 07 jari 262     this.foldLabel = new JLabel( "# Folds" );
2 26 Feb 07 jari 263     
2 26 Feb 07 jari 264     SpinnerNumberModel xValModel = new SpinnerNumberModel( defaultXVal, 1, 100, 1 );
2 26 Feb 07 jari 265     this.numXVal = new JSpinner( xValModel );
2 26 Feb 07 jari 266     this.numXVal.setMaximumSize( d );
2 26 Feb 07 jari 267     this.numXVal.setMinimumSize( d );
2 26 Feb 07 jari 268     this.numXVal.setPreferredSize( d );
2 26 Feb 07 jari 269     this.xValLabel = new JLabel( "# CV runs" );
2 26 Feb 07 jari 270     
2 26 Feb 07 jari 271     SpinnerNumberModel numBinsModel = new SpinnerNumberModel( 20, 1, 500, 1 );
2 26 Feb 07 jari 272     this.numBins = new JSpinner( numBinsModel );
2 26 Feb 07 jari 273     this.numBins.setMaximumSize( d );
2 26 Feb 07 jari 274     this.numBins.setMinimumSize( d );
2 26 Feb 07 jari 275     this.numBins.setPreferredSize( d );
2 26 Feb 07 jari 276     this.binLabel = new JLabel( "# Bins" );
2 26 Feb 07 jari 277     
2 26 Feb 07 jari 278     SpinnerNumberModel deltaMaxModel = new SpinnerNumberModel( 10, 1, 500, 1 );
2 26 Feb 07 jari 279     this.deltaMax = new JSpinner( deltaMaxModel );
2 26 Feb 07 jari 280     this.deltaMax.setMaximumSize( d );
2 26 Feb 07 jari 281     this.deltaMax.setMinimumSize( d );
2 26 Feb 07 jari 282     this.deltaMax.setPreferredSize( d );
2 26 Feb 07 jari 283     this.deltaLabel = new JLabel( "Max Delta" );
2 26 Feb 07 jari 284     
2 26 Feb 07 jari 285     this.corrLo = new JTextField( "0.5" );
2 26 Feb 07 jari 286     this.corrLo.setMaximumSize( d );
2 26 Feb 07 jari 287     this.corrLo.setMinimumSize( d );
2 26 Feb 07 jari 288     this.corrLo.setPreferredSize( d );
2 26 Feb 07 jari 289     this.loLabel = new JLabel( "Corr Low" );
2 26 Feb 07 jari 290     
2 26 Feb 07 jari 291     this.corrHi = new JTextField( "1.0" );
2 26 Feb 07 jari 292     this.corrHi.setMaximumSize( d );
2 26 Feb 07 jari 293     this.corrHi.setMinimumSize( d );
2 26 Feb 07 jari 294     this.corrHi.setPreferredSize( d );
2 26 Feb 07 jari 295     this.hiLabel = new JLabel( "Corr High" );
2 26 Feb 07 jari 296     
2 26 Feb 07 jari 297     this.corrStep = new JTextField( "0.1" );
2 26 Feb 07 jari 298     this.corrStep.setMaximumSize( d );
2 26 Feb 07 jari 299     this.corrStep.setMinimumSize( d );
2 26 Feb 07 jari 300     this.corrStep.setPreferredSize( d );
2 26 Feb 07 jari 301     this.stepLabel = new JLabel( "Corr Step" );
2 26 Feb 07 jari 302     
2 26 Feb 07 jari 303     this.advActive.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 304     this.numFolds.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 305     this.numXVal.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 306     this.numBins.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 307     this.deltaMax.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 308     this.corrLo.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 309     this.corrHi.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 310     this.corrStep.setAlignmentX( Component.CENTER_ALIGNMENT );
2 26 Feb 07 jari 311
2 26 Feb 07 jari 312     this.foldLabel.setForeground( Color.gray );
2 26 Feb 07 jari 313     this.binLabel.setForeground( Color.gray );
2 26 Feb 07 jari 314     this.xValLabel.setForeground( Color.gray );
2 26 Feb 07 jari 315     this.deltaLabel.setForeground( Color.gray );
2 26 Feb 07 jari 316     this.loLabel.setForeground( Color.gray );
2 26 Feb 07 jari 317     this.hiLabel.setForeground( Color.gray );
2 26 Feb 07 jari 318     this.stepLabel.setForeground( Color.gray );
2 26 Feb 07 jari 319     
2 26 Feb 07 jari 320     this.paramPanel.add( advLabel );
2 26 Feb 07 jari 321     this.paramPanel.add( this.advActive );
2 26 Feb 07 jari 322     this.paramPanel.add( this.foldLabel );
2 26 Feb 07 jari 323     this.paramPanel.add( this.numFolds );
2 26 Feb 07 jari 324     this.paramPanel.add( this.xValLabel );
2 26 Feb 07 jari 325     this.paramPanel.add( this.numXVal );
2 26 Feb 07 jari 326     this.paramPanel.add( this.binLabel );
2 26 Feb 07 jari 327     this.paramPanel.add( this.numBins );
2 26 Feb 07 jari 328     this.paramPanel.add( this.deltaLabel );
2 26 Feb 07 jari 329     this.paramPanel.add( this.deltaMax );
2 26 Feb 07 jari 330     this.paramPanel.add( this.loLabel );
2 26 Feb 07 jari 331     this.paramPanel.add( this.corrLo );
2 26 Feb 07 jari 332     this.paramPanel.add( this.hiLabel );
2 26 Feb 07 jari 333     this.paramPanel.add( this.corrHi );
2 26 Feb 07 jari 334     this.paramPanel.add( this.stepLabel );
2 26 Feb 07 jari 335     this.paramPanel.add( this.corrStep );
2 26 Feb 07 jari 336     
2 26 Feb 07 jari 337     SpringUtilities.makeCompactGrid( this.paramPanel, 8, 2, 0, 0, 10, 0 );
2 26 Feb 07 jari 338     
2 26 Feb 07 jari 339     this.setParamEnabled( false );
2 26 Feb 07 jari 340   }//end createParamPanel()
2 26 Feb 07 jari 341   
2 26 Feb 07 jari 342   
2 26 Feb 07 jari 343   /**
2 26 Feb 07 jari 344    * The user clicked on the advActive JCheckBox.  Enable or Disable as necessary
2 26 Feb 07 jari 345    * @param isEnabled
2 26 Feb 07 jari 346    */
2 26 Feb 07 jari 347   private void setParamEnabled( boolean isEnabled ) {
2 26 Feb 07 jari 348     if( isEnabled ) {
2 26 Feb 07 jari 349       this.foldLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 350       this.xValLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 351       this.binLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 352       this.deltaLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 353       this.loLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 354       this.hiLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 355       this.stepLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 356     } else {
2 26 Feb 07 jari 357       this.foldLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 358       this.xValLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 359       this.binLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 360       this.deltaLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 361       this.loLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 362       this.hiLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 363       this.stepLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 364     }
2 26 Feb 07 jari 365     
2 26 Feb 07 jari 366     this.corrHi.setEnabled( isEnabled );
2 26 Feb 07 jari 367     this.corrLo.setEnabled( isEnabled );
2 26 Feb 07 jari 368     this.corrStep.setEnabled( isEnabled );
2 26 Feb 07 jari 369     this.numBins.setEnabled( isEnabled );
2 26 Feb 07 jari 370     this.deltaMax.setEnabled( isEnabled );
2 26 Feb 07 jari 371     this.numFolds.setEnabled( isEnabled );
2 26 Feb 07 jari 372     this.numXVal.setEnabled( isEnabled );
2 26 Feb 07 jari 373   }//end setParamEnabled()
2 26 Feb 07 jari 374   
2 26 Feb 07 jari 375   
2 26 Feb 07 jari 376   /**
2 26 Feb 07 jari 377    * Enables of Disables the Advanced Parameters JCheckBox and the Parameters
2 26 Feb 07 jari 378    * @param isEnabled
2 26 Feb 07 jari 379    */
2 26 Feb 07 jari 380   private void setAdvEnabled( boolean isEnabled ) {
2 26 Feb 07 jari 381     if( isEnabled ) {
2 26 Feb 07 jari 382       this.advActive.setEnabled( true );
2 26 Feb 07 jari 383       if( this.advActive.isSelected() ) {
2 26 Feb 07 jari 384         this.setParamEnabled( true );
2 26 Feb 07 jari 385       } else {
2 26 Feb 07 jari 386         this.setParamEnabled( false );
2 26 Feb 07 jari 387       }
2 26 Feb 07 jari 388     } else {
2 26 Feb 07 jari 389       this.advActive.setEnabled( false );
2 26 Feb 07 jari 390       this.setParamEnabled( false );
2 26 Feb 07 jari 391     }
2 26 Feb 07 jari 392   }
2 26 Feb 07 jari 393   
2 26 Feb 07 jari 394   
2 26 Feb 07 jari 395   /**
2 26 Feb 07 jari 396    * Enables or Disables the numClasses JSpinner and the corresponding JTextFields 
2 26 Feb 07 jari 397    * @param isEnabled
2 26 Feb 07 jari 398    */
2 26 Feb 07 jari 399   private void setLabelEnabled( boolean isEnabled ) {
2 26 Feb 07 jari 400     this.numClasses.setEnabled( isEnabled );
2 26 Feb 07 jari 401     if( isEnabled ) {
2 26 Feb 07 jari 402       this.numLabel.setForeground( Color.BLACK );
2 26 Feb 07 jari 403     } else {
2 26 Feb 07 jari 404       this.numLabel.setForeground( Color.GRAY );
2 26 Feb 07 jari 405     }
2 26 Feb 07 jari 406     for( int i = 0; i < this.vField.size(); i ++ ) {
2 26 Feb 07 jari 407       JTextField field = ( JTextField ) this.vField.elementAt( i );
2 26 Feb 07 jari 408       field.setEnabled( isEnabled );
2 26 Feb 07 jari 409       
2 26 Feb 07 jari 410       JLabel label = ( JLabel ) this.vLabel.elementAt( i );
2 26 Feb 07 jari 411       if( isEnabled ) {
2 26 Feb 07 jari 412         label.setForeground( Color.BLACK ); 
2 26 Feb 07 jari 413       } else {
2 26 Feb 07 jari 414         label.setForeground( Color.GRAY );
2 26 Feb 07 jari 415       }
2 26 Feb 07 jari 416     }
2 26 Feb 07 jari 417   }//end setLabelEnabled()
2 26 Feb 07 jari 418   
2 26 Feb 07 jari 419   
2 26 Feb 07 jari 420   /**
2 26 Feb 07 jari 421    * The user clicked on the numClasses JSpinner.  Either add or remove JTextFields 
2 26 Feb 07 jari 422    * as necessary
2 26 Feb 07 jari 423    */
2 26 Feb 07 jari 424   private void numClassesChanged() {
2 26 Feb 07 jari 425     SpinnerNumberModel model = ( SpinnerNumberModel ) this.numClasses.getModel();
2 26 Feb 07 jari 426     int i = model.getNumber().intValue();
2 26 Feb 07 jari 427     
2 26 Feb 07 jari 428     if( i > this.vField.size() ) {
2 26 Feb 07 jari 429       this.addFields( i - this.vField.size() );
2 26 Feb 07 jari 430     } else if( i < this.vField.size() ) {
2 26 Feb 07 jari 431       this.removeFields( this.vField.size() - i );
2 26 Feb 07 jari 432     }
2 26 Feb 07 jari 433   }//end numClassesChanged()
2 26 Feb 07 jari 434   
2 26 Feb 07 jari 435   
2 26 Feb 07 jari 436   /**
2 26 Feb 07 jari 437    * Adds classLabel JTextFields and their JLabels to the GUI and the Vectors that 
2 26 Feb 07 jari 438    * keep track of them - vField and vLabel respectively
2 26 Feb 07 jari 439    * @param numToAdd
2 26 Feb 07 jari 440    */
2 26 Feb 07 jari 441   private void addFields( int numToAdd ) {
2 26 Feb 07 jari 442     int currentNum = this.vField.size();
2 26 Feb 07 jari 443     
2 26 Feb 07 jari 444     for( int i = 0; i < numToAdd; i ++ ) {
2 26 Feb 07 jari 445       int nextIndex = currentNum + i;
2 26 Feb 07 jari 446       
2 26 Feb 07 jari 447       JTextField field = new JTextField();
2 26 Feb 07 jari 448       field.setMaximumSize( this.dField );
2 26 Feb 07 jari 449       field.setMinimumSize( this.dField );
2 26 Feb 07 jari 450       field.setPreferredSize( this.dField );
2 26 Feb 07 jari 451       this.fieldPanel.add( field );
2 26 Feb 07 jari 452       
2 26 Feb 07 jari 453       JLabel label = new JLabel( "Label " + ( nextIndex + 1 ) );
2 26 Feb 07 jari 454       label.setMaximumSize( this.dLabel );
2 26 Feb 07 jari 455       label.setMinimumSize( this.dLabel );
2 26 Feb 07 jari 456       label.setPreferredSize( this.dLabel );
2 26 Feb 07 jari 457       this.textPanel.add( label );
2 26 Feb 07 jari 458       
2 26 Feb 07 jari 459       this.vField.add( field );
2 26 Feb 07 jari 460       this.vLabel.add( label );
2 26 Feb 07 jari 461     }
2 26 Feb 07 jari 462     
2 26 Feb 07 jari 463     this.getRootPane().revalidate();
2 26 Feb 07 jari 464   }//end addFields()
2 26 Feb 07 jari 465   
2 26 Feb 07 jari 466   
2 26 Feb 07 jari 467   /**
2 26 Feb 07 jari 468    * Removes class label JTextFields and their JLabels from the GUI and the Vectors 
2 26 Feb 07 jari 469    * that keep track of them vField and vLabel respectively.
2 26 Feb 07 jari 470    * @param numToRemove
2 26 Feb 07 jari 471    */
2 26 Feb 07 jari 472   private void removeFields( int numToRemove ) {
2 26 Feb 07 jari 473     int currentNum = this.vField.size();
2 26 Feb 07 jari 474     
2 26 Feb 07 jari 475     for( int i = 0; i < numToRemove; i ++ ) {
2 26 Feb 07 jari 476       JTextField field = ( JTextField ) this.vField.elementAt( currentNum - 1 );
2 26 Feb 07 jari 477       JLabel label = ( JLabel ) this.vLabel.elementAt( currentNum - 1 );
2 26 Feb 07 jari 478
2 26 Feb 07 jari 479       this.fieldPanel.remove( field );
2 26 Feb 07 jari 480       this.textPanel.remove( label );
2 26 Feb 07 jari 481       this.vField.remove( field );
2 26 Feb 07 jari 482       this.vLabel.remove( label );
2 26 Feb 07 jari 483     }//end i
2 26 Feb 07 jari 484     
2 26 Feb 07 jari 485     this.getRootPane().revalidate();
2 26 Feb 07 jari 486   }//end removeFields()
2 26 Feb 07 jari 487   
2 26 Feb 07 jari 488   
2 26 Feb 07 jari 489   /**
2 26 Feb 07 jari 490    * Makes sure all the class labels have been accounted for.  Displays an error dialog
2 26 Feb 07 jari 491    * when somethign is awry.
2 26 Feb 07 jari 492    * @return
2 26 Feb 07 jari 493    */
2 26 Feb 07 jari 494   private boolean validateLabels() {
2 26 Feb 07 jari 495     boolean toReturn = true;
2 26 Feb 07 jari 496     
2 26 Feb 07 jari 497     Vector v = new Vector();
2 26 Feb 07 jari 498     
2 26 Feb 07 jari 499     for( int i = 0; i < this.vField.size(); i ++ ) {
2 26 Feb 07 jari 500       JTextField field = ( JTextField ) this.vField.elementAt( i );
2 26 Feb 07 jari 501       
2 26 Feb 07 jari 502       //make sure there are no blank fields
2 26 Feb 07 jari 503       if( field.getText() == null || field.getText().equals( "" ) ) {
2 26 Feb 07 jari 504         this.error( "Please make sure every class has a valid Label" );
2 26 Feb 07 jari 505         toReturn = false;
2 26 Feb 07 jari 506         break;
2 26 Feb 07 jari 507       }
2 26 Feb 07 jari 508       
2 26 Feb 07 jari 509       //make sure this label doesn't already exist
2 26 Feb 07 jari 510       for( int j = 0; j < v.size(); j ++ ) {
2 26 Feb 07 jari 511         String s = ( String ) v.elementAt( j );
2 26 Feb 07 jari 512         if( s.equalsIgnoreCase( field.getText() ) ) {
2 26 Feb 07 jari 513           this.error( "There is more than 1 class with the label - " + s );
2 26 Feb 07 jari 514           toReturn = false;
2 26 Feb 07 jari 515           break;
2 26 Feb 07 jari 516         }
2 26 Feb 07 jari 517       }
2 26 Feb 07 jari 518       
2 26 Feb 07 jari 519       //add a new and novel class label
2 26 Feb 07 jari 520       v.add( field.getText() );
2 26 Feb 07 jari 521     }//end i
2 26 Feb 07 jari 522     
2 26 Feb 07 jari 523     return toReturn;
2 26 Feb 07 jari 524   }//end validateLabels()
2 26 Feb 07 jari 525   
2 26 Feb 07 jari 526   
2 26 Feb 07 jari 527   /**
2 26 Feb 07 jari 528    * Displays a dialog box with a message
2 26 Feb 07 jari 529    * @param message
2 26 Feb 07 jari 530    */
2 26 Feb 07 jari 531   public void error( String message ) {
2 26 Feb 07 jari 532     JOptionPane.showMessageDialog( this, message, "Input Error", JOptionPane.ERROR_MESSAGE );
2 26 Feb 07 jari 533   }//end error()
2 26 Feb 07 jari 534   
2 26 Feb 07 jari 535     
2 26 Feb 07 jari 536   /**
2 26 Feb 07 jari 537    * Shows this AlgorithmDialog
2 26 Feb 07 jari 538    * @return  
2 26 Feb 07 jari 539    */
2 26 Feb 07 jari 540   public int showModal() {
2 26 Feb 07 jari 541     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2 26 Feb 07 jari 542     setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2);
2 26 Feb 07 jari 543     show();
2 26 Feb 07 jari 544     return result;
2 26 Feb 07 jari 545   }//end showModal()
2 26 Feb 07 jari 546   
2 26 Feb 07 jari 547   
2 26 Feb 07 jari 548   private class SpinListener implements ChangeListener {
2 26 Feb 07 jari 549     public void stateChanged(ChangeEvent e) {
2 26 Feb 07 jari 550       numClassesChanged();
2 26 Feb 07 jari 551     }
2 26 Feb 07 jari 552   }
2 26 Feb 07 jari 553   
2 26 Feb 07 jari 554   
2 26 Feb 07 jari 555   private class ButtonListener implements ItemListener {
2 26 Feb 07 jari 556     public void itemStateChanged(ItemEvent e) {
2 26 Feb 07 jari 557       if( e.getSource() == advActive ) {
2 26 Feb 07 jari 558         if( e.getStateChange() == ItemEvent.DESELECTED ) {
2 26 Feb 07 jari 559           setParamEnabled( false );
2 26 Feb 07 jari 560         } else if( e.getStateChange() == ItemEvent.SELECTED ) {
2 26 Feb 07 jari 561           setParamEnabled( true );
2 26 Feb 07 jari 562         }
2 26 Feb 07 jari 563       } else if( e.getSource() == trainClassify ) {
2 26 Feb 07 jari 564         if( e.getStateChange() == ItemEvent.SELECTED ) {
2 26 Feb 07 jari 565           setLabelEnabled( true );
2 26 Feb 07 jari 566           setAdvEnabled( true );
2 26 Feb 07 jari 567         }
2 26 Feb 07 jari 568       } else if( e.getSource() == fileClassify ) {
2 26 Feb 07 jari 569         if( e.getStateChange() == ItemEvent.SELECTED ) {
2 26 Feb 07 jari 570           setLabelEnabled( false );
2 26 Feb 07 jari 571           setAdvEnabled( false );
2 26 Feb 07 jari 572         }
2 26 Feb 07 jari 573       }
2 26 Feb 07 jari 574     }//end itemStateChanged()
2 26 Feb 07 jari 575   }//end ButtonListener class
2 26 Feb 07 jari 576   
2 26 Feb 07 jari 577     
2 26 Feb 07 jari 578   /**
2 26 Feb 07 jari 579    * The class to listen to the dialog and check boxes items events.
2 26 Feb 07 jari 580    */
2 26 Feb 07 jari 581   private class Listener extends DialogListener implements ItemListener {
2 26 Feb 07 jari 582         
2 26 Feb 07 jari 583     public void actionPerformed(ActionEvent e) {
2 26 Feb 07 jari 584       String command = e.getActionCommand();
2 26 Feb 07 jari 585       if (command.equals("ok-command")) {
2 26 Feb 07 jari 586         if( trainClassify.isSelected() ) {
2 26 Feb 07 jari 587           //need to validate class labels
2 26 Feb 07 jari 588           if( validateLabels() ) {
2 26 Feb 07 jari 589             result = JOptionPane.OK_OPTION;
2 26 Feb 07 jari 590             dispose();
2 26 Feb 07 jari 591           } else {
2 26 Feb 07 jari 592             //do nothing
2 26 Feb 07 jari 593           }
2 26 Feb 07 jari 594         } else {
2 26 Feb 07 jari 595           //loading a file
2 26 Feb 07 jari 596           result = JOptionPane.OK_OPTION;
2 26 Feb 07 jari 597           dispose();
2 26 Feb 07 jari 598         }
2 26 Feb 07 jari 599       } else if (command.equals("cancel-command")) {
2 26 Feb 07 jari 600         result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 601         dispose();
2 26 Feb 07 jari 602       } else if (command.equals("reset-command")) {
2 26 Feb 07 jari 603         //resetControls();
2 26 Feb 07 jari 604         result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 605         return;
2 26 Feb 07 jari 606       } else if (command.equals("info-command")) {
2 26 Feb 07 jari 607         HelpWindow hw = new HelpWindow(USCClassDialog.this, "USC Initialization Dialog");
2 26 Feb 07 jari 608         result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 609         if(hw.getWindowContent()){
2 26 Feb 07 jari 610           hw.setSize(450,600);
2 26 Feb 07 jari 611           hw.setLocation();
2 26 Feb 07 jari 612           hw.show();
2 26 Feb 07 jari 613           return;
2 26 Feb 07 jari 614         } else {
2 26 Feb 07 jari 615           hw.setVisible(false);
2 26 Feb 07 jari 616           hw.dispose();
2 26 Feb 07 jari 617           return;
2 26 Feb 07 jari 618         }
2 26 Feb 07 jari 619       }
2 26 Feb 07 jari 620       //dispose();
2 26 Feb 07 jari 621     }//end actionPerformed()
2 26 Feb 07 jari 622         
2 26 Feb 07 jari 623     public void itemStateChanged(ItemEvent e) {
2 26 Feb 07 jari 624       //okButton.setEnabled(genes_box.isSelected() || cluster_box.isSelected());
2 26 Feb 07 jari 625     }
2 26 Feb 07 jari 626         
2 26 Feb 07 jari 627     public void windowClosing(WindowEvent e) {
2 26 Feb 07 jari 628       result = JOptionPane.CLOSED_OPTION;
2 26 Feb 07 jari 629       dispose();
2 26 Feb 07 jari 630     }
2 26 Feb 07 jari 631   }//end internal Listener class
2 26 Feb 07 jari 632   
2 26 Feb 07 jari 633   
2 26 Feb 07 jari 634   //--------------------------------------Getters & Setters----------------------------------
2 26 Feb 07 jari 635   public int getAnalysisOption() {
2 26 Feb 07 jari 636     if( this.trainClassify.isSelected() ) {
2 26 Feb 07 jari 637       return USCClassDialog.TRAIN_THEN_CLASSIFY;
2 26 Feb 07 jari 638     } else {
2 26 Feb 07 jari 639       return USCClassDialog.CLASSIFY_FROM_FILE;
2 26 Feb 07 jari 640     }
2 26 Feb 07 jari 641   }
2 26 Feb 07 jari 642   public int getNumClasses() {
2 26 Feb 07 jari 643     SpinnerNumberModel model = ( SpinnerNumberModel ) this.numClasses.getModel();
2 26 Feb 07 jari 644     return model.getNumber().intValue();
2 26 Feb 07 jari 645   }
2 26 Feb 07 jari 646   public int getFolds() {
2 26 Feb 07 jari 647     SpinnerNumberModel model = ( SpinnerNumberModel ) this.numFolds.getModel();
2 26 Feb 07 jari 648     return model.getNumber().intValue();
2 26 Feb 07 jari 649   }
2 26 Feb 07 jari 650   public int getXValRuns() {
2 26 Feb 07 jari 651     SpinnerNumberModel model = ( SpinnerNumberModel ) this.numXVal.getModel();
2 26 Feb 07 jari 652     return model.getNumber().intValue();
2 26 Feb 07 jari 653   }
2 26 Feb 07 jari 654   public int getNumBins() {
2 26 Feb 07 jari 655     SpinnerNumberModel model = ( SpinnerNumberModel ) this.numBins.getModel();
2 26 Feb 07 jari 656     return model.getNumber().intValue();
2 26 Feb 07 jari 657   }
2 26 Feb 07 jari 658   public int getDeltaMax() {
2 26 Feb 07 jari 659     SpinnerNumberModel model = ( SpinnerNumberModel ) this.deltaMax.getModel();
2 26 Feb 07 jari 660     return model.getNumber().intValue();
2 26 Feb 07 jari 661   }
2 26 Feb 07 jari 662   public double getCorrLo() {
2 26 Feb 07 jari 663     Double D = new Double( this.corrLo.getText() );
2 26 Feb 07 jari 664     return D.doubleValue();
2 26 Feb 07 jari 665   }
2 26 Feb 07 jari 666   public double getCorrHi() {
2 26 Feb 07 jari 667     Double D = new Double( this.corrHi.getText() );
2 26 Feb 07 jari 668     return D.doubleValue();
2 26 Feb 07 jari 669   }
2 26 Feb 07 jari 670   public double getCorrStep() {
2 26 Feb 07 jari 671     Double D = new Double( this.corrStep.getText() );
2 26 Feb 07 jari 672     return D.doubleValue();
2 26 Feb 07 jari 673   }
2 26 Feb 07 jari 674   public String[] getClassLabels() {
2 26 Feb 07 jari 675     String[] toReturn = new String[ this.vField.size() + 1 ];
2 26 Feb 07 jari 676     
2 26 Feb 07 jari 677     for( int i = 0; i < this.vField.size(); i ++ ) {
2 26 Feb 07 jari 678       JTextField field = ( JTextField ) this.vField.elementAt( i );
2 26 Feb 07 jari 679       toReturn[ i ] = field.getText();
2 26 Feb 07 jari 680     }//end i
2 26 Feb 07 jari 681     
2 26 Feb 07 jari 682     //add the option to let algorithm know this is a test hyb
2 26 Feb 07 jari 683     toReturn[ this.vField.size() ] = ClassAssigner.TEST_CLASS_STRING;
2 26 Feb 07 jari 684     
2 26 Feb 07 jari 685     return toReturn;
2 26 Feb 07 jari 686   }
2 26 Feb 07 jari 687 }//end class