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 ObjectValue to create children with.protected booleanDoes the thisJTreehave children?protected booleanHave the children been loaded yet?Fields declared in class DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObjectModifier and TypeFieldDescriptionprotected booleantrue 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 MutableTreeNodethis node's parent, or null if this node has no parentprotected Objectoptional 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 voidcreateChildren(DefaultMutableTreeNode parent, Object children) Adds to parent all the children inchildren.getChildAt(int index) Subclassed to load the children, if necessary.intReturns the number of child nodes.booleanisLeaf()Returns true if this node allows children.protected voidLoads 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, toStringModifier and TypeMethodDescriptionvoidadd(MutableTreeNode newChild) RemovesnewChildfrom 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.booleanReturns 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.intgetDepth()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.intReturns 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.intReturns the total number of leaves that are descendants of this node.intgetLevel()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.intReturns 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.voidinsert(MutableTreeNode newChild, int childIndex) RemovesnewChildfrom 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.booleanisNodeAncestor(TreeNode anotherNode) Returns true ifanotherNodeis an ancestor of this node -- if it is this node, this node's parent, or an ancestor of this node's parent.booleanisNodeChild(TreeNode aNode) Returns true ifaNodeis a child of this node.booleanisNodeDescendant(DefaultMutableTreeNode anotherNode) Returns true ifanotherNodeis 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.booleanReturns true if and only ifaNodeis in the same tree as this node.booleanisNodeSibling(TreeNode anotherNode) Returns true ifanotherNodeis a sibling of (has the same parent as) this node.booleanisRoot()Returns true if this node is the root of the tree.pathFromAncestorEnumeration(TreeNode ancestor) Creates and returns an enumeration that follows the path fromancestorto 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.voidremove(int childIndex) Removes the child at the specified index from this node's children and sets that node's parent to null.voidremove(MutableTreeNode aChild) RemovesaChildfrom this node's child array, giving it a null parent.voidRemoves all of this node's children, setting their parents to null.voidRemoves the subtree rooted at this node from the tree, giving this node a null parent.voidsetAllowsChildren(boolean allows) Determines whether or not this node is allowed to have children.voidsetParent(MutableTreeNode newParent) Sets this node's parent tonewParentbut does not change the parent's child array.voidsetUserObject(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, waitModifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" this one.protected voidfinalize()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.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(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 voidwait(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 thisJTreehave 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- theObjectthat is the value for the new nodechildren- an array ofObjects, aVector, or aHashtableused 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. Ifchildrenis an array or vector all of its elements are added is children, otherwise ifchildrenis a hashtable all the key/value pairs are added in the orderEnumerationreturns 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:
isLeafin interfaceTreeNode- Overrides:
isLeafin classDefaultMutableTreeNode- Returns:
- true if this node allows children, false otherwise
- See Also:
-
getChildCount
public int getChildCount()Returns the number of child nodes.- Specified by:
getChildCountin interfaceTreeNode- Overrides:
getChildCountin classDefaultMutableTreeNode- Returns:
- the number of child nodes
-
loadChildren
protected void loadChildren()Loads the children based onchildValue. IfchildValueis aVectoror array each element is added as a child, ifchildValueis aHashtableeach key/value pair is added in the order thatEnumerationreturns the keys. -
getChildAt
Subclassed to load the children, if necessary.- Specified by:
getChildAtin interfaceTreeNode- Overrides:
getChildAtin 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:
childrenin interfaceTreeNode- Overrides:
childrenin classDefaultMutableTreeNode- Returns:
- an Enumeration of this node's children
-