Class fvaswing.components.tree.FvTreeNode

Description

Tree node for FvTree componant.

Method Index

new FvTreeNode()
append(), duplicate(), getChildAfter(), getChildAt(), getChildBefore(), getFirstChild(), getFirstLeaf(), getIndex(), getLastChild(), getLastLeaf(), getNextLeaf(), getNextNode(), getNextSibling(), getParent(), getPreviousLeaf(), getPreviousNode(), getPreviousSibling(), getRoot(), getSharedAncestor(), getUserObject(), insert(), isNodeAncestor(), isNodeChild(), isNodeDescendant(), isNodeRelated(), isNodeSibling(), pathFromAncestorEnumeration(), remove(), setParent(), setUserObject()

Inherited from FvAbstractTreeNode

Constructor Detail

FvTreeNode

public function FvTreeNode(userObject:FvTreeItem, allowsChildren:Boolean, draggable:Boolean, editable:Boolean, deletable:Boolean)

Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified.

Parameters

userObjectan Object provided by the user that constitutes the node's data
allowsChildren(optional)if true, the node is allowed to have child nodes -- otherwise, it is always a leaf node. Default is true.
draggableNode is draggable or not ( override tree behaviour for this specific node )
editableNode is editable or not ( override tree behaviour for this specific node )

Method Detail

setUserObject

public function setUserObject(userObject:FvTreeItem):Void

Sets the user object for this node to userObject.

Parameters

userObjectthe Object that constitutes this node's user-specified data

Overrides

setUserObject() in fvaswing.components.tree.FvAbstractTreeNode

getUserObject

public function getUserObject():FvTreeItem

Returns this node's user object.

insert

public function insert(newChild:FvTreeNode, childIndex:Number):Void

Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex. newChild must not be null and must not be an ancestor of this node.

Parameters

newChildthe FvTreeNode to insert under this node
childIndexthe index in this node's child array where this node is to be inserted

Throws

Errorif newChild is null or is an ancestor of this node, or if childIndex is out of bounds, or if this node does not allow children

Overrides

insert() in fvaswing.components.tree.FvAbstractTreeNode

See Also

setParent

public function setParent(newParent:FvTreeNode):Void

Sets this node's parent to newParent but does not change the parent's child array. This method is called from insert() and remove() to reassign a child's parent, it should not be messaged from anywhere else.

Parameters

newParentthis node's new parent

Overrides

setParent() in fvaswing.components.tree.FvAbstractTreeNode

getParent

public function getParent():FvTreeNode

Returns this node's parent or null if this node has no parent.

Return

this node's parent TreeNode, or null if this node has no parent

Overrides

getParent() in fvaswing.components.tree.FvAbstractTreeNode

getChildAt

public function getChildAt(index:Number):FvTreeNode

Returns the child at the specified index in this node's child array.

Parameters

indexan index into this node's child array

Return

the TreeNode in this node's child array at the specified index

Throws

ArrayIndexOutOfBoundsExceptionif index is out of bounds

Overrides

getChildAt() in fvaswing.components.tree.FvAbstractTreeNode

getIndex

public function getIndex(aChild:FvTreeNode):Number

Returns the index of the specified child in this node's child array. If the specified node is not a child of this node, returns -1. This method performs a linear search and is O(n) where n is the number of children.

Parameters

aChildthe FvTreeNode to search for among this node's children

Return

an int giving the index of the node in this node's child array, or -1 if the specified node is a not a child of this node

Overrides

getIndex() in fvaswing.components.tree.FvAbstractTreeNode

remove

public function remove(aChild:FvTreeNode):Void

Removes aChild from this node's child array, giving it a null parent.

Parameters

aChilda child of this node to remove

Overrides

remove() in fvaswing.components.tree.FvAbstractTreeNode

append

public function append(newChild:FvTreeNode):Void

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Parameters

newChildnode to add as a child of this node

Overrides

append() in fvaswing.components.tree.FvAbstractTreeNode

isNodeAncestor

public function isNodeAncestor(anotherNode:FvTreeNode):Boolean

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. (Note that a node is considered an ancestor of itself.) If anotherNode is null, this method returns false. This operation is at worst O(h) where h is the distance from the root to this node.

Parameters

anotherNodenode to test as an ancestor of this node

Return

true if this node is a descendant of anotherNode

Overrides

isNodeAncestor() in fvaswing.components.tree.FvAbstractTreeNode

isNodeDescendant

public function isNodeDescendant(anotherNode:FvTreeNode):Boolean

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. Note that a node is considered a descendant of itself. If anotherNode is null, returns false. This operation is at worst O(h) where h is the distance from the root to anotherNode.

Parameters

anotherNodenode to test as descendant of this node

Return

true if this node is an ancestor of anotherNode

Overrides

isNodeDescendant() in fvaswing.components.tree.FvAbstractTreeNode

getSharedAncestor

public function getSharedAncestor(aNode:FvTreeNode):FvTreeNode

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. A node is considered an ancestor of itself.

Parameters

aNodenode to find common ancestor with

Return

nearest ancestor common to this node and aNode, or null if none

Overrides

getSharedAncestor() in fvaswing.components.tree.FvAbstractTreeNode

isNodeRelated

public function isNodeRelated(aNode:FvTreeNode):Boolean

Returns true if and only if aNode is in the same tree as this node. Returns false if aNode is null.

Return

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

Overrides

isNodeRelated() in fvaswing.components.tree.FvAbstractTreeNode

See Also

getRoot

public function getRoot():FvTreeNode

Returns the root of the tree that contains this node. The root is the ancestor with a null parent.

Return

the root of the tree that contains this node

Overrides

getRoot() in fvaswing.components.tree.FvAbstractTreeNode

getNextNode

public function getNextNode():FvTreeNode

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. This is an inefficient way to traverse the entire tree; use an enumeration, instead.

Return

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

Overrides

getNextNode() in fvaswing.components.tree.FvAbstractTreeNode

See Also

getPreviousNode

public function getPreviousNode():FvTreeNode

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 traversal -- the root of the tree. This is an inefficient way to traverse the entire tree; use an enumeration, instead.

Return

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

Overrides

getPreviousNode() in fvaswing.components.tree.FvAbstractTreeNode

See Also

pathFromAncestorEnumeration

public function pathFromAncestorEnumeration(ancestor:FvTreeNode):Array

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. Creation of the enumeration is O(m) where m is the number of nodes between this node and ancestor, inclusive. Each nextElement() message is O(1).

Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.

Return

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

Throws

IllegalArgumentExceptionif ancestor is not an ancestor of this node

Overrides

pathFromAncestorEnumeration() in fvaswing.components.tree.FvAbstractTreeNode

See Also

isNodeChild

public function isNodeChild(aNode:FvTreeNode):Boolean

Returns true if aNode is a child of this node. If aNode is null, this method returns false.

Return

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

Overrides

isNodeChild() in fvaswing.components.tree.FvAbstractTreeNode

getFirstChild

public function getFirstChild():FvTreeNode

Returns this node's first child.

Return

the first child of this node, null if this node has no children

Overrides

getFirstChild() in fvaswing.components.tree.FvAbstractTreeNode

getLastChild

public function getLastChild():FvTreeNode

Returns this node's last child.

Return

the last child of this node, null if this node has no children

Overrides

getLastChild() in fvaswing.components.tree.FvAbstractTreeNode

getChildAfter

public function getChildAfter(aChild:FvTreeNode):FvTreeNode

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. This method performs a linear search of this node's children for aChild and is O(n) where n is the number of children; to traverse the entire array of children, use an enumeration instead.

Return

the child of this node that immediately follows aChild

Throws

Errorif aChild is null or is not a child of this node

Overrides

getChildAfter() in fvaswing.components.tree.FvAbstractTreeNode

See Also

getChildBefore

public function getChildBefore(aChild:FvTreeNode):FvTreeNode

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. This method performs a linear search of this node's children for aChild and is O(n) where n is the number of children.

Return

the child of this node that immediately precedes aChild

Throws

IllegalArgumentExceptionif aChild is null or is not a child of this node

Overrides

getChildBefore() in fvaswing.components.tree.FvAbstractTreeNode

isNodeSibling

public function isNodeSibling(anotherNode:FvTreeNode):Boolean

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

anotherNodenode to test as sibling of this node

Return

true if anotherNode is a sibling of this node

Overrides

isNodeSibling() in fvaswing.components.tree.FvAbstractTreeNode

getNextSibling

public function getNextSibling():FvTreeNode

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. This method performs a linear search that is O(n) where n is the number of children; to traverse the entire array, use the parent's child enumeration instead.

Return

the sibling of this node that immediately follows this node

Overrides

getNextSibling() in fvaswing.components.tree.FvAbstractTreeNode

See Also

getPreviousSibling

public function getPreviousSibling():FvTreeNode

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. This method performs a linear search that is O(n) where n is the number of children.

Return

the sibling of this node that immediately precedes this node

Overrides

getPreviousSibling() in fvaswing.components.tree.FvAbstractTreeNode

getFirstLeaf

public function getFirstLeaf():FvTreeNode

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.

Return

the first leaf in the subtree rooted at this node

Overrides

getFirstLeaf() in fvaswing.components.tree.FvAbstractTreeNode

getLastLeaf

public function getLastLeaf():FvTreeNode

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.

Return

the last leaf in the subtree rooted at this node

Overrides

getLastLeaf() in fvaswing.components.tree.FvAbstractTreeNode

See Also

getNextLeaf

public function getNextLeaf():FvTreeNode

Returns the leaf after this node or null if this node is the last leaf in the tree.

In this implementation of the MutableNode interface, this operation is very inefficient. In order to determine the next node, this method first performs a linear search in the parent's child-list in order to find the current node.

That implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use depthFirstEnumeration to enumerate the nodes in the tree and use isLeaf on each node to determine which are leaves.

Return

returns the next leaf past this node

Overrides

getNextLeaf() in fvaswing.components.tree.FvAbstractTreeNode

getPreviousLeaf

public function getPreviousLeaf():FvTreeNode

Returns the leaf before this node or null if this node is the first leaf in the tree.

In this implementation of the MutableNode interface, this operation is very inefficient. In order to determine the previous node, this method first performs a linear search in the parent's child-list in order to find the current node.

That implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use depthFirstEnumeration to enumerate the nodes in the tree and use isLeaf on each node to determine which are leaves.

Return

returns the leaf before this node

Overrides

getPreviousLeaf() in fvaswing.components.tree.FvAbstractTreeNode

duplicate

public function duplicate():FvTreeNode

Returns a duplicated node.