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.
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.
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.
19
* Copyright (C) 2006 Robert Jung
23
package weka.gui.ensembleLibraryEditor.tree;
25
import weka.gui.EnsembleLibraryEditor;
27
import java.beans.PropertyChangeEvent;
28
import java.beans.PropertyChangeListener;
29
import java.beans.PropertyEditor;
31
import javax.swing.tree.DefaultMutableTreeNode;
34
* This class is responsible for representing objects that we haven't explicitly
35
* written custom tree node editors for. In other words - Objects that are
36
* "weird". It didn't make sense for us to try to come up with a nice tree
37
* representation for absolutely everything, e.g. CostMatrixes or ArrayLists.
38
* This class is responsible for representing Classifier parameter values that
39
* are not numbers, an enumeration of values (e.g. true/false), or Objects that
40
* have their own GenericObjectEditors (like other Classifiers). So in these
41
* cases we can just use the default editor that came with the object.
43
* @author Robert Jung (mrbobjung@gmail.com)
44
* @version $Revision: 1.1 $
46
public class DefaultNode
47
extends DefaultMutableTreeNode
48
implements PropertyChangeListener {
50
/** for serialization */
51
private static final long serialVersionUID = -2182147677358461880L;
53
/** the name of this node */
54
private String m_Name;
56
/** the tip text for our node editor to display */
57
private String m_ToolTipText;
59
/** The default PropertyEditor that was supplied for this node */
60
private PropertyEditor m_PropertyEditor;
63
* The constructor initializes the members of this node.
66
* the name of the value represented by this node
68
* the tool tip text to be displayed
71
* @param propertyEditor
72
* the editor provided for this node
74
public DefaultNode(String name, String toolTipText, Object value,
75
PropertyEditor propertyEditor) {
80
this.m_ToolTipText = toolTipText;
81
this.m_PropertyEditor = propertyEditor;
83
m_PropertyEditor.addPropertyChangeListener(this);
88
* this returns the property editor that was provided for this object. This
89
* propertyEditor object is initially chosen inside of the GenericObjectNode
90
* updateTree() method if you are interested in where it comes from.
92
* @return the default editor for this node
94
public PropertyEditor getEditor() {
95
m_PropertyEditor.setValue(this.getUserObject());
96
return m_PropertyEditor;
100
* getter for the tooltip text
102
* @return tooltip text
104
public String getToolTipText() {
105
return m_ToolTipText;
109
* gets the name of the parameter value represented by this node
111
* @return the name of this parameter
113
public String getName() {
118
* this is a simple filter for the setUserObject method. We basically don't
119
* want null values to be passed in.
121
* @param o the user object
123
public void setUserObject(Object o) {
125
super.setUserObject(o);
129
* ToString method simply prints out the user object toString for this node
131
* @return a string representation
133
public String toString() {
134
return getClass().getName() + "[" + getUserObject().toString() + "]";
138
* This implements the PropertyChangeListener for this node that gets
139
* registered with its Editor. All we really have to do is change the Object
140
* value stored internally at this node when its editor says the value
143
* @param evt the event
145
public void propertyChange(PropertyChangeEvent evt) {
147
Object source = evt.getSource();
149
Object value = EnsembleLibraryEditor.getEditorValue(source);
152
* //was useful for debugging when we encountered some strange value
153
* types //these printouts tell you the classes that the editor is
154
* supplying System.out.println("prop name: " + evt.getPropertyName() +
155
* "new value: " + evt.getNewValue() + "old value: " +
156
* evt.getOldValue()); System.out.println("prop val: " +
157
* source.toString() + " expected val: " + value);
159
setUserObject(value);
b'\\ No newline at end of file'