kiwi.ui.model
Class TreeModelTreeAdapter

java.lang.Object
  |
  +--kiwi.ui.model.TreeModelTreeAdapter

public class TreeModelTreeAdapter
extends Object
implements TreeModel, TreeModelListener

An adapter that allows a Swing JTree to be used with the StaticTreeModel and DynamicTreeModel data models. The adapter translates messages and events between the JTree and the ITreeModel implementation.

Version:
1.1 (11/98)
Author:
Mark Lindner, PING Software Group
See Also:
JTree, ITreeModel

Constructor Summary
TreeModelTreeAdapter(JTree jtree)
          Construct a new tree model tree adapter.
 
Method Summary
 void addTreeModelListener(TreeModelListener listener)
          Add a tree model listener.
 void dispose()
          Dispose of the adapter.
protected  void fireTreeNodesChanged(Object node, int index, Object parent)
          Fire a tree nodes changed event.
protected  void fireTreeNodesInserted(Object node, int index, Object parent)
          Fire a tree nodes inserted event.
protected  void fireTreeNodesRemoved(Object node, int index, Object parent)
          Fire a tree nodes removed event.
protected  void fireTreeStructureChanged(ITreeNode node)
          Fire a tree structure changed event.
 Object getChild(Object parent, int index)
          Get the child of a node.
 int getChildCount(Object parent)
          Get the child count of a node.
 int getIndexOfChild(Object parent, Object child)
          Get the index of a child within its parent.
 TreePath getPathForNode(ITreeNode node)
          Compute a TreePath for a given node.
 Object getRoot()
          Get the root of the tree.
 ITreeModel getTreeModel()
          Get the tree model in use by this adapter.
 boolean isLeaf(Object node)
          Determine if a node is a leaf.
 void nodeAdded(TreeModelEvent evt)
          Handle a node added event.
 void nodeChanged(TreeModelEvent evt)
          Handle a node changed event.
 void nodeCollapsed(TreeModelEvent evt)
          Handle folder closed events.
 void nodeCollapsing(TreeModelEvent evt)
          Handle folder will close events.
 void nodeExpanded(TreeModelEvent evt)
          Handle folder opened events.
 void nodeExpanding(TreeModelEvent evt)
          Handle folder will open events.
 void nodeRemoved(TreeModelEvent evt)
          Handle a node removed event.
 void nodeStructureChanged(TreeModelEvent evt)
          Handle a node structure changed event.
 void removeTreeModelListener(TreeModelListener listener)
          Remove a tree model listener.
 void setTreeModel(ITreeModel model)
          Set the tree model to be used by this adapter.
 void valueForPathChanged(TreePath path, Object newValue)
          Handle JTree events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeModelTreeAdapter

public TreeModelTreeAdapter(JTree jtree)
Construct a new tree model tree adapter. Creates a new adapter for the specified JFC tree component.
Parameters:
jtree - The JFC tree component to be associated with this adapter.
Method Detail

setTreeModel

public void setTreeModel(ITreeModel model)
Set the tree model to be used by this adapter. The adapter adds itself as a listener of the tree model. If a model was already set prior to this call, it is replaced, and the adapter removes itself as a listener from that model.
Parameters:
model - The model to set.
See Also:
getTreeModel()

getTreeModel

public ITreeModel getTreeModel()
Get the tree model in use by this adapter. Returns the tree model currently associated with this adapter (may be null if no model has been set).
See Also:
setTreeModel(kiwi.ui.model.ITreeModel)

addTreeModelListener

public void addTreeModelListener(TreeModelListener listener)
Add a tree model listener. Adds a TreeModelListener to this adapter's list of tree model listeners.
Specified by:
addTreeModelListener in interface TreeModel
Parameters:
listener - The listener to add.
See Also:
removeTreeModelListener(javax.swing.event.TreeModelListener)

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener listener)
Remove a tree model listener. Removes a TreeModelListener from this adapter's list of tree model listeners.
Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
listener - The listener to remove.
See Also:
addTreeModelListener(javax.swing.event.TreeModelListener)

nodeExpanding

public void nodeExpanding(TreeModelEvent evt)
Handle folder will open events. These come from the ITreeModel.
Specified by:
nodeExpanding in interface TreeModelListener

nodeExpanded

public void nodeExpanded(TreeModelEvent evt)
Handle folder opened events. These come from the ITreeModel.
Specified by:
nodeExpanded in interface TreeModelListener

nodeCollapsing

public void nodeCollapsing(TreeModelEvent evt)
Handle folder will close events. These come from the ITreeModel.
Specified by:
nodeCollapsing in interface TreeModelListener

nodeCollapsed

public void nodeCollapsed(TreeModelEvent evt)
Handle folder closed events. These come from the ITreeModel.
Specified by:
nodeCollapsed in interface TreeModelListener

nodeAdded

public void nodeAdded(TreeModelEvent evt)
Handle a node added event. These come from the ITreeModel.
Specified by:
nodeAdded in interface TreeModelListener

nodeRemoved

public void nodeRemoved(TreeModelEvent evt)
Handle a node removed event. These come from the ITreeModel.
Specified by:
nodeRemoved in interface TreeModelListener

nodeChanged

public void nodeChanged(TreeModelEvent evt)
Handle a node changed event. These come from the ITreeModel.
Specified by:
nodeChanged in interface TreeModelListener

nodeStructureChanged

public void nodeStructureChanged(TreeModelEvent evt)
Handle a node structure changed event. These come from the ITreeModel.
Specified by:
nodeStructureChanged in interface TreeModelListener

getChild

public Object getChild(Object parent,
                       int index)
Get the child of a node. (Implementation of TreeModel.)
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Get the child count of a node. (Implementation of TreeModel.)
Specified by:
getChildCount in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Determine if a node is a leaf. (Implementation of TreeModel.)
Specified by:
isLeaf in interface TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Handle JTree events. (Implementation of TreeModel.)
Specified by:
valueForPathChanged in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Get the index of a child within its parent. (Implementation of TreeModel.)
Specified by:
getIndexOfChild in interface TreeModel

getRoot

public Object getRoot()
Get the root of the tree. (Implementation of TreeModel.)
Specified by:
getRoot in interface TreeModel

getPathForNode

public TreePath getPathForNode(ITreeNode node)
Compute a TreePath for a given node.
Parameters:
node - The node.
Returns:
A TreePath to the given node.
See Also:
TreePath

fireTreeNodesInserted

protected void fireTreeNodesInserted(Object node,
                                     int index,
                                     Object parent)
Fire a tree nodes inserted event. This event notifies the JTree that a new node has been added to the tree data model.
Parameters:
node - The node that was added.
index - The offset within the parent's list of children at which this node was added.
parent - The parent of the inserted node.

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(Object node,
                                    int index,
                                    Object parent)
Fire a tree nodes removed event. This event notifies the JTree that a node has been removed from the tree data model.
Parameters:
node - The node that was removed.
index - The offset within the parent's list of children of this node.
parent - The parent of the deleted node.

fireTreeNodesChanged

protected void fireTreeNodesChanged(Object node,
                                    int index,
                                    Object parent)
Fire a tree nodes changed event. This event notifies the JTree that a node has changed in some way.
Parameters:
node - The node that changed.
index - The offset within the parent's list of children of this node.
parent - The parent of the changed node.

fireTreeStructureChanged

protected void fireTreeStructureChanged(ITreeNode node)
Fire a tree structure changed event. This event notifies the JTree that the subtree rooted at a given node has changed in some major way.
Parameters:
node - The node that is the root of the subtree that changed.

dispose

public void dispose()
Dispose of the adapter. Causes the adapter to detach its listeners from its associated JTree component, and then null out its references to the JTree and to the associated ITreeModel.