org.geotoolkit.gui.swing.tree
Class NamedTreeNode

Object
  extended by DefaultMutableTreeNode
      extended by DefaultMutableTreeNode
          extended by NamedTreeNode
All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode, Localized
Direct Known Subclasses:
MetadataTreeNode

public class NamedTreeNode
extends DefaultMutableTreeNode

A tree node with a name which may be different than the user object. Because the JTree component invokes the toString() method for populating the tree widget, this class is useful when the label to display is different than the value of userObject.toString().


Localization
Every constructors in this class expect a name of type CharSequence. The names are typically instances of String, but instances of InternationalString are also accepted. In the later case, the toString() method may return a localized string depending on the return value of the getLocale() method. By default, the later is the locale of the parent node.

Since:
2.0
Version:
3.17
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
Serialized Form
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
 
Fields inherited from class DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
NamedTreeNode(CharSequence name)
          Creates a tree node that has no parent and no children, but which allows children.
NamedTreeNode(CharSequence name, Object userObject)
          Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
NamedTreeNode(CharSequence name, Object userObject, boolean allowsChildren)
          Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified.
 
Method Summary
 CharSequence getName()
          Returns the name of this node as an instance of String or InternationalString.
 void setName(CharSequence name)
          Sets the name of this node.
 String toString()
          Returns the name given at construction time.
 
Methods inherited from class DefaultMutableTreeNode
children, getLocale
 
Methods inherited from class DefaultMutableTreeNode
add, breadthFirstEnumeration, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface MutableTreeNode
insert, remove, remove, removeFromParent, setParent, setUserObject
 
Methods inherited from interface TreeNode
getUserObject
 
Methods inherited from interface TreeNode
getAllowsChildren, getChildAt, getChildCount, getIndex, getParent, isLeaf
 

Constructor Detail

NamedTreeNode

public NamedTreeNode(CharSequence name)
Creates a tree node that has no parent and no children, but which allows children.

Parameters:
name - The node name to be returned by toString().

NamedTreeNode

public NamedTreeNode(CharSequence name,
                     Object userObject)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Parameters:
name - The node name to be returned by toString().
userObject - an Object provided by the user that constitutes the node's data

NamedTreeNode

public NamedTreeNode(CharSequence name,
                     Object userObject,
                     boolean allowsChildren)
Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified.

Parameters:
name - The node name to be returned by toString().
userObject - an Object provided by the user that constitutes the node's data
allowsChildren - if true, the node is allowed to have child nodes. Otherwise, it is always a leaf node
Method Detail

getName

public CharSequence getName()
Returns the name of this node as an instance of String or InternationalString.

Returns:
The name, or null if none.
Since:
3.17

setName

public void setName(CharSequence name)
Sets the name of this node. While this method accepts null value (because Swing DefaultMutableTreeNode.toString() is designed that way), it is highly recommended to set only non-null values.

Parameters:
name - The new name of this node.
Since:
3.17

toString

public String toString()
Returns the name given at construction time. If that name is an instance of InternationalString and the getLocale() method returns a non-null value, then the InternationalString.toString(Locale) value is returned.

Overrides:
toString in class DefaultMutableTreeNode
Returns:
The localized string value of the user object, or null if none.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.