|
.useful Home Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.tree.DefaultMutableTreeNode org.dotuseful.ui.tree.AutomatedTreeNode
AutomatedTreeNode extends DefaultMutableTreeNode adding support for automatic notification of node changes. AutomatedTreeNodes are used with AutomatedTreeModel. In this model each node considered as a little tree which can fire TreeModel events about its changes. Each parent node registers itself as a listener of its child nodes events and transfers events to its own listeners (which is its parent) up to the root node. You can use AutomatedTreeModel which automatically handles events and fires them as usual TreeModel.
A sample of code that uses DefaultTreeModel and DefaultTreeNodes
setUserObject( event.getObject() );
//getting a tree model from somewhere
DefaultTreeModel model = ( DefaultTreeModel ) titleTree.getModel();
model.nodeChanged( node );
A sample of code that uses AutomatedTreeModel and AutomatedTreeNodes
setUserObject( event.getObject() );
//Everything else automated
This is not a thread safe class. If you intend to use an AutomatedTreeNode (or a tree of TreeNodes) in more than one thread, you need to do your own synchronizing. A good convention to adopt is synchronizing on the root node of a tree.
Field Summary | |
protected javax.swing.event.EventListenerList |
listenerList
Listeners. |
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode |
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject |
Constructor Summary | |
AutomatedTreeNode()
Creates an AutomatedTreeNode that has no parent and no children, but which allows children. |
|
AutomatedTreeNode(java.lang.Object userObject)
Creates an AutomatedTreeNode node with no parent, no children, but which allows children, and initializes it with the specified user object. |
|
AutomatedTreeNode(java.lang.Object userObject,
boolean allowsChildren)
Creates an AutomatedTreeNode with no parent, no children, initialized with the specified user object, and that allows children only if specified. |
Method Summary | |
void |
addTreeModelListener(javax.swing.event.TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the node changes. |
protected void |
fireTreeNodesChanged(int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesChanged() method. |
protected void |
fireTreeNodesChanged(java.lang.Object[] path,
int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesChanged() method. |
protected void |
fireTreeNodesChanged(java.lang.Object source,
java.lang.Object[] path,
int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesChanged() method. |
protected void |
fireTreeNodesInserted(int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesInserted() method. |
protected void |
fireTreeNodesInserted(java.lang.Object source,
java.lang.Object[] path,
int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesInserted() method. |
protected void |
fireTreeNodesRemoved(int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesRemoved() method. |
protected void |
fireTreeNodesRemoved(java.lang.Object source,
java.lang.Object[] path,
int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeNodesRemoved() method. |
protected void |
fireTreeStructureChanged()
Notifies all listeners that have registered interest for notification on this event type by firing a treeStructureChanged() method. |
protected void |
fireTreeStructureChanged(int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeStructureChanged() method. |
protected void |
fireTreeStructureChanged(java.lang.Object source,
java.lang.Object[] path,
int[] childIndices,
java.lang.Object[] children)
Notifies all listeners that have registered interest for notification on this event type by firing a treeStructureChanged() method. |
void |
insert(javax.swing.tree.MutableTreeNode newChild,
int childIndex)
Removes newChild from its present parent (if it has a
parent), sets the child's parent to this node, adds the child to this
node's child array at index childIndex , fires a
nodesWereInserted event, and then adds itself as a
TreeModelListener to newChild .
|
protected void |
nodeChanged()
Invoke this method after the node changed how it is to be represented in the tree. |
protected void |
nodeStructureChanged()
Invoke this method if you've totally changed the children of node and its childrens children. |
protected void |
nodesWereInserted(int[] childIndices)
This method invoked after you've inserted some AutomatedTreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order. |
protected void |
nodesWereRemoved(int[] childIndices,
java.lang.Object[] removedChildren)
This method invoked after you've removed some AutomatedTreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order. |
void |
remove(int childIndex)
Removes the child at the specified index from this node's children and sets that node's parent to null. |
void |
removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener() . |
void |
setUserObject(java.lang.Object userObject)
Sets the user object for this node to userObject . |
void |
treeNodesChanged(javax.swing.event.TreeModelEvent e)
Invoked after a node (or a set of siblings) has changed in some way. |
void |
treeNodesInserted(javax.swing.event.TreeModelEvent e)
Invoked after nodes have been inserted into the tree. |
void |
treeNodesRemoved(javax.swing.event.TreeModelEvent e)
Invoked after nodes have been removed from the tree. |
void |
treeStructureChanged(javax.swing.event.TreeModelEvent e)
Invoked after the tree has drastically changed structure from a given node down. |
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode |
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, toString |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected javax.swing.event.EventListenerList listenerList
Constructor Detail |
public AutomatedTreeNode()
public AutomatedTreeNode(java.lang.Object userObject)
userObject
- an Object provided by the user that constitutes the node's
datapublic AutomatedTreeNode(java.lang.Object userObject, boolean allowsChildren)
userObject
- an Object provided by the user that constitutes the node's
dataallowsChildren
- if true, the node is allowed to have child nodes -- otherwise,
it is always a leaf nodeMethod Detail |
public void insert(javax.swing.tree.MutableTreeNode newChild, int childIndex)
newChild
from its present parent (if it has a
parent), sets the child's parent to this node, adds the child to this
node's child array at index childIndex
, fires a
nodesWereInserted
event, and then adds itself as a
TreeModelListener
to newChild
.
newChild
must not be null and must not be an ancestor of
this node.
insert
in interface javax.swing.tree.MutableTreeNode
newChild
- the MutableTreeNode to insert under this nodechildIndex
- the index in this node's child array where this node is to be
inserted
java.lang.ArrayIndexOutOfBoundsException
- if childIndex
is out of bounds
java.lang.IllegalArgumentException
- if newChild
is null or is an ancestor of
this node
java.lang.IllegalStateException
- if this node does not allow childrenDefaultMutableTreeNode.isNodeDescendant(javax.swing.tree.DefaultMutableTreeNode)
public void remove(int childIndex)
MutableTreeNode
.
remove
in interface javax.swing.tree.MutableTreeNode
childIndex
- the index in this node's child array of the child to remove
java.lang.ArrayIndexOutOfBoundsException
- if childIndex
is out of boundspublic void setUserObject(java.lang.Object userObject)
userObject
.
setUserObject
in interface javax.swing.tree.MutableTreeNode
userObject
- the Object that constitutes this node's user-specified dataDefaultMutableTreeNode.toString()
public void treeNodesChanged(javax.swing.event.TreeModelEvent e)
Invoked after a node (or a set of siblings) has changed in some way. The node(s) have not changed locations in the tree or altered their children arrays, but other attributes have changed and may affect presentation. Example: the name of a file has changed, but it is in the same location in the file system.
treeNodesChanged
in interface javax.swing.event.TreeModelListener
public void treeNodesInserted(javax.swing.event.TreeModelEvent e)
Invoked after nodes have been inserted into the tree.
treeNodesInserted
in interface javax.swing.event.TreeModelListener
public void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
Invoked after nodes have been removed from the tree. Note that if a subtree is removed from the tree, this method may only be invoked once for the root of the removed subtree, not once for each individual set of siblings removed.
treeNodesRemoved
in interface javax.swing.event.TreeModelListener
public void treeStructureChanged(javax.swing.event.TreeModelEvent e)
Invoked after the tree has drastically changed structure from a given node down. If the path returned by e.getPath() is of length one and the first element does not identify the current root node the first element should become the new root of the tree.
treeStructureChanged
in interface javax.swing.event.TreeModelListener
protected void nodeChanged()
protected void nodesWereInserted(int[] childIndices)
protected void nodesWereRemoved(int[] childIndices, java.lang.Object[] removedChildren)
protected void nodeStructureChanged()
public void addTreeModelListener(javax.swing.event.TreeModelListener l)
l
- the listener to addremoveTreeModelListener(javax.swing.event.TreeModelListener)
public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
l
- the listener to removeaddTreeModelListener(javax.swing.event.TreeModelListener)
protected void fireTreeNodesChanged(int[] childIndices, java.lang.Object[] children)
childIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesChanged(java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
path
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesInserted(int[] childIndices, java.lang.Object[] children)
childIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesRemoved(int[] childIndices, java.lang.Object[] children)
childIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeStructureChanged()
EventListenerList
protected void fireTreeStructureChanged(int[] childIndices, java.lang.Object[] children)
childIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
protected void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsEventListenerList
|
© 2004 .useful community | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |