edu.ucsb.nceas.metaedit
Class ElementFactory.TreeElement

edu.ucsb.nceas.metaedit.ElementFactory.TreeElement
Enclosing class:
ElementFactory

public static class ElementFactory.TreeElement
implements javax.swing.tree.TreeNode

An extended TXElement with additioanl methods such as getPath(...).

Version:
0.9Beta
Author:
Rudolf Nottrott

Constructor Summary
ElementFactory.TreeElement(java.lang.String qname)
           
 
Method Summary
 java.util.Enumeration breadthFirstEnumeration()
           
 java.util.Enumeration children()
           
 boolean getAllowsChildren()
           
 javax.swing.tree.TreeNode getChildAt(int childIndex)
           
 int getChildCount()
           
 int getDepth()
          Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf.
 int getIndex(javax.swing.tree.TreeNode node)
           
 int getLevel()
           
 javax.swing.tree.TreeNode getParent()
           
 javax.swing.tree.TreeNode[] getPath()
          Returns the path from the root, to get to this node.
protected  javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode 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.
 java.lang.Object getUserObject(java.lang.Object userObject)
           
 boolean isLeaf()
           
 void setText(java.lang.String text)
           
 void setUserObject(java.lang.Object userObject)
           
 java.lang.String toString()
           
 

Constructor Detail

ElementFactory.TreeElement

public ElementFactory.TreeElement(java.lang.String qname)
Method Detail

setUserObject

public void setUserObject(java.lang.Object userObject)

getUserObject

public java.lang.Object getUserObject(java.lang.Object userObject)

children

public java.util.Enumeration children()
Specified by:
children in interface javax.swing.tree.TreeNode

getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode

getChildAt

public javax.swing.tree.TreeNode getChildAt(int childIndex)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Specified by:
getIndex in interface javax.swing.tree.TreeNode

getParent

public javax.swing.tree.TreeNode getParent()
Specified by:
getParent in interface javax.swing.tree.TreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode

toString

public java.lang.String toString()

setText

public void setText(java.lang.String text)

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. This operation is much more expensive than getLevel() because it must effectively traverse the entire tree rooted at this node.
Returns:
the depth of the tree whose root is this node
See Also:
getLevel()

getLevel

public int getLevel()

breadthFirstEnumeration

public java.util.Enumeration breadthFirstEnumeration()

getPath

public javax.swing.tree.TreeNode[] 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 javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode 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 TreeNode 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 TreeNodes giving the path from the root to the specified node


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.