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 | * Experimenter.java |
---|
19 | * Copyright (C) 1999 University of Waikato, Hamilton, New Zealand |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | package weka.gui.experiment; |
---|
24 | |
---|
25 | import weka.core.Memory; |
---|
26 | import weka.experiment.Experiment; |
---|
27 | import weka.gui.LookAndFeel; |
---|
28 | |
---|
29 | import java.awt.BorderLayout; |
---|
30 | import java.awt.event.WindowAdapter; |
---|
31 | import java.awt.event.WindowEvent; |
---|
32 | import java.beans.PropertyChangeEvent; |
---|
33 | import java.beans.PropertyChangeListener; |
---|
34 | |
---|
35 | import javax.swing.JFrame; |
---|
36 | import javax.swing.JPanel; |
---|
37 | import javax.swing.JTabbedPane; |
---|
38 | |
---|
39 | /** |
---|
40 | * The main class for the experiment environment. Lets the user create, |
---|
41 | * open, save, configure, run experiments, and analyse experimental results. |
---|
42 | * |
---|
43 | * @author Len Trigg (trigg@cs.waikato.ac.nz) |
---|
44 | * @version $Revision: 4721 $ |
---|
45 | */ |
---|
46 | public class Experimenter |
---|
47 | extends JPanel { |
---|
48 | |
---|
49 | /** for serialization */ |
---|
50 | private static final long serialVersionUID = -5751617505738193788L; |
---|
51 | |
---|
52 | /** The panel for configuring the experiment */ |
---|
53 | protected SetupModePanel m_SetupPanel; |
---|
54 | |
---|
55 | /** The panel for running the experiment */ |
---|
56 | protected RunPanel m_RunPanel; |
---|
57 | |
---|
58 | /** The panel for analysing experimental results */ |
---|
59 | protected ResultsPanel m_ResultsPanel; |
---|
60 | |
---|
61 | /** The tabbed pane that controls which sub-pane we are working with */ |
---|
62 | protected JTabbedPane m_TabbedPane = new JTabbedPane(); |
---|
63 | |
---|
64 | /** True if the class attribute is the first attribute for all |
---|
65 | datasets involved in this experiment. */ |
---|
66 | protected boolean m_ClassFirst = false; |
---|
67 | |
---|
68 | /** |
---|
69 | * Creates the experiment environment gui with no initial experiment |
---|
70 | */ |
---|
71 | public Experimenter(boolean classFirst) { |
---|
72 | |
---|
73 | m_SetupPanel = new SetupModePanel(); |
---|
74 | m_ResultsPanel = new ResultsPanel(); |
---|
75 | m_RunPanel = new RunPanel(); |
---|
76 | m_RunPanel.setResultsPanel(m_ResultsPanel); |
---|
77 | |
---|
78 | m_ClassFirst = classFirst; |
---|
79 | |
---|
80 | m_TabbedPane.addTab("Setup", null, m_SetupPanel, "Set up the experiment"); |
---|
81 | m_TabbedPane.addTab("Run", null, m_RunPanel, "Run the experiment"); |
---|
82 | m_TabbedPane.addTab("Analyse", null, m_ResultsPanel, |
---|
83 | "Analyse experiment results"); |
---|
84 | m_TabbedPane.setSelectedIndex(0); |
---|
85 | m_TabbedPane.setEnabledAt(1, false); |
---|
86 | m_SetupPanel.addPropertyChangeListener(new PropertyChangeListener() { |
---|
87 | public void propertyChange(PropertyChangeEvent e) { |
---|
88 | //System.err.println("Updated experiment"); |
---|
89 | Experiment exp = m_SetupPanel.getExperiment(); |
---|
90 | exp.classFirst(m_ClassFirst); |
---|
91 | m_RunPanel.setExperiment(exp); |
---|
92 | //m_ResultsPanel.setExperiment(exp); |
---|
93 | m_TabbedPane.setEnabledAt(1, true); |
---|
94 | } |
---|
95 | }); |
---|
96 | setLayout(new BorderLayout()); |
---|
97 | add(m_TabbedPane, BorderLayout.CENTER); |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /** variable for the Experimenter class which would be set to null by the memory |
---|
102 | monitoring thread to free up some memory if we running out of memory |
---|
103 | */ |
---|
104 | private static Experimenter m_experimenter; |
---|
105 | |
---|
106 | /** for monitoring the Memory consumption */ |
---|
107 | private static Memory m_Memory = new Memory(true); |
---|
108 | |
---|
109 | /** |
---|
110 | * Tests out the experiment environment. |
---|
111 | * |
---|
112 | * @param args ignored. |
---|
113 | */ |
---|
114 | public static void main(String [] args) { |
---|
115 | weka.core.logging.Logger.log(weka.core.logging.Logger.Level.INFO, "Logging started"); |
---|
116 | LookAndFeel.setLookAndFeel(); |
---|
117 | |
---|
118 | try { |
---|
119 | // uncomment to disable the memory management: |
---|
120 | //m_Memory.setEnabled(false); |
---|
121 | |
---|
122 | boolean classFirst = false; |
---|
123 | if (args.length > 0) { |
---|
124 | classFirst = args[0].equals("CLASS_FIRST"); |
---|
125 | } |
---|
126 | m_experimenter = new Experimenter(classFirst); |
---|
127 | final JFrame jf = new JFrame("Weka Experiment Environment"); |
---|
128 | jf.getContentPane().setLayout(new BorderLayout()); |
---|
129 | jf.getContentPane().add(m_experimenter, BorderLayout.CENTER); |
---|
130 | jf.addWindowListener(new WindowAdapter() { |
---|
131 | public void windowClosing(WindowEvent e) { |
---|
132 | jf.dispose(); |
---|
133 | System.exit(0); |
---|
134 | } |
---|
135 | }); |
---|
136 | jf.pack(); |
---|
137 | jf.setSize(800, 600); |
---|
138 | jf.setVisible(true); |
---|
139 | |
---|
140 | Thread memMonitor = new Thread() { |
---|
141 | public void run() { |
---|
142 | while(true) { |
---|
143 | try { |
---|
144 | this.sleep(4000); |
---|
145 | |
---|
146 | System.gc(); |
---|
147 | |
---|
148 | if (m_Memory.isOutOfMemory()) { |
---|
149 | // clean up |
---|
150 | jf.dispose(); |
---|
151 | m_experimenter = null; |
---|
152 | System.gc(); |
---|
153 | |
---|
154 | // stop threads |
---|
155 | m_Memory.stopThreads(); |
---|
156 | |
---|
157 | // display error |
---|
158 | System.err.println("\ndisplayed message:"); |
---|
159 | m_Memory.showOutOfMemory(); |
---|
160 | System.err.println("\nexiting"); |
---|
161 | System.exit(-1); |
---|
162 | } |
---|
163 | |
---|
164 | } catch(InterruptedException ex) { ex.printStackTrace(); } |
---|
165 | } |
---|
166 | } |
---|
167 | }; |
---|
168 | |
---|
169 | memMonitor.setPriority(Thread.NORM_PRIORITY); |
---|
170 | memMonitor.start(); |
---|
171 | } catch (Exception ex) { |
---|
172 | ex.printStackTrace(); |
---|
173 | System.err.println(ex.getMessage()); |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|