de.tkuhn.util.prefs.gui
Class PrefTreeModel

java.lang.Object
  extended by de.tkuhn.swing.tree.AbstractTreeModel
      extended by de.tkuhn.util.prefs.gui.PrefTreeModel
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.swing.tree.TreeModel

public class PrefTreeModel
extends de.tkuhn.swing.tree.AbstractTreeModel
implements javax.swing.tree.TreeModel, java.awt.event.ActionListener

This is a TreeModel showing a tree of Preferences nodes. It also allows insertion and deletion of node.

Author:
Tilmann Kuhn

Field Summary
 
Fields inherited from class de.tkuhn.swing.tree.AbstractTreeModel
listeners
 
Constructor Summary
PrefTreeModel(java.util.prefs.Preferences prefs, boolean modifyMode)
          Creates a new instance of PrefsTreeModel.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          Gets invoked when any Action of this Model takes place.
 java.util.Collection<javax.swing.Action> getActions()
          Get all Actions that have impact on the TreeModel.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 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.
 java.lang.Object getRoot()
          Returns the root of the tree.
 boolean isLeaf(java.lang.Object node)
          Returns true if node is a leaf.
 void setPrefs(java.util.prefs.Preferences prefs)
          Setter for the property prefs which is the root node of the tree display.
 
Methods inherited from class de.tkuhn.swing.tree.AbstractTreeModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesChanged, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesInserted, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeNodesRemoved, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeStructureChanged, fireTreeStructureChanged, removeTreeModelListener, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, removeTreeModelListener, valueForPathChanged
 

Constructor Detail

PrefTreeModel

public PrefTreeModel(java.util.prefs.Preferences prefs,
                     boolean modifyMode)
Creates a new instance of PrefsTreeModel.

Parameters:
prefs - the root node for tree display
modifyMode - determines if the Tree may be modified
Method Detail

setPrefs

public void setPrefs(java.util.prefs.Preferences prefs)
Setter for the property prefs which is the root node of the tree display.

Parameters:
prefs - the new value for the property prefs.

getChild

public 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
Specified by:
getChild in class de.tkuhn.swing.tree.AbstractTreeModel
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

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
Specified by:
getChildCount in class de.tkuhn.swing.tree.AbstractTreeModel
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 parent is null or child is null, returns -1.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Overrides:
getIndexOfChild in class de.tkuhn.swing.tree.AbstractTreeModel
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 child or parent are 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
Specified by:
getRoot in class de.tkuhn.swing.tree.AbstractTreeModel
Returns:
the root of the tree

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Gets invoked when any Action of this Model takes place. You should not have to call this yourself.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ae - the ActionEvent to be processed

getActions

public java.util.Collection<javax.swing.Action> getActions()
Get all Actions that have impact on the TreeModel.

Returns:
a Collection containing the Actions

isLeaf

public boolean isLeaf(java.lang.Object node)
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
Overrides:
isLeaf in class de.tkuhn.swing.tree.AbstractTreeModel
Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf


Copyright © Tilmann Kuhn