/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * LoaderCustomizer.java * Copyright (C) 2002 Mark Hall * */ package weka.gui.beans; import weka.gui.FileEditor; import java.io.File; import java.beans.*; import java.awt.BorderLayout; import javax.swing.JPanel; import weka.gui.GenericObjectEditor; import weka.core.converters.Loader; /** * GUI Customizer for the loader bean * * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a> * @version 1.0 */ public class LoaderCustomizer extends JPanel implements Customizer { static { java.beans.PropertyEditorManager .registerEditor(weka.core.converters.Loader.class, weka.gui.GenericObjectEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.core.SelectedTag.class, weka.gui.SelectedTagEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.filters.Filter.class, weka.gui.GenericObjectEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.attributeSelection.ASSearch.class, weka.gui.GenericObjectEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.attributeSelection.ASEvaluation.class, weka.gui.GenericObjectEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.classifiers.Classifier [].class, weka.gui.GenericArrayEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.classifiers.Classifier.class, weka.gui.GenericObjectEditor.class); java.beans.PropertyEditorManager .registerEditor(weka.classifiers.CostMatrix.class, weka.gui.CostMatrixEditor.class); java.beans.PropertyEditorManager .registerEditor(java.io.File.class, weka.gui.FileEditor.class); } private PropertyChangeSupport m_pcSupport = new PropertyChangeSupport(this); private weka.gui.beans.Loader m_dsLoader; private FileEditor m_fileEditor = new FileEditor(); private GenericObjectEditor m_LoaderEditor = new GenericObjectEditor(true); public LoaderCustomizer() { /* m_fileEditor.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (m_dsLoader != null) { m_dsLoader.setDataSetFile((File)m_fileEditor.getValue()); } } }); */ try { m_LoaderEditor.setClassType(weka.core.converters.Loader.class); m_LoaderEditor.setValue(new weka.core.converters.ArffLoader()); m_LoaderEditor.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { repaint(); if (m_dsLoader != null) { m_dsLoader.setLoader((weka.core.converters.Loader)m_LoaderEditor. getValue()); } } }); repaint(); } catch (Exception ex) { ex.printStackTrace(); } setLayout(new BorderLayout()); // add(m_fileEditor.getCustomEditor(), BorderLayout.CENTER); add(m_LoaderEditor.getCustomEditor(), BorderLayout.CENTER); } /** * Set the loader to be customized * * @param object a weka.gui.beans.Loader */ public void setObject(Object object) { m_dsLoader = (weka.gui.beans.Loader)object; // m_fileEditor.setValue(m_dsLoader.getDataSetFile()); m_LoaderEditor.setValue(m_dsLoader.getLoader()); } /** * Add a property change listener * * @param pcl a <code>PropertyChangeListener</code> value */ public void addPropertyChangeListener(PropertyChangeListener pcl) { m_pcSupport.addPropertyChangeListener(pcl); } /** * Remove a property change listener * * @param pcl a <code>PropertyChangeListener</code> value */ public void removePropertyChangeListener(PropertyChangeListener pcl) { m_pcSupport.removePropertyChangeListener(pcl); } }