SetupPanel.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 21k
Category:

Windows Develop

Development Platform:

Java

  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.  *    SetupPanel.java
  18.  *    Copyright (C) 1999 Len Trigg, Mark Hall
  19.  *
  20.  */
  21. package weka.gui.experiment;
  22. import weka.core.Tag;
  23. import weka.core.SelectedTag;
  24. import weka.core.Utils;
  25. import weka.gui.ExtensionFileFilter;
  26. import weka.gui.SelectedTagEditor;
  27. import weka.gui.GenericObjectEditor;
  28. import weka.gui.GenericArrayEditor;
  29. import weka.gui.PropertyPanel;
  30. import weka.gui.FileEditor;
  31. import weka.experiment.Experiment;
  32. import weka.experiment.RemoteExperiment;
  33. import weka.experiment.ResultProducer;
  34. import weka.experiment.ResultListener;
  35. import weka.experiment.CrossValidationResultProducer;
  36. import weka.experiment.DatabaseResultListener;
  37. import java.beans.PropertyChangeListener;
  38. import java.beans.PropertyChangeEvent;
  39. import java.beans.PropertyChangeSupport;
  40. import java.io.File;
  41. import java.io.FileOutputStream;
  42. import java.io.ObjectOutputStream;
  43. import java.io.BufferedOutputStream;
  44. import java.io.FileInputStream;
  45. import java.io.ObjectInputStream;
  46. import java.io.BufferedInputStream;
  47. import java.awt.Component;
  48. import java.awt.BorderLayout;
  49. import java.awt.GridLayout;
  50. import java.awt.GridBagLayout;
  51. import java.awt.GridBagConstraints;
  52. import java.awt.Dimension;
  53. import java.awt.event.KeyAdapter;
  54. import java.awt.event.KeyEvent;
  55. import java.awt.event.FocusAdapter;
  56. import java.awt.event.FocusEvent;
  57. import java.awt.event.ActionListener;
  58. import java.awt.event.ActionEvent;
  59. import java.awt.event.WindowAdapter;
  60. import java.awt.event.WindowEvent;
  61. import java.awt.Insets;
  62. import javax.swing.JPanel;
  63. import javax.swing.JLabel;
  64. import javax.swing.JFrame;
  65. import javax.swing.SwingConstants;
  66. import javax.swing.JTextField;
  67. import javax.swing.Box;
  68. import javax.swing.BorderFactory;
  69. import javax.swing.BoxLayout;
  70. import javax.swing.JTextArea;
  71. import javax.swing.JScrollPane;
  72. import javax.swing.JButton;
  73. import javax.swing.JFileChooser;
  74. import javax.swing.JOptionPane;
  75. import javax.swing.filechooser.FileFilter;
  76. import javax.swing.JRadioButton;
  77. import javax.swing.ButtonGroup;
  78. /** 
  79.  * This panel controls the configuration of an experiment.
  80.  *
  81.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  82.  * @author Mark Hall (mhall@cs.waikato.ac.nz)
  83.  * @version $Revision: 1.17 $
  84.  */
  85. public class SetupPanel extends JPanel {
  86.   /** The experiment being configured */
  87.   protected Experiment m_Exp;
  88.   /** Click to load an experiment */
  89.   protected JButton m_OpenBut = new JButton("Open...");
  90.   /** Click to save an experiment */
  91.   protected JButton m_SaveBut = new JButton("Save...");
  92.   /** Click to create a new experiment with default settings */
  93.   protected JButton m_NewBut = new JButton("New");
  94.   /** A filter to ensure only experiment files get shown in the chooser */
  95.   protected FileFilter m_ExpFilter = 
  96.     new ExtensionFileFilter(Experiment.FILE_EXTENSION, 
  97.                             "Experiment configuration files");
  98.   /** The file chooser for selecting experiments */
  99.   protected JFileChooser m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
  100.   /** The ResultProducer editor */
  101.   protected GenericObjectEditor m_RPEditor = new GenericObjectEditor();
  102.   /** The panel to contain the ResultProducer editor */
  103.   protected PropertyPanel m_RPEditorPanel = new PropertyPanel(m_RPEditor);
  104.   /** The ResultListener editor */
  105.   protected GenericObjectEditor m_RLEditor = new GenericObjectEditor();
  106.   /** The panel to contain the ResultListener editor */
  107.   protected PropertyPanel m_RLEditorPanel = new PropertyPanel(m_RLEditor);
  108.   /** The panel that configures iteration on custom resultproducer property */
  109.   protected GeneratorPropertyIteratorPanel m_GeneratorPropertyPanel
  110.     = new GeneratorPropertyIteratorPanel();
  111.   /** The panel for configuring run numbers */
  112.   protected RunNumberPanel m_RunNumberPanel = new RunNumberPanel();
  113.   /** The panel for enabling a distributed experiment */
  114.   protected DistributeExperimentPanel m_DistributeExperimentPanel = 
  115.     new DistributeExperimentPanel();
  116.   /** The panel for configuring selected datasets */
  117.   protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel();
  118.   /** Area for user notes Default of 5 rows */
  119.   protected JTextArea m_NotesText = new JTextArea(null, 5, 0);
  120.   /**
  121.    * Manages sending notifications to people when we change the experiment,
  122.    * at this stage, only the resultlistener so the resultpanel can update.
  123.    */
  124.   protected PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
  125.   /** Click to advacne data set before custom generator */
  126.   protected JRadioButton m_advanceDataSetFirst = 
  127.     new JRadioButton("Data sets first");
  128.   /** Click to advance custom generator before data set */
  129.   protected JRadioButton m_advanceIteratorFirst = 
  130.     new JRadioButton("Custom generator first");
  131.   /** Handle radio buttons */
  132.   ActionListener m_RadioListener = new ActionListener() {
  133.       public void actionPerformed(ActionEvent e) {
  134. updateRadioLinks();
  135.       }
  136.     };
  137.   
  138.   // Registers the appropriate property editors
  139.   static {
  140.     System.err.println("---Registering Weka Editors---");
  141.     java.beans.PropertyEditorManager
  142.       .registerEditor(java.io.File.class,
  143.       FileEditor.class);
  144.     java.beans.PropertyEditorManager
  145.       .registerEditor(weka.experiment.ResultListener.class,
  146.       GenericObjectEditor.class);
  147.     java.beans.PropertyEditorManager
  148.       .registerEditor(weka.experiment.ResultProducer.class,
  149.       GenericObjectEditor.class);
  150.     java.beans.PropertyEditorManager
  151.       .registerEditor(weka.experiment.SplitEvaluator.class,
  152.       GenericObjectEditor.class);
  153.     java.beans.PropertyEditorManager
  154.       .registerEditor(weka.classifiers.Classifier.class,
  155.       GenericObjectEditor.class);
  156.     java.beans.PropertyEditorManager
  157.       .registerEditor(weka.classifiers.DistributionClassifier.class,
  158.       GenericObjectEditor.class);
  159.     java.beans.PropertyEditorManager
  160.       .registerEditor(weka.classifiers.Classifier [].class,
  161.       GenericArrayEditor.class);
  162.     java.beans.PropertyEditorManager
  163.       .registerEditor(weka.filters.Filter.class,
  164.       GenericObjectEditor.class);
  165.     java.beans.PropertyEditorManager
  166.       .registerEditor(weka.attributeSelection.ASEvaluation.class,
  167.       GenericObjectEditor.class);
  168.     java.beans.PropertyEditorManager
  169.       .registerEditor(weka.attributeSelection.ASSearch.class,
  170.       GenericObjectEditor.class);
  171.     java.beans.PropertyEditorManager
  172.       .registerEditor(weka.clusterers.Clusterer.class,
  173.       GenericObjectEditor.class);
  174.     java.beans.PropertyEditorManager
  175.       .registerEditor(SelectedTag.class,
  176.       SelectedTagEditor.class);
  177.     java.beans.PropertyEditorManager
  178.       .registerEditor(weka.classifiers.CostMatrix.class,
  179.       weka.gui.CostMatrixEditor.class);
  180.   }
  181.   
  182.   /**
  183.    * Creates the setup panel with the supplied initial experiment.
  184.    *
  185.    * @param exp a value of type 'Experiment'
  186.    */
  187.   public SetupPanel(Experiment exp) {
  188.     this();
  189.     setExperiment(exp);
  190.   }
  191.   
  192.   /**
  193.    * Creates the setup panel with no initial experiment.
  194.    */
  195.   public SetupPanel() {
  196.     m_DistributeExperimentPanel.
  197.       addCheckBoxActionListener(new ActionListener() {
  198.   public void actionPerformed(ActionEvent e) {
  199.     if (m_DistributeExperimentPanel.distributedExperimentSelected()) {
  200.       if (!(m_Exp instanceof RemoteExperiment)) {
  201. try {
  202.   RemoteExperiment re = new RemoteExperiment(m_Exp);
  203.   setExperiment(re);
  204. } catch (Exception ex) {
  205.   ex.printStackTrace();
  206. }
  207.       }
  208.     } else {
  209.       if (m_Exp instanceof RemoteExperiment) {
  210. setExperiment(((RemoteExperiment)m_Exp).getBaseExperiment());
  211.       }
  212.     }
  213.   }
  214. });       
  215.     m_NewBut.addActionListener(new ActionListener() {
  216.       public void actionPerformed(ActionEvent e) {
  217. setExperiment(new Experiment());
  218.       }
  219.     });
  220.     m_SaveBut.setEnabled(false);
  221.     m_SaveBut.addActionListener(new ActionListener() {
  222.       public void actionPerformed(ActionEvent e) {
  223. saveExperiment();
  224.       }
  225.     });
  226.     m_OpenBut.addActionListener(new ActionListener() {
  227.       public void actionPerformed(ActionEvent e) {
  228. openExperiment();
  229.       }
  230.     });
  231.     m_FileChooser.setFileFilter(m_ExpFilter);
  232.     m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  233.     
  234.     m_GeneratorPropertyPanel.addActionListener(new ActionListener() {
  235. public void actionPerformed(ActionEvent e) {
  236.   updateRadioLinks();
  237. }
  238.       });
  239.     m_RPEditor.setClassType(ResultProducer.class);
  240.     m_RPEditor.setEnabled(false);
  241.     m_RPEditor.addPropertyChangeListener(new PropertyChangeListener() {
  242.       public void propertyChange(PropertyChangeEvent e) {
  243. m_Exp.setResultProducer((ResultProducer) m_RPEditor.getValue());
  244. m_Exp.setUsePropertyIterator(false);
  245. m_Exp.setPropertyArray(null);
  246. m_Exp.setPropertyPath(null);
  247. m_GeneratorPropertyPanel.setExperiment(m_Exp);
  248. repaint();
  249.       }
  250.     });
  251.     m_RLEditor.setClassType(ResultListener.class);
  252.     m_RLEditor.setEnabled(false);
  253.     m_RLEditor.addPropertyChangeListener(new PropertyChangeListener() {
  254.       public void propertyChange(PropertyChangeEvent e) {
  255. m_Exp.setResultListener((ResultListener) m_RLEditor.getValue());
  256. m_Support.firePropertyChange("", null, null);
  257. repaint();
  258.       }
  259.     });
  260.     m_NotesText.setEnabled(false);
  261.     m_NotesText.setEditable(true);
  262.     m_NotesText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  263.     m_NotesText.addKeyListener(new KeyAdapter() {
  264.       public void keyReleased(KeyEvent e) {
  265. m_Exp.setNotes(m_NotesText.getText());
  266.       }
  267.     });
  268.     m_NotesText.addFocusListener(new FocusAdapter() {
  269.       public void focusLost(FocusEvent e) {
  270. m_Exp.setNotes(m_NotesText.getText());
  271.       }
  272.     });
  273.     // Set up the GUI layout
  274.     JPanel buttons = new JPanel();
  275.     GridBagLayout gb = new GridBagLayout();
  276.     GridBagConstraints constraints = new GridBagConstraints();
  277.     buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
  278.     //    buttons.setLayout(new GridLayout(1, 3, 5, 5));
  279.     buttons.setLayout(gb);
  280.     constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;
  281.     constraints.fill = GridBagConstraints.HORIZONTAL;
  282.     constraints.gridwidth=1;constraints.gridheight=1;
  283.     constraints.insets = new Insets(0,2,0,2);
  284.     buttons.add(m_OpenBut,constraints);
  285.     constraints.gridx=1;constraints.gridy=0;constraints.weightx=5;
  286.     constraints.gridwidth=1;constraints.gridheight=1;
  287.     buttons.add(m_SaveBut,constraints);
  288.     constraints.gridx=2;constraints.gridy=0;constraints.weightx=5;
  289.     constraints.gridwidth=1;constraints.gridheight=1;
  290.     buttons.add(m_NewBut,constraints);
  291.     
  292.     JPanel src = new JPanel();
  293.     src.setLayout(new BorderLayout());
  294.     src.setBorder(BorderFactory.createCompoundBorder(
  295.   BorderFactory.createTitledBorder("Result generator"),
  296.   BorderFactory.createEmptyBorder(0, 5, 5, 5)
  297.   ));
  298.     src.add(m_RPEditorPanel, BorderLayout.NORTH);
  299.     JPanel dest = new JPanel();
  300.     dest.setLayout(new BorderLayout());
  301.     dest.setBorder(BorderFactory.createCompoundBorder(
  302.    BorderFactory.createTitledBorder("Destination"),
  303.    BorderFactory.createEmptyBorder(0, 5, 5, 5)
  304.    ));
  305.     dest.add(m_RLEditorPanel, BorderLayout.NORTH);
  306.     m_advanceDataSetFirst.setEnabled(false);
  307.     m_advanceIteratorFirst.setEnabled(false);
  308.     m_advanceDataSetFirst.
  309.       setToolTipText("Advance data set before custom generator");
  310.     m_advanceIteratorFirst.
  311.       setToolTipText("Advance custom generator before data set");
  312.     m_advanceDataSetFirst.setSelected(true);
  313.     ButtonGroup bg = new ButtonGroup();
  314.     bg.add(m_advanceDataSetFirst);
  315.     bg.add(m_advanceIteratorFirst);
  316.     m_advanceDataSetFirst.addActionListener(m_RadioListener);
  317.     m_advanceIteratorFirst.addActionListener(m_RadioListener);
  318.     JPanel radioButs = new JPanel();
  319.     radioButs.setBorder(BorderFactory.
  320. createTitledBorder("Iteration control"));
  321.     radioButs.setLayout(new GridLayout(1, 2));
  322.     radioButs.add(m_advanceDataSetFirst);
  323.     radioButs.add(m_advanceIteratorFirst);
  324.     JPanel simpleIterators = new JPanel();
  325.     simpleIterators.setLayout(new BorderLayout());
  326.     
  327.     JPanel tmp = new JPanel();
  328.     tmp.setLayout(new GridBagLayout());
  329.     //    tmp.setLayout(new GridLayout(1, 2));
  330.     constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;
  331.     constraints.fill = GridBagConstraints.HORIZONTAL;
  332.     constraints.gridwidth=1;constraints.gridheight=1;
  333.     constraints.insets = new Insets(0,2,0,2);
  334.     tmp.add(m_RunNumberPanel,constraints);
  335.     
  336.     constraints.gridx=1;constraints.gridy=0;constraints.weightx=5;
  337.     constraints.fill = GridBagConstraints.HORIZONTAL;
  338.     constraints.gridwidth=1;constraints.gridheight=2;
  339.     tmp.add(m_DistributeExperimentPanel, constraints);
  340.     JPanel tmp2 = new JPanel();
  341.     //    tmp2.setLayout(new GridLayout(2, 1));
  342.     tmp2.setLayout(new GridBagLayout());
  343.     constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;
  344.     constraints.fill = GridBagConstraints.HORIZONTAL;
  345.     constraints.gridwidth=1;constraints.gridheight=1;
  346.     constraints.insets = new Insets(0,2,0,2);
  347.     tmp2.add(tmp,constraints);
  348.     constraints.gridx=0;constraints.gridy=1;constraints.weightx=5;
  349.     constraints.fill = GridBagConstraints.HORIZONTAL;
  350.     constraints.gridwidth=1;constraints.gridheight=1;
  351.     tmp2.add(radioButs,constraints);
  352.    
  353.     simpleIterators.add(tmp2, BorderLayout.NORTH);
  354.     simpleIterators.add(m_DatasetListPanel, BorderLayout.CENTER);
  355.     JPanel iterators = new JPanel();
  356.     iterators.setLayout(new GridLayout(1, 2));
  357.     iterators.add(simpleIterators);
  358.     iterators.add(m_GeneratorPropertyPanel);
  359.     JPanel top = new JPanel();
  360.     top.setLayout(new GridLayout(2, 1));
  361.     top.add(dest);
  362.     top.add(src);
  363.     JPanel notes = new JPanel();
  364.     notes.setLayout(new BorderLayout());
  365.     notes.setBorder(BorderFactory.createTitledBorder("Notes"));
  366.     notes.add(new JScrollPane(m_NotesText), BorderLayout.CENTER);
  367.     
  368.     JPanel p2 = new JPanel();
  369.     //    p2.setLayout(new GridLayout(2, 1));
  370.     p2.setLayout(new BorderLayout());
  371.     p2.add(iterators, BorderLayout.CENTER);
  372.     p2.add(notes, BorderLayout.SOUTH);
  373.     JPanel p3 = new JPanel();
  374.     p3.setLayout(new BorderLayout());
  375.     p3.add(buttons, BorderLayout.NORTH);
  376.     p3.add(top, BorderLayout.SOUTH);
  377.     setLayout(new BorderLayout());
  378.     add(p3, BorderLayout.NORTH);
  379.     add(p2, BorderLayout.CENTER);
  380.   }
  381.   
  382.   /**
  383.    * Sets the experiment to configure.
  384.    *
  385.    * @param exp a value of type 'Experiment'
  386.    */
  387.   public void setExperiment(Experiment exp) {
  388.     
  389.     m_Exp = exp;
  390.     m_SaveBut.setEnabled(true);
  391.     m_RPEditor.setValue(m_Exp.getResultProducer());
  392.     m_RPEditor.setEnabled(true);
  393.     m_RPEditorPanel.repaint();
  394.     m_RLEditor.setValue(m_Exp.getResultListener());
  395.     m_RLEditor.setEnabled(true);
  396.     m_RLEditorPanel.repaint();
  397.     m_NotesText.setText(m_Exp.getNotes());
  398.     m_NotesText.setEnabled(true);
  399.     m_advanceDataSetFirst.setSelected(m_Exp.getAdvanceDataSetFirst());
  400.     m_advanceIteratorFirst.setSelected(!m_Exp.getAdvanceDataSetFirst());
  401.     m_advanceDataSetFirst.setEnabled(true);
  402.     m_advanceIteratorFirst.setEnabled(true);
  403.    
  404.     m_GeneratorPropertyPanel.setExperiment(m_Exp);
  405.     m_RunNumberPanel.setExperiment(m_Exp);
  406.     m_DatasetListPanel.setExperiment(m_Exp);
  407.     m_DistributeExperimentPanel.setExperiment(m_Exp);
  408.     m_Support.firePropertyChange("", null, null);
  409.   }
  410.   /**
  411.    * Gets the currently configured experiment.
  412.    *
  413.    * @return the currently configured experiment.
  414.    */
  415.   public Experiment getExperiment() {
  416.     return m_Exp;
  417.   }
  418.   
  419.   /**
  420.    * Prompts the user to select an experiment file and loads it.
  421.    */
  422.   private void openExperiment() {
  423.     
  424.     int returnVal = m_FileChooser.showOpenDialog(this);
  425.     if (returnVal != JFileChooser.APPROVE_OPTION) {
  426.       return;
  427.     }
  428.     File expFile = m_FileChooser.getSelectedFile();
  429.     if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION)) {
  430.       expFile = new File(expFile.getParent(), expFile.getName()
  431.                          + Experiment.FILE_EXTENSION);
  432.     }
  433.     try {
  434.       FileInputStream fi = new FileInputStream(expFile);
  435.       ObjectInputStream oi = new ObjectInputStream(
  436.      new BufferedInputStream(fi));
  437.       Experiment exp = (Experiment)oi.readObject();
  438.       oi.close();
  439.       setExperiment(exp);
  440.       System.err.println("Opened experiment:n" + m_Exp);
  441.     } catch (Exception ex) {
  442.       ex.printStackTrace();
  443.       JOptionPane.showMessageDialog(this, "Couldn't open experiment file:n"
  444.     + expFile
  445.     + "nReason:n" + ex.getMessage(),
  446.     "Open Experiment",
  447.     JOptionPane.ERROR_MESSAGE);
  448.       // Pop up error dialog
  449.     }
  450.   }
  451.   /**
  452.    * Prompts the user for a filename to save the experiment to, then saves
  453.    * the experiment.
  454.    */
  455.   private void saveExperiment() {
  456.     int returnVal = m_FileChooser.showSaveDialog(this);
  457.     if (returnVal != JFileChooser.APPROVE_OPTION) {
  458.       return;
  459.     }
  460.     File expFile = m_FileChooser.getSelectedFile();
  461.     if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION)) {
  462.       expFile = new File(expFile.getParent(), expFile.getName() 
  463.                          + Experiment.FILE_EXTENSION);
  464.     }
  465.     try {
  466.       FileOutputStream fo = new FileOutputStream(expFile);
  467.       ObjectOutputStream oo = new ObjectOutputStream(
  468.       new BufferedOutputStream(fo));
  469.       oo.writeObject(m_Exp);
  470.       oo.close();
  471.       System.err.println("Saved experiment:n" + m_Exp);
  472.     } catch (Exception ex) {
  473.       ex.printStackTrace();
  474.       JOptionPane.showMessageDialog(this, "Couldn't save experiment file:n"
  475.     + expFile
  476.     + "nReason:n" + ex.getMessage(),
  477.     "Save Experiment",
  478.     JOptionPane.ERROR_MESSAGE);
  479.     }
  480.   }
  481.   /**
  482.    * Adds a PropertyChangeListener who will be notified of value changes.
  483.    *
  484.    * @param l a value of type 'PropertyChangeListener'
  485.    */
  486.   public void addPropertyChangeListener(PropertyChangeListener l) {
  487.     m_Support.addPropertyChangeListener(l);
  488.   }
  489.   /**
  490.    * Removes a PropertyChangeListener.
  491.    *
  492.    * @param l a value of type 'PropertyChangeListener'
  493.    */
  494.   public void removePropertyChangeListener(PropertyChangeListener l) {
  495.     m_Support.removePropertyChangeListener(l);
  496.   }
  497.   /**
  498.    * Updates the primary loop iteration control of the experiment
  499.    */
  500.   private void updateRadioLinks() {
  501.     
  502.     m_advanceDataSetFirst.
  503.       setEnabled(m_GeneratorPropertyPanel.getEditorActive());
  504.     m_advanceIteratorFirst.
  505.       setEnabled(m_GeneratorPropertyPanel.getEditorActive());
  506.     if (m_Exp != null) {
  507.       if (!m_GeneratorPropertyPanel.getEditorActive()) {
  508. m_Exp.setAdvanceDataSetFirst(true);
  509.       } else {
  510. m_Exp.setAdvanceDataSetFirst(m_advanceDataSetFirst.isSelected());
  511.       }
  512.     }
  513.   }
  514.   /**
  515.    * Tests out the experiment setup from the command line.
  516.    *
  517.    * @param args arguments to the program.
  518.    */
  519.   public static void main(String [] args) {
  520.     try {
  521.       boolean readExp = Utils.getFlag('l', args);
  522.       final boolean writeExp = Utils.getFlag('s', args);
  523.       final String expFile = Utils.getOption('f', args);
  524.       if ((readExp || writeExp) && (expFile.length() == 0)) {
  525. throw new Exception("A filename must be given with the -f option");
  526.       }
  527.       Experiment exp = null;
  528.       if (readExp) {
  529. FileInputStream fi = new FileInputStream(expFile);
  530. ObjectInputStream oi = new ObjectInputStream(
  531.        new BufferedInputStream(fi));
  532. exp = (Experiment)oi.readObject();
  533. oi.close();
  534.       } else {
  535. exp = new Experiment();
  536.       }
  537.       System.err.println("Initial Experiment:n" + exp.toString());
  538.       final JFrame jf = new JFrame("Weka Experiment Setup");
  539.       jf.getContentPane().setLayout(new BorderLayout());
  540.       final SetupPanel sp = new SetupPanel();
  541.       //sp.setBorder(BorderFactory.createTitledBorder("Setup"));
  542.       jf.getContentPane().add(sp, BorderLayout.CENTER);
  543.       jf.addWindowListener(new WindowAdapter() {
  544. public void windowClosing(WindowEvent e) {
  545.   System.err.println("nFinal Experiment:n"
  546.      + sp.m_Exp.toString());
  547.   // Save the experiment to a file
  548.   if (writeExp) {
  549.     try {
  550.       FileOutputStream fo = new FileOutputStream(expFile);
  551.       ObjectOutputStream oo = new ObjectOutputStream(
  552.       new BufferedOutputStream(fo));
  553.       oo.writeObject(sp.m_Exp);
  554.       oo.close();
  555.     } catch (Exception ex) {
  556.               ex.printStackTrace();
  557.       System.err.println("Couldn't write experiment to: " + expFile
  558.  + 'n' + ex.getMessage());
  559.     }
  560.   }
  561.   jf.dispose();
  562.   System.exit(0);
  563. }
  564.       });
  565.       jf.pack();
  566.       jf.setVisible(true);
  567.       System.err.println("Short nap");
  568.       Thread.currentThread().sleep(3000);
  569.       System.err.println("Done");
  570.       sp.setExperiment(exp);
  571.     } catch (Exception ex) {
  572.       ex.printStackTrace();
  573.       System.err.println(ex.getMessage());
  574.     }
  575.   }
  576. }