ElegantJ Trees Java API Specification v1.1

com.elegantj.awt.tree
Class AWTTreeNode

java.lang.Object
  extended bycom.elegantj.awt.tree.AWTTreeNode
All Implemented Interfaces:
java.io.Serializable

public class AWTTreeNode
extends java.lang.Object
implements java.io.Serializable

AWTTreeNode class provides the data structure of the node of the AWTTree

See Also:
Serialized Form

Field Summary
protected  boolean allowsChildren
           
protected  java.util.Vector children
           
static java.util.Enumeration EMPTY_ENUMERATION
           
protected  AWTTreeNode parent
           
protected  java.lang.Object userObject
           
 
Constructor Summary
AWTTreeNode()
          Default constructor for the AWTTreeNode
AWTTreeNode(java.lang.Object userObject)
          Constructs the AWTTreeNode with the specified userObject
AWTTreeNode(java.lang.Object userObject, boolean allowsChildren)
          Constructs the AWTTreeNode with the specified userObject and the wheather childrens allowed or not
 
Method Summary
 void add(AWTTreeNode newChild)
          Adds the specified newChild to the node
 java.util.Enumeration breadthFirstEnumeration()
          Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order.
 java.util.Enumeration children()
          Returns the Enumeration of the childrens
 java.lang.Object clone()
          Overridden to make clone public.
 java.util.Enumeration depthFirstEnumeration()
          Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order.
 boolean getAllowsChildren()
          Returns the wheather childrens are allowed or not
 AWTTreeNode getChildAfter(AWTTreeNode aChild)
          Returns the child in this node's child array that immediately follows aChild, which must be a child of this node.
 AWTTreeNode getChildAt(int index)
          Returns the child at the specified index
 AWTTreeNode getChildBefore(AWTTreeNode aChild)
          Returns the child in this node's child array that immediately precedes aChild, which must be a child of this node.
 int getChildCount()
          Returns the total child of the node
 int getDepth()
          Returns the depth of the tree rooted at this node the longest distance from this node to a leaf, If this node has no children, returns 0
 AWTTreeNode getFirstChild()
          Returns this node's first child.
 AWTTreeNode getFirstLeaf()
          Finds and returns the first leaf that is a descendant of this node either this node or its first child's first leaf.
 int getIndex(AWTTreeNode aChild)
          Returns the index of the specified AWTTreeNode
 AWTTreeNode getLastChild()
          Returns this node's last child.
 AWTTreeNode getLastLeaf()
          Finds and returns the last leaf that is a descendant of this node either this node or its last child's last leaf.
 int getLeafCount()
          Returns the total number of leaves that are descendants of this node.
 int getLevel()
          Returns the number of levels above this node the distance from the root to this node.
 AWTTreeNode getNextLeaf()
          Returns the leaf after this node or null if this node is the last leaf in the tree.
 AWTTreeNode getNextNode()
          Returns the node that follows this node in a preorder traversal of this node's tree.
 AWTTreeNode getNextSibling()
          Returns the next sibling of this node in the parent's children array.
 AWTTreeNode getParent()
          Returns the parent of the node
 AWTTreeNode[] getPath()
          Returns the path from the root, to get to this node.
protected  AWTTreeNode[] getPathToRoot(AWTTreeNode 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.
 AWTTreeNode getPreviousLeaf()
          Returns the leaf before this node or null if this node is the first leaf in the tree.
 AWTTreeNode getPreviousNode()
          Returns the node that precedes this node in a preorder traversal of this node's tree.
 AWTTreeNode getPreviousSibling()
          Returns the previous sibling of this node in the parent's children array.
 AWTTreeNode getRoot()
          Returns the root of the node
 AWTTreeNode getSharedAncestor(AWTTreeNode aNode)
          Returns the nearest common ancestor to this node and aNode Returns null, if no such ancestor exists if this node and aNode are in different trees or if aNode is null.
 int getSiblingCount()
          Returns the number of siblings of this node.
 java.lang.Object getUserObject()
          Returns the user object of the node
 java.lang.Object[] getUserObjectPath()
          Returns the user object path, from the root, to get to this node.
 void insert(AWTTreeNode newChild, int childIndex)
          Inserts the new child at the specified child index
 boolean isExpanded()
          Returns the node is expanded or collapsed
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isNodeAncestor(AWTTreeNode anotherNode)
          Returns true if anotherNode is an ancestor of this node if it is this node, this node's parent, or an ancestor of this node's parent
 boolean isNodeChild(AWTTreeNode aNode)
          Returns true if aNode is a child of this node.
 boolean isNodeDescendant(AWTTreeNode anotherNode)
          Returns true if anotherNode is 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
 boolean isNodeRelated(AWTTreeNode aNode)
          Returns true if and only if aNode is in the same tree as this node.
 boolean isNodeSibling(AWTTreeNode anotherNode)
          Returns true if anotherNode is a sibling of (has the same parent as) this node.
 boolean isRoot()
          Returns true if the node is the root else returns the false
 boolean isSelected()
          Returns the node is selected or not
 boolean isVisible()
          Returns the node is visible or not
 java.util.Enumeration pathFromAncestorEnumeration(AWTTreeNode ancestor)
          Creates and returns an enumeration that follows the path from ancestor to this node.
 java.util.Enumeration postorderEnumeration()
          Creates and returns an enumeration that traverses the subtree rooted at this node in postorder.
 java.util.Enumeration preorderEnumeration()
          Creates and returns an enumeration that traverses the subtree rooted at this node in preorder The first node returned by the enumeration's nextElement() method is this node Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.
 void remove(AWTTreeNode aChild)
          Removes the specified node from it's
 void remove(int childIndex)
          Removes the node at the child index
 void removeAllChildren()
          Removes the all childrens
 void removeFromParent()
          Removes the node from it's parent
 void setAllowsChildren(boolean allows)
          Sets the wheather childrens are allowed or not
 void setParent(AWTTreeNode newParent)
          Sets the patent to the new specified parent
 void setUserObject(java.lang.Object userObject)
          Sets the user object for the node
 java.lang.String toString()
          Returns the result of sending toString() to this node's user object, or null if this node has no user object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ENUMERATION

public static final java.util.Enumeration EMPTY_ENUMERATION

parent

protected AWTTreeNode parent

children

protected java.util.Vector children

userObject

protected transient java.lang.Object userObject

allowsChildren

protected boolean allowsChildren
Constructor Detail

AWTTreeNode

public AWTTreeNode()
Default constructor for the AWTTreeNode


AWTTreeNode

public AWTTreeNode(java.lang.Object userObject)
Constructs the AWTTreeNode with the specified userObject

Parameters:
userObject - The specified object

AWTTreeNode

public AWTTreeNode(java.lang.Object userObject,
                   boolean allowsChildren)
Constructs the AWTTreeNode with the specified userObject and the wheather childrens allowed or not

Parameters:
userObject - The specified userObject allowsChildren wheather the childrens are allowed or not
Method Detail

insert

public void insert(AWTTreeNode newChild,
                   int childIndex)
Inserts the new child at the specified child index

Parameters:
newChild - The AWTTreeNode
childIndex - The specified child index

remove

public void remove(int childIndex)
Removes the node at the child index

Parameters:
childIndex - The specified child index

setParent

public void setParent(AWTTreeNode newParent)
Sets the patent to the new specified parent

Parameters:
newParent - The AWTTreeNode which is new parent

getParent

public AWTTreeNode getParent()
Returns the parent of the node

Returns:
The parent of the node

getChildAt

public AWTTreeNode getChildAt(int index)
Returns the child at the specified index

Parameters:
index - The specified index
Returns:
The node at the specified index

getChildCount

public int getChildCount()
Returns the total child of the node

Returns:
The total child of the node

getIndex

public int getIndex(AWTTreeNode aChild)
Returns the index of the specified AWTTreeNode

Parameters:
aChild - The specified node

children

public java.util.Enumeration children()
Returns the Enumeration of the childrens

Returns:
the Enumeration of the childrens

setAllowsChildren

public void setAllowsChildren(boolean allows)
Sets the wheather childrens are allowed or not

Parameters:
allows - The wheather childrens are allowed or not

getAllowsChildren

public boolean getAllowsChildren()
Returns the wheather childrens are allowed or not

Returns:
The wheather childrens are allowed or not

setUserObject

public void setUserObject(java.lang.Object userObject)
Sets the user object for the node

Parameters:
userObject - The user object for the node

getUserObject

public java.lang.Object getUserObject()
Returns the user object of the node

Returns:
The user object

isExpanded

public boolean isExpanded()
Returns the node is expanded or collapsed

Returns:
The node is expanded or collapsed

isVisible

public boolean isVisible()
Returns the node is visible or not

Returns:
The node is visible or not

isSelected

public boolean isSelected()
Returns the node is selected or not

Returns:
The node is selected or not

removeFromParent

public void removeFromParent()
Removes the node from it's parent


remove

public void remove(AWTTreeNode aChild)
Removes the specified node from it's

Parameters:
aChild - The specified node

removeAllChildren

public void removeAllChildren()
Removes the all childrens


add

public void add(AWTTreeNode newChild)
Adds the specified newChild to the node

Parameters:
newChild - The specified child node

isNodeAncestor

public boolean isNodeAncestor(AWTTreeNode anotherNode)
Returns true if anotherNode is an ancestor of this node if it is this node, this node's parent, or an ancestor of this node's parent

Parameters:
anotherNode - node to test as an ancestor of this node
Returns:
true if this node is a descendant of anotherNode

isNodeDescendant

public boolean isNodeDescendant(AWTTreeNode anotherNode)
Returns true if anotherNode is 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

Parameters:
anotherNode - node to test as descendant of this node
Returns:
true if this node is an ancestor of anotherNode

getSharedAncestor

public AWTTreeNode getSharedAncestor(AWTTreeNode aNode)
Returns the nearest common ancestor to this node and aNode Returns null, if no such ancestor exists if this node and aNode are in different trees or if aNode is null.

Parameters:
aNode - node to find common ancestor with
Returns:
nearest ancestor common to this node and aNode, or null if none

isNodeRelated

public boolean isNodeRelated(AWTTreeNode aNode)
Returns true if and only if aNode is in the same tree as this node. Returns false if aNode is null

Returns:
true if aNode is in the same tree as this node false if aNode is null

getDepth

public int getDepth()
Returns the depth of the tree rooted at this node the longest distance from this node to a leaf, If this node has no children, returns 0

Returns:
the depth of the tree whose root is this node

getLevel

public int getLevel()
Returns the number of levels above this node the distance from the root to this node. If this node is the root, returns 0.

Returns:
the number of levels above this node

getPath

public AWTTreeNode[] getPath()
Returns the path from the root, to get to this node. The last element in the path is this node.

Returns:
an array of TreeNode objects giving the path, where the first element in the path is the root and the last element is this node

getPathToRoot

protected AWTTreeNode[] getPathToRoot(AWTTreeNode 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. The length of the returned array gives the node's depth in the tree.

Parameters:
aNode - the AWTTreeNode to get the path for
depth - an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array
Returns:
an array of AWTTreeNodes giving the path from the root to the specified node

getUserObjectPath

public java.lang.Object[] getUserObjectPath()
Returns the user object path, from the root, to get to this node. If some of the AWTTreeNodes in the path have null user objects, the returned path will contain nulls.


getRoot

public AWTTreeNode getRoot()
Returns the root of the node


isRoot

public boolean isRoot()
Returns true if the node is the root else returns the false


getNextNode

public AWTTreeNode getNextNode()
Returns the node that follows this node in a preorder traversal of this node's tree. Returns null if this node is the last node of the traversal.

Returns:
the node that follows this node in a preorder traversal, or null if this node is last

getPreviousNode

public AWTTreeNode getPreviousNode()
Returns the node that precedes this node in a preorder traversal of this node's tree. Returns null if this node is the first node of the traveral the root of the tree

Returns:
the node that precedes this node in a preorder traversal, or null if this node is the first

preorderEnumeration

public java.util.Enumeration preorderEnumeration()
Creates and returns an enumeration that traverses the subtree rooted at this node in preorder The first node returned by the enumeration's nextElement() method is this node Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.

Returns:
an enumeration for traversing the tree in preorder

postorderEnumeration

public java.util.Enumeration postorderEnumeration()
Creates and returns an enumeration that traverses the subtree rooted at this node in postorder. The first node returned by the enumeration's nextElement() method is the leftmost leaf. This is the same as a depth-first traversal. Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.

Returns:
an enumeration for traversing the tree in postorder

breadthFirstEnumeration

public java.util.Enumeration breadthFirstEnumeration()
Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order. The first node returned by the enumeration's nextElement() method is this node.

Returns:
an enumeration for traversing the tree in breadth-first order

depthFirstEnumeration

public java.util.Enumeration depthFirstEnumeration()
Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order. The first node returned by the enumeration's nextElement() method is the leftmost leaf This is the same as a postorder traversal.

Returns:
an enumeration for traversing the tree in depth-first order

pathFromAncestorEnumeration

public java.util.Enumeration pathFromAncestorEnumeration(AWTTreeNode ancestor)
Creates and returns an enumeration that follows the path from ancestor to this node. The enumeration's nextElement() method first returns ancestor, then the child of ancestor that is an ancestor of this node, and so on, and finally returns this node.

Returns:
an enumeration for following the path from an ancestor of this node to this one

isNodeChild

public boolean isNodeChild(AWTTreeNode aNode)
Returns true if aNode is a child of this node. If aNode is null, this method returns false.

Returns:
true if aNode is a child of this node; false if aNode is null

getFirstChild

public AWTTreeNode getFirstChild()
Returns this node's first child. If this node has no children, throws NoSuchElementException.

Returns:
the first child of this node
Throws:
java.util.NoSuchElementException - if this node has no children

getLastChild

public AWTTreeNode getLastChild()
Returns this node's last child. If this node has no children, throws NoSuchElementException.

Returns:
the last child of this node
Throws:
java.util.NoSuchElementException - if this node has no children

getChildAfter

public AWTTreeNode getChildAfter(AWTTreeNode aChild)
Returns the child in this node's child array that immediately follows aChild, which must be a child of this node. If aChild is the last child, returns null.

Returns:
the child of this node that immediately follows aChild
Throws:
java.lang.IllegalArgumentException - if aChild is null or is not a child of this node

getChildBefore

public AWTTreeNode getChildBefore(AWTTreeNode aChild)
Returns the child in this node's child array that immediately precedes aChild, which must be a child of this node. If aChild is the first child, returns null.

Returns:
the child of this node that immediately precedes aChild
Throws:
java.lang.IllegalArgumentException - if aChild is null or is not a child of this node

isNodeSibling

public boolean isNodeSibling(AWTTreeNode anotherNode)
Returns true if anotherNode is a sibling of (has the same parent as) this node. A node is its own sibling. If anotherNode is null, returns false.

Parameters:
anotherNode - node to test as sibling of this node
Returns:
true if anotherNode is a sibling of this node

getSiblingCount

public int getSiblingCount()
Returns the number of siblings of this node. A node is its own sibling (if it has no parent or no siblings, this method returns 1.

Returns:
the number of siblings of this node

getNextSibling

public AWTTreeNode getNextSibling()
Returns the next sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's last child.

Returns:
the sibling of this node that immediately follows this node

getPreviousSibling

public AWTTreeNode getPreviousSibling()
Returns the previous sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's first child.

Returns:
the sibling of this node that immediately precedes this node

isLeaf

public boolean isLeaf()
Returns true if this node has no children. To distinguish between nodes that have no children and nodes that cannot have children (e.g. to distinguish files from empty directories), use this method in conjunction with getAllowsChildren

Returns:
true if this node has no children

getFirstLeaf

public AWTTreeNode getFirstLeaf()
Finds and returns the first leaf that is a descendant of this node either this node or its first child's first leaf. Returns this node if it is a leaf.

Returns:
the first leaf in the subtree rooted at this node

getLastLeaf

public AWTTreeNode getLastLeaf()
Finds and returns the last leaf that is a descendant of this node either this node or its last child's last leaf. Returns this node if it is a leaf.

Returns:
the last leaf in the subtree rooted at this node

getNextLeaf

public AWTTreeNode getNextLeaf()
Returns the leaf after this node or null if this node is the last leaf in the tree.

Returns:
returns the next leaf past this node

getPreviousLeaf

public AWTTreeNode getPreviousLeaf()
Returns the leaf before this node or null if this node is the first leaf in the tree.

Returns:
returns the leaf before this node

getLeafCount

public int getLeafCount()
Returns the total number of leaves that are descendants of this node. If this node is a leaf, returns 1

Returns:
the number of leaves beneath this node

toString

public java.lang.String toString()
Returns the result of sending toString() to this node's user object, or null if this node has no user object.


clone

public java.lang.Object clone()
Overridden to make clone public.

Returns:
a copy of this node

ElegantJ Trees Java API Specification v1.1

Submit a bug or feature

Copyright(c)
Elegant Microweb Technologies Pvt. Ltd.
www.elegantmicroweb.com
www.elegantjbeans.com
All Rights Reserved.