javax.swing.event
Class TreeModelEvent

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.EventObject sample code for java.util.EventObject definition code for java.util.EventObject 
      extended by javax.swing.event.TreeModelEvent
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class TreeModelEvent
extends EventObject sample code for java.util.EventObject definition code for java.util.EventObject

Encapsulates information describing changes to a tree model, and used to notify tree model listeners of the change. For more information and examples see How to Write a Tree Model Listener, a section in The Java Tutorial.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder sample code for java.beans.XMLEncoder definition code for java.beans.XMLEncoder .

See Also:
Serialized Form

Field Summary
protected  int[] childIndices sample code for javax.swing.event.TreeModelEvent.childIndices definition code for javax.swing.event.TreeModelEvent.childIndices
          Indices identifying the position of where the children were.
protected  Object sample code for java.lang.Object definition code for java.lang.Object [] children sample code for javax.swing.event.TreeModelEvent.children definition code for javax.swing.event.TreeModelEvent.children
          Children that have been removed.
protected  TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath path sample code for javax.swing.event.TreeModelEvent.path definition code for javax.swing.event.TreeModelEvent.path
          Path to the parent of the nodes that have changed.
 
Fields inherited from class java.util.EventObject sample code for java.util.EventObject definition code for java.util.EventObject
source sample code for java.util.EventObject.source definition code for java.util.EventObject.source
 
Constructor Summary
TreeModelEvent sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[]) (Object sample code for java.lang.Object definition code for java.lang.Object  source, Object sample code for java.lang.Object definition code for java.lang.Object [] path)
          Used to create an event when the node structure has changed in some way, identifying the path to the root of a modified subtree as an array of Objects.
TreeModelEvent sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[]) (Object sample code for java.lang.Object definition code for java.lang.Object  source, Object sample code for java.lang.Object definition code for java.lang.Object [] path, int[] childIndices, Object sample code for java.lang.Object definition code for java.lang.Object [] children)
          Used to create an event when nodes have been changed, inserted, or removed, identifying the path to the parent of the modified items as an array of Objects.
TreeModelEvent sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath) (Object sample code for java.lang.Object definition code for java.lang.Object  source, TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  path)
          Used to create an event when the node structure has changed in some way, identifying the path to the root of the modified subtree as a TreePath object.
TreeModelEvent sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath, int[], java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath, int[], java.lang.Object[]) (Object sample code for java.lang.Object definition code for java.lang.Object  source, TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  path, int[] childIndices, Object sample code for java.lang.Object definition code for java.lang.Object [] children)
          Used to create an event when nodes have been changed, inserted, or removed, identifying the path to the parent of the modified items as a TreePath object.
 
Method Summary
 int[] getChildIndices sample code for javax.swing.event.TreeModelEvent.getChildIndices() definition code for javax.swing.event.TreeModelEvent.getChildIndices() ()
          Returns the values of the child indexes.
 Object sample code for java.lang.Object definition code for java.lang.Object [] getChildren sample code for javax.swing.event.TreeModelEvent.getChildren() definition code for javax.swing.event.TreeModelEvent.getChildren() ()
          Returns the objects that are children of the node identified by getPath at the locations specified by getChildIndices.
 Object sample code for java.lang.Object definition code for java.lang.Object [] getPath sample code for javax.swing.event.TreeModelEvent.getPath() definition code for javax.swing.event.TreeModelEvent.getPath() ()
          Convenience method to get the array of objects from the TreePath instance that this event wraps.
 TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath getTreePath sample code for javax.swing.event.TreeModelEvent.getTreePath() definition code for javax.swing.event.TreeModelEvent.getTreePath() ()
          For all events, except treeStructureChanged, returns the parent of the changed nodes.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for javax.swing.event.TreeModelEvent.toString() definition code for javax.swing.event.TreeModelEvent.toString() ()
          Returns a string that displays and identifies this object's properties.
 
Methods inherited from class java.util.EventObject sample code for java.util.EventObject definition code for java.util.EventObject
getSource sample code for java.util.EventObject.getSource() definition code for java.util.EventObject.getSource()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

path sample code for javax.swing.event.TreeModelEvent.path

protected TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  path
Path to the parent of the nodes that have changed.


childIndices sample code for javax.swing.event.TreeModelEvent.childIndices

protected int[] childIndices
Indices identifying the position of where the children were.


children sample code for javax.swing.event.TreeModelEvent.children

protected Object sample code for java.lang.Object definition code for java.lang.Object [] children
Children that have been removed.

Constructor Detail

TreeModelEvent sample code for javax.swing.event.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[])

public TreeModelEvent(Object sample code for java.lang.Object definition code for java.lang.Object  source,
                      Object sample code for java.lang.Object definition code for java.lang.Object [] path,
                      int[] childIndices,
                      Object sample code for java.lang.Object definition code for java.lang.Object [] children)
Used to create an event when nodes have been changed, inserted, or removed, identifying the path to the parent of the modified items as an array of Objects. All of the modified objects are siblings which are direct descendents (not grandchildren) of the specified parent. The positions at which the inserts, deletes, or changes occurred are specified by an array of int. The indexes in that array must be in order, from lowest to highest.

For changes, the indexes in the model correspond exactly to the indexes of items currently displayed in the UI. As a result, it is not really critical if the indexes are not in their exact order. But after multiple inserts or deletes, the items currently in the UI no longer correspond to the items in the model. It is therefore critical to specify the indexes properly for inserts and deletes.

For inserts, the indexes represent the final state of the tree, after the inserts have occurred. Since the indexes must be specified in order, the most natural processing methodology is to do the inserts starting at the lowest index and working towards the highest. Accumulate a Vector of Integer objects that specify the insert-locations as you go, then convert the Vector to an array of int to create the event. When the postition-index equals zero, the node is inserted at the beginning of the list. When the position index equals the size of the list, the node is "inserted" at (appended to) the end of the list.

For deletes, the indexes represent the initial state of the tree, before the deletes have occurred. Since the indexes must be specified in order, the most natural processing methodology is to use a delete-counter. Start by initializing the counter to zero and start work through the list from lowest to higest. Every time you do a delete, add the current value of the delete-counter to the index-position where the delete occurred, and append the result to a Vector of delete-locations, using addElement(). Then increment the delete-counter. The index positions stored in the Vector therefore reflect the effects of all previous deletes, so they represent each object's position in the initial tree. (You could also start at the highest index and working back towards the lowest, accumulating a Vector of delete-locations as you go using the insertElementAt(Integer, 0).) However you produce the Vector of initial-positions, you then need to convert the Vector of Integer objects to an array of int to create the event.

Notes:


TreeModelEvent sample code for javax.swing.event.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath, int[], java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath, int[], java.lang.Object[])

public TreeModelEvent(Object sample code for java.lang.Object definition code for java.lang.Object  source,
                      TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  path,
                      int[] childIndices,
                      Object sample code for java.lang.Object definition code for java.lang.Object [] children)
Used to create an event when nodes have been changed, inserted, or removed, identifying the path to the parent of the modified items as a TreePath object. For more information on how to specify the indexes and objects, see TreeModelEvent(Object,Object[],int[],Object[]).

Parameters:
source - the Object responsible for generating the event (typically the creator of the event object passes this for its value)
path - a TreePath object that identifies the path to the parent of the modified item(s)
childIndices - an array of int that specifies the index values of the modified items
children - an array of Object containing the inserted, removed, or changed objects
See Also:
TreeModelEvent(Object,Object[],int[],Object[]) sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[], int[], java.lang.Object[])

TreeModelEvent sample code for javax.swing.event.TreeModelEvent(java.lang.Object, java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent(java.lang.Object, java.lang.Object[])

public TreeModelEvent(Object sample code for java.lang.Object definition code for java.lang.Object  source,
                      Object sample code for java.lang.Object definition code for java.lang.Object [] path)
Used to create an event when the node structure has changed in some way, identifying the path to the root of a modified subtree as an array of Objects. A structure change event might involve nodes swapping position, for example, or it might encapsulate multiple inserts and deletes in the subtree stemming from the node, where the changes may have taken place at different levels of the subtree.
Note:
JTree collapses all nodes under the specified node, so that only its immediate children are visible.

Parameters:
source - the Object responsible for generating the event (typically the creator of the event object passes this for its value)
path - an array of Object identifying the path to the root of the modified subtree, where the first element of the array is the object stored at the root node and the last element is the object stored at the changed node
See Also:
TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath

TreeModelEvent sample code for javax.swing.event.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath) definition code for javax.swing.event.TreeModelEvent(java.lang.Object, javax.swing.tree.TreePath)

public TreeModelEvent(Object sample code for java.lang.Object definition code for java.lang.Object  source,
                      TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  path)
Used to create an event when the node structure has changed in some way, identifying the path to the root of the modified subtree as a TreePath object. For more information on this event specification, see TreeModelEvent(Object,Object[]).

Parameters:
source - the Object responsible for generating the event (typically the creator of the event object passes this for its value)
path - a TreePath object that identifies the path to the change. In the DefaultTreeModel, this object contains an array of user-data objects, but a subclass of TreePath could use some totally different mechanism -- for example, a node ID number
See Also:
TreeModelEvent(Object,Object[]) sample code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[]) definition code for javax.swing.event.TreeModelEvent.TreeModelEvent(java.lang.Object, java.lang.Object[])
Method Detail

getTreePath sample code for javax.swing.event.TreeModelEvent.getTreePath() definition code for javax.swing.event.TreeModelEvent.getTreePath()

public TreePath sample code for javax.swing.tree.TreePath definition code for javax.swing.tree.TreePath  getTreePath()
For all events, except treeStructureChanged, returns the parent of the changed nodes. For treeStructureChanged events, returns the ancestor of the structure that has changed. This and getChildIndices are used to get a list of the effected nodes.

The one exception to this is a treeNodesChanged event that is to identify the root, in which case this will return the root and getChildIndices will return null.

Returns:
the TreePath used in identifying the changed nodes.
See Also:
TreePath.getLastPathComponent() sample code for javax.swing.tree.TreePath.getLastPathComponent() definition code for javax.swing.tree.TreePath.getLastPathComponent()

getPath sample code for javax.swing.event.TreeModelEvent.getPath() definition code for javax.swing.event.TreeModelEvent.getPath()

public Object sample code for java.lang.Object definition code for java.lang.Object [] getPath()
Convenience method to get the array of objects from the TreePath instance that this event wraps.

Returns:
an array of Objects, where the first Object is the one stored at the root and the last object is the one stored at the node identified by the path

getChildren sample code for javax.swing.event.TreeModelEvent.getChildren() definition code for javax.swing.event.TreeModelEvent.getChildren()

public Object sample code for java.lang.Object definition code for java.lang.Object [] getChildren()
Returns the objects that are children of the node identified by getPath at the locations specified by getChildIndices. If this is a removal event the returned objects are no longer children of the parent node.

Returns:
an array of Object containing the children specified by the event
See Also:
getPath() sample code for javax.swing.event.TreeModelEvent.getPath() definition code for javax.swing.event.TreeModelEvent.getPath() , getChildIndices() sample code for javax.swing.event.TreeModelEvent.getChildIndices() definition code for javax.swing.event.TreeModelEvent.getChildIndices()

getChildIndices sample code for javax.swing.event.TreeModelEvent.getChildIndices() definition code for javax.swing.event.TreeModelEvent.getChildIndices()

public int[] getChildIndices()
Returns the values of the child indexes. If this is a removal event the indexes point to locations in the initial list where items were removed. If it is an insert, the indices point to locations in the final list where the items were added. For node changes, the indices point to the locations of the modified nodes.

Returns:
an array of int containing index locations for the children specified by the event

toString sample code for javax.swing.event.TreeModelEvent.toString() definition code for javax.swing.event.TreeModelEvent.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a string that displays and identifies this object's properties.

Overrides:
toString sample code for java.util.EventObject.toString() definition code for java.util.EventObject.toString() in class EventObject sample code for java.util.EventObject definition code for java.util.EventObject
Returns:
a String representation of this object