javax.swing.tree

Class DefaultMutableTreeNode

Implemented Interfaces:
Cloneable, MutableTreeNode, Serializable, TreeNode
Known Direct Subclasses:
JTree.DynamicUtilTreeNode

public class DefaultMutableTreeNode
extends Object
implements Cloneable, MutableTreeNode, Serializable

DefaultMutableTreeNode

See Also:
Serialized Form

Field Summary

static Enumeration
EMPTY_ENUMERATION
EMPTY_ENUMERATION
protected boolean
allowsChildren
allowsChildren
protected Vector
children
children
protected MutableTreeNode
parent
parent
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.
Enumeration
breadthFirstEnumeration()
breadthFirstEnumeration
Enumeration
children()
Returns an enumeration containing all children of this node.
Object
clone()
clone
Enumeration
depthFirstEnumeration()
depthFirstEnumeration
boolean
getAllowsChildren()
getAllowsChildren
TreeNode
getChildAfter(TreeNode node)
getChildAfter
TreeNode
getChildAt(int index)
Returns the child node at a given index.
TreeNode
getChildBefore(TreeNode node)
getChildBefore
int
getChildCount()
Returns the number of children of this node.
int
getDepth()
getDepth
TreeNode
getFirstChild()
getFirstChild
DefaultMutableTreeNode
getFirstLeaf()
getFirstLeaf
int
getIndex(TreeNode node)
Returns the child index for a given node.
TreeNode
getLastChild()
getLastChild
DefaultMutableTreeNode
getLastLeaf()
getLastLeaf
int
getLeafCount()
getLeafCount
int
getLevel()
getLevel
DefaultMutableTreeNode
getNextLeaf()
getNextLeaf
DefaultMutableTreeNode
getNextNode()
getNextNode
DefaultMutableTreeNode
getNextSibling()
getNextSibling
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()
getPreviousLeaf
DefaultMutableTreeNode
getPreviousNode()
getPreviousNode
DefaultMutableTreeNode
getPreviousSibling()
getPreviousSibling
TreeNode
getRoot()
Returns the root node by iterating the parents of this node.
TreeNode
getSharedAncestor(DefaultMutableTreeNode node)
getSharedAncestor
int
getSiblingCount()
getSiblingCount
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()
isLeaf
boolean
isNodeAncestor(TreeNode node)
isNodeAncestor
boolean
isNodeChild(TreeNode node)
isNodeChild
boolean
isNodeDescendant(DefaultMutableTreeNode node)
isNodeDescendant
boolean
isNodeRelated(DefaultMutableTreeNode node)
isNodeRelated
boolean
isNodeSibling(TreeNode node)
isNodeSibling
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.
void
removeAllChildren()
Removes all child nodes from this node.
void
removeFromParent()
Removes this node from its parent.
void
setAllowsChildren(boolean allowsChildren)
setAllowsChildren
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 this node

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

EMPTY_ENUMERATION

public static final Enumeration EMPTY_ENUMERATION
EMPTY_ENUMERATION


allowsChildren

protected boolean allowsChildren
allowsChildren


children

protected Vector children
children


parent

protected MutableTreeNode parent
parent


userObject

protected Object userObject
userObject

Constructor Details

DefaultMutableTreeNode

public DefaultMutableTreeNode()
Creates a DefaultMutableTreeNode object. This node allows to add child nodes.


DefaultMutableTreeNode

public DefaultMutableTreeNode(Object userObject)
Creates a DefaultMutableTreeNode object with the given user object attached to it. This node allows to add child nodes.

Parameters:
userObject - the user object


DefaultMutableTreeNode

public DefaultMutableTreeNode(Object userObject,
                              boolean allowsChildren)
Creates a DefaultMutableTreeNode object with the given user object attached to it.

Parameters:
userObject - the user object
allowsChildren - true if the code allows to add child nodes, false otherwise

Method Details

add

public void add(MutableTreeNode child)
Adds a new child node to this node.

Parameters:
child - the child node

Throws:
IllegalArgumentException - if child is null
IllegalStateException - if the node does not allow children


breadthFirstEnumeration

public Enumeration breadthFirstEnumeration()
breadthFirstEnumeration

Returns:
Enumeration


children

public Enumeration children()
Returns an enumeration containing all children of this node. EMPTY_ENUMERATION is returned if this node has no children.
Specified by:
children in interface TreeNode

Returns:
an enumeration of tree nodes


clone

public Object clone()
clone
Overrides:
clone in interface Object

Returns:
Object


depthFirstEnumeration

public Enumeration depthFirstEnumeration()
depthFirstEnumeration

Returns:
Enumeration


getAllowsChildren

public boolean getAllowsChildren()
getAllowsChildren
Specified by:
getAllowsChildren in interface TreeNode

Returns:
boolean


getChildAfter

public TreeNode getChildAfter(TreeNode node)
getChildAfter

Parameters:
node - TODO

Returns:
TreeNode


getChildAt

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


getChildBefore

public TreeNode getChildBefore(TreeNode node)
getChildBefore

Parameters:
node - TODO

Returns:
TreeNode


getChildCount

public int getChildCount()
Returns the number of children of this node.
Specified by:
getChildCount in interface TreeNode

Returns:
the number of children


getDepth

public int getDepth()
getDepth

Returns:
int


getFirstChild

public TreeNode getFirstChild()
getFirstChild

Returns:
TreeNode


getFirstLeaf

public DefaultMutableTreeNode getFirstLeaf()
getFirstLeaf

Returns:
DefaultMutableTreeNode


getIndex

public int getIndex(TreeNode node)
Returns the child index for a given node.
Specified by:
getIndex in interface TreeNode

Parameters:
node - this node

Returns:
the index


getLastChild

public TreeNode getLastChild()
getLastChild

Returns:
TreeNode


getLastLeaf

public DefaultMutableTreeNode getLastLeaf()
getLastLeaf

Returns:
DefaultMutableTreeNode


getLeafCount

public int getLeafCount()
getLeafCount

Returns:
int


getLevel

public int getLevel()
getLevel

Returns:
int


getNextLeaf

public DefaultMutableTreeNode getNextLeaf()
getNextLeaf

Returns:
DefaultMutableTreeNode


getNextNode

public DefaultMutableTreeNode getNextNode()
getNextNode

Returns:
DefaultMutableTreeNode


getNextSibling

public DefaultMutableTreeNode getNextSibling()
getNextSibling

Returns:
DefaultMutableTreeNode


getParent

public TreeNode getParent()
Returns the parent node of this node.
Specified by:
getParent in interface TreeNode

Returns:
the parent node


getPath

public TreeNode[] getPath()
Returns a path to this node from the root.

Returns:
an array of tree nodes


getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode node,
                                   int depth)
getPathToRoot

Parameters:
node - TODO
depth - TODO

Returns:
TreeNode[]


getPreviousLeaf

public DefaultMutableTreeNode getPreviousLeaf()
getPreviousLeaf

Returns:
DefaultMutableTreeNode


getPreviousNode

public DefaultMutableTreeNode getPreviousNode()
getPreviousNode

Returns:
DefaultMutableTreeNode


getPreviousSibling

public DefaultMutableTreeNode getPreviousSibling()
getPreviousSibling

Returns:
DefaultMutableTreeNode


getRoot

public TreeNode getRoot()
Returns the root node by iterating the parents of this node.

Returns:
the root node


getSharedAncestor

public TreeNode getSharedAncestor(DefaultMutableTreeNode node)
getSharedAncestor

Parameters:
node - TODO

Returns:
TreeNode


getSiblingCount

public int getSiblingCount()
getSiblingCount

Returns:
int


getUserObject

public Object getUserObject()
Returns the user object attached to this node. null is returned when no user object is set.

Returns:
the user object


getUserObjectPath

public Object[] getUserObjectPath()
getUserObjectPath

Returns:
Object[]


insert

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
index - the index.


isLeaf

public boolean isLeaf()
isLeaf
Specified by:
isLeaf in interface TreeNode

Returns:
boolean


isNodeAncestor

public boolean isNodeAncestor(TreeNode node)
isNodeAncestor

Parameters:
node - TODO

Returns:
boolean


isNodeChild

public boolean isNodeChild(TreeNode node)
isNodeChild

Parameters:
node - TODO

Returns:
boolean


isNodeDescendant

public boolean isNodeDescendant(DefaultMutableTreeNode node)
isNodeDescendant

Parameters:
node - TODO

Returns:
boolean


isNodeRelated

public boolean isNodeRelated(DefaultMutableTreeNode node)
isNodeRelated

Parameters:
node - TODO

Returns:
boolean


isNodeSibling

public boolean isNodeSibling(TreeNode node)
isNodeSibling

Parameters:
node - TODO

Returns:
boolean


isRoot

public boolean isRoot()
Tells whether this node is the root node or not.

Returns:
true if this is the root node, falseotherwise


pathFromAncestorEnumeration

public Enumeration pathFromAncestorEnumeration(TreeNode node)
pathFromAncestorEnumeration

Parameters:
node - TODO

Returns:
Enumeration


postorderEnumeration

public Enumeration postorderEnumeration()
postorderEnumeration

Returns:
Enumeration


preorderEnumeration

public Enumeration preorderEnumeration()
preorderEnumeration

Returns:
Enumeration


remove

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


remove

public void remove(MutableTreeNode node)
Removes the given child from this node.
Specified by:
remove in interface MutableTreeNode

Parameters:
node - the child node


removeAllChildren

public void removeAllChildren()
Removes all child nodes from this node.


removeFromParent

public void removeFromParent()
Removes this node from its parent.
Specified by:
removeFromParent in interface MutableTreeNode


setAllowsChildren

public void setAllowsChildren(boolean allowsChildren)
setAllowsChildren

Parameters:
allowsChildren - TODO


setParent

public void setParent(MutableTreeNode node)
Set the parent node for this node.
Specified by:
setParent in interface MutableTreeNode

Parameters:
node - the parent node


setUserObject

public void setUserObject(Object userObject)
Sets the user object for this node
Specified by:
setUserObject in interface MutableTreeNode

Parameters:
userObject - the user object


toString

public String toString()
Returns a string representation of this node
Overrides:
toString in interface Object

Returns:
a human-readable String representing this node


DefaultMutableTreeNode.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.