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

« back to all changes in this revision

Viewing changes to weka/gui/beans/FilterCustomizer.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
 *    FilterCustomizer.java
 
19
 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
 
20
 *
 
21
 */
 
22
 
 
23
package weka.gui.beans;
 
24
 
 
25
import weka.filters.Filter;
 
26
import weka.gui.GenericObjectEditor;
 
27
 
 
28
import java.awt.BorderLayout;
 
29
import java.beans.Customizer;
 
30
import java.beans.PropertyChangeEvent;
 
31
import java.beans.PropertyChangeListener;
 
32
import java.beans.PropertyChangeSupport;
 
33
 
 
34
import javax.swing.JPanel;
 
35
 
 
36
/**
 
37
 * GUI customizer for the filter bean
 
38
 *
 
39
 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
 
40
 * @version $Revision: 1.9 $
 
41
 */
 
42
public class FilterCustomizer
 
43
  extends JPanel
 
44
  implements Customizer {
 
45
 
 
46
  /** for serialization */
 
47
  private static final long serialVersionUID = 2049895469240109738L;
 
48
  
 
49
  static {
 
50
     GenericObjectEditor.registerEditors();
 
51
  }
 
52
 
 
53
  private PropertyChangeSupport m_pcSupport = 
 
54
    new PropertyChangeSupport(this);
 
55
 
 
56
  private weka.gui.beans.Filter m_filter;
 
57
  private GenericObjectEditor m_filterEditor = 
 
58
    new GenericObjectEditor(true);
 
59
 
 
60
  public FilterCustomizer() {
 
61
    try {
 
62
      m_filterEditor.
 
63
        setClassType(Filter.class);      
 
64
      m_filterEditor.setValue(new weka.filters.unsupervised.attribute.Add());
 
65
      m_filterEditor.addPropertyChangeListener(new PropertyChangeListener() {
 
66
          public void propertyChange(PropertyChangeEvent e) {
 
67
            repaint();
 
68
            if (m_filter != null) {
 
69
              Filter editedF = (Filter)m_filterEditor.getValue();
 
70
              m_filter.setFilter(editedF);
 
71
              // should pass on the property change to any other interested
 
72
              // listeners
 
73
            }
 
74
          }
 
75
        });
 
76
      //      System.out.println("Here");
 
77
      repaint();
 
78
    } catch (Exception ex) {
 
79
      ex.printStackTrace();
 
80
    }
 
81
 
 
82
    setLayout(new BorderLayout());
 
83
    add(m_filterEditor.getCustomEditor(), BorderLayout.CENTER);
 
84
  }
 
85
  
 
86
  /**
 
87
   * Set the filter bean to be edited
 
88
   *
 
89
   * @param object a Filter bean
 
90
   */
 
91
  public void setObject(Object object) {
 
92
    m_filter = (weka.gui.beans.Filter)object;
 
93
    m_filterEditor.setValue(m_filter.getFilter());
 
94
  }
 
95
 
 
96
  /**
 
97
   * Add a property change listener
 
98
   *
 
99
   * @param pcl a <code>PropertyChangeListener</code> value
 
100
   */
 
101
  public void addPropertyChangeListener(PropertyChangeListener pcl) {
 
102
    m_pcSupport.addPropertyChangeListener(pcl);
 
103
  }
 
104
 
 
105
  /**
 
106
   * Remove a property change listener
 
107
   *
 
108
   * @param pcl a <code>PropertyChangeListener</code> value
 
109
   */
 
110
  public void removePropertyChangeListener(PropertyChangeListener pcl) {
 
111
    m_pcSupport.removePropertyChangeListener(pcl);
 
112
  }
 
113
}
 
114