| [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 | * SetupModePanel.java |
|---|
| 19 | * Copyright (C) 2002 University of Waikato, Hamilton, New Zealand |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | package weka.gui.experiment; |
|---|
| 24 | |
|---|
| 25 | import weka.experiment.Experiment; |
|---|
| 26 | |
|---|
| 27 | import java.awt.BorderLayout; |
|---|
| 28 | import java.awt.GridLayout; |
|---|
| 29 | import java.awt.event.ActionEvent; |
|---|
| 30 | import java.awt.event.ActionListener; |
|---|
| 31 | import java.beans.PropertyChangeListener; |
|---|
| 32 | |
|---|
| 33 | import javax.swing.ButtonGroup; |
|---|
| 34 | import javax.swing.JLabel; |
|---|
| 35 | import javax.swing.JPanel; |
|---|
| 36 | import javax.swing.JRadioButton; |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * This panel switches between simple and advanced experiment setup panels. |
|---|
| 40 | * |
|---|
| 41 | * @author Richard Kirkby (rkirkby@cs.waikato.ac.nz) |
|---|
| 42 | * @version $Revision: 1.5 $ |
|---|
| 43 | */ |
|---|
| 44 | public class SetupModePanel |
|---|
| 45 | extends JPanel { |
|---|
| 46 | |
|---|
| 47 | /** for serialization */ |
|---|
| 48 | private static final long serialVersionUID = -3758035565520727822L; |
|---|
| 49 | |
|---|
| 50 | /** The button for choosing simple setup mode */ |
|---|
| 51 | protected JRadioButton m_SimpleSetupRBut = |
|---|
| 52 | new JRadioButton("Simple"); |
|---|
| 53 | |
|---|
| 54 | /** The button for choosing advanced setup mode */ |
|---|
| 55 | protected JRadioButton m_AdvancedSetupRBut = |
|---|
| 56 | new JRadioButton("Advanced"); |
|---|
| 57 | |
|---|
| 58 | /** The simple setup panel */ |
|---|
| 59 | protected SimpleSetupPanel m_simplePanel = new SimpleSetupPanel(); |
|---|
| 60 | |
|---|
| 61 | /** The advanced setup panel */ |
|---|
| 62 | protected SetupPanel m_advancedPanel = new SetupPanel(); |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * Creates the setup panel with no initial experiment. |
|---|
| 66 | */ |
|---|
| 67 | public SetupModePanel() { |
|---|
| 68 | |
|---|
| 69 | m_simplePanel.setModePanel(this); |
|---|
| 70 | |
|---|
| 71 | m_SimpleSetupRBut.setMnemonic('S'); |
|---|
| 72 | m_SimpleSetupRBut.addActionListener(new ActionListener() { |
|---|
| 73 | public void actionPerformed(ActionEvent e) { |
|---|
| 74 | switchToSimple(null); |
|---|
| 75 | } |
|---|
| 76 | }); |
|---|
| 77 | |
|---|
| 78 | m_AdvancedSetupRBut.setMnemonic('A'); |
|---|
| 79 | m_AdvancedSetupRBut.addActionListener(new ActionListener() { |
|---|
| 80 | public void actionPerformed(ActionEvent e) { |
|---|
| 81 | switchToAdvanced(null); |
|---|
| 82 | } |
|---|
| 83 | }); |
|---|
| 84 | |
|---|
| 85 | ButtonGroup modeBG = new ButtonGroup(); |
|---|
| 86 | modeBG.add(m_SimpleSetupRBut); |
|---|
| 87 | modeBG.add(m_AdvancedSetupRBut); |
|---|
| 88 | m_SimpleSetupRBut.setSelected(true); |
|---|
| 89 | |
|---|
| 90 | JPanel modeButtons = new JPanel(); |
|---|
| 91 | modeButtons.setLayout(new GridLayout(1,0)); |
|---|
| 92 | modeButtons.add(m_SimpleSetupRBut); |
|---|
| 93 | modeButtons.add(m_AdvancedSetupRBut); |
|---|
| 94 | |
|---|
| 95 | JPanel switchPanel = new JPanel(); |
|---|
| 96 | switchPanel.setLayout(new GridLayout(1,0)); |
|---|
| 97 | switchPanel.add(new JLabel("Experiment Configuration Mode:")); |
|---|
| 98 | switchPanel.add(modeButtons); |
|---|
| 99 | |
|---|
| 100 | setLayout(new BorderLayout()); |
|---|
| 101 | add(switchPanel, BorderLayout.NORTH); |
|---|
| 102 | add(m_simplePanel, BorderLayout.CENTER); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Switches to the advanced setup mode. |
|---|
| 107 | * |
|---|
| 108 | * @param exp the experiment to configure |
|---|
| 109 | */ |
|---|
| 110 | public void switchToAdvanced(Experiment exp) { |
|---|
| 111 | |
|---|
| 112 | if (exp == null) { |
|---|
| 113 | exp = m_simplePanel.getExperiment(); |
|---|
| 114 | } |
|---|
| 115 | if (exp != null) { |
|---|
| 116 | m_AdvancedSetupRBut.setSelected(true); |
|---|
| 117 | m_advancedPanel.setExperiment(exp); |
|---|
| 118 | } |
|---|
| 119 | remove(m_simplePanel); |
|---|
| 120 | m_simplePanel.removeNotesFrame(); |
|---|
| 121 | add(m_advancedPanel, BorderLayout.CENTER); |
|---|
| 122 | validate(); |
|---|
| 123 | repaint(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * Switches to the simple setup mode only if allowed to. |
|---|
| 128 | * |
|---|
| 129 | * @param exp the experiment to configure |
|---|
| 130 | */ |
|---|
| 131 | public void switchToSimple(Experiment exp) { |
|---|
| 132 | |
|---|
| 133 | if (exp == null) { |
|---|
| 134 | exp = m_advancedPanel.getExperiment(); |
|---|
| 135 | } |
|---|
| 136 | if (exp != null && !m_simplePanel.setExperiment(exp)) { |
|---|
| 137 | m_AdvancedSetupRBut.setSelected(true); |
|---|
| 138 | switchToAdvanced(exp); |
|---|
| 139 | } else { |
|---|
| 140 | remove(m_advancedPanel); |
|---|
| 141 | m_advancedPanel.removeNotesFrame(); |
|---|
| 142 | add(m_simplePanel, BorderLayout.CENTER); |
|---|
| 143 | validate(); |
|---|
| 144 | repaint(); |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * Adds a PropertyChangeListener who will be notified of value changes. |
|---|
| 150 | * |
|---|
| 151 | * @param l a value of type 'PropertyChangeListener' |
|---|
| 152 | */ |
|---|
| 153 | public void addPropertyChangeListener(PropertyChangeListener l) { |
|---|
| 154 | |
|---|
| 155 | m_simplePanel.addPropertyChangeListener(l); |
|---|
| 156 | m_advancedPanel.addPropertyChangeListener(l); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * Gets the currently configured experiment. |
|---|
| 161 | * |
|---|
| 162 | * @return the currently configured experiment. |
|---|
| 163 | */ |
|---|
| 164 | public Experiment getExperiment() { |
|---|
| 165 | |
|---|
| 166 | if (m_SimpleSetupRBut.isSelected()) return m_simplePanel.getExperiment(); |
|---|
| 167 | else return m_advancedPanel.getExperiment(); |
|---|
| 168 | } |
|---|
| 169 | } |
|---|