|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.tree.DefaultMutableTreeNode
public class DefaultMutableTreeNode
A default implementation of the MutableTreeNode interface.
| Field Summary | |
|---|---|
protected boolean |
allowsChildren
allowsChildren |
protected Vector<MutableTreeNode> |
children
The child nodes for this node (may be empty). |
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. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected MutableTreeNode parent
null).
protected Vector<MutableTreeNode> children
protected transient Object userObject
protected boolean allowsChildren
| Constructor Detail |
|---|
public DefaultMutableTreeNode()
DefaultMutableTreeNode object.
This is equivalent to DefaultMutableTreeNode(null, true).
public DefaultMutableTreeNode(Object userObject)
DefaultMutableTreeNode object with the given
user object attached to it. This is equivalent to
DefaultMutableTreeNode(userObject, true).
userObject - the user object (null permitted).
public DefaultMutableTreeNode(Object userObject,
boolean allowsChildren)
DefaultMutableTreeNode object with the given
user object attached to it.
userObject - the user object (null permitted).allowsChildren - true if the code allows to add child
nodes, false otherwise| Method Detail |
|---|
public Object clone()
clone in class ObjectCloneablepublic String toString()
getUserObject().toString(), or null if there
is no user object.
toString in class Objectnull).Object.getClass(),
Object.hashCode(),
Class.getName(),
Integer.toHexString(int)public void add(MutableTreeNode child)
DefaultTreeModel, you must subsequently
call DefaultTreeModel.reload(TreeNode).
child - the child node (null not permitted).
IllegalStateException - if getAllowsChildren() returns
false.
IllegalArgumentException - if isNodeAncestor(javax.swing.tree.TreeNode) returns
true.
IllegalArgumentException - if child is
null.public TreeNode getParent()
getParent in interface TreeNodenull).public void remove(int index)
remove in interface MutableTreeNodeindex - the index (in the range 0 to
getChildCount() - 1).
ArrayIndexOutOfBoundsException - if index is outside
the valid range.MutableTreeNode.insert(MutableTreeNode,int),
MutableTreeNode.remove(MutableTreeNode),
MutableTreeNode.removeFromParent()public void remove(MutableTreeNode node)
null.
remove in interface MutableTreeNodenode - the child node (null not permitted).
IllegalArgumentException - if node is not a child of
this node.
IllegalArgumentException - if node is null.MutableTreeNode.insert(MutableTreeNode,int),
MutableTreeNode.remove(int),
MutableTreeNode.removeFromParent()
public void insert(MutableTreeNode node,
int index)
insert in interface MutableTreeNodenode - the child node (null not permitted).index - the index.
IllegalArgumentException - if node is
null.MutableTreeNode.remove(int),
MutableTreeNode.remove(MutableTreeNode),
MutableTreeNode.setParent(MutableTreeNode)public TreeNode[] getPath()
public Enumeration children()
EMPTY_ENUMERATION is returned if this node has no children.
children in interface TreeNodepublic void setParent(MutableTreeNode node)
setParent in interface MutableTreeNodenode - the parent nodeMutableTreeNode.insert(MutableTreeNode,int)public TreeNode getChildAt(int index)
getChildAt in interface TreeNodeindex - the index
public int getChildCount()
getChildCount in interface TreeNodepublic int getIndex(TreeNode node)
getIndex in interface TreeNodenode - the node (null not permitted).
IllegalArgumentException - if node is null.public void setAllowsChildren(boolean allowsChildren)
false, any
existing children are removed.
allowsChildren - the flag.public boolean getAllowsChildren()
getAllowsChildren in interface TreeNodepublic void setUserObject(Object userObject)
setUserObject in interface MutableTreeNodeuserObject - the user objectpublic Object getUserObject()
null is
returned when no user object is set.
public void removeFromParent()
removeFromParent in interface MutableTreeNodeMutableTreeNode.remove(int),
MutableTreeNode.remove(MutableTreeNode)public void removeAllChildren()
public boolean isNodeAncestor(TreeNode node)
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.
node - the node (null permitted).
public boolean isNodeDescendant(DefaultMutableTreeNode node)
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.
node - the node (null permitted).
public TreeNode getSharedAncestor(DefaultMutableTreeNode node)
node - TODO
public boolean isNodeRelated(DefaultMutableTreeNode node)
node - TODO
public int getDepth()
public int getLevel()
protected TreeNode[] getPathToRoot(TreeNode node,
int depth)
node - TODOdepth - TODO
public Object[] getUserObjectPath()
public TreeNode getRoot()
public boolean isRoot()
true if this is the root node,
falseotherwisepublic DefaultMutableTreeNode getNextNode()
public DefaultMutableTreeNode getPreviousNode()
public Enumeration preorderEnumeration()
public Enumeration postorderEnumeration()
public Enumeration breadthFirstEnumeration()
public Enumeration depthFirstEnumeration()
public Enumeration pathFromAncestorEnumeration(TreeNode node)
node - TODO
public boolean isNodeChild(TreeNode node)
true if node is a child of this tree
node, and false otherwise. If node is
null, this method returns false.
node - the node (null permitted).
public TreeNode getFirstChild()
NoSuchElementException - if this tree node has no children.public TreeNode getLastChild()
NoSuchElementException - if this tree node has no children.public TreeNode getChildAfter(TreeNode node)
node, or
null if there is no child after the specified
node.
node - a child of this node (null not permitted).
null.
IllegalArgumentException - if node is not a child of
this node, or is null.public TreeNode getChildBefore(TreeNode node)
node, or
null if there is no child before the specified
node.
node - a child of this node (null not permitted).
null.
IllegalArgumentException - if node is not a child of
this node, or is null.public boolean isNodeSibling(TreeNode node)
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.
node - the node (null permitted).
public int getSiblingCount()
1.
public DefaultMutableTreeNode getNextSibling()
null.
null.public DefaultMutableTreeNode getPreviousSibling()
null.
null.public boolean isLeaf()
true if this tree node is a lead node (that is, it
has no children), and false.
- Specified by:
isLeaf in interface TreeNode
- Returns:
- A boolean.
public DefaultMutableTreeNode getFirstLeaf()
public DefaultMutableTreeNode getLastLeaf()
public DefaultMutableTreeNode getNextLeaf()
null.public DefaultMutableTreeNode getPreviousLeaf()
null.public int getLeafCount()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||