Package com.moneydance.awt
Class HashTreeModel<T>
java.lang.Object
com.moneydance.awt.HashTreeModel<T>
- All Implemented Interfaces:
javax.swing.tree.TreeModel
public class HashTreeModel<T>
extends java.lang.Object
implements javax.swing.tree.TreeModel
A
HashTreeModel
is an implementation of the Swing TreeModel
backed by a
HashMap
. Any objects can be added as nodes or the class can be parameterized so that only nodes
belonging to some type may be added (noting that TreeModel
methods will still use Object
).
An object may only be inserted into the tree once as enforced by Object.equals(java.lang.Object)
as this causes problems with the
JTree
.- Author:
- Jay Detwiler
-
Constructor Summary
Constructors Constructor Description HashTreeModel(T root)
Create theHashTreeModel
with the given object as root. -
Method Summary
Modifier and Type Method Description void
addChild(T parent, T child)
Add a node to a parent.void
addTreeModelListener(javax.swing.event.TreeModelListener l)
T
getChild(java.lang.Object parent, int index)
int
getChildCount(java.lang.Object parent)
int
getIndexOfChild(java.lang.Object parent, java.lang.Object child)
T
getRoot()
Returns the root object.boolean
isLeaf(java.lang.Object node)
boolean
isMember(java.lang.Object node)
Return true if the given node is a member of the tree.void
removeChildren(T node)
void
removeNode(T node)
Remove a node from the tree.void
removeTreeModelListener(javax.swing.event.TreeModelListener l)
void
valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
-
Constructor Details
-
HashTreeModel
Create theHashTreeModel
with the given object as root.- Parameters:
root
- the root object
-
-
Method Details
-
getRoot
Returns the root object.- Specified by:
getRoot
in interfacejavax.swing.tree.TreeModel
- Returns:
- the root object.
-
addChild
Add a node to a parent. To be valid, the parent must be a member and the child must not be a member of the tree.- Parameters:
parent
- the node in the tree to add a new node tochild
- a node to add to the tree- Throws:
java.lang.IllegalArgumentException
- if the parent is not a member or the child already is a member of the treejava.lang.NullPointerException
- if either argument isnull
-
removeNode
Remove a node from the tree. This removes the node and any children. The node must be a member of the tree and not the root.- Parameters:
node
- a node to remove- Throws:
java.lang.NullPointerException
- if the node isnull
java.lang.IllegalArgumentException
- if the node is not a member or if the node is the root of the tree
-
removeChildren
-
isMember
public boolean isMember(java.lang.Object node)Return true if the given node is a member of the tree.- Parameters:
node
- a node to test- Returns:
- true if the given node is a member of the tree.
-
getChild
- Specified by:
getChild
in interfacejavax.swing.tree.TreeModel
-
getChildCount
public int getChildCount(java.lang.Object parent)- Specified by:
getChildCount
in interfacejavax.swing.tree.TreeModel
-
isLeaf
public boolean isLeaf(java.lang.Object node)- Specified by:
isLeaf
in interfacejavax.swing.tree.TreeModel
-
valueForPathChanged
public void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)- Specified by:
valueForPathChanged
in interfacejavax.swing.tree.TreeModel
-
getIndexOfChild
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)- Specified by:
getIndexOfChild
in interfacejavax.swing.tree.TreeModel
-
addTreeModelListener
public void addTreeModelListener(javax.swing.event.TreeModelListener l)- Specified by:
addTreeModelListener
in interfacejavax.swing.tree.TreeModel
-
removeTreeModelListener
public void removeTreeModelListener(javax.swing.event.TreeModelListener l)- Specified by:
removeTreeModelListener
in interfacejavax.swing.tree.TreeModel
-