FilterCustomizer.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 4k
Category:

Windows Develop

Development Platform:

Java

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