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 | * DistributeExperimentPanel.java |
---|
19 | * Copyright (C) 2000 University of Waikato, Hamilton, New Zealand |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | package weka.gui.experiment; |
---|
24 | |
---|
25 | import weka.experiment.Experiment; |
---|
26 | import weka.experiment.RemoteExperiment; |
---|
27 | |
---|
28 | import java.awt.BorderLayout; |
---|
29 | import java.awt.GridLayout; |
---|
30 | import java.awt.event.ActionEvent; |
---|
31 | import java.awt.event.ActionListener; |
---|
32 | import java.awt.event.WindowAdapter; |
---|
33 | import java.awt.event.WindowEvent; |
---|
34 | |
---|
35 | import javax.swing.BorderFactory; |
---|
36 | import javax.swing.ButtonGroup; |
---|
37 | import javax.swing.JButton; |
---|
38 | import javax.swing.JCheckBox; |
---|
39 | import javax.swing.JFrame; |
---|
40 | import javax.swing.JPanel; |
---|
41 | import javax.swing.JRadioButton; |
---|
42 | |
---|
43 | /** |
---|
44 | * This panel enables an experiment to be distributed to multiple hosts; |
---|
45 | * it also allows remote host names to be specified. |
---|
46 | * |
---|
47 | * @author Mark Hall (mhall@cs.waikato.ac.nz) |
---|
48 | * @version $Revision: 1.6 $ |
---|
49 | */ |
---|
50 | public class DistributeExperimentPanel |
---|
51 | extends JPanel { |
---|
52 | |
---|
53 | /** for serialization */ |
---|
54 | private static final long serialVersionUID = 5206721431754800278L; |
---|
55 | |
---|
56 | /** |
---|
57 | * The experiment to configure. |
---|
58 | */ |
---|
59 | RemoteExperiment m_Exp = null; |
---|
60 | |
---|
61 | /** Distribute the current experiment to remote hosts */ |
---|
62 | protected JCheckBox m_enableDistributedExperiment = |
---|
63 | new JCheckBox(); |
---|
64 | |
---|
65 | /** Popup the HostListPanel */ |
---|
66 | protected JButton m_configureHostNames = new JButton("Hosts"); |
---|
67 | |
---|
68 | /** The host list panel */ |
---|
69 | protected HostListPanel m_hostList = new HostListPanel(); |
---|
70 | |
---|
71 | /** |
---|
72 | * Split experiment up by data set. |
---|
73 | */ |
---|
74 | protected JRadioButton m_splitByDataSet = new JRadioButton("By data set"); |
---|
75 | |
---|
76 | /** |
---|
77 | * Split experiment up by run number. |
---|
78 | */ |
---|
79 | protected JRadioButton m_splitByRun = new JRadioButton("By run"); |
---|
80 | |
---|
81 | /** Handle radio buttons */ |
---|
82 | ActionListener m_radioListener = new ActionListener() { |
---|
83 | public void actionPerformed(ActionEvent e) { |
---|
84 | updateRadioLinks(); |
---|
85 | } |
---|
86 | }; |
---|
87 | |
---|
88 | /** |
---|
89 | * Constructor |
---|
90 | */ |
---|
91 | public DistributeExperimentPanel() { |
---|
92 | m_enableDistributedExperiment.setSelected(false); |
---|
93 | m_enableDistributedExperiment. |
---|
94 | setToolTipText("Allow this experiment to be distributed to remote hosts"); |
---|
95 | m_enableDistributedExperiment.setEnabled(false); |
---|
96 | m_configureHostNames.setEnabled(false); |
---|
97 | m_configureHostNames.setToolTipText("Edit the list of remote hosts"); |
---|
98 | |
---|
99 | m_enableDistributedExperiment.addActionListener(new ActionListener() { |
---|
100 | public void actionPerformed(ActionEvent e) { |
---|
101 | m_configureHostNames.setEnabled(m_enableDistributedExperiment. |
---|
102 | isSelected()); |
---|
103 | m_splitByDataSet.setEnabled(m_enableDistributedExperiment. |
---|
104 | isSelected()); |
---|
105 | m_splitByRun.setEnabled(m_enableDistributedExperiment. |
---|
106 | isSelected()); |
---|
107 | |
---|
108 | } |
---|
109 | }); |
---|
110 | |
---|
111 | m_configureHostNames.addActionListener(new ActionListener() { |
---|
112 | public void actionPerformed(ActionEvent e) { |
---|
113 | popupHostPanel(); |
---|
114 | } |
---|
115 | }); |
---|
116 | |
---|
117 | m_splitByDataSet.setToolTipText("Distribute experiment by data set"); |
---|
118 | m_splitByRun.setToolTipText("Distribute experiment by run number"); |
---|
119 | m_splitByDataSet.setSelected(true); |
---|
120 | m_splitByDataSet.setEnabled(false); |
---|
121 | m_splitByRun.setEnabled(false); |
---|
122 | m_splitByDataSet.addActionListener(m_radioListener); |
---|
123 | m_splitByRun.addActionListener(m_radioListener); |
---|
124 | |
---|
125 | ButtonGroup bg = new ButtonGroup(); |
---|
126 | bg.add(m_splitByDataSet); |
---|
127 | bg.add(m_splitByRun); |
---|
128 | |
---|
129 | JPanel rbuts = new JPanel(); |
---|
130 | rbuts.setLayout(new GridLayout(1, 2)); |
---|
131 | rbuts.add(m_splitByDataSet); |
---|
132 | rbuts.add(m_splitByRun); |
---|
133 | |
---|
134 | setLayout(new BorderLayout()); |
---|
135 | setBorder(BorderFactory.createTitledBorder("Distribute experiment")); |
---|
136 | add(m_enableDistributedExperiment, BorderLayout.WEST); |
---|
137 | add(m_configureHostNames, BorderLayout.CENTER); |
---|
138 | add(rbuts, BorderLayout.SOUTH); |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * Creates the panel with the supplied initial experiment. |
---|
143 | * |
---|
144 | * @param exp a value of type 'Experiment' |
---|
145 | */ |
---|
146 | public DistributeExperimentPanel(Experiment exp) { |
---|
147 | this(); |
---|
148 | setExperiment(exp); |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * Sets the experiment to be configured. |
---|
153 | * |
---|
154 | * @param exp a value of type 'Experiment' |
---|
155 | */ |
---|
156 | public void setExperiment(Experiment exp) { |
---|
157 | |
---|
158 | m_enableDistributedExperiment.setEnabled(true); |
---|
159 | m_Exp = null; |
---|
160 | if (exp instanceof RemoteExperiment) { |
---|
161 | m_Exp = (RemoteExperiment)exp; |
---|
162 | m_enableDistributedExperiment.setSelected(true); |
---|
163 | m_configureHostNames.setEnabled(true); |
---|
164 | m_hostList.setExperiment(m_Exp); |
---|
165 | m_splitByDataSet.setEnabled(true); |
---|
166 | m_splitByRun.setEnabled(true); |
---|
167 | m_splitByDataSet.setSelected(m_Exp.getSplitByDataSet()); |
---|
168 | m_splitByRun.setSelected(!m_Exp.getSplitByDataSet()); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * Pop up the host list panel |
---|
174 | */ |
---|
175 | private void popupHostPanel() { |
---|
176 | try { |
---|
177 | final JFrame jf = new JFrame("Edit host names"); |
---|
178 | |
---|
179 | jf.getContentPane().setLayout(new BorderLayout()); |
---|
180 | jf.getContentPane().add(m_hostList, |
---|
181 | BorderLayout.CENTER); |
---|
182 | jf.addWindowListener(new WindowAdapter() { |
---|
183 | public void windowClosing(WindowEvent e) { |
---|
184 | jf.dispose(); |
---|
185 | } |
---|
186 | }); |
---|
187 | jf.pack(); |
---|
188 | jf.setVisible(true); |
---|
189 | } catch (Exception ex) { |
---|
190 | ex.printStackTrace(); |
---|
191 | System.err.println(ex.getMessage()); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Returns true if the distribute experiment checkbox is selected |
---|
197 | * @return true if the user has opted for distributing the experiment |
---|
198 | */ |
---|
199 | public boolean distributedExperimentSelected() { |
---|
200 | return m_enableDistributedExperiment.isSelected(); |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * Enable objects to listen for changes to the check box |
---|
205 | * @param al an ActionListener |
---|
206 | */ |
---|
207 | public void addCheckBoxActionListener(ActionListener al) { |
---|
208 | m_enableDistributedExperiment.addActionListener(al); |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * Updates the remote experiment when a radio button is clicked |
---|
213 | */ |
---|
214 | private void updateRadioLinks() { |
---|
215 | if (m_Exp != null) { |
---|
216 | m_Exp.setSplitByDataSet(m_splitByDataSet.isSelected()); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * Tests out the panel from the command line. |
---|
222 | * |
---|
223 | * @param args ignored. |
---|
224 | */ |
---|
225 | public static void main(String [] args) { |
---|
226 | try { |
---|
227 | final JFrame jf = new JFrame("DistributeExperiment"); |
---|
228 | jf.getContentPane().setLayout(new BorderLayout()); |
---|
229 | jf.getContentPane().add(new DistributeExperimentPanel(new Experiment()), |
---|
230 | BorderLayout.CENTER); |
---|
231 | jf.addWindowListener(new WindowAdapter() { |
---|
232 | public void windowClosing(WindowEvent e) { |
---|
233 | jf.dispose(); |
---|
234 | System.exit(0); |
---|
235 | } |
---|
236 | }); |
---|
237 | jf.pack(); |
---|
238 | jf.setVisible(true); |
---|
239 | } catch (Exception ex) { |
---|
240 | ex.printStackTrace(); |
---|
241 | System.err.println(ex.getMessage()); |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|