source: src/main/java/weka/gui/ensembleLibraryEditor/tree/CheckBoxNode.java @ 21

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

Import di weka.

File size: 4.3 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 *    CheckBoxNode.java
19 *    Copyright (C) 2006 Robert Jung
20 *
21 */
22
23package weka.gui.ensembleLibraryEditor.tree;
24
25import java.awt.event.ItemEvent;
26import java.awt.event.ItemListener;
27
28import javax.swing.tree.DefaultMutableTreeNode;
29
30/**
31 * This class is responsible for implementing the underlying logic of
32 * tree nodes representing a single nominal value.  This is either going to
33 * be true/false values or an enumeration of values defined by the model.
34 * Check box nodes are relatively simple in that they are simply toggled
35 * on or off by the user indicating whether or not they are to be used.
36 *
37 * @author  Robert Jung (mrbobjung@gmail.com)
38 * @version $Revision: 1.1 $
39 */
40public class CheckBoxNode
41  extends DefaultMutableTreeNode
42  implements ItemListener {
43 
44  /** for serialization */
45  private static final long serialVersionUID = 727140674668443817L;
46
47  /** tracks whether this node is currently selected as a model parameter */
48  private boolean m_Selected;
49 
50  /** the tip text for our node editor to display */
51  private String m_ToolTipText;
52 
53  /**
54   * The constructor initializes the members of this node.  Note that
55   * the text String is stored as the userObject.
56   *
57   * @param name the name of this attribute
58   * @param selected the initial value of this node
59   * @param toolTipText the toolTipText to be displayed
60   */
61  public CheckBoxNode(String name, boolean selected, String toolTipText) {
62    super(name);
63    setName(name);
64    this.m_Selected = selected;
65    this.m_ToolTipText = toolTipText;
66  }
67 
68  /**
69   * getter for the node state
70   *
71   * @return whether or not this node is selected
72   */
73  public boolean getSelected() {
74    return m_Selected;
75  }
76 
77  /**
78   * setter for the node state
79   *
80   * @param newValue the new selected state
81   */
82  public void setSelected(boolean newValue) {
83    m_Selected = newValue;
84  }
85 
86  /**
87   * sets whether the box is selected
88   *
89   * @param newValue    if true the box will be selected
90   */
91  public void setBoxSelected(boolean newValue) {
92    m_Selected = newValue;
93  }
94 
95  /**
96   * gets the name of the parameter value represented by this node
97   * which is stored as the node's user object
98   *
99   * @return the name of this parameter
100   */
101  public String getName() {
102    return (String) getUserObject().toString();
103  }
104 
105  /**
106   * sets the name of the parameter value represented by this node
107   * and stores it as the node's user object
108   *
109   * @param newValue    the new name
110   */
111  public void setName(String newValue) {
112    setUserObject(newValue);
113  }
114 
115  /**
116   * getter for the tooltip text
117   *
118   * @return tooltip text
119   */
120  public String getToolTipText() {
121    return m_ToolTipText;
122  }
123 
124  /**
125   * this is a simple filter for the setUserObject method.  We basically
126   * don't want null values to be passed in.
127   *
128   * @param o           the user object
129   */
130  public void setUserObject(Object o) {
131    if (o != null)
132      super.setUserObject(o);
133  }
134 
135  /**
136   * ToString methods prints out the toString method of this nodes user
137   * object
138   *
139   * @return            a string representation
140   */
141  public String toString() {
142    return getClass().getName() + "[" + getUserObject() + "/" + m_Selected
143    + "]";
144  }
145 
146  /**
147   * This is the listener that fires when the check box is actually toggled.
148   * Here we just want to change the selected state accordingly.
149   *
150   * @param e           the event
151   */
152  public void itemStateChanged(ItemEvent e) {
153    if (e.getStateChange() == ItemEvent.SELECTED) {
154      setBoxSelected(true);
155     
156    } else if (e.getStateChange() == ItemEvent.DESELECTED) {
157      setBoxSelected(false);
158    }
159  }
160}
Note: See TracBrowser for help on using the repository browser.