source: src/main/java/weka/gui/experiment/SimpleSetupPanel.java @ 20

Last change on this file since 20 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 42.2 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    SimpleSetupPanel.java
19 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.experiment;
24
25import weka.classifiers.Classifier;
26import weka.classifiers.AbstractClassifier;
27import weka.core.xml.KOML;
28import weka.experiment.CSVResultListener;
29import weka.experiment.ClassifierSplitEvaluator;
30import weka.experiment.CrossValidationResultProducer;
31import weka.experiment.DatabaseResultListener;
32import weka.experiment.Experiment;
33import weka.experiment.InstancesResultListener;
34import weka.experiment.PropertyNode;
35import weka.experiment.RandomSplitResultProducer;
36import weka.experiment.RegressionSplitEvaluator;
37import weka.experiment.SplitEvaluator;
38import weka.gui.DatabaseConnectionDialog;
39import weka.gui.ExtensionFileFilter;
40
41import java.awt.BorderLayout;
42import java.awt.GridBagConstraints;
43import java.awt.GridBagLayout;
44import java.awt.GridLayout;
45import java.awt.Insets;
46import java.awt.event.ActionEvent;
47import java.awt.event.ActionListener;
48import java.awt.event.FocusAdapter;
49import java.awt.event.FocusEvent;
50import java.awt.event.KeyAdapter;
51import java.awt.event.KeyEvent;
52import java.awt.event.WindowAdapter;
53import java.awt.event.WindowEvent;
54import java.beans.IntrospectionException;
55import java.beans.PropertyChangeListener;
56import java.beans.PropertyChangeSupport;
57import java.beans.PropertyDescriptor;
58import java.io.File;
59
60import javax.swing.BorderFactory;
61import javax.swing.ButtonGroup;
62import javax.swing.JButton;
63import javax.swing.JComboBox;
64import javax.swing.JFileChooser;
65import javax.swing.JFrame;
66import javax.swing.JLabel;
67import javax.swing.JOptionPane;
68import javax.swing.JPanel;
69import javax.swing.JRadioButton;
70import javax.swing.JScrollPane;
71import javax.swing.JTextArea;
72import javax.swing.JTextField;
73import javax.swing.event.DocumentEvent;
74import javax.swing.event.DocumentListener;
75import javax.swing.filechooser.FileFilter;
76
77/**
78 * This panel controls the configuration of an experiment.
79  * <p>
80 * If <a href="http://koala.ilog.fr/XML/serialization/" target="_blank">KOML</a>
81 * is in the classpath the experiments can also be serialized to XML instead of a
82 * binary format.
83*
84 * @author Richard kirkby (rkirkby@cs.waikato.ac.nz)
85 * @author FracPete (fracpete at waikato dot ac dot nz)
86 * @version $Revision: 5928 $
87 */
88public class SimpleSetupPanel
89  extends JPanel {
90
91  /** for serialization */
92  private static final long serialVersionUID = 5257424515609176509L;
93
94  /** The experiment being configured */
95  protected Experiment m_Exp;
96
97  /** The panel which switched between simple and advanced setup modes */
98  protected SetupModePanel m_modePanel = null;
99
100  /** The database destination URL to store results into */
101  protected String m_destinationDatabaseURL;
102
103  /** The filename to store results into */
104  protected String m_destinationFilename = "";
105
106  /** The number of folds for a cross-validation experiment */
107  protected int m_numFolds = 10;
108
109  /** The training percentage for a train/test split experiment */
110  protected double m_trainPercent = 66;
111
112  /** The number of times to repeat the sub-experiment */
113  protected int m_numRepetitions = 10;
114
115  /** Whether or not the user has consented for the experiment to be simplified */
116  protected boolean m_userHasBeenAskedAboutConversion;
117
118  /** Filter for choosing CSV files */
119  protected ExtensionFileFilter m_csvFileFilter =
120    new ExtensionFileFilter(".csv", "Comma separated value files");
121
122  /** FIlter for choosing ARFF files */
123  protected ExtensionFileFilter m_arffFileFilter =
124    new ExtensionFileFilter(".arff", "ARFF files");
125
126  /** Click to load an experiment */
127  protected JButton m_OpenBut = new JButton("Open...");
128
129  /** Click to save an experiment */
130  protected JButton m_SaveBut = new JButton("Save...");
131
132  /** Click to create a new experiment with default settings */
133  protected JButton m_NewBut = new JButton("New");
134
135  /** A filter to ensure only experiment files get shown in the chooser */
136  protected FileFilter m_ExpFilter = 
137    new ExtensionFileFilter(Experiment.FILE_EXTENSION, 
138                            "Experiment configuration files (*" + Experiment.FILE_EXTENSION + ")");
139
140  /** A filter to ensure only experiment (in KOML format) files get shown in the chooser */
141  protected FileFilter m_KOMLFilter = 
142    new ExtensionFileFilter(KOML.FILE_EXTENSION, 
143                            "Experiment configuration files (*" + KOML.FILE_EXTENSION + ")");
144
145  /** A filter to ensure only experiment (in XML format) files get shown in the chooser */
146  protected FileFilter m_XMLFilter = 
147    new ExtensionFileFilter(".xml", 
148                            "Experiment configuration files (*.xml)");
149
150  /** The file chooser for selecting experiments */
151  protected JFileChooser m_FileChooser =
152    new JFileChooser(new File(System.getProperty("user.dir")));
153
154  /** The file chooser for selecting result destinations */
155  protected JFileChooser m_DestFileChooser =
156    new JFileChooser(new File(System.getProperty("user.dir")));
157
158  /** Combo box for choosing experiment destination type */
159  protected JComboBox m_ResultsDestinationCBox = new JComboBox();
160
161  /** Label for destination field */
162  protected JLabel m_ResultsDestinationPathLabel = new JLabel("Filename:");
163
164  /** Input field for result destination path */ 
165  protected JTextField m_ResultsDestinationPathTField = new JTextField();
166
167  /** Button for browsing destination files */
168  protected JButton m_BrowseDestinationButton = new JButton("Browse...");
169
170  /** Combo box for choosing experiment type */
171  protected JComboBox m_ExperimentTypeCBox = new JComboBox();
172
173  /** Label for parameter field */
174  protected JLabel m_ExperimentParameterLabel = new JLabel("Number of folds:");
175
176  /** Input field for experiment parameter */
177  protected JTextField m_ExperimentParameterTField = new JTextField(); 
178
179  /** Radio button for choosing classification experiment */
180  protected JRadioButton m_ExpClassificationRBut = 
181    new JRadioButton("Classification");
182
183  /** Radio button for choosing regression experiment */
184  protected JRadioButton m_ExpRegressionRBut = 
185    new JRadioButton("Regression");
186
187  /** Input field for number of repetitions */
188  protected JTextField m_NumberOfRepetitionsTField = new JTextField(); 
189
190  /** Radio button for choosing datasets first in order of execution */ 
191  protected JRadioButton m_OrderDatasetsFirstRBut = 
192    new JRadioButton("Data sets first");
193
194  /** Radio button for choosing algorithms first in order of execution */ 
195  protected JRadioButton m_OrderAlgorithmsFirstRBut = 
196    new JRadioButton("Algorithms first");
197
198  /** The strings used to identify the combo box choices */
199  protected static String DEST_DATABASE_TEXT = ("JDBC database");
200  protected static String DEST_ARFF_TEXT = ("ARFF file");
201  protected static String DEST_CSV_TEXT = ("CSV file");
202  protected static String TYPE_CROSSVALIDATION_TEXT = ("Cross-validation");
203  protected static String TYPE_RANDOMSPLIT_TEXT = ("Train/Test Percentage Split (data randomized)");
204  protected static String TYPE_FIXEDSPLIT_TEXT = ("Train/Test Percentage Split (order preserved)");
205
206  /** The panel for configuring selected datasets */
207  protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel();
208
209  /** The panel for configuring selected algorithms */
210  protected AlgorithmListPanel m_AlgorithmListPanel = new AlgorithmListPanel();
211
212  /** A button for bringing up the notes */
213  protected JButton m_NotesButton =  new JButton("Notes");
214
215  /** Frame for the notes */
216  protected JFrame m_NotesFrame = new JFrame("Notes");
217
218  /** Area for user notes Default of 10 rows */
219  protected JTextArea m_NotesText = new JTextArea(null, 10, 0);
220
221  /**
222   * Manages sending notifications to people when we change the experiment,
223   * at this stage, only the resultlistener so the resultpanel can update.
224   */
225  protected PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
226 
227  /**
228   * Creates the setup panel with the supplied initial experiment.
229   *
230   * @param exp a value of type 'Experiment'
231   */
232  public SimpleSetupPanel(Experiment exp) {
233
234    this();
235    setExperiment(exp);
236  }
237 
238  /**
239   * Creates the setup panel with no initial experiment.
240   */
241  public SimpleSetupPanel() {
242
243    // everything disabled on startup
244    m_ResultsDestinationCBox.setEnabled(false);
245    m_ResultsDestinationPathLabel.setEnabled(false);
246    m_ResultsDestinationPathTField.setEnabled(false);
247    m_BrowseDestinationButton.setEnabled(false); 
248    m_ExperimentTypeCBox.setEnabled(false);
249    m_ExperimentParameterLabel.setEnabled(false);
250    m_ExperimentParameterTField.setEnabled(false);
251    m_ExpClassificationRBut.setEnabled(false);
252    m_ExpRegressionRBut.setEnabled(false);
253    m_NumberOfRepetitionsTField.setEnabled(false);
254    m_OrderDatasetsFirstRBut.setEnabled(false);
255    m_OrderAlgorithmsFirstRBut.setEnabled(false);
256
257    // get sensible default database address
258    try {
259      m_destinationDatabaseURL = (new DatabaseResultListener()).getDatabaseURL();
260    } catch (Exception e) {}
261
262    // create action listeners
263    m_NewBut.setMnemonic('N');
264    m_NewBut.addActionListener(new ActionListener() {
265        public void actionPerformed(ActionEvent e) {
266          Experiment newExp = new Experiment();
267          CrossValidationResultProducer cvrp = new CrossValidationResultProducer();
268          cvrp.setNumFolds(10);
269          cvrp.setSplitEvaluator(new ClassifierSplitEvaluator());
270          newExp.setResultProducer(cvrp);
271          newExp.setPropertyArray(new Classifier[0]);
272          newExp.setUsePropertyIterator(true);
273          setExperiment(newExp);
274
275          // defaults
276          if (ExperimenterDefaults.getUseClassification())
277            m_ExpClassificationRBut.setSelected(true);
278          else
279            m_ExpRegressionRBut.setSelected(true);
280         
281          setSelectedItem(
282              m_ResultsDestinationCBox, ExperimenterDefaults.getDestination());
283          destinationTypeChanged();
284         
285          setSelectedItem(
286              m_ExperimentTypeCBox, ExperimenterDefaults.getExperimentType());
287         
288          m_numRepetitions = ExperimenterDefaults.getRepetitions();
289          m_NumberOfRepetitionsTField.setText(
290              "" + m_numRepetitions);
291         
292          if (ExperimenterDefaults.getExperimentType().equals(
293                TYPE_CROSSVALIDATION_TEXT)) {
294            m_numFolds = ExperimenterDefaults.getFolds();
295            m_ExperimentParameterTField.setText(
296                "" + m_numFolds);
297          }
298          else {
299            m_trainPercent = ExperimenterDefaults.getTrainPercentage();
300            m_ExperimentParameterTField.setText(
301                "" + m_trainPercent);
302          }
303         
304          if (ExperimenterDefaults.getDatasetsFirst())
305            m_OrderDatasetsFirstRBut.setSelected(true);
306          else
307            m_OrderAlgorithmsFirstRBut.setSelected(true);
308
309          expTypeChanged();
310        }
311      });
312    m_SaveBut.setEnabled(false);
313    m_SaveBut.setMnemonic('S');
314    m_SaveBut.addActionListener(new ActionListener() {
315        public void actionPerformed(ActionEvent e) {
316          saveExperiment();
317        }
318      });
319    m_OpenBut.setMnemonic('O');
320    m_OpenBut.addActionListener(new ActionListener() {
321        public void actionPerformed(ActionEvent e) {
322          openExperiment();
323        }
324      });
325    m_FileChooser.addChoosableFileFilter(m_ExpFilter);
326    if (KOML.isPresent())
327       m_FileChooser.addChoosableFileFilter(m_KOMLFilter);
328    m_FileChooser.addChoosableFileFilter(m_XMLFilter);
329    if (ExperimenterDefaults.getExtension().equals(".xml"))
330      m_FileChooser.setFileFilter(m_XMLFilter);
331    else if (KOML.isPresent() && ExperimenterDefaults.getExtension().equals(KOML.FILE_EXTENSION))
332      m_FileChooser.setFileFilter(m_KOMLFilter);
333    else
334      m_FileChooser.setFileFilter(m_ExpFilter);
335    m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
336    m_DestFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
337
338    m_BrowseDestinationButton.addActionListener(new ActionListener() {
339        public void actionPerformed(ActionEvent e) {
340          //using this button for both browsing file & setting username/password
341          if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT){
342            chooseURLUsername();
343          } else {
344            chooseDestinationFile();
345          }
346        }
347      });
348
349    m_ExpClassificationRBut.addActionListener(new ActionListener() {
350        public void actionPerformed(ActionEvent e) {
351          expTypeChanged();
352        }
353      });
354 
355    m_ExpRegressionRBut.addActionListener(new ActionListener() {
356        public void actionPerformed(ActionEvent e) {
357          expTypeChanged();
358        }
359      });
360
361    m_OrderDatasetsFirstRBut.addActionListener(new ActionListener() {
362        public void actionPerformed(ActionEvent e) {
363          if (m_Exp != null) {
364            m_Exp.setAdvanceDataSetFirst(true);
365            m_Support.firePropertyChange("", null, null);
366          }
367        }
368      });
369   
370    m_OrderAlgorithmsFirstRBut.addActionListener(new ActionListener() {
371        public void actionPerformed(ActionEvent e) {
372          if (m_Exp != null) {
373            m_Exp.setAdvanceDataSetFirst(false);
374            m_Support.firePropertyChange("", null, null);
375          }
376        }
377      });
378
379    m_ResultsDestinationPathTField.getDocument().addDocumentListener(new DocumentListener() {
380        public void insertUpdate(DocumentEvent e) {destinationAddressChanged();}
381        public void removeUpdate(DocumentEvent e) {destinationAddressChanged();}
382        public void changedUpdate(DocumentEvent e) {destinationAddressChanged();}
383      });
384
385    m_ExperimentParameterTField.getDocument().addDocumentListener(new DocumentListener() {
386        public void insertUpdate(DocumentEvent e) {expParamChanged();}
387        public void removeUpdate(DocumentEvent e) {expParamChanged();}
388        public void changedUpdate(DocumentEvent e) {expParamChanged();}
389      });
390
391    m_NumberOfRepetitionsTField.getDocument().addDocumentListener(new DocumentListener() {
392        public void insertUpdate(DocumentEvent e) {numRepetitionsChanged();}
393        public void removeUpdate(DocumentEvent e) {numRepetitionsChanged();}
394        public void changedUpdate(DocumentEvent e) {numRepetitionsChanged();}
395      });
396
397    m_NotesFrame.addWindowListener(new WindowAdapter() {
398        public void windowClosing(WindowEvent e) {
399          m_NotesButton.setEnabled(true);
400        }
401      });
402    m_NotesFrame.getContentPane().add(new JScrollPane(m_NotesText));
403    m_NotesFrame.setSize(600, 400);
404
405    m_NotesButton.addActionListener(new ActionListener() {
406        public void actionPerformed(ActionEvent e) {
407          m_NotesButton.setEnabled(false);
408          m_NotesFrame.setVisible(true);
409        }
410      });
411    m_NotesButton.setEnabled(false);
412
413    m_NotesText.setEditable(true);
414    //m_NotesText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
415    m_NotesText.addKeyListener(new KeyAdapter() {
416        public void keyReleased(KeyEvent e) {
417          m_Exp.setNotes(m_NotesText.getText());
418        }
419      });
420    m_NotesText.addFocusListener(new FocusAdapter() {
421        public void focusLost(FocusEvent e) {
422          m_Exp.setNotes(m_NotesText.getText());
423        }
424      });
425   
426    // Set up the GUI layout
427    JPanel buttons = new JPanel();
428    GridBagLayout gb = new GridBagLayout();
429    GridBagConstraints constraints = new GridBagConstraints();
430    buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
431    buttons.setLayout(gb);
432    constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;
433    constraints.fill = GridBagConstraints.HORIZONTAL;
434    constraints.gridwidth=1;constraints.gridheight=1;
435    constraints.insets = new Insets(0,2,0,2);
436    buttons.add(m_OpenBut,constraints);
437    constraints.gridx=1;constraints.gridy=0;constraints.weightx=5;
438    constraints.gridwidth=1;constraints.gridheight=1;
439    buttons.add(m_SaveBut,constraints);
440    constraints.gridx=2;constraints.gridy=0;constraints.weightx=5;
441    constraints.gridwidth=1;constraints.gridheight=1;
442    buttons.add(m_NewBut,constraints);
443
444    JPanel destName = new JPanel();
445    destName.setLayout(new BorderLayout(5, 5));
446    destName.add(m_ResultsDestinationPathLabel, BorderLayout.WEST);
447    destName.add(m_ResultsDestinationPathTField, BorderLayout.CENTER);
448   
449    m_ResultsDestinationCBox.addItem(DEST_ARFF_TEXT);
450    m_ResultsDestinationCBox.addItem(DEST_CSV_TEXT);
451    m_ResultsDestinationCBox.addItem(DEST_DATABASE_TEXT);
452   
453    m_ResultsDestinationCBox.addActionListener(new ActionListener() {
454        public void actionPerformed(ActionEvent e) {
455          destinationTypeChanged();
456        }
457      });
458
459    JPanel destInner = new JPanel();
460    destInner.setLayout(new BorderLayout(5, 5));
461    destInner.add(m_ResultsDestinationCBox, BorderLayout.WEST);
462    destInner.add(destName, BorderLayout.CENTER);
463    destInner.add(m_BrowseDestinationButton, BorderLayout.EAST);
464
465    JPanel dest = new JPanel();
466    dest.setLayout(new BorderLayout());
467    dest.setBorder(BorderFactory.createCompoundBorder(
468                  BorderFactory.createTitledBorder("Results Destination"),
469                  BorderFactory.createEmptyBorder(0, 5, 5, 5)
470                  ));
471    dest.add(destInner, BorderLayout.NORTH);
472
473    JPanel expParam = new JPanel();
474    expParam.setLayout(new BorderLayout(5, 5));
475    expParam.add(m_ExperimentParameterLabel, BorderLayout.WEST);
476    expParam.add(m_ExperimentParameterTField, BorderLayout.CENTER);
477
478    ButtonGroup typeBG = new ButtonGroup();
479    typeBG.add(m_ExpClassificationRBut);
480    typeBG.add(m_ExpRegressionRBut);
481    m_ExpClassificationRBut.setSelected(true);
482
483    JPanel typeRButtons = new JPanel();
484    typeRButtons.setLayout(new GridLayout(1,0));
485    typeRButtons.add(m_ExpClassificationRBut);
486    typeRButtons.add(m_ExpRegressionRBut);
487
488    m_ExperimentTypeCBox.addItem(TYPE_CROSSVALIDATION_TEXT);
489    m_ExperimentTypeCBox.addItem(TYPE_RANDOMSPLIT_TEXT);
490    m_ExperimentTypeCBox.addItem(TYPE_FIXEDSPLIT_TEXT);
491
492    m_ExperimentTypeCBox.addActionListener(new ActionListener() {
493        public void actionPerformed(ActionEvent e) {
494          expTypeChanged();
495        }
496      });
497
498    JPanel typeInner = new JPanel();
499    typeInner.setLayout(new GridLayout(0,1));
500    typeInner.add(m_ExperimentTypeCBox);
501    typeInner.add(expParam);
502    typeInner.add(typeRButtons);
503
504    JPanel type = new JPanel();
505    type.setLayout(new BorderLayout());
506    type.setBorder(BorderFactory.createCompoundBorder(
507                  BorderFactory.createTitledBorder("Experiment Type"),
508                  BorderFactory.createEmptyBorder(0, 5, 5, 5)
509                  ));
510    type.add(typeInner, BorderLayout.NORTH);
511
512    ButtonGroup iterBG = new ButtonGroup();
513    iterBG.add(m_OrderDatasetsFirstRBut);
514    iterBG.add(m_OrderAlgorithmsFirstRBut);
515    m_OrderDatasetsFirstRBut.setSelected(true);
516
517    JPanel numIter = new JPanel();
518    numIter.setLayout(new BorderLayout(5, 5));
519    numIter.add(new JLabel("Number of repetitions:"), BorderLayout.WEST);
520    numIter.add(m_NumberOfRepetitionsTField, BorderLayout.CENTER);
521
522    JPanel controlInner = new JPanel();
523    controlInner.setLayout(new GridLayout(0,1));
524    controlInner.add(numIter);
525    controlInner.add(m_OrderDatasetsFirstRBut);
526    controlInner.add(m_OrderAlgorithmsFirstRBut);
527
528    JPanel control = new JPanel();
529    control.setLayout(new BorderLayout());
530    control.setBorder(BorderFactory.createCompoundBorder(
531                  BorderFactory.createTitledBorder("Iteration Control"),
532                  BorderFactory.createEmptyBorder(0, 5, 5, 5)
533                  ));
534    control.add(controlInner, BorderLayout.NORTH);
535
536    JPanel type_control = new JPanel();
537    type_control.setLayout(new GridLayout(1,0));
538    type_control.add(type);
539    type_control.add(control);
540
541    JPanel notes = new JPanel();
542    notes.setLayout(new BorderLayout());
543    notes.add(m_NotesButton, BorderLayout.CENTER);
544
545    JPanel top1 = new JPanel();
546    top1.setLayout(new BorderLayout());
547    top1.add(dest, BorderLayout.NORTH);
548    top1.add(type_control, BorderLayout.CENTER);
549
550    JPanel top = new JPanel();
551    top.setLayout(new BorderLayout());
552    top.add(buttons, BorderLayout.NORTH);
553    top.add(top1, BorderLayout.CENTER); 
554
555    JPanel datasets = new JPanel();
556    datasets.setLayout(new BorderLayout());
557    datasets.add(m_DatasetListPanel, BorderLayout.CENTER);
558
559    JPanel algorithms = new JPanel();
560    algorithms.setLayout(new BorderLayout());
561    algorithms.add(m_AlgorithmListPanel, BorderLayout.CENTER);
562
563    JPanel schemes = new JPanel();
564    schemes.setLayout(new GridLayout(1,0));
565    schemes.add(datasets);
566    schemes.add(algorithms);
567
568    setLayout(new BorderLayout());
569    add(top, BorderLayout.NORTH);
570    add(schemes, BorderLayout.CENTER);
571    add(notes, BorderLayout.SOUTH);
572  }
573 
574  /**
575   * Sets the selected item of an combobox, since using setSelectedItem(...)
576   * doesn't work, if one checks object references!
577   *
578   * @param cb      the combobox to set the item for
579   * @param item    the item to set active
580   */
581  protected void setSelectedItem(JComboBox cb, String item) {
582    int       i;
583
584    for (i = 0; i < cb.getItemCount(); i++) {
585      if (cb.getItemAt(i).toString().equals(item)) {
586        cb.setSelectedIndex(i);
587        break;
588      }
589    }
590  }
591 
592  /**
593   * Deletes the notes frame.
594   */
595  protected void removeNotesFrame() {
596    m_NotesFrame.setVisible(false);
597  }
598
599  /**
600   * Gets te users consent for converting the experiment to a simpler form.
601   *
602   * @return true if the user has given consent, false otherwise
603   */ 
604  private boolean userWantsToConvert() {
605   
606    if (m_userHasBeenAskedAboutConversion) return true;
607    m_userHasBeenAskedAboutConversion = true;
608    return (JOptionPane.showConfirmDialog(this,
609                                          "This experiment has settings that are too advanced\n" +
610                                          "to be represented in the simple setup mode.\n" +
611                                          "Do you want the experiment to be converted,\n" +
612                                          "losing some of the advanced settings?\n",
613                                          "Confirm conversion",
614                                          JOptionPane.YES_NO_OPTION,
615                                          JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION);
616  }
617
618  /**
619   * Sets the panel used to switch between simple and advanced modes.
620   *
621   * @param modePanel the panel
622   */
623  public void setModePanel(SetupModePanel modePanel) {
624
625    m_modePanel = modePanel;
626  }
627
628  /**
629   * Sets the experiment to configure.
630   *
631   * @param exp a value of type 'Experiment'
632   * @return true if experiment could be configured, false otherwise
633   */
634  public boolean setExperiment(Experiment exp) {
635   
636    m_userHasBeenAskedAboutConversion = false;
637    m_Exp = null; // hold off until we are sure we want conversion
638    m_SaveBut.setEnabled(true);
639
640    if (exp.getResultListener() instanceof DatabaseResultListener) {
641      m_ResultsDestinationCBox.setSelectedItem(DEST_DATABASE_TEXT);
642      m_ResultsDestinationPathLabel.setText("URL:");
643      m_destinationDatabaseURL = ((DatabaseResultListener)exp.getResultListener()).getDatabaseURL();
644      m_ResultsDestinationPathTField.setText(m_destinationDatabaseURL);
645      m_BrowseDestinationButton.setEnabled(true);
646    } else if (exp.getResultListener() instanceof InstancesResultListener) {
647      m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT);
648      m_ResultsDestinationPathLabel.setText("Filename:");
649      m_destinationFilename = ((InstancesResultListener)exp.getResultListener()).outputFileName();
650      m_ResultsDestinationPathTField.setText(m_destinationFilename);
651      m_BrowseDestinationButton.setEnabled(true);
652    } else if (exp.getResultListener() instanceof CSVResultListener) {
653      m_ResultsDestinationCBox.setSelectedItem(DEST_CSV_TEXT);
654      m_ResultsDestinationPathLabel.setText("Filename:");
655      m_destinationFilename = ((CSVResultListener)exp.getResultListener()).outputFileName();
656      m_ResultsDestinationPathTField.setText(m_destinationFilename);
657      m_BrowseDestinationButton.setEnabled(true);
658    } else {
659      // unrecognised result listener
660      System.out.println("SimpleSetup incompatibility: unrecognised result destination");
661      if (userWantsToConvert()) {
662        m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT);
663        m_ResultsDestinationPathLabel.setText("Filename:");
664        m_destinationFilename = "";
665        m_ResultsDestinationPathTField.setText(m_destinationFilename);
666        m_BrowseDestinationButton.setEnabled(true);
667      } else {
668        return false;
669      }
670    }
671    m_ResultsDestinationCBox.setEnabled(true);
672    m_ResultsDestinationPathLabel.setEnabled(true);
673    m_ResultsDestinationPathTField.setEnabled(true);
674
675    if (exp.getResultProducer() instanceof CrossValidationResultProducer) {
676      CrossValidationResultProducer cvrp = (CrossValidationResultProducer) exp.getResultProducer();
677      m_numFolds = cvrp.getNumFolds();
678      m_ExperimentParameterTField.setText("" + m_numFolds);
679     
680      if (cvrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) {
681        m_ExpClassificationRBut.setSelected(true);
682        m_ExpRegressionRBut.setSelected(false);
683      } else if (cvrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) {
684        m_ExpClassificationRBut.setSelected(false);
685        m_ExpRegressionRBut.setSelected(true);
686      } else {
687        // unknown split evaluator
688        System.out.println("SimpleSetup incompatibility: unrecognised split evaluator");
689        if (userWantsToConvert()) {
690          m_ExpClassificationRBut.setSelected(true);
691          m_ExpRegressionRBut.setSelected(false);
692        } else {
693          return false;
694        }
695      }
696      m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT);
697    } else if (exp.getResultProducer() instanceof RandomSplitResultProducer) {
698      RandomSplitResultProducer rsrp = (RandomSplitResultProducer) exp.getResultProducer();
699      if (rsrp.getRandomizeData()) {
700        m_ExperimentTypeCBox.setSelectedItem(TYPE_RANDOMSPLIT_TEXT);
701      } else {
702        m_ExperimentTypeCBox.setSelectedItem(TYPE_FIXEDSPLIT_TEXT);
703      }
704      if (rsrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) {
705        m_ExpClassificationRBut.setSelected(true);
706        m_ExpRegressionRBut.setSelected(false);
707      } else if (rsrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) {
708        m_ExpClassificationRBut.setSelected(false);
709        m_ExpRegressionRBut.setSelected(true);
710      } else {
711        // unknown split evaluator
712        System.out.println("SimpleSetup incompatibility: unrecognised split evaluator");
713        if (userWantsToConvert()) {
714          m_ExpClassificationRBut.setSelected(true);
715          m_ExpRegressionRBut.setSelected(false);
716        } else {
717          return false;
718        }
719      }
720      m_trainPercent = rsrp.getTrainPercent();
721      m_ExperimentParameterTField.setText("" + m_trainPercent);
722     
723    } else {
724      // unknown experiment type
725      System.out.println("SimpleSetup incompatibility: unrecognised resultProducer");
726      if (userWantsToConvert()) {
727        m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT);
728        m_ExpClassificationRBut.setSelected(true);
729        m_ExpRegressionRBut.setSelected(false);
730      } else {
731        return false;
732      }
733    }
734
735    m_ExperimentTypeCBox.setEnabled(true);
736    m_ExperimentParameterLabel.setEnabled(true);
737    m_ExperimentParameterTField.setEnabled(true);
738    m_ExpClassificationRBut.setEnabled(true);
739    m_ExpRegressionRBut.setEnabled(true);
740   
741    if (exp.getRunLower() == 1) {
742      m_numRepetitions = exp.getRunUpper();
743      m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
744    } else {
745      // unsupported iterations
746      System.out.println("SimpleSetup incompatibility: runLower is not 1");
747      if (userWantsToConvert()) {
748        exp.setRunLower(1);
749        if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) {
750          exp.setRunUpper(1);
751          m_NumberOfRepetitionsTField.setEnabled(false);
752          m_NumberOfRepetitionsTField.setText("1");
753        } else {
754          exp.setRunUpper(10);
755          m_numRepetitions = 10;
756          m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
757        }
758       
759      } else {
760        return false;
761      }
762    }
763    m_NumberOfRepetitionsTField.setEnabled(true);
764
765    m_OrderDatasetsFirstRBut.setSelected(exp.getAdvanceDataSetFirst());
766    m_OrderAlgorithmsFirstRBut.setSelected(!exp.getAdvanceDataSetFirst());
767    m_OrderDatasetsFirstRBut.setEnabled(true);
768    m_OrderAlgorithmsFirstRBut.setEnabled(true);
769
770    m_NotesText.setText(exp.getNotes());
771    m_NotesButton.setEnabled(true);
772
773    if (!exp.getUsePropertyIterator() || !(exp.getPropertyArray() instanceof Classifier[])) {
774      // unknown property iteration
775      System.out.println("SimpleSetup incompatibility: unrecognised property iteration");
776      if (userWantsToConvert()) {
777        exp.setPropertyArray(new Classifier[0]);
778        exp.setUsePropertyIterator(true);
779      } else {
780        return false;
781      }
782    }
783
784    m_DatasetListPanel.setExperiment(exp);
785    m_AlgorithmListPanel.setExperiment(exp);
786   
787    m_Exp = exp;
788    expTypeChanged(); // recreate experiment
789   
790    m_Support.firePropertyChange("", null, null);
791   
792    return true;
793  }
794
795  /**
796   * Gets the currently configured experiment.
797   *
798   * @return the currently configured experiment.
799   */
800  public Experiment getExperiment() {
801
802    return m_Exp;
803  }
804 
805  /**
806   * Prompts the user to select an experiment file and loads it.
807   */
808  private void openExperiment() {
809   
810    int returnVal = m_FileChooser.showOpenDialog(this);
811    if (returnVal != JFileChooser.APPROVE_OPTION) {
812      return;
813    }
814    File expFile = m_FileChooser.getSelectedFile();
815   
816    // add extension if necessary
817    if (m_FileChooser.getFileFilter() == m_ExpFilter) {
818      if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION))
819        expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION);
820    }
821    else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {
822      if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION))
823        expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION);
824    }
825    else if (m_FileChooser.getFileFilter() == m_XMLFilter) {
826      if (!expFile.getName().toLowerCase().endsWith(".xml"))
827        expFile = new File(expFile.getParent(), expFile.getName() + ".xml");
828    }
829   
830    try {
831      Experiment exp = Experiment.read(expFile.getAbsolutePath());
832      if (!setExperiment(exp)) {
833        if (m_modePanel != null) m_modePanel.switchToAdvanced(exp);
834      }
835      System.err.println("Opened experiment:\n" + exp);
836    } catch (Exception ex) {
837      ex.printStackTrace();
838      JOptionPane.showMessageDialog(this, "Couldn't open experiment file:\n"
839                                    + expFile
840                                    + "\nReason:\n" + ex.getMessage(),
841                                    "Open Experiment",
842                                    JOptionPane.ERROR_MESSAGE);
843      // Pop up error dialog
844    }
845  }
846
847  /**
848   * Prompts the user for a filename to save the experiment to, then saves
849   * the experiment.
850   */
851  private void saveExperiment() {
852
853    int returnVal = m_FileChooser.showSaveDialog(this);
854    if (returnVal != JFileChooser.APPROVE_OPTION) {
855      return;
856    }
857    File expFile = m_FileChooser.getSelectedFile();
858   
859    // add extension if necessary
860    if (m_FileChooser.getFileFilter() == m_ExpFilter) {
861      if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION))
862        expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION);
863    }
864    else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {
865      if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION))
866        expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION);
867    }
868    else if (m_FileChooser.getFileFilter() == m_XMLFilter) {
869      if (!expFile.getName().toLowerCase().endsWith(".xml"))
870        expFile = new File(expFile.getParent(), expFile.getName() + ".xml");
871    }
872   
873    try {
874      Experiment.write(expFile.getAbsolutePath(), m_Exp);
875      System.err.println("Saved experiment:\n" + m_Exp);
876    } catch (Exception ex) {
877      ex.printStackTrace();
878      JOptionPane.showMessageDialog(this, "Couldn't save experiment file:\n"
879                                    + expFile
880                                    + "\nReason:\n" + ex.getMessage(),
881                                    "Save Experiment",
882                                    JOptionPane.ERROR_MESSAGE);
883    }
884  }
885
886  /**
887   * Adds a PropertyChangeListener who will be notified of value changes.
888   *
889   * @param l a value of type 'PropertyChangeListener'
890   */
891  public void addPropertyChangeListener(PropertyChangeListener l) {
892    m_Support.addPropertyChangeListener(l);
893  }
894
895  /**
896   * Removes a PropertyChangeListener.
897   *
898   * @param l a value of type 'PropertyChangeListener'
899   */
900  public void removePropertyChangeListener(PropertyChangeListener l) {
901    m_Support.removePropertyChangeListener(l);
902  }
903
904  /**
905   * Responds to a change in the destination type.
906   */
907  private void destinationTypeChanged() {
908
909    if (m_Exp == null) return;
910
911    String str = "";
912
913    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
914      m_ResultsDestinationPathLabel.setText("URL:");
915      str = m_destinationDatabaseURL;
916      m_BrowseDestinationButton.setEnabled(true); //!!!
917      m_BrowseDestinationButton.setText("User...");
918    } else {
919      m_ResultsDestinationPathLabel.setText("Filename:");
920      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
921        int ind = m_destinationFilename.lastIndexOf(".csv");
922        if (ind > -1) {
923          m_destinationFilename = m_destinationFilename.substring(0, ind) + ".arff";
924        }
925      }
926      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
927        int ind = m_destinationFilename.lastIndexOf(".arff");
928        if (ind > -1) {
929          m_destinationFilename = m_destinationFilename.substring(0, ind) + ".csv";
930        }
931      }
932      str = m_destinationFilename;
933      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
934        int ind = str.lastIndexOf(".csv");
935        if (ind > -1) {
936          str = str.substring(0, ind) + ".arff";
937        }
938      }
939      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
940        int ind = str.lastIndexOf(".arff");
941        if (ind > -1) {
942          str = str.substring(0, ind) + ".csv";
943        }
944      }
945      m_BrowseDestinationButton.setEnabled(true);
946      m_BrowseDestinationButton.setText("Browse...");
947    }
948
949    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
950      DatabaseResultListener drl = null;
951      try {
952        drl = new DatabaseResultListener();
953      } catch (Exception e) {
954        e.printStackTrace();
955      }
956      drl.setDatabaseURL(m_destinationDatabaseURL);
957      m_Exp.setResultListener(drl);
958    } else {
959      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
960        InstancesResultListener irl = new InstancesResultListener();
961        if (!m_destinationFilename.equals("")) {
962          irl.setOutputFile(new File(m_destinationFilename));
963        }
964        m_Exp.setResultListener(irl);
965      } else if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
966        CSVResultListener crl = new CSVResultListener();
967        if (!m_destinationFilename.equals("")) {
968          crl.setOutputFile(new File(m_destinationFilename));
969        }
970        m_Exp.setResultListener(crl);
971      }
972    }
973
974    m_ResultsDestinationPathTField.setText(str);
975
976    m_Support.firePropertyChange("", null, null);
977  }
978
979  /**
980   * Responds to a change in the destination address.
981   */
982  private void destinationAddressChanged() {
983
984    if (m_Exp == null) return;
985
986    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
987      m_destinationDatabaseURL = m_ResultsDestinationPathTField.getText();
988      if (m_Exp.getResultListener() instanceof DatabaseResultListener) {
989        ((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(m_destinationDatabaseURL);
990      }
991    } else {
992      File resultsFile = null;
993      m_destinationFilename = m_ResultsDestinationPathTField.getText();
994
995      // Use temporary file if no file name is provided
996      if (m_destinationFilename.equals("")) {
997        try {
998          if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
999            resultsFile = File.createTempFile("weka_experiment", ".arff");
1000          }
1001          if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1002            resultsFile = File.createTempFile("weka_experiment", ".csv");
1003          }
1004          resultsFile.deleteOnExit();
1005        } catch (Exception e) {
1006          System.err.println("Cannot create temp file, writing to standard out.");
1007          resultsFile = new File("-");
1008        }
1009      } else {
1010        if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
1011          if (!m_destinationFilename.endsWith(".arff")) {
1012            m_destinationFilename += ".arff";
1013          }
1014        }
1015        if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1016          if (!m_destinationFilename.endsWith(".csv")) {
1017            m_destinationFilename += ".csv";
1018          }
1019        }
1020        resultsFile = new File(m_destinationFilename);
1021      }
1022      ((CSVResultListener)m_Exp.getResultListener()).setOutputFile(resultsFile);
1023      ((CSVResultListener)m_Exp.getResultListener()).setOutputFileName(m_destinationFilename);
1024    }
1025
1026    m_Support.firePropertyChange("", null, null);
1027  }
1028
1029  /**
1030   * Responds to a change in the experiment type.
1031   */
1032  private void expTypeChanged() {
1033
1034    if (m_Exp == null) return;
1035
1036    // update parameter ui
1037    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1038      m_ExperimentParameterLabel.setText("Number of folds:");
1039      m_ExperimentParameterTField.setText("" + m_numFolds);
1040    } else {
1041      m_ExperimentParameterLabel.setText("Train percentage:");
1042      m_ExperimentParameterTField.setText("" + m_trainPercent);
1043    }
1044
1045    // update iteration ui
1046    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) {
1047      m_NumberOfRepetitionsTField.setEnabled(false);
1048      m_NumberOfRepetitionsTField.setText("1");
1049      m_Exp.setRunLower(1);
1050      m_Exp.setRunUpper(1);
1051    } else {
1052      m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
1053      m_NumberOfRepetitionsTField.setEnabled(true);
1054      m_Exp.setRunLower(1);
1055      m_Exp.setRunUpper(m_numRepetitions);
1056    }
1057
1058    SplitEvaluator se = null;
1059    Classifier sec = null;
1060    if (m_ExpClassificationRBut.isSelected()) {
1061      se = new ClassifierSplitEvaluator();
1062      sec = ((ClassifierSplitEvaluator)se).getClassifier();
1063    } else {
1064      se = new RegressionSplitEvaluator();
1065      sec = ((RegressionSplitEvaluator)se).getClassifier();
1066    }
1067   
1068    // build new ResultProducer
1069    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1070      CrossValidationResultProducer cvrp = new CrossValidationResultProducer();
1071      cvrp.setNumFolds(m_numFolds);
1072      cvrp.setSplitEvaluator(se);
1073     
1074      PropertyNode[] propertyPath = new PropertyNode[2];
1075      try {
1076        propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",
1077                                                                      CrossValidationResultProducer.class),
1078                                           CrossValidationResultProducer.class);
1079        propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",
1080                                                                       se.getClass()),
1081                                           se.getClass());
1082      } catch (IntrospectionException e) {
1083        e.printStackTrace();
1084      }
1085     
1086      m_Exp.setResultProducer(cvrp);
1087      m_Exp.setPropertyPath(propertyPath);
1088
1089    } else {
1090      RandomSplitResultProducer rsrp = new RandomSplitResultProducer();
1091      rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);
1092      rsrp.setTrainPercent(m_trainPercent);
1093      rsrp.setSplitEvaluator(se);
1094
1095      PropertyNode[] propertyPath = new PropertyNode[2];
1096      try {
1097        propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",
1098                                                                      RandomSplitResultProducer.class),
1099                                           RandomSplitResultProducer.class);
1100        propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",
1101                                                                       se.getClass()),
1102                                           se.getClass());
1103      } catch (IntrospectionException e) {
1104        e.printStackTrace();
1105      }
1106
1107      m_Exp.setResultProducer(rsrp);
1108      m_Exp.setPropertyPath(propertyPath);
1109
1110    }
1111
1112    m_Exp.setUsePropertyIterator(true);
1113    m_Support.firePropertyChange("", null, null);
1114  }
1115
1116  /**
1117   * Responds to a change in the experiment parameter.
1118   */
1119  private void expParamChanged() {
1120
1121    if (m_Exp == null) return;
1122
1123    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1124      try {
1125        m_numFolds = Integer.parseInt(m_ExperimentParameterTField.getText());
1126      } catch (NumberFormatException e) {
1127        return;
1128      }
1129    } else {
1130      try {
1131        m_trainPercent = Double.parseDouble(m_ExperimentParameterTField.getText());
1132      } catch (NumberFormatException e) {
1133        return;
1134      }
1135    }
1136
1137    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1138
1139      if (m_Exp.getResultProducer() instanceof CrossValidationResultProducer) {
1140        CrossValidationResultProducer cvrp = (CrossValidationResultProducer) m_Exp.getResultProducer();
1141        cvrp.setNumFolds(m_numFolds);
1142      } else {
1143        return;
1144      }
1145
1146    } else {
1147     
1148      if (m_Exp.getResultProducer() instanceof RandomSplitResultProducer) {
1149        RandomSplitResultProducer rsrp = (RandomSplitResultProducer) m_Exp.getResultProducer();
1150        rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);
1151        rsrp.setTrainPercent(m_trainPercent);
1152      } else {
1153        //System.err.println("not rsrp");
1154        return;
1155      }
1156    }
1157
1158    m_Support.firePropertyChange("", null, null);
1159  }
1160
1161  /**
1162   * Responds to a change in the number of repetitions.
1163   */
1164  private void numRepetitionsChanged() {
1165
1166    if (m_Exp == null || !m_NumberOfRepetitionsTField.isEnabled()) return;
1167
1168    try {
1169      m_numRepetitions = Integer.parseInt(m_NumberOfRepetitionsTField.getText());
1170    } catch (NumberFormatException e) {
1171      return;
1172    }
1173
1174    m_Exp.setRunLower(1);
1175    m_Exp.setRunUpper(m_numRepetitions);
1176
1177    m_Support.firePropertyChange("", null, null);
1178  }
1179
1180  /**
1181   * Lets user enter username/password/URL.
1182   */
1183  private void chooseURLUsername() {
1184    String dbaseURL=((DatabaseResultListener)m_Exp.getResultListener()).getDatabaseURL();
1185    String username=((DatabaseResultListener)m_Exp.getResultListener()).getUsername();
1186    DatabaseConnectionDialog dbd= new DatabaseConnectionDialog(null,dbaseURL,username);
1187    dbd.setVisible(true);
1188     
1189    //if (dbaseURL == null) {
1190    if (dbd.getReturnValue()==JOptionPane.CLOSED_OPTION) {
1191      return;
1192    }
1193
1194    ((DatabaseResultListener)m_Exp.getResultListener()).setUsername(dbd.getUsername());
1195    ((DatabaseResultListener)m_Exp.getResultListener()).setPassword(dbd.getPassword());
1196    ((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(dbd.getURL());
1197    ((DatabaseResultListener)m_Exp.getResultListener()).setDebug(dbd.getDebug());
1198    m_ResultsDestinationPathTField.setText(dbd.getURL());
1199  }
1200  /**
1201   * Lets user browse for a destination file..
1202   */
1203  private void chooseDestinationFile() {
1204
1205    FileFilter fileFilter = null;
1206    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1207      fileFilter = m_csvFileFilter;
1208    } else {
1209      fileFilter = m_arffFileFilter;
1210    }
1211    m_DestFileChooser.setFileFilter(fileFilter);
1212    int returnVal = m_DestFileChooser.showSaveDialog(this);
1213    if (returnVal != JFileChooser.APPROVE_OPTION) {
1214      return;
1215    }
1216    m_ResultsDestinationPathTField.setText(m_DestFileChooser.getSelectedFile().toString());
1217  }
1218}
Note: See TracBrowser for help on using the repository browser.