/* * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.event; import java.util.EventObject; import javax.swing.tree.TreePath; /** * 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 {@link java.beans.XMLEncoder}. * * @author Rob Davis * @author Ray Ryan * @author Scott Violet */ public class TreeModelEvent extends EventObject { /** Path to the parent of the nodes that have changed. */ protected TreePath path; /** Indices identifying the position of where the children were. */ protected int[] childIndices; /** Children that have been removed. */ protected 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: