de.tkuhn.swing.tree
Class AbstractTreeModel

java.lang.Object
  extended by de.tkuhn.swing.tree.AbstractTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

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

An abstract implementation of TreeModel that provides basic implementations for some of the functions in this interface and can help implementing own TreeModels not using DefaultMutableTreeNodes as DefautlTreeModel does.

Version:
0.9.3
Author:
Tilmann Kuhn

Field Summary
protected  java.util.Set<javax.swing.event.TreeModelListener> listeners
          A set containing TreeModelListeners
 
Constructor Summary
AbstractTreeModel()
          Creates a new instance of AbstractTreeModel
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener tml)
          Adds a listener for the TreeModelEvent posted after the tree changes.
protected  void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesChanged(java.lang.Object source, javax.swing.tree.TreePath path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesChanged(javax.swing.event.TreeModelEvent tme)
          Fire a treeNodesChanged(tme) for all listeners registered with this TreeModel.
protected  void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesInserted(java.lang.Object source, javax.swing.tree.TreePath path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesInserted(javax.swing.event.TreeModelEvent tme)
          Fire a treeNodesInserted(tme) for all listeners registered with this TreeModel.
protected  void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesRemoved(java.lang.Object source, javax.swing.tree.TreePath path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent tme)
          Fire a treeNodesRemoved(tme) for all listeners registered with this TreeModel.
protected  void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeStructureChanged(java.lang.Object source, javax.swing.tree.TreePath path, int[] childIndicies, java.lang.Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireTreeStructureChanged(javax.swing.event.TreeModelEvent tme)
          Fire a treeStructureChanged(tme) for all listeners registered with this TreeModel.
abstract  java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
abstract  int getChildCount(java.lang.Object parent)
          Returns the number of children of parent.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns the index of child in parent.
abstract  java.lang.Object getRoot()
          Returns the root of the tree.
 boolean isLeaf(java.lang.Object node)
          Returns whether the specified node is a leaf node.
 void removeTreeModelListener(javax.swing.event.TreeModelListener tml)
          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
 

Field Detail

listeners

protected java.util.Set<javax.swing.event.TreeModelListener> listeners
A set containing TreeModelListeners

Constructor Detail

AbstractTreeModel

public AbstractTreeModel()
Creates a new instance of AbstractTreeModel

Method Detail

addTreeModelListener

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

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - the listener to add
See Also:
removeTreeModelListener(javax.swing.event.TreeModelListener)

getChild

public abstract java.lang.Object getChild(java.lang.Object parent,
                                          int index)
Returns the child of parent at index 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
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getChildCount

public abstract 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
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of child in parent. If either the parent or child is null, returns -1. This functionality is emulated using getChildCount(parent) and getChild(parent,index). So it is not supposed to be fast ;-)

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - a note in the tree, obtained from this data source
child - the node we are interested in
Returns:
the index of the child in the parent, or -1 if either the parent or the child is null

getRoot

public abstract java.lang.Object getRoot()
Returns the root of the tree. Is not implemented here.

Specified by:
getRoot in interface javax.swing.tree.TreeModel
Returns:
the root of the tree

isLeaf

public boolean isLeaf(java.lang.Object node)
Returns whether the specified node is a leaf node. This implementation simply checks if getChildCount(node) == 0

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Parameters:
node - the node to check
Returns:
true if the node is a leaf node

removeTreeModelListener

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

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - the listener to remove
See Also:
addTreeModelListener(javax.swing.event.TreeModelListener)

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. This is an empty implementation that does nothing.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndicies,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node being changed
path - the path to the root node
childIndicies - the indices of the changed elements
children - the changed elements

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     java.lang.Object[] path,
                                     int[] childIndicies,
                                     java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where new elements are being inserted
path - the path to the root node
childIndicies - the indices of the new elements
children - the new elements

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndicies,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where elements are being removed
path - the path to the root node
childIndicies - the indices of the removed elements
children - the removed elements

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        java.lang.Object[] path,
                                        int[] childIndicies,
                                        java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where the tree model has changed
path - the path to the root node
childIndicies - the indices of the affected elements
children - the affected elements

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    javax.swing.tree.TreePath path,
                                    int[] childIndicies,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node being changed
path - the path to the root node
childIndicies - the indices of the changed elements
children - the changed elements

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     javax.swing.tree.TreePath path,
                                     int[] childIndicies,
                                     java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where new elements are being inserted
path - the path to the root node
childIndicies - the indices of the new elements
children - the new elements

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    javax.swing.tree.TreePath path,
                                    int[] childIndicies,
                                    java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where elements are being removed
path - the path to the root node
childIndicies - the indices of the removed elements
children - the removed elements

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        javax.swing.tree.TreePath path,
                                        int[] childIndicies,
                                        java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
source - the node where the tree model has changed
path - the path to the root node
childIndicies - the indices of the affected elements
children - the affected elements

fireTreeNodesChanged

protected void fireTreeNodesChanged(javax.swing.event.TreeModelEvent tme)
Fire a treeNodesChanged(tme) for all listeners registered with this TreeModel.

Parameters:
tme - the TreeModelEvent to be passed

fireTreeNodesInserted

protected void fireTreeNodesInserted(javax.swing.event.TreeModelEvent tme)
Fire a treeNodesInserted(tme) for all listeners registered with this TreeModel.

Parameters:
tme - the TreeModelEvent to be passed

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent tme)
Fire a treeNodesRemoved(tme) for all listeners registered with this TreeModel.

Parameters:
tme - the TreeModelEvent to be passed

fireTreeStructureChanged

protected void fireTreeStructureChanged(javax.swing.event.TreeModelEvent tme)
Fire a treeStructureChanged(tme) for all listeners registered with this TreeModel.

Parameters:
tme - the TreeModelEvent to be passed


Copyright © Tilmann Kuhn