public class Node extends Vector implements Comparable
Modifier and Type | Field and Description |
---|---|
boolean |
allowsChildren
flag to determine if this node can have children
|
int |
backColor
The background color, or -1 to use the default.
|
int |
foreColor
The foreground color, or -1 to use the default.
|
boolean |
isChecked
flag to determine if this node is checked (in multiple-selection trees).
|
protected Node |
parent
This node's parent (root node is when the parent node = null).
|
int |
userInt
The user's int that can be set with anything you want.
|
java.lang.Object |
userObject
The user's object that can be set with anything you want.
|
boolean |
visited
flag to determine if the leaf node has been clicked before
|
Constructor and Description |
---|
Node()
Default constructor to create a tree node that has no parent and no children, but which allows children.
|
Node(java.lang.Object userObject)
Default constructor to create a tree node with no parent, no children, but which allows children, and initializes
it with the specified user object.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Node newChild)
Method to remove newChild from its parent and makes it a child of this node by adding it to the end of this node's
child vector.
|
Vector |
breadthFirstVector()
Method to create and return a vector that traverses the subtree rooted at this node in breadth-first order.
|
int |
compareTo(java.lang.Object o)
Must return > 0 if this object is greater than the other one, < 0 if its smaller, and 0 if they are equal.
|
boolean |
equals(java.lang.Object o) |
Node |
getChildAfter(Node aChild)
Method to returns the child in this node's child array that immediately follows aChild, which must be a child of
this node; otherwise, retrun null.
|
Node |
getChildBefore(Node aChild)
Method to returns the child in this node's child array that immediately precedes aChild, which must be a child of
this node; otherwise, retrun null.
|
Node |
getFirstChild()
Method to return this node's first child.
|
Node |
getLastChild()
Method to return this node's last child.
|
int |
getLevel()
Method to return the number of levels above this node -- the distance from the root to this node.
|
Node |
getNextSibling()
Method to return the next sibling of this node in the parent's children array.
|
java.lang.String |
getNodeName()
Method to return the node name of this node.
|
Node |
getParent()
Method to return this node's parent or null if this node has no parent.
|
Node[] |
getPath()
Method to return the path from the root, to get to this node.
|
protected Node[] |
getPathToRoot()
Method to builds the parents of node up to and including the root node, where the original node is the last
element in the returned array.
|
Node |
getPreviousSibling()
Method to return the previous sibling of this node in the parent's children array.
|
Node |
getRoot()
Method to return the root of the tree that contains this node.
|
java.lang.Object[] |
getUserObjectPath()
Method to return the user object path, from the root, to get to this node.
|
int |
insert(Node newChild,
int childIndex)
Method to 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.
|
boolean |
isLeaf()
Method to return true if this node has no children.
|
boolean |
isLeaf(boolean useAllowsChildren)
Method to return true if this node has no children.
|
boolean |
isNodeChild(Node aNode)
Method to return true if aNode is a child of this node.
|
boolean |
isNodeSibling(Node anotherNode)
Method to return true if anotherNode is a sibling of (has the same parent as) this node.
|
boolean |
isRoot()
Method to return true if this node is a root.
|
void |
remove(int childIndex)
Method to remove the child at the specified index from this node's children and sets that node's parent to null.
|
void |
remove(Node aChild)
Method to remove aChild from this node's child array, giving it a null parent.
|
void |
removeAllChildren()
Method to remove all of this node's children, setting their parents to null.
|
void |
removeFromParent()
Method to remove the subtree rooted at this node from the tree, giving this node a null parent.
|
void |
setParent(Node parent)
Method to sets this node's parent to newParent but does not change the parent's child array.
|
java.lang.String |
toString()
Method to return the result of sending toString() to this node's user object, or null if this node has no user
object.
|
addElement, addElements, addElementsNotNull, contains, copyInto, dump, elementAt, ensureCapacity, indexOf, indexOf, insertElementAt, isEmpty, peek, peek, peek, pop, pop, pop, push, qsort, qsort, qsort, qsort, removeAllElements, removeElement, removeElementAt, reverse, setSize, size, toObjectArray, toString
protected Node parent
public java.lang.Object userObject
class Item extends Container { String txt; public Item(String s) {txt = s;} public void initUI() { add(new Check("Here"),LEFT,CENTER,PARENTSIZE+50,PREFERRED); add(new Button(txt),AFTER,CENTER,PARENTSIZE+50,PREFERRED); } } public void initUI() { try { setUIStyle(Settings.Android); TreeModel tmodel = new TreeModel(); Tree tree = new Tree(tmodel); tree.setCursorColor(Color.RED); tree.setLineHeight(fmH*3/2); add(tree,LEFT+50,TOP+50,FILL-50,FILL-50); Node root = new Node("Tree"); tmodel.setRoot(root); Node n; root.add(n = new Node("Branch1")); n.add(new Node(new Item("b1"))); n.add(new Node(new Item("b2"))); } catch (Exception ee) { MessageBox.showException(ee,true); } }
public int userInt
public boolean allowsChildren
public boolean visited
public boolean isChecked
public int backColor
public int foreColor
public Node()
public Node(java.lang.Object userObject)
userObject
- the user object.public void add(Node newChild)
newChild
- the new child node to add to the end of the child vector.public Vector breadthFirstVector()
public Node getChildAfter(Node aChild)
public Node getChildBefore(Node aChild)
public Node getFirstChild()
public Node getLastChild()
public int getLevel()
public java.lang.String getNodeName()
public Node getNextSibling()
public Node getPreviousSibling()
public Node getParent()
public Node[] getPath()
protected Node[] getPathToRoot()
public Node getRoot()
public java.lang.Object[] getUserObjectPath()
public int insert(Node newChild, int childIndex)
newChild
- the new child to remove from this subtree and add to this node children vector at the specified index.childIndex
- the position in the children vector to insert newChild.public boolean isLeaf()
public boolean isLeaf(boolean useAllowsChildren)
public boolean isRoot()
public boolean isNodeChild(Node aNode)
aNode
- the node to deterimine if it's a shild of this node.public boolean isNodeSibling(Node anotherNode)
public void remove(int childIndex)
childIndex
- the index of the this node's children to be removedpublic void remove(Node aChild)
aChild
- the child node to remove.public void removeAllChildren()
public void removeFromParent()
public void setParent(Node parent)
parent
- the newParent nodepublic java.lang.String toString()
public int compareTo(java.lang.Object o)
Comparable
compareTo
in interface Comparable
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object