net.percederberg.mib
Class MibTreeModel

java.lang.Object
  |
  +--net.percederberg.mib.MibTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

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

A tree model interface to a MIB file. This class adapts the Mib class API to a TreeModel, making it possible to insert MIB:s into some types of graphical components.

Version:
1.1
Author:
Per Cederberg, per@percederberg.net

Constructor Summary
MibTreeModel(Mib mib)
          Creates a MIB tree model for the specified MIB.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns a child node at the specified index.
 int getChildCount(java.lang.Object parent)
          Returns the number of child nodes.
 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)
          Checks if the specified node is a leaf.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Removes a listener previously added.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Called 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

MibTreeModel

public MibTreeModel(Mib mib)
Creates a MIB tree model for the specified MIB.

Parameters:
mib - the MIB object
Method Detail

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
Returns:
the root of the tree

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns a child node at the specified index. The parent node must be a node previously obtained from this tree model. The index should be in the range 0 to getChildCount(parent) - 1.

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - the parent node in this tree model
index - the child index
Returns:
the child node at the specified index, or null if not found

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of child nodes. This method returns zero (0) if the node is a leaf or if it has no children. The parent node must be a node previously obtained from this tree model.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - the parent node in this tree model
Returns:
the number of children to the specified node

isLeaf

public boolean isLeaf(java.lang.Object node)
Checks if the specified node is a leaf. It is possible for this method to return false even if the node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory still isn't a leaf, however.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Parameters:
node - a node in this tree model
Returns:
true if the node is a leaf, or false otherwise

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Called 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
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of child in parent.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - the parent node
child - the child node
Returns:
the child node index, or -1 if not present

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
Parameters:
l - the listener to add
See Also:
removeTreeModelListener(javax.swing.event.TreeModelListener)

removeTreeModelListener

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

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