GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.tree.DefaultMutableTreeNode
public class DefaultMutableTreeNode
extends Object
implements Cloneable, MutableTreeNode, Serializable
MutableTreeNode
interface.
Field Summary | |
static Enumeration |
|
protected boolean |
|
protected Vector |
|
protected MutableTreeNode |
|
protected Object |
|
Constructor Summary | |
| |
| |
|
Method Summary | |
void |
|
Enumeration<E> |
|
Enumeration<E> |
|
Object |
|
Enumeration<E> |
|
boolean |
|
TreeNode |
|
TreeNode |
|
TreeNode |
|
int |
|
int |
|
TreeNode |
|
DefaultMutableTreeNode |
|
int | |
TreeNode |
|
DefaultMutableTreeNode |
|
int |
|
int |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
TreeNode |
|
TreeNode[] |
|
protected TreeNode[] |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
TreeNode |
|
TreeNode |
|
int |
|
Object |
|
Object[] |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Enumeration<E> |
|
Enumeration<E> |
|
Enumeration<E> |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final EnumerationEMPTY_ENUMERATION
An empty enumeration, returned bychildren()
if a node has no children.
public DefaultMutableTreeNode()
Creates aDefaultMutableTreeNode
object. This is equivalent toDefaultMutableTreeNode(null, true)
.
public DefaultMutableTreeNode(Object userObject)
Creates aDefaultMutableTreeNode
object with the given user object attached to it. This is equivalent toDefaultMutableTreeNode(userObject, true)
.
- Parameters:
userObject
- the user object (null
permitted).
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
Creates aDefaultMutableTreeNode
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
public void add(MutableTreeNode child)
Adds a new child node to this node and sets this node as the parent of the child node. The child node must not be an ancestor of this node. If the tree uses theDefaultTreeModel
, you must subsequently callDefaultTreeModel.reload(TreeNode)
.
- Parameters:
child
- the child node (null
not permitted).
- Throws:
IllegalStateException
- ifgetAllowsChildren()
returnsfalse
.IllegalArgumentException
- ifisNodeAncestor(TreeNode)
returnstrue
.IllegalArgumentException
- ifchild
isnull
.
public Enumeration<E> breadthFirstEnumeration()
breadthFirstEnumeration
- Returns:
- Enumeration
public Enumeration<E> children()
Returns an enumeration containing all children of this node.EMPTY_ENUMERATION
is returned if this node has no children.
- Returns:
- an enumeration of tree nodes
public Object clone()
Returns a clone of the node. The clone contains a shallow copy of the user object, and does not copy the parent node or the child nodes.
- Returns:
- A clone of the node.
public Enumeration<E> depthFirstEnumeration()
depthFirstEnumeration
- Returns:
- Enumeration
public boolean getAllowsChildren()
getAllowsChildren
- Specified by:
- getAllowsChildren in interface TreeNode
- Returns:
- boolean
public TreeNode getChildAfter(TreeNode node)
Returns the next child after the specifiednode
, ornull
if there is no child after the specifiednode
.
- Parameters:
node
- a child of this node (null
not permitted).
- Returns:
- The next child, or
null
.
- Throws:
IllegalArgumentException
- ifnode
is not a child of this node, or isnull
.
public TreeNode getChildAt(int index)
Returns the child node at a given index.
- Specified by:
- getChildAt in interface TreeNode
- Parameters:
index
- the index
- Returns:
- the child node
public TreeNode getChildBefore(TreeNode node)
Returns the previous child before the specifiednode
, ornull
if there is no child before the specifiednode
.
- Parameters:
node
- a child of this node (null
not permitted).
- Returns:
- The previous child, or
null
.
- Throws:
IllegalArgumentException
- ifnode
is not a child of this node, or isnull
.
public int getChildCount()
Returns the number of children of this node.
- Specified by:
- getChildCount in interface TreeNode
- Returns:
- the number of children
public TreeNode getFirstChild()
Returns the first child node belonging to this tree node.
- Returns:
- The first child node.
- Throws:
NoSuchElementException
- if this tree node has no children.
public DefaultMutableTreeNode getFirstLeaf()
Returns the first leaf node that is a descendant of this node. Recall that a node is its own descendant, so if this node has no children then it is returned as the first leaf.
- Returns:
- The first leaf node.
public 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.
- Parameters:
node
- the node (null
not permitted).
- Returns:
- The index of the specified child node, or -1.
- Throws:
IllegalArgumentException
- ifnode
isnull
.
public TreeNode getLastChild()
Returns the last child node belonging to this tree node.
- Returns:
- The last child node.
- Throws:
NoSuchElementException
- if this tree node has no children.
public DefaultMutableTreeNode getLastLeaf()
Returns the last leaf node that is a descendant of this node. Recall that a node is its own descendant, so if this node has no children then it is returned as the last leaf.
- Returns:
- The first leaf node.
public DefaultMutableTreeNode getNextLeaf()
Returns the next leaf node after this tree node.
- Returns:
- The next leaf node, or
null
.
public DefaultMutableTreeNode getNextSibling()
Returns the next sibling for this tree node. If this node has no parent, or this node is the last child of its parent, this method returnsnull
.
- Returns:
- The next sibling, or
null
.
public TreeNode getParent()
Returns the parent node of this node.
- Returns:
- The parent node (possibly
null
).
public TreeNode[] getPath()
Returns a path to this node from the root.
- Returns:
- an array of tree nodes
protected TreeNode[] getPathToRoot(TreeNode node, int depth)
getPathToRoot
- Parameters:
node
- TODOdepth
- TODO
- Returns:
- TreeNode[]
public DefaultMutableTreeNode getPreviousLeaf()
Returns the previous leaf node before this tree node.
- Returns:
- The previous leaf node, or
null
.
public DefaultMutableTreeNode getPreviousNode()
getPreviousNode
- Returns:
- DefaultMutableTreeNode
public DefaultMutableTreeNode getPreviousSibling()
Returns the previous sibling for this tree node. If this node has no parent, or this node is the first child of its parent, this method returnsnull
.
- Returns:
- The previous sibling, or
null
.
public TreeNode getRoot()
Returns the root node by iterating the parents of this node.
- Returns:
- the root node
public TreeNode getSharedAncestor(DefaultMutableTreeNode node)
getSharedAncestor
- Parameters:
node
- TODO
- Returns:
- TreeNode
public int getSiblingCount()
Returns the number of siblings for this tree node. If the tree node has a parent, this method returns the child count for the parent, otherwise it returns1
.
- Returns:
- The sibling count.
public Object getUserObject()
Returns the user object attached to this node.null
is returned when no user object is set.
- Returns:
- the user object
public void insert(MutableTreeNode node, int index)
Inserts given child node at the given index.
- Specified by:
- insert in interface MutableTreeNode
- Parameters:
node
- the child node (null
not permitted).index
- the index.
- Throws:
IllegalArgumentException
- ifnode
is null.
public boolean isLeaf()
Returnstrue
if this tree node is a lead node (that is, it has no children), andfalse.
- Returns:
- A boolean.
public boolean isNodeAncestor(TreeNode node)
Returnstrue
ifnode
is an ancestor of this tree node, andfalse
otherwise. An ancestor node is any of:If
- this tree node;
- the parent node (if there is one);
- any ancestor of the parent node;
node
isnull
, this method returnsfalse
.
- Parameters:
node
- the node (null
permitted).
- Returns:
- A boolean.
public boolean isNodeChild(TreeNode node)
Returnstrue
ifnode
is a child of this tree node, andfalse
otherwise. Ifnode
isnull
, this method returnsfalse
.
- Parameters:
node
- the node (null
permitted).
- Returns:
- A boolean.
public boolean isNodeDescendant(DefaultMutableTreeNode node)
Returnstrue
ifnode
is a descendant of this tree node, andfalse
otherwise. A descendant node is any of:If
- this tree node;
- the child nodes belonging to this tree node, if there are any;
- any descendants of the child nodes;
node
isnull
, this method returnsfalse
.
- Parameters:
node
- the node (null
permitted).
- Returns:
- A boolean.
public boolean isNodeRelated(DefaultMutableTreeNode node)
isNodeRelated
- Parameters:
node
- TODO
- Returns:
- boolean
public boolean isNodeSibling(TreeNode node)
Returnstrue
if this tree node andnode
share the same parent. Ifnode
is this tree node, the method returnstrue
and ifnode
isnull
this method returnsfalse
.
- Parameters:
node
- the node (null
permitted).
- Returns:
- A boolean.
public boolean isRoot()
Tells whether this node is the root node or not.
- Returns:
true
if this is the root node,false
otherwise
public Enumeration<E> pathFromAncestorEnumeration(TreeNode node)
pathFromAncestorEnumeration
- Parameters:
node
- TODO
- Returns:
- Enumeration
public Enumeration<E> postorderEnumeration()
postorderEnumeration
- Returns:
- Enumeration
public Enumeration<E> preorderEnumeration()
preorderEnumeration
- Returns:
- Enumeration
public void remove(int index)
Removes the child with the given index from this node.
- Specified by:
- remove in interface MutableTreeNode
- Parameters:
index
- the index (in the range0
togetChildCount() - 1
).
- Throws:
ArrayIndexOutOfBoundsException
- ifindex
is outside the valid range.
public void remove(MutableTreeNode node)
Removes the given child from this node and sets its parent tonull
.
- Specified by:
- remove in interface MutableTreeNode
- Parameters:
node
- the child node (null
not permitted).
- Throws:
IllegalArgumentException
- ifnode
is not a child of this node.IllegalArgumentException
- ifnode
is null.
public void removeFromParent()
Removes this node from its parent.
- Specified by:
- removeFromParent in interface MutableTreeNode
public void setAllowsChildren(boolean allowsChildren)
Sets the flag that controls whether or not this node allows the addition / insertion of child nodes. If the flag is set tofalse
, any existing children are removed.
- Parameters:
allowsChildren
- the flag.
public void setParent(MutableTreeNode node)
Set the parent node for this node.
- Specified by:
- setParent in interface MutableTreeNode
- Parameters:
node
- the parent node
public void setUserObject(Object userObject)
Sets the user object for this node
- Specified by:
- setUserObject in interface MutableTreeNode
- Parameters:
userObject
- the user object
GNU Classpath (0.95) |