01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
05: * (C) 2003, Institut de Recherche pour le Développement
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.gui.swing.tree;
18:
19: // J2SE dependencies
20: import javax.swing.JTree;
21:
22: /**
23: * A tree node with a name which may be different than the user object. The {@link JTree}
24: * component invokes the {@link #toString} method for populating the tree widget. This class
25: * overrides the default implementation (<code>{@link #getUserObject userObject}.toString</code>)
26: * with a custom label.
27: *
28: * @since 2.0
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/main/java/org/geotools/gui/swing/tree/NamedTreeNode.java $
30: * @version $Id: NamedTreeNode.java 20883 2006-08-07 13:48:09Z jgarnett $
31: * @author Martin Desruisseaux
32: */
33: public class NamedTreeNode extends DefaultMutableTreeNode {
34: /**
35: * Serial number for compatibility with different versions.
36: */
37: private static final long serialVersionUID = -5052321314347001298L;
38:
39: /**
40: * The node label to be returned by {@link #toString}.
41: */
42: private final String name;
43:
44: /**
45: * Creates a tree node that has no parent and no children, but which allows children.
46: *
47: * @param name The node name to be returned by {@link #toString}.
48: */
49: public NamedTreeNode(final String name) {
50: super ();
51: this .name = name;
52: }
53:
54: /**
55: * Creates a tree node with no parent, no children, but which allows
56: * children, and initializes it with the specified user object.
57: *
58: * @param name The node name to be returned by {@link #toString}.
59: * @param userObject an Object provided by the user that constitutes the node's data
60: */
61: public NamedTreeNode(final String name, final Object userObject) {
62: super (userObject);
63: this .name = name;
64: }
65:
66: /**
67: * Creates a tree node with no parent, no children, initialized with
68: * the specified user object, and that allows children only if specified.
69: *
70: * @param name The node name to be returned by {@link #toString}.
71: * @param userObject an Object provided by the user that constitutes the node's data
72: * @param allowsChildren if true, the node is allowed to have child nodes -- otherwise,
73: * it is always a leaf node
74: */
75: public NamedTreeNode(final String name, Object userObject,
76: boolean allowsChildren) {
77: super (userObject, allowsChildren);
78: this .name = name;
79: }
80:
81: /**
82: * Returns this node label. This method is invoked by {@link JTree} for populating
83: * the tree widget.
84: */
85: public String toString() {
86: return name;
87: }
88: }
|