[4] | 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 | * ClustererCustomizer.java |
---|
| 19 | * Copyright (C) 2004 University of Waikato, Hamilton, New Zealand |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | package weka.gui.beans; |
---|
| 24 | |
---|
| 25 | import weka.gui.GenericObjectEditor; |
---|
| 26 | import weka.gui.PropertySheetPanel; |
---|
| 27 | |
---|
| 28 | import java.awt.BorderLayout; |
---|
| 29 | import java.awt.GridLayout; |
---|
| 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.JButton; |
---|
| 37 | import javax.swing.JFrame; |
---|
| 38 | import javax.swing.JPanel; |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * GUI customizer for the Clusterer wrapper bean |
---|
| 42 | * |
---|
| 43 | * @author <a href="mailto:mutter@cs.waikato.ac.nz">Stefan Mutter</a> |
---|
| 44 | * @version $Revision: 5340 $ |
---|
| 45 | */ |
---|
| 46 | public class ClustererCustomizer |
---|
| 47 | extends JPanel |
---|
| 48 | implements Customizer, CustomizerCloseRequester { |
---|
| 49 | |
---|
| 50 | /** for serialization */ |
---|
| 51 | private static final long serialVersionUID = -2035688458149534161L; |
---|
| 52 | |
---|
| 53 | static { |
---|
| 54 | GenericObjectEditor.registerEditors(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | private PropertyChangeSupport m_pcSupport = |
---|
| 58 | new PropertyChangeSupport(this); |
---|
| 59 | |
---|
| 60 | private weka.gui.beans.Clusterer m_dsClusterer; |
---|
| 61 | |
---|
| 62 | private PropertySheetPanel m_ClustererEditor = |
---|
| 63 | new PropertySheetPanel(); |
---|
| 64 | |
---|
| 65 | private JFrame m_parentFrame; |
---|
| 66 | |
---|
| 67 | /** Backup if the user presses cancel */ |
---|
| 68 | private weka.clusterers.Clusterer m_backup; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | public ClustererCustomizer() { |
---|
| 72 | |
---|
| 73 | setLayout(new BorderLayout()); |
---|
| 74 | add(m_ClustererEditor, BorderLayout.CENTER); |
---|
| 75 | |
---|
| 76 | JPanel butHolder = new JPanel(); |
---|
| 77 | butHolder.setLayout(new GridLayout(1,2)); |
---|
| 78 | JButton OKBut = new JButton("OK"); |
---|
| 79 | OKBut.addActionListener(new ActionListener() { |
---|
| 80 | public void actionPerformed(ActionEvent e) { |
---|
| 81 | m_parentFrame.dispose(); |
---|
| 82 | } |
---|
| 83 | }); |
---|
| 84 | |
---|
| 85 | JButton CancelBut = new JButton("Cancel"); |
---|
| 86 | CancelBut.addActionListener(new ActionListener() { |
---|
| 87 | public void actionPerformed(ActionEvent e) { |
---|
| 88 | // cancel requested, so revert to backup and then |
---|
| 89 | // close the dialog |
---|
| 90 | if (m_backup != null) { |
---|
| 91 | m_dsClusterer.setClusterer(m_backup); |
---|
| 92 | } |
---|
| 93 | m_parentFrame.dispose(); |
---|
| 94 | } |
---|
| 95 | }); |
---|
| 96 | |
---|
| 97 | butHolder.add(OKBut); |
---|
| 98 | butHolder.add(CancelBut); |
---|
| 99 | add(butHolder, BorderLayout.SOUTH); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Set the Clusterer object to be edited |
---|
| 104 | * |
---|
| 105 | * @param object an <code>Object</code> value |
---|
| 106 | */ |
---|
| 107 | public void setObject(Object object) { |
---|
| 108 | m_dsClusterer = (weka.gui.beans.Clusterer)object; |
---|
| 109 | try { |
---|
| 110 | m_backup = |
---|
| 111 | (weka.clusterers.Clusterer)GenericObjectEditor.makeCopy(m_dsClusterer.getClusterer()); |
---|
| 112 | } catch (Exception ex) { |
---|
| 113 | // ignore |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | m_ClustererEditor.setTarget(m_dsClusterer.getClusterer()); |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | * Add a property change listener |
---|
| 122 | * |
---|
| 123 | * @param pcl a <code>PropertyChangeListener</code> value |
---|
| 124 | */ |
---|
| 125 | public void addPropertyChangeListener(PropertyChangeListener pcl) { |
---|
| 126 | m_pcSupport.addPropertyChangeListener(pcl); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * Remove a property change listener |
---|
| 131 | * |
---|
| 132 | * @param pcl a <code>PropertyChangeListener</code> value |
---|
| 133 | */ |
---|
| 134 | public void removePropertyChangeListener(PropertyChangeListener pcl) { |
---|
| 135 | m_pcSupport.removePropertyChangeListener(pcl); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | public void setParentFrame(JFrame parent) { |
---|
| 139 | m_parentFrame = parent; |
---|
| 140 | } |
---|
| 141 | } |
---|