jdk/src/share/classes/javax/swing/event/TreeModelEvent.java
author mcherkas
Fri, 04 Oct 2013 20:13:32 +0400
changeset 20455 f6f9a0c2796b
parent 20428 929cd48fca8a
child 20458 f2423fb3fd19
permissions -rw-r--r--
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index. Reviewed-by: anthony, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.tree.TreePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Encapsulates information describing changes to a tree model, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * used to notify tree model listeners of the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * For more information and examples see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20428
diff changeset
    37
 href="http://docs.oracle.com/javase/tutorial/uiswing/events/treemodellistener.html">How to Write a Tree Model Listener</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Rob Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Ray Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class TreeModelEvent extends EventObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /** Path to the parent of the nodes that have changed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected TreePath  path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /** Indices identifying the position of where the children were. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected int[]     childIndices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /** Children that have been removed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected Object[]  children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Used to create an event when nodes have been changed, inserted, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * removed, identifying the path to the parent of the modified items as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * an array of Objects. All of the modified objects are siblings which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * direct descendents (not grandchildren) of the specified parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The positions at which the inserts, deletes, or changes occurred are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * specified by an array of <code>int</code>. The indexes in that array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * must be in order, from lowest to highest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * For changes, the indexes in the model correspond exactly to the indexes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * of items currently displayed in the UI. As a result, it is not really
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * critical if the indexes are not in their exact order. But after multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * inserts or deletes, the items currently in the UI no longer correspond
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * to the items in the model. It is therefore critical to specify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * indexes properly for inserts and deletes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * For inserts, the indexes represent the <i>final</i> state of the tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * after the inserts have occurred. Since the indexes must be specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * order, the most natural processing methodology is to do the inserts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * starting at the lowest index and working towards the highest. Accumulate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * a Vector of <code>Integer</code> objects that specify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * insert-locations as you go, then convert the Vector to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * array of <code>int</code> to create the event. When the postition-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * equals zero, the node is inserted at the beginning of the list. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * position index equals the size of the list, the node is "inserted" at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * (appended to) the end of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * For deletes, the indexes represent the <i>initial</i> state of the tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * before the deletes have occurred. Since the indexes must be specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * order, the most natural processing methodology is to use a delete-counter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Start by initializing the counter to zero and start work through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * list from lowest to higest. Every time you do a delete, add the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * value of the delete-counter to the index-position where the delete occurred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * and append the result to a Vector of delete-locations, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <code>addElement()</code>. Then increment the delete-counter. The index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * positions stored in the Vector therefore reflect the effects of all previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * deletes, so they represent each object's position in the initial tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * (You could also start at the highest index and working back towards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * lowest, accumulating a Vector of delete-locations as you go using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>insertElementAt(Integer, 0)</code>.) However you produce the Vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * of initial-positions, you then need to convert the Vector of <code>Integer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * objects to an array of <code>int</code> to create the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <p>
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 18133
diff changeset
   104
     * <b>Notes:</b><ul style="list-style-type:none">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <li>Like the <code>insertNodeInto</code> method in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *    <code>DefaultTreeModel</code> class, <code>insertElementAt</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *    appends to the <code>Vector</code> when the index matches the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *    of the vector. So you can use <code>insertElementAt(Integer, 0)</code>
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 18133
diff changeset
   109
     *    even when the vector is empty.</li>
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 18133
diff changeset
   110
     * <li>To create a node changed event for the root node, specify the parent
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 18133
diff changeset
   111
     *     and the child indices as <code>null</code>.</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param source the Object responsible for generating the event (typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *               the creator of the event object passes <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *               for its value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param path   an array of Object identifying the path to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *               parent of the modified item(s), where the first element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *               of the array is the Object stored at the root node and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *               the last element is the Object stored at the parent node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param childIndices an array of <code>int</code> that specifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *               index values of the removed items. The indices must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *               in sorted order, from lowest to highest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param children an array of Object containing the inserted, removed, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *                 changed objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see TreePath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public TreeModelEvent(Object source, Object[] path, int[] childIndices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                          Object[] children)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 5506
diff changeset
   131
        this(source, (path == null) ? null : new TreePath(path), childIndices, children);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Used to create an event when nodes have been changed, inserted, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * removed, identifying the path to the parent of the modified items as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * a TreePath object. For more information on how to specify the indexes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * and objects, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <code>TreeModelEvent(Object,Object[],int[],Object[])</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param source the Object responsible for generating the event (typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *               the creator of the event object passes <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *               for its value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param path   a TreePath object that identifies the path to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *               parent of the modified item(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param childIndices an array of <code>int</code> that specifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *               index values of the modified items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param children an array of Object containing the inserted, removed, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *                 changed objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #TreeModelEvent(Object,Object[],int[],Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public TreeModelEvent(Object source, TreePath path, int[] childIndices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                          Object[] children)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.childIndices = childIndices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.children = children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Used to create an event when the node structure has changed in some way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * identifying the path to the root of a modified subtree as an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Objects. A structure change event might involve nodes swapping position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * for example, or it might encapsulate multiple inserts and deletes in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * subtree stemming from the node, where the changes may have taken place at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * different levels of the subtree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *   <b>Note:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *   JTree collapses all nodes under the specified node, so that only its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *   immediate children are visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param source the Object responsible for generating the event (typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *               the creator of the event object passes <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *               for its value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param path   an array of Object identifying the path to the root of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *               modified subtree, where the first element of the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *               the object stored at the root node and the last element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *               is the object stored at the changed node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see TreePath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public TreeModelEvent(Object source, Object[] path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    {
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 5506
diff changeset
   186
        this(source, (path == null) ? null : new TreePath(path));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Used to create an event when the node structure has changed in some way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * identifying the path to the root of the modified subtree as a TreePath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * object. For more information on this event specification, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <code>TreeModelEvent(Object,Object[])</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param source the Object responsible for generating the event (typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *               the creator of the event object passes <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *               for its value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param path   a TreePath object that identifies the path to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *               change. In the DefaultTreeModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *               this object contains an array of user-data objects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *               but a subclass of TreePath could use some totally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *               different mechanism -- for example, a node ID number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #TreeModelEvent(Object,Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public TreeModelEvent(Object source, TreePath path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.childIndices = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * For all events, except treeStructureChanged,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * returns the parent of the changed nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * For treeStructureChanged events, returns the ancestor of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * structure that has changed. This and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>getChildIndices</code> are used to get a list of the effected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * The one exception to this is a treeNodesChanged event that is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * identify the root, in which case this will return the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * and <code>getChildIndices</code> will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @return the TreePath used in identifying the changed nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see TreePath#getLastPathComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public TreePath getTreePath() { return path; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Convenience method to get the array of objects from the TreePath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * instance that this event wraps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return an array of Objects, where the first Object is the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *         stored at the root and the last object is the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *         stored at the node identified by the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Object[] getPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns the objects that are children of the node identified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>getPath</code> at the locations specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <code>getChildIndices</code>. If this is a removal event the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * returned objects are no longer children of the parent node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return an array of Object containing the children specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *         the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see #getPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see #getChildIndices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public Object[] getChildren() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if(children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            int            cCount = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            Object[]       retChildren = new Object[cCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            System.arraycopy(children, 0, retChildren, 0, cCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return retChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Returns the values of the child indexes. If this is a removal event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the indexes point to locations in the initial list where items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * were removed. If it is an insert, the indices point to locations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * in the final list where the items were added. For node changes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * the indices point to the locations of the modified nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @return an array of <code>int</code> containing index locations for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *         the children specified by the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public int[] getChildIndices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if(childIndices != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            int            cCount = childIndices.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            int[]          retArray = new int[cCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            System.arraycopy(childIndices, 0, retArray, 0, cCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return retArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns a string that displays and identifies this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return a String representation of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        StringBuffer   retBuffer = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        retBuffer.append(getClass().getName() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                         Integer.toString(hashCode()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            retBuffer.append(" path " + path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if(childIndices != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            retBuffer.append(" indices [ ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            for(int counter = 0; counter < childIndices.length; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                retBuffer.append(Integer.toString(childIndices[counter])+ " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            retBuffer.append("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if(children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            retBuffer.append(" children [ ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            for(int counter = 0; counter < children.length; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                retBuffer.append(children[counter] + " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            retBuffer.append("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return retBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}