Experimenter.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 4k
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.  *    Experimenter.java
  18.  *    Copyright (C) 1999 Len Trigg
  19.  *
  20.  */
  21. package weka.gui.experiment;
  22. import weka.experiment.Experiment;
  23. import java.beans.PropertyChangeEvent;
  24. import java.beans.PropertyChangeListener;
  25. import java.awt.BorderLayout;
  26. import java.awt.event.WindowAdapter;
  27. import java.awt.event.WindowEvent;
  28. import java.awt.event.ActionListener;
  29. import java.awt.event.ActionEvent;
  30. import javax.swing.JFrame;
  31. import javax.swing.JTabbedPane;
  32. import javax.swing.JPanel;
  33. /** 
  34.  * The main class for the experiment environment. Lets the user create,
  35.  * open, save, configure, run experiments, and analyse experimental results.
  36.  *
  37.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  38.  * @version $Revision: 1.4 $
  39.  */
  40. public class Experimenter extends JPanel {
  41.   /** The panel for configuring the experiment */
  42.   protected SetupPanel m_SetupPanel;
  43.   /** The panel for running the experiment */
  44.   protected RunPanel m_RunPanel;
  45.   /** The panel for analysing experimental results */
  46.   protected ResultsPanel m_ResultsPanel;
  47.   /** The tabbed pane that controls which sub-pane we are working with */
  48.   protected JTabbedPane m_TabbedPane = new JTabbedPane();
  49.   /** True if the class attribute is the first attribute for all
  50.       datasets involved in this experiment. */
  51.   protected boolean m_ClassFirst = false;
  52.   /**
  53.    * Creates the experiment environment gui with no initial experiment
  54.    */
  55.   public Experimenter(boolean classFirst) {
  56.     m_SetupPanel = new SetupPanel();
  57.     m_RunPanel = new RunPanel();
  58.     m_ResultsPanel = new ResultsPanel();
  59.     m_ClassFirst = classFirst;
  60.     m_TabbedPane.addTab("Setup", null, m_SetupPanel, "Set up the experiment");
  61.     m_TabbedPane.addTab("Run", null, m_RunPanel, "Run the experiment");
  62.     m_TabbedPane.addTab("Analyse", null, m_ResultsPanel,
  63. "Analyse experiment results");
  64.     m_TabbedPane.setSelectedIndex(0);
  65.     m_TabbedPane.setEnabledAt(1, false);
  66.     m_SetupPanel.addPropertyChangeListener(new PropertyChangeListener() {
  67.       public void propertyChange(PropertyChangeEvent e) {
  68. System.err.println("Updated experiment");
  69. Experiment exp = m_SetupPanel.getExperiment();
  70. exp.classFirst(m_ClassFirst);
  71. m_RunPanel.setExperiment(exp);
  72. m_ResultsPanel.setExperiment(exp);
  73. m_TabbedPane.setEnabledAt(1, true);
  74.       }
  75.     });
  76.     
  77.     setLayout(new BorderLayout());
  78.     add(m_TabbedPane, BorderLayout.CENTER);
  79.   }
  80.   /**
  81.    * Tests out the experiment environment.
  82.    *
  83.    * @param args ignored.
  84.    */
  85.   public static void main(String [] args) {
  86.     try {
  87.       
  88.       boolean classFirst = false;
  89.       if (args.length > 0) {
  90. classFirst = args[0].equals("CLASS_FIRST");
  91.       }
  92.       final JFrame jf = new JFrame("Weka Experiment Environment");
  93.       jf.getContentPane().setLayout(new BorderLayout());
  94.       jf.getContentPane().add(new Experimenter(classFirst), BorderLayout.CENTER);
  95.       jf.addWindowListener(new WindowAdapter() {
  96. public void windowClosing(WindowEvent e) {
  97.   jf.dispose();
  98.   System.exit(0);
  99. }
  100.       });
  101.       jf.pack();
  102.       jf.setSize(800, 600);
  103.       jf.setVisible(true);
  104.     } catch (Exception ex) {
  105.       ex.printStackTrace();
  106.       System.err.println(ex.getMessage());
  107.     }
  108.   }
  109. }