public abstract class AbstractCheckBoxTreeModel extends AbstractTreeModel implements CheckBoxTreeModel
CheckBoxTreeModel which maintains the checkbox
state and fires change events more or less optimally.
Clients are expected to populate the tree with implementations of AbstractCheckBoxTreeModel.CheckBoxNode. The root node is provided by overriding {#link #getRoot()}.
The methods of AbstractCheckBoxTreeModel.CheckBoxNode that are typically overridden are
AbstractCheckBoxTreeModel.CheckBoxNode.getChildren(), AbstractCheckBoxTreeModel.CheckBoxNode.isLeaf(), and
AbstractCheckBoxTreeModel.CheckBoxNode.getLabel().
A subclass may extract the state of the leaf nodes from an external source
by overriding AbstractCheckBoxTreeModel.CheckBoxNode.setState(boolean) and AbstractCheckBoxTreeModel.CheckBoxNode.getState().
A subclass may control the criteria which determine which nodes should be
visible by overriding AbstractCheckBoxTreeModel.CheckBoxNode.isVisible().
When either an external source of state or the visibility criteria change,
the subclass should invoke the treeChanged(javax.swing.tree.TreePath) method to notify the
model.| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractCheckBoxTreeModel.CheckBoxNode<T extends AbstractCheckBoxTreeModel.CheckBoxNode> |
listenerList| Constructor and Description |
|---|
AbstractCheckBoxTreeModel() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
convertValueToText(java.lang.Object node)
Gets the label text for an object in this tree.
|
java.lang.Object |
getChild(java.lang.Object parent,
int index)
The default
AbstractCheckBoxTreeModel implementation considers only
visible children. |
int |
getChildCount(java.lang.Object parent)
The default
AbstractCheckBoxTreeModel implementation returns the
number of visible children. |
int |
getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
The default
AbstractCheckBoxTreeModel implementation returns the
index of the child within the visible children of this node, or -1 if the
child is not visible. |
abstract java.lang.Object |
getRoot() |
java.lang.Boolean |
getState(java.lang.Object node)
Gets the selection state of an object in this tree.
|
boolean |
isLeaf(java.lang.Object node) |
boolean |
isModified(java.lang.Object node)
Gets whether an object in the tree is modified, relative to a baseline
defined by the model.
|
void |
nodeChanged(javax.swing.tree.TreePath path)
Notify this model that attributes of a node, but not visibility, may have
changed (and its descendants are unaffected).
|
void |
stateForPathChanged(javax.swing.tree.TreePath path,
boolean newState)
Sets the selection state of an object in this tree.
|
void |
treeChanged()
Notify this model that attributes or visibility any node in this model may
have changed.
|
void |
treeChanged(javax.swing.tree.TreePath path)
Notify this model that attributes or visibility of a node or any of its
descendants may have changed.
|
void |
valueForPathChanged(javax.swing.tree.TreePath path,
java.lang.Object newValue) |
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeStructureChanged, getListeners, getTreeModelListeners, removeTreeModelListenerpublic abstract java.lang.Object getRoot()
getRoot in interface javax.swing.tree.TreeModelpublic java.lang.Object getChild(java.lang.Object parent,
int index)
AbstractCheckBoxTreeModel implementation considers only
visible children.getChild in interface javax.swing.tree.TreeModelpublic int getChildCount(java.lang.Object parent)
AbstractCheckBoxTreeModel implementation returns the
number of visible children.getChildCount in interface javax.swing.tree.TreeModelpublic int getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
AbstractCheckBoxTreeModel implementation returns the
index of the child within the visible children of this node, or -1 if the
child is not visible.getIndexOfChild in interface javax.swing.tree.TreeModelpublic boolean isLeaf(java.lang.Object node)
isLeaf in interface javax.swing.tree.TreeModelpublic void valueForPathChanged(javax.swing.tree.TreePath path,
java.lang.Object newValue)
valueForPathChanged in interface javax.swing.tree.TreeModelpublic java.lang.Boolean getState(java.lang.Object node)
CheckBoxTreeModelGets Boolean.TRUE or Boolean.FALSE if the
object is selected or unselected, respectively, and null if
it is neither (e.g., if it is not a leaf node and some but not all of its
children are selected).
getState in interface CheckBoxTreeModelpublic boolean isModified(java.lang.Object node)
AbstractCheckBoxTreeModel
implementation delegates to AbstractCheckBoxTreeModel.CheckBoxNode.isModified().public void stateForPathChanged(javax.swing.tree.TreePath path,
boolean newState)
CheckBoxTreeModeltreeNodesChanged events for
any objects in the tree for which the selection state actually changes.stateForPathChanged in interface CheckBoxTreeModelpath - path to the object whose state was changed by the user.newState - the new state from the user.public void treeChanged(javax.swing.tree.TreePath path)
public void treeChanged()
public void nodeChanged(javax.swing.tree.TreePath path)
stateForPathChanged(javax.swing.tree.TreePath, boolean)), this is the appropriate method to call
to update the tree to reflect the change.public java.lang.String convertValueToText(java.lang.Object node)
The default AbstractCheckBoxTreeModel implementation delegates to
the getLabel method of the CheckBoxNode
object.
convertValueToText in interface CheckBoxTreeModel