source: src/main/java/weka/gui/beans/AssociatorCustomizer.java @ 8

Last change on this file since 8 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.1 KB
Line 
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 *    AssociatorCustomizer.java
19 *    Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.beans;
24
25import weka.gui.GenericObjectEditor;
26import weka.gui.PropertySheetPanel;
27
28import java.awt.BorderLayout;
29import java.awt.GridLayout;
30import java.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import java.beans.Customizer;
33import java.beans.PropertyChangeListener;
34import java.beans.PropertyChangeSupport;
35
36import javax.swing.JButton;
37import javax.swing.JFrame;
38import javax.swing.JPanel;
39
40/**
41 * GUI customizer for the associator wrapper bean
42 *
43 * @author Mark Hall (mhall at cs dot waikato dot ac dot nz)
44 * @version $Revision: 5340 $
45 */
46public class AssociatorCustomizer
47  extends JPanel
48  implements Customizer, CustomizerCloseRequester {
49
50  /** for serialization */
51  private static final long serialVersionUID = 5767664969353495974L;
52
53  static {
54    GenericObjectEditor.registerEditors();
55  }
56
57  private PropertyChangeSupport m_pcSupport = 
58    new PropertyChangeSupport(this);
59 
60  private weka.gui.beans.Associator m_dsAssociator;
61  /*  private GenericObjectEditor m_ClassifierEditor =
62      new GenericObjectEditor(true); */
63  private PropertySheetPanel m_AssociatorEditor = 
64    new PropertySheetPanel();
65 
66  protected JFrame m_parentFrame;
67 
68  /** Backup is user presses cancel */
69  private weka.associations.Associator m_backup;
70
71  public AssociatorCustomizer() {
72    setLayout(new BorderLayout());
73    add(m_AssociatorEditor, BorderLayout.CENTER);
74   
75    JPanel butHolder = new JPanel();
76    butHolder.setLayout(new GridLayout(1,2));
77    JButton OKBut = new JButton("OK");
78    OKBut.addActionListener(new ActionListener() {
79      public void actionPerformed(ActionEvent e) {
80        m_parentFrame.dispose();
81      }
82    });
83
84    JButton CancelBut = new JButton("Cancel");
85    CancelBut.addActionListener(new ActionListener() {
86      public void actionPerformed(ActionEvent e) {
87        // cancel requested, so revert to backup and then
88        // close the dialog
89        if (m_backup != null) {
90          m_dsAssociator.setAssociator(m_backup);
91        }
92        m_parentFrame.dispose();
93      }
94    });
95   
96    butHolder.add(OKBut);
97    butHolder.add(CancelBut);
98    add(butHolder, BorderLayout.SOUTH);
99  }
100
101  /**
102   * Set the classifier object to be edited
103   *
104   * @param object an <code>Object</code> value
105   */
106  public void setObject(Object object) {
107    m_dsAssociator = (weka.gui.beans.Associator)object;
108    //    System.err.println(Utils.joinOptions(((OptionHandler)m_dsClassifier.getClassifier()).getOptions()));
109    try {
110      m_backup = 
111        (weka.associations.Associator)GenericObjectEditor.makeCopy(m_dsAssociator.getAssociator());
112    } catch (Exception ex) {
113      // ignore
114    }
115   
116    m_AssociatorEditor.setTarget(m_dsAssociator.getAssociator());
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
137  public void setParentFrame(JFrame parent) {
138    m_parentFrame = parent;
139  }
140}
Note: See TracBrowser for help on using the repository browser.