source: src/main/java/weka/gui/experiment/SetupPanel.java @ 16

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

Import di weka.

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