jas2.util.tree
Class SimpleNode
- java.lang.Object
-
- jas2.util.tree.SimpleNode
-
- Direct Known Subclasses:
- JobFolder, OrderedNode
public class SimpleNode extends java.lang.ObjectA simple node represents a node in a tree. Each node has a number of properties: SimpleNode contains a number of methods for making it easy to use TreeItems to build the tree. It is also possible to add a NodeListener to any node of the tree, and this will be informed of all changes (additions and deletions) below that node. Within a node, children are kept in a OrderedHashmap, which keeps items ordered by insertion order, and also enables nodes to be rapidly looked up by name.- Name: The name of the node
- Type: The type of the node
- Flags: A set of flags associated with the node
- Object: An object associated with the node
-
-
Constructor Summary
Constructors Constructor and Description SimpleNode()Create a root node, with no name, type or flagSimpleNode(SimpleNode parent, java.lang.String name, java.lang.String type, int flags, java.lang.Object object)Create a nodeSimpleNode(java.lang.String name, java.lang.String type, int flags, java.lang.Object object)Create a root node
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description SimpleNodeadd(TreeItem item)Add a node specified by a TreeItem.SimpleNodeadd(TreeItem item, java.lang.Object object)Add a node specified by a TreeItem, with an associated object.voidaddNodeListener(SimpleNodeListener l)java.util.Enumerationchildren()voidclearFlags(int mask)voiddestroy()Destroy a node (remove it from its parents list of children) No further use of a node or its chilren should be made after it has been destroyedjava.util.Enumerationelements()Returns an enumeration of the objects associated with the child nodes.SimpleNodefind(TreeItem item)Find a node specified by a TreeItem.SimpleNodefindChild(java.lang.String name)Find a child node with a given nameSimpleNodegetChild(int index)intgetChildCount()intgetFlags()intgetIndexOfChild(java.lang.Object child)java.lang.StringgetName()java.lang.ObjectgetObject()Get the associated object.SimpleNodegetParent()TreeItemgetTreeItem(SimpleNode base)Get a TreeItem describing this node, relative to a base nodejava.lang.StringgetType()booleanisAncestorOf(SimpleNode root)voidremove(TreeItem item)Remove a node specified by a TreeItem.voidremoveNodeListener(SimpleNodeListener l)voidsetFlags(int mask)java.lang.StringtoString()
-
-
-
Constructor Detail
-
SimpleNode
public SimpleNode()
Create a root node, with no name, type or flag
-
SimpleNode
public SimpleNode(java.lang.String name, java.lang.String type, int flags, java.lang.Object object)Create a root node- Parameters:
name- The name of the nodetype- The type of the nodeobject- The Object associated with the node
-
SimpleNode
public SimpleNode(SimpleNode parent, java.lang.String name, java.lang.String type, int flags, java.lang.Object object)
Create a node- Parameters:
parent- The parent of this nodename- The name of the nodetype- The type of the nodeobject- The Object associated with the node
-
-
Method Detail
-
getTreeItem
public TreeItem getTreeItem(SimpleNode base)
Get a TreeItem describing this node, relative to a base node- Parameters:
base- The base node- Returns:
- The TreeItem describing the relative path
-
findChild
public SimpleNode findChild(java.lang.String name)
Find a child node with a given name- Parameters:
name- The name to search for- Returns:
- The child node, or null of no node was found by the given name
-
destroy
public void destroy()
Destroy a node (remove it from its parents list of children) No further use of a node or its chilren should be made after it has been destroyed
-
add
public SimpleNode add(TreeItem item)
Add a node specified by a TreeItem. The path in the TreeItem is interpreted as relavive to the current node, and any intervening nodes specified by the path are created automatically as needed.- Parameters:
item- The subnode to add- Returns:
- The leaf node created
-
add
public SimpleNode add(TreeItem item, java.lang.Object object)
Add a node specified by a TreeItem, with an associated object. The path in the TreeItem is interpreted as relavive to the current node, and any intervening nodes specified by the path are created automatically as needed.- Parameters:
item- The subnode to addobject- The associated object- Returns:
- The leaf node created
-
remove
public void remove(TreeItem item)
Remove a node specified by a TreeItem. Intervening nodes are not removed, but the leaf node is destroyed, as are its children.- Parameters:
item- The subnode to remove
-
find
public SimpleNode find(TreeItem item)
Find a node specified by a TreeItem.- Parameters:
item- The subnode to remove- Returns:
- The found node, or null if the node was not found
-
getChildCount
public int getChildCount()
-
getChild
public SimpleNode getChild(int index)
-
getIndexOfChild
public int getIndexOfChild(java.lang.Object child)
-
children
public java.util.Enumeration children()
-
elements
public java.util.Enumeration elements()
Returns an enumeration of the objects associated with the child nodes.
-
getObject
public java.lang.Object getObject()
Get the associated object. Note if the object is currently null, we will traverse up towards the root of the tree looking for a node whose associated object is a TreeObjectSource and if we find one we will use it to locate the object.- Returns:
- the Object, or null if there is no associated object.
-
setFlags
public void setFlags(int mask)
-
clearFlags
public void clearFlags(int mask)
-
isAncestorOf
public boolean isAncestorOf(SimpleNode root)
-
getType
public java.lang.String getType()
-
getFlags
public int getFlags()
-
getName
public java.lang.String getName()
-
getParent
public SimpleNode getParent()
-
addNodeListener
public void addNodeListener(SimpleNodeListener l)
-
removeNodeListener
public void removeNodeListener(SimpleNodeListener l)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG