kiwi.ui.model
Class TreeModelListAdapter

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

public class TreeModelListAdapter
extends Object
implements ListModel, TreeModelListener

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

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

Inner Class Summary
 class TreeModelListAdapter.ListEntry
          Internal class for managing list items.
 
Constructor Summary
TreeModelListAdapter(JList jlist)
          Construct a new tree model list adapter.
 
Method Summary
 void addListDataListener(ListDataListener listener)
          Add a list data listener.
 void dispose()
          Dispose of the adapter.
protected  void fireContentsChanged()
          Fire a contents changed event.
protected  void fireIntervalAdded(int first, int last)
          Fire an interval added event.
protected  void fireIntervalRemoved(int first, int last)
          Fire an interval removed event.
 Object getElementAt(int index)
          Get an element from the list.
 int getIndexForNode(ITreeNode node)
          Get the list index for a given node.
 int getSize()
          Get the size of the list.
 ITreeModel getTreeModel()
          Get the tree model in use by this adapter.
 void nodeAdded(TreeModelEvent evt)
          Handle node added events.
 void nodeChanged(TreeModelEvent evt)
          Handle node changed events.
 void nodeCollapsed(TreeModelEvent evt)
          Handle node collapsed events.
 void nodeCollapsing(TreeModelEvent evt)
          Handle node collapsing events.
 void nodeExpanded(TreeModelEvent evt)
          Handle node expanded events.
 void nodeExpanding(TreeModelEvent evt)
          Handle node expanding events.
 void nodeRemoved(TreeModelEvent evt)
          Handle node removed events.
 void nodeStructureChanged(TreeModelEvent evt)
          Handle node structure changed events.
 void removeListDataListener(ListDataListener listener)
          Remove a list data listener.
 void setTreeModel(ITreeModel model)
          Set the tree model to be used by this adapter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeModelListAdapter

public TreeModelListAdapter(JList jlist)
Construct a new tree model list adapter. Creates a new adapter for the specified JFC list component.
Parameters:
jlist - The JFC list 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)

addListDataListener

public void addListDataListener(ListDataListener listener)
Add a list data listener. Adds a ListDataListener to this adapter's list of list data listeners.
Specified by:
addListDataListener in interface ListModel
Parameters:
listener - The listener to add.
See Also:
removeListDataListener(javax.swing.event.ListDataListener)

removeListDataListener

public void removeListDataListener(ListDataListener listener)
Remove a list data listener. Removes a ListDataListener from this adapter's list of list data listeners.
Specified by:
removeListDataListener in interface ListModel
Parameters:
listener - The listener to remove.
See Also:
addListDataListener(javax.swing.event.ListDataListener)

getSize

public int getSize()
Get the size of the list. (Implementation of ListModel.)
Specified by:
getSize in interface ListModel

getElementAt

public Object getElementAt(int index)
Get an element from the list. (Implementation of ListModel.)
Specified by:
getElementAt in interface ListModel
Parameters:
index - The index of the desired element.

fireContentsChanged

protected void fireContentsChanged()
Fire a contents changed event. Notifies listeners that the list has changed in a way that cannot be characterized by a single change interval.

fireIntervalAdded

protected void fireIntervalAdded(int first,
                                 int last)
Fire an interval added event. Notifies listeners that an interval of items has been inserted into the list.
Parameters:
first - The index of the first item in the interval.
last - The index of the last item in the interval.

fireIntervalRemoved

protected void fireIntervalRemoved(int first,
                                   int last)
Fire an interval removed event. Notifies listeners that an interval of items has been removed from the list.
Parameters:
first - The index of the first item in the interval.
last - The index of the last item in the interval.

getIndexForNode

public final int getIndexForNode(ITreeNode node)
Get the list index for a given node.
Parameters:
node - The node.
row - The index in the list at which this node is currently displayed. Note that this value will become invalid when any node in the list is expanded or collapsed, as this could potentially change the position of node in the list.
Returns:
The index at which the node currently resides in the list, or -1 if the node was not found in the list.

nodeExpanding

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

nodeExpanded

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

nodeCollapsing

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

nodeCollapsed

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

nodeAdded

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

nodeRemoved

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

nodeChanged

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

nodeStructureChanged

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

dispose

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