Class JTree.DynamicUtilTreeNode
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
javax.swing.JTree.DynamicUtilTreeNode
- All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode
- Enclosing class:
JTree
DynamicUtilTreeNode
can wrap
vectors/hashtables/arrays/strings and
create the appropriate children tree nodes as necessary. It is
dynamic in that it will only create the children as necessary.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see XMLEncoder
.
- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Object
Value to create children with.protected boolean
Does the thisJTree
have children?protected boolean
Have the children been loaded yet?Fields declared in class DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
Modifier and TypeFieldDescriptionprotected boolean
true if the node is able to have childrenarray of children, may be null if this node has no childrenstatic final Enumeration
<TreeNode> An enumeration that is always empty.protected MutableTreeNode
this node's parent, or null if this node has no parentprotected Object
optional user object -
Constructor Summary
ConstructorsConstructorDescriptionDynamicUtilTreeNode
(Object value, Object children) Creates a node with the specified object as its value and with the specified children. -
Method Summary
Modifier and TypeMethodDescriptionchildren()
Subclassed to load the children, if necessary.static void
createChildren
(DefaultMutableTreeNode parent, Object children) Adds to parent all the children inchildren
.getChildAt
(int index) Subclassed to load the children, if necessary.int
Returns the number of child nodes.boolean
isLeaf()
Returns true if this node allows children.protected void
Loads the children based onchildValue
.Methods declared in class DefaultMutableTreeNode
add, breadthFirstEnumeration, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildBefore, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
Modifier and TypeMethodDescriptionvoid
add
(MutableTreeNode newChild) RemovesnewChild
from its parent and makes it a child of this node by adding it to the end of this node's child array.Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order.clone()
Overridden to make clone public.Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order.boolean
Returns true if this node is allowed to have children.getChildAfter
(TreeNode aChild) Returns the child in this node's child array that immediately followsaChild
, which must be a child of this node.getChildBefore
(TreeNode aChild) Returns the child in this node's child array that immediately precedesaChild
, which must be a child of this node.int
getDepth()
Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf.Returns this node's first child.Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf.int
Returns the index of the specified child in this node's child array.Returns this node's last child.Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf.int
Returns the total number of leaves that are descendants of this node.int
getLevel()
Returns the number of levels above this node -- the distance from the root to this node.Returns the leaf after this node or null if this node is the last leaf in the tree.Returns the node that follows this node in a preorder traversal of this node's tree.Returns the next sibling of this node in the parent's children array.Returns this node's parent or null if this node has no parent.TreeNode[]
getPath()
Returns the path from the root, to get to this node.protected TreeNode[]
getPathToRoot
(TreeNode aNode, int depth) Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.Returns the leaf before this node or null if this node is the first leaf in the tree.Returns the node that precedes this node in a preorder traversal of this node's tree.Returns the previous sibling of this node in the parent's children array.getRoot()
Returns the root of the tree that contains this node.Returns the nearest common ancestor to this node andaNode
.int
Returns the number of siblings of this node.Returns this node's user object.Object[]
Returns the user object path, from the root, to get to this node.void
insert
(MutableTreeNode newChild, int childIndex) RemovesnewChild
from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at indexchildIndex
.boolean
isNodeAncestor
(TreeNode anotherNode) Returns true ifanotherNode
is an ancestor of this node -- if it is this node, this node's parent, or an ancestor of this node's parent.boolean
isNodeChild
(TreeNode aNode) Returns true ifaNode
is a child of this node.boolean
isNodeDescendant
(DefaultMutableTreeNode anotherNode) Returns true ifanotherNode
is a descendant of this node -- if it is this node, one of this node's children, or a descendant of one of this node's children.boolean
Returns true if and only ifaNode
is in the same tree as this node.boolean
isNodeSibling
(TreeNode anotherNode) Returns true ifanotherNode
is a sibling of (has the same parent as) this node.boolean
isRoot()
Returns true if this node is the root of the tree.pathFromAncestorEnumeration
(TreeNode ancestor) Creates and returns an enumeration that follows the path fromancestor
to this node.Creates and returns an enumeration that traverses the subtree rooted at this node in postorder.Creates and returns an enumeration that traverses the subtree rooted at this node in preorder.void
remove
(int childIndex) Removes the child at the specified index from this node's children and sets that node's parent to null.void
remove
(MutableTreeNode aChild) RemovesaChild
from this node's child array, giving it a null parent.void
Removes all of this node's children, setting their parents to null.void
Removes the subtree rooted at this node from the tree, giving this node a null parent.void
setAllowsChildren
(boolean allows) Determines whether or not this node is allowed to have children.void
setParent
(MutableTreeNode newParent) Sets this node's parent tonewParent
but does not change the parent's child array.void
setUserObject
(Object userObject) Sets the user object for this node touserObject
.toString()
Returns the result of sendingtoString()
to this node's user object, or the empty string if the node has no user object.Methods declared in class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Modifier and TypeMethodDescriptionboolean
Indicates whether some other object is "equal to" this one.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class
<?> getClass()
Returns the runtime class of thisObject
.int
hashCode()
Returns a hash code value for this object.final void
notify()
Wakes up a single thread that is waiting on this object's monitor.final void
Wakes up all threads that are waiting on this object's monitor.final void
wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final void
wait
(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final void
wait
(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Field Details
-
hasChildren
protected boolean hasChildrenDoes the thisJTree
have children? This property is currently not implemented. -
childValue
Value to create children with. -
loadedChildren
protected boolean loadedChildrenHave the children been loaded yet?
-
-
Constructor Details
-
DynamicUtilTreeNode
Creates a node with the specified object as its value and with the specified children. For the node to allow children, the children-object must be an array of objects, aVector
, or aHashtable
-- even if empty. Otherwise, the node is not allowed to have children.- Parameters:
value
- theObject
that is the value for the new nodechildren
- an array ofObject
s, aVector
, or aHashtable
used to create the child nodes; if any other object is specified, or if the value isnull
, then the node is not allowed to have children
-
-
Method Details
-
createChildren
Adds to parent all the children inchildren
. Ifchildren
is an array or vector all of its elements are added is children, otherwise ifchildren
is a hashtable all the key/value pairs are added in the orderEnumeration
returns them.- Parameters:
parent
- the parent nodechildren
- the children
-
isLeaf
public boolean isLeaf()Returns true if this node allows children. Whether the node allows children depends on how it was created.- Specified by:
isLeaf
in interfaceTreeNode
- Overrides:
isLeaf
in classDefaultMutableTreeNode
- Returns:
- true if this node allows children, false otherwise
- See Also:
-
getChildCount
public int getChildCount()Returns the number of child nodes.- Specified by:
getChildCount
in interfaceTreeNode
- Overrides:
getChildCount
in classDefaultMutableTreeNode
- Returns:
- the number of child nodes
-
loadChildren
protected void loadChildren()Loads the children based onchildValue
. IfchildValue
is aVector
or array each element is added as a child, ifchildValue
is aHashtable
each key/value pair is added in the order thatEnumeration
returns the keys. -
getChildAt
Subclassed to load the children, if necessary.- Specified by:
getChildAt
in interfaceTreeNode
- Overrides:
getChildAt
in classDefaultMutableTreeNode
- Parameters:
index
- an index into this node's child array- Returns:
- the TreeNode in this node's child array at the specified index
-
children
Subclassed to load the children, if necessary.- Specified by:
children
in interfaceTreeNode
- Overrides:
children
in classDefaultMutableTreeNode
- Returns:
- an Enumeration of this node's children
-