~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/gui/beans/ClassifierCustomizer.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *    ClassifierCustomizer.java
 
19
 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
 
20
 *
 
21
 */
 
22
 
 
23
package weka.gui.beans;
 
24
 
 
25
import weka.classifiers.Classifier;
 
26
import weka.gui.GenericObjectEditor;
 
27
import weka.gui.PropertySheetPanel;
 
28
 
 
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;
 
35
 
 
36
import javax.swing.JCheckBox;
 
37
import javax.swing.JPanel;
 
38
 
 
39
/**
 
40
 * GUI customizer for the classifier wrapper bean
 
41
 *
 
42
 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
 
43
 * @version $Revision: 1.11 $
 
44
 */
 
45
public class ClassifierCustomizer
 
46
  extends JPanel
 
47
  implements Customizer {
 
48
 
 
49
  /** for serialization */
 
50
  private static final long serialVersionUID = -6688000820160821429L;
 
51
 
 
52
  static {
 
53
     GenericObjectEditor.registerEditors();
 
54
  }
 
55
 
 
56
  private PropertyChangeSupport m_pcSupport = 
 
57
    new PropertyChangeSupport(this);
 
58
  
 
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();
 
64
 
 
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;
 
69
 
 
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) {
 
78
              m_dsClassifier.
 
79
                setUpdateIncrementalClassifier(m_updateIncrementalClassifier.
 
80
                                               isSelected());
 
81
            }
 
82
          }
 
83
        });
 
84
    m_incrementalPanel.add(m_updateIncrementalClassifier);
 
85
    setLayout(new BorderLayout());
 
86
    add(m_ClassifierEditor, BorderLayout.CENTER);
 
87
  }
 
88
  
 
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;
 
96
      }
 
97
    } else {
 
98
      if (m_panelVisible) {
 
99
        remove(m_incrementalPanel);
 
100
        m_panelVisible = false;
 
101
      }
 
102
    }
 
103
  }
 
104
 
 
105
  /**
 
106
   * Set the classifier object to be edited
 
107
   *
 
108
   * @param object an <code>Object</code> value
 
109
   */
 
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();
 
117
  }
 
118
 
 
119
  /**
 
120
   * Add a property change listener
 
121
   *
 
122
   * @param pcl a <code>PropertyChangeListener</code> value
 
123
   */
 
124
  public void addPropertyChangeListener(PropertyChangeListener pcl) {
 
125
    m_pcSupport.addPropertyChangeListener(pcl);
 
126
  }
 
127
 
 
128
  /**
 
129
   * Remove a property change listener
 
130
   *
 
131
   * @param pcl a <code>PropertyChangeListener</code> value
 
132
   */
 
133
  public void removePropertyChangeListener(PropertyChangeListener pcl) {
 
134
    m_pcSupport.removePropertyChangeListener(pcl);
 
135
  }
 
136
}