public class MyTreeNode
extends java.lang.Object
implements javax.swing.tree.TreeNode
Modifier and Type | Class and Description |
---|---|
static class |
MyTreeNode.ChildEnumerator |
Constructor and Description |
---|
MyTreeNode(java.lang.String name,
java.lang.String comment)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
java.util.Enumeration |
children() |
boolean |
getAllowsChildren() |
MyTreeNode |
getChildAt(int index)
Return selected child
|
int |
getChildCount()
return the number of children
|
MyTreeNode[] |
getDescendents()
Returns all nodes below the current node in the hierarchy.
|
MyTreeNode[] |
getHierarchy()
Return the node hierarchy from root down to this.
|
int |
getIndex(javax.swing.tree.TreeNode child)
return the index of the child
|
java.lang.String |
getName()
Get short version of node name.
|
static MyTreeNode |
getNode(MyTreeNode root,
java.lang.String path)
find a node given root node and partial path string.
|
MyTreeNode |
getParent()
Returns MyTreeNode object one level up in hierarchy
|
java.lang.String |
getPathString(int startLevel)
return part of the string representation of the path.
|
boolean |
isLeaf() |
static void |
main(java.lang.String[] args)
Unit test.
|
void |
setName(java.lang.String name)
Accessor method, sets node name
|
java.lang.String |
toString()
Get long version of node name.
|
public MyTreeNode(java.lang.String name, java.lang.String comment)
name
- node name.comment
- comment attached to this nodepublic java.lang.String toString()
toString
in class java.lang.Object
public final java.lang.String getName()
public void setName(java.lang.String name)
public java.util.Enumeration children()
children
in interface javax.swing.tree.TreeNode
public boolean getAllowsChildren()
getAllowsChildren
in interface javax.swing.tree.TreeNode
public MyTreeNode getChildAt(int index)
getChildAt
in interface javax.swing.tree.TreeNode
index
- index of the childpublic int getChildCount()
getChildCount
in interface javax.swing.tree.TreeNode
public MyTreeNode getParent()
getParent
in interface javax.swing.tree.TreeNode
public int getIndex(javax.swing.tree.TreeNode child)
getIndex
in interface javax.swing.tree.TreeNode
child
- node to be foundpublic boolean isLeaf()
isLeaf
in interface javax.swing.tree.TreeNode
public MyTreeNode[] getHierarchy()
public java.lang.String getPathString(int startLevel)
startLevel
- start point of the path. 0=root, 1=first level, ..public static MyTreeNode getNode(MyTreeNode root, java.lang.String path)
root
- starting node of the pathpath
- path string, starting at level 1 (excludes root node)public MyTreeNode[] getDescendents()
this
nodepublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception