com.acarter.composabletree
Class ComposableTreeModel

java.lang.Object
  extended by com.acarter.composabletree.ComposableTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class ComposableTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

Author:
Andrew Carter

Constructor Summary
ComposableTreeModel(java.lang.Object root)
          Constructor.
 
Method Summary
 void addNodeType(ComposableTreeNode nodeType, java.util.Vector<ComposableTreeNode> childrenNodes)
           
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 java.lang.Class<?> findRegisteredClass(java.lang.Class<?> c)
           
 void fireTreeNodesChanged(javax.swing.event.TreeModelEvent e)
           
 void fireTreeNodesInserted(javax.swing.event.TreeModelEvent e)
           
 void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent e)
           
 void fireTreeStructureChanged(javax.swing.event.TreeModelEvent e)
           
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at the index in the parent's child array.
 int getChildCount(java.lang.Object parent)
          Returns the number of children of parent.
 java.util.Vector<ComposableTreeNode> getChildNodeTypes(java.lang.Class<?> c)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns the index of child in parent.
 ComposableTreeNode getNodeType(java.lang.Class<?> c)
           
 java.lang.Object getParent(java.lang.Object child)
          Returns the parent of this child (only if this child is aware of its parent).
 javax.swing.tree.TreePath getPathToRoot(java.lang.Object object)
          Returns the tree path from the given object back to the root.
 java.lang.Object getRoot()
          Returns the root of the tree.
 boolean isLeaf(java.lang.Object object)
          Returns true if node is a leaf.
 void removeNodeType(java.lang.Class<?> c)
           
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Removes a listener previously added with addTreeModelListener.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComposableTreeModel

public ComposableTreeModel(java.lang.Object root)
Constructor.

Parameters:
root -
Method Detail

addNodeType

public void addNodeType(ComposableTreeNode nodeType,
                        java.util.Vector<ComposableTreeNode> childrenNodes)
Parameters:
c -
nodeTypes -

removeNodeType

public void removeNodeType(java.lang.Class<?> c)
Parameters:
c -

getNodeType

public ComposableTreeNode getNodeType(java.lang.Class<?> c)
Parameters:
c -
Returns:

getChildNodeTypes

public java.util.Vector<ComposableTreeNode> getChildNodeTypes(java.lang.Class<?> c)
Parameters:
c -
Returns:

findRegisteredClass

public java.lang.Class<?> findRegisteredClass(java.lang.Class<?> c)
Parameters:
c -
Returns:

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns the child of parent at the index in the parent's child array. Parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).

Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of child in parent. If either parent or child is null, returns -1. If either parent or child don't belong to this tree model, returns -1.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getParent

public java.lang.Object getParent(java.lang.Object child)
Returns the parent of this child (only if this child is aware of its parent).

Parameters:
child - The child of the desired parent
Returns:
The parent of the child, or null

getPathToRoot

public javax.swing.tree.TreePath getPathToRoot(java.lang.Object object)
Returns the tree path from the given object back to the root. This requires that all nodes along the path be aware of their parent.

Parameters:
object - a child object
Returns:
a tree path from the root to the object, or null

getRoot

public java.lang.Object getRoot()
Returns the root of the tree. Returns null only if the tree has no nodes.

Specified by:
getRoot in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object object)
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a file system, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

fireTreeNodesChanged

public void fireTreeNodesChanged(javax.swing.event.TreeModelEvent e)
Parameters:
e -

fireTreeNodesInserted

public void fireTreeNodesInserted(javax.swing.event.TreeModelEvent e)
Parameters:
e -

fireTreeNodesRemoved

public void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent e)
Parameters:
e -

fireTreeStructureChanged

public void fireTreeStructureChanged(javax.swing.event.TreeModelEvent e)
Parameters:
e -