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.
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.
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.
18
* ClassifierCustomizer.java
19
* Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
23
package weka.gui.beans;
25
import weka.classifiers.Classifier;
26
import weka.gui.GenericObjectEditor;
27
import weka.gui.PropertySheetPanel;
29
import java.awt.BorderLayout;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.beans.Customizer;
33
import java.beans.PropertyChangeListener;
34
import java.beans.PropertyChangeSupport;
36
import javax.swing.JCheckBox;
37
import javax.swing.JPanel;
40
* GUI customizer for the classifier wrapper bean
42
* @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
43
* @version $Revision: 1.11 $
45
public class ClassifierCustomizer
47
implements Customizer {
49
/** for serialization */
50
private static final long serialVersionUID = -6688000820160821429L;
53
GenericObjectEditor.registerEditors();
56
private PropertyChangeSupport m_pcSupport =
57
new PropertyChangeSupport(this);
59
private weka.gui.beans.Classifier m_dsClassifier;
60
/* private GenericObjectEditor m_ClassifierEditor =
61
new GenericObjectEditor(true); */
62
private PropertySheetPanel m_ClassifierEditor =
63
new PropertySheetPanel();
65
private JPanel m_incrementalPanel = new JPanel();
66
private JCheckBox m_updateIncrementalClassifier
67
= new JCheckBox("Update classifier on incoming instance stream");
68
private boolean m_panelVisible = false;
70
public ClassifierCustomizer() {
71
m_updateIncrementalClassifier.
72
setToolTipText("Train the classifier on "
73
+"each individual incoming streamed instance.");
74
m_updateIncrementalClassifier.
75
addActionListener(new ActionListener() {
76
public void actionPerformed(ActionEvent e) {
77
if (m_dsClassifier != null) {
79
setUpdateIncrementalClassifier(m_updateIncrementalClassifier.
84
m_incrementalPanel.add(m_updateIncrementalClassifier);
85
setLayout(new BorderLayout());
86
add(m_ClassifierEditor, BorderLayout.CENTER);
89
private void checkOnClassifierType() {
90
Classifier editedC = m_dsClassifier.getClassifier();
91
if (editedC instanceof weka.classifiers.UpdateableClassifier &&
92
m_dsClassifier.hasIncomingStreamInstances()) {
93
if (!m_panelVisible) {
94
add(m_incrementalPanel, BorderLayout.SOUTH);
95
m_panelVisible = true;
99
remove(m_incrementalPanel);
100
m_panelVisible = false;
106
* Set the classifier object to be edited
108
* @param object an <code>Object</code> value
110
public void setObject(Object object) {
111
m_dsClassifier = (weka.gui.beans.Classifier)object;
112
// System.err.println(Utils.joinOptions(((OptionHandler)m_dsClassifier.getClassifier()).getOptions()));
113
m_ClassifierEditor.setTarget(m_dsClassifier.getClassifier());
114
m_updateIncrementalClassifier.
115
setSelected(m_dsClassifier.getUpdateIncrementalClassifier());
116
checkOnClassifierType();
120
* Add a property change listener
122
* @param pcl a <code>PropertyChangeListener</code> value
124
public void addPropertyChangeListener(PropertyChangeListener pcl) {
125
m_pcSupport.addPropertyChangeListener(pcl);
129
* Remove a property change listener
131
* @param pcl a <code>PropertyChangeListener</code> value
133
public void removePropertyChangeListener(PropertyChangeListener pcl) {
134
m_pcSupport.removePropertyChangeListener(pcl);