javax.swing.tree
public class DefaultMutableTreeNode extends Object implements Cloneable, MutableTreeNode, Serializable
Field Summary | |
---|---|
protected boolean | allowsChildren
allowsChildren |
protected Vector<MutableTreeNode> | children
The child nodes for this node (may be empty). |
static Enumeration<TreeNode> | EMPTY_ENUMERATION
An empty enumeration, returned by {@link #children()} if a node has no
children. |
protected MutableTreeNode | parent
The parent of this node (possibly null ). |
protected Object | userObject
userObject |
Constructor Summary | |
---|---|
DefaultMutableTreeNode()
Creates a DefaultMutableTreeNode object.
| |
DefaultMutableTreeNode(Object userObject)
Creates a DefaultMutableTreeNode object with the given
user object attached to it. | |
DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
Creates a DefaultMutableTreeNode object with the given
user object attached to it.
|
Method Summary | |
---|---|
void | add(MutableTreeNode child)
Adds a new child node to this node and sets this node as the parent of
the child node. |
Enumeration | breadthFirstEnumeration()
breadthFirstEnumeration
|
Enumeration | children()
Returns an enumeration containing all children of this node.
|
Object | clone()
Returns a clone of the node. |
Enumeration | depthFirstEnumeration()
depthFirstEnumeration
|
boolean | getAllowsChildren()
getAllowsChildren
|
TreeNode | getChildAfter(TreeNode node)
Returns the next child after the specified node , or
null if there is no child after the specified
node .
|
TreeNode | getChildAt(int index)
Returns the child node at a given index.
|
TreeNode | getChildBefore(TreeNode node)
Returns the previous child before the specified node , or
null if there is no child before the specified
node .
|
int | getChildCount()
Returns the number of children of this node.
|
int | getDepth()
getDepth
|
TreeNode | getFirstChild()
Returns the first child node belonging to this tree node.
|
DefaultMutableTreeNode | getFirstLeaf()
Returns the first leaf node that is a descendant of this node. |
int | getIndex(TreeNode node)
Returns the index of the specified child node, or -1 if the node is not
in fact a child of this node.
|
TreeNode | getLastChild()
Returns the last child node belonging to this tree node.
|
DefaultMutableTreeNode | getLastLeaf()
Returns the last leaf node that is a descendant of this node. |
int | getLeafCount()
getLeafCount
|
int | getLevel()
getLevel
|
DefaultMutableTreeNode | getNextLeaf()
Returns the next leaf node after this tree node.
|
DefaultMutableTreeNode | getNextNode()
getNextNode
|
DefaultMutableTreeNode | getNextSibling()
Returns the next sibling for this tree node. |
TreeNode | getParent()
Returns the parent node of this node.
|
TreeNode[] | getPath()
Returns a path to this node from the root.
|
protected TreeNode[] | getPathToRoot(TreeNode node, int depth)
getPathToRoot
|
DefaultMutableTreeNode | getPreviousLeaf()
Returns the previous leaf node before this tree node.
|
DefaultMutableTreeNode | getPreviousNode()
getPreviousNode
|
DefaultMutableTreeNode | getPreviousSibling()
Returns the previous sibling for this tree node. |
TreeNode | getRoot()
Returns the root node by iterating the parents of this node.
|
TreeNode | getSharedAncestor(DefaultMutableTreeNode node)
getSharedAncestor
|
int | getSiblingCount()
Returns the number of siblings for this tree node. |
Object | getUserObject()
Returns the user object attached to this node. |
Object[] | getUserObjectPath()
getUserObjectPath
|
void | insert(MutableTreeNode node, int index)
Inserts given child node at the given index.
|
boolean | isLeaf()
Returns true if this tree node is a lead node (that is, it
has no children), and false.
|
boolean | isNodeAncestor(TreeNode node)
Returns true if node is an ancestor of this
tree node, and false otherwise. |
boolean | isNodeChild(TreeNode node)
Returns true if node is a child of this tree
node, and false otherwise. |
boolean | isNodeDescendant(DefaultMutableTreeNode node)
Returns true if node is a descendant of this
tree node, and false otherwise. |
boolean | isNodeRelated(DefaultMutableTreeNode node)
isNodeRelated
|
boolean | isNodeSibling(TreeNode node)
Returns true if this tree node and node share
the same parent. |
boolean | isRoot()
Tells whether this node is the root node or not.
|
Enumeration | pathFromAncestorEnumeration(TreeNode node)
pathFromAncestorEnumeration
|
Enumeration | postorderEnumeration()
postorderEnumeration
|
Enumeration | preorderEnumeration()
preorderEnumeration
|
void | remove(int index)
Removes the child with the given index from this node.
|
void | remove(MutableTreeNode node)
Removes the given child from this node and sets its parent to
null .
|
void | removeAllChildren()
Removes all child nodes from this node. |
void | removeFromParent()
Removes this node from its parent. |
void | setAllowsChildren(boolean allowsChildren)
Sets the flag that controls whether or not this node allows the addition /
insertion of child nodes. |
void | setParent(MutableTreeNode node)
Set the parent node for this node.
|
void | setUserObject(Object userObject)
Sets the user object for this node
|
String | toString()
Returns a string representation of the node. |
null
).DefaultMutableTreeNode
object.
This is equivalent to DefaultMutableTreeNode(null, true)
.DefaultMutableTreeNode
object with the given
user object attached to it. This is equivalent to
DefaultMutableTreeNode(userObject, true)
.
Parameters: userObject the user object (null
permitted).
DefaultMutableTreeNode
object with the given
user object attached to it.
Parameters: userObject the user object (null
permitted). allowsChildren true
if the code allows to add child
nodes, false
otherwise
Parameters: child the child node (null
not permitted).
Throws: IllegalStateException if {@link #getAllowsChildren()} returns
false
. IllegalArgumentException if {@link #isNodeAncestor} returns
true
. IllegalArgumentException if child
is
null
.
Returns: Enumeration
EMPTY_ENUMERATION
is returned if this node has no children.
Returns: an enumeration of tree nodes
Returns: A clone of the node.
Returns: Enumeration
Returns: boolean
node
, or
null
if there is no child after the specified
node
.
Parameters: node a child of this node (null
not permitted).
Returns: The next child, or null
.
Throws: IllegalArgumentException if node
is not a child of
this node, or is null
.
Parameters: index the index
Returns: the child node
node
, or
null
if there is no child before the specified
node
.
Parameters: node a child of this node (null
not permitted).
Returns: The previous child, or null
.
Throws: IllegalArgumentException if node
is not a child of
this node, or is null
.
Returns: the number of children
Returns: int
Returns: The first child node.
Throws: NoSuchElementException if this tree node has no children.
Returns: The first leaf node.
Parameters: node the node (null
not permitted).
Returns: The index of the specified child node, or -1.
Throws: IllegalArgumentException if node
is null
.
Returns: The last child node.
Throws: NoSuchElementException if this tree node has no children.
Returns: The first leaf node.
Returns: int
Returns: int
Returns: The next leaf node, or null
.
Returns: DefaultMutableTreeNode
null
.
Returns: The next sibling, or null
.
Returns: The parent node (possibly null
).
Returns: an array of tree nodes
Parameters: node TODO depth TODO
Returns: TreeNode[]
Returns: The previous leaf node, or null
.
Returns: DefaultMutableTreeNode
null
.
Returns: The previous sibling, or null
.
Returns: the root node
Parameters: node TODO
Returns: TreeNode
1
.
Returns: The sibling count.
null
is
returned when no user object is set.
Returns: the user object
Returns: Object[]
Parameters: node the child node (null
not permitted). index the index.
Throws: IllegalArgumentException if node
is
null.
true
if this tree node is a lead node (that is, it
has no children), and false.
Returns: A boolean.
true
if node
is an ancestor of this
tree node, and false
otherwise. An ancestor node is any of:
node
is null
, this method returns
false
.
Parameters: node the node (null
permitted).
Returns: A boolean.
true
if node
is a child of this tree
node, and false
otherwise. If node
is
null
, this method returns false
.
Parameters: node the node (null
permitted).
Returns: A boolean.
true
if node
is a descendant of this
tree node, and false
otherwise. A descendant node is any of:
node
is null
, this method returns
false
.
Parameters: node the node (null
permitted).
Returns: A boolean.
Parameters: node TODO
Returns: boolean
true
if this tree node and node
share
the same parent. If node
is this tree node, the method
returns true
and if node
is null
this method returns false
.
Parameters: node the node (null
permitted).
Returns: A boolean.
Returns: true
if this is the root node,
false
otherwise
Parameters: node TODO
Returns: Enumeration
Returns: Enumeration
Returns: Enumeration
Parameters: index the index (in the range 0
to
getChildCount() - 1
).
Throws: ArrayIndexOutOfBoundsException if index
is outside
the valid range.
null
.
Parameters: node the child node (null
not permitted).
Throws: IllegalArgumentException if node
is not a child of
this node. IllegalArgumentException if node
is null.
false
, any
existing children are removed.
Parameters: allowsChildren the flag.
Parameters: node the parent node
Parameters: userObject the user object
getUserObject().toString()
, or null
if there
is no user object.
Returns: A string representation of the node (possibly null
).