0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.event;
0N/A
0N/Aimport java.util.EventObject;
0N/Aimport javax.swing.tree.TreePath;
0N/A
0N/A/**
0N/A * An event that characterizes a change in the current
0N/A * selection. The change is based on any number of paths.
0N/A * TreeSelectionListeners will generally query the source of
0N/A * the event for the new selected status of each potentially
0N/A * changed row.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @see TreeSelectionListener
0N/A * @see javax.swing.tree.TreeSelectionModel
0N/A *
0N/A * @author Scott Violet
0N/A */
0N/Apublic class TreeSelectionEvent extends EventObject
0N/A{
0N/A /** Paths this event represents. */
0N/A protected TreePath[] paths;
0N/A /** For each path identifies if that path is in fact new. */
0N/A protected boolean[] areNew;
0N/A /** leadSelectionPath before the paths changed, may be null. */
0N/A protected TreePath oldLeadSelectionPath;
0N/A /** leadSelectionPath after the paths changed, may be null. */
0N/A protected TreePath newLeadSelectionPath;
0N/A
0N/A /**
0N/A * Represents a change in the selection of a TreeSelectionModel.
0N/A * paths identifies the paths that have been either added or
0N/A * removed from the selection.
0N/A *
0N/A * @param source source of event
0N/A * @param paths the paths that have changed in the selection
0N/A */
0N/A public TreeSelectionEvent(Object source, TreePath[] paths,
0N/A boolean[] areNew, TreePath oldLeadSelectionPath,
0N/A TreePath newLeadSelectionPath)
0N/A {
0N/A super(source);
0N/A this.paths = paths;
0N/A this.areNew = areNew;
0N/A this.oldLeadSelectionPath = oldLeadSelectionPath;
0N/A this.newLeadSelectionPath = newLeadSelectionPath;
0N/A }
0N/A
0N/A /**
0N/A * Represents a change in the selection of a TreeSelectionModel.
0N/A * path identifies the path that have been either added or
0N/A * removed from the selection.
0N/A *
0N/A * @param source source of event
0N/A * @param path the path that has changed in the selection
0N/A * @param isNew whether or not the path is new to the selection, false
0N/A * means path was removed from the selection.
0N/A */
0N/A public TreeSelectionEvent(Object source, TreePath path, boolean isNew,
0N/A TreePath oldLeadSelectionPath,
0N/A TreePath newLeadSelectionPath)
0N/A {
0N/A super(source);
0N/A paths = new TreePath[1];
0N/A paths[0] = path;
0N/A areNew = new boolean[1];
0N/A areNew[0] = isNew;
0N/A this.oldLeadSelectionPath = oldLeadSelectionPath;
0N/A this.newLeadSelectionPath = newLeadSelectionPath;
0N/A }
0N/A
0N/A /**
0N/A * Returns the paths that have been added or removed from the
0N/A * selection.
0N/A */
0N/A public TreePath[] getPaths()
0N/A {
0N/A int numPaths;
0N/A TreePath[] retPaths;
0N/A
0N/A numPaths = paths.length;
0N/A retPaths = new TreePath[numPaths];
0N/A System.arraycopy(paths, 0, retPaths, 0, numPaths);
0N/A return retPaths;
0N/A }
0N/A
0N/A /**
0N/A * Returns the first path element.
0N/A */
0N/A public TreePath getPath()
0N/A {
0N/A return paths[0];
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the path identified by {@code getPath} was
0N/A * added to the selection. A return value of {@code true}
0N/A * indicates the path identified by {@code getPath} was added to
0N/A * the selection. A return value of {@code false} indicates {@code
0N/A * getPath} was selected, but is no longer selected.
0N/A *
0N/A * @return {@code true} if {@code getPath} was added to the selection,
0N/A * {@code false} otherwise
0N/A */
0N/A public boolean isAddedPath() {
0N/A return areNew[0];
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the specified path was added to the selection.
0N/A * A return value of {@code true} indicates the path identified by
0N/A * {@code path} was added to the selection. A return value of
0N/A * {@code false} indicates {@code path} is no longer selected. This method
0N/A * is only valid for the paths returned from {@code getPaths()}; invoking
0N/A * with a path not included in {@code getPaths()} throws an
0N/A * {@code IllegalArgumentException}.
0N/A *
0N/A * @param path the path to test
0N/A * @return {@code true} if {@code path} was added to the selection,
0N/A * {@code false} otherwise
0N/A * @throws IllegalArgumentException if {@code path} is not contained
0N/A * in {@code getPaths}
0N/A * @see #getPaths
0N/A */
0N/A public boolean isAddedPath(TreePath path) {
0N/A for(int counter = paths.length - 1; counter >= 0; counter--)
0N/A if(paths[counter].equals(path))
0N/A return areNew[counter];
0N/A throw new IllegalArgumentException("path is not a path identified by the TreeSelectionEvent");
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the path at {@code getPaths()[index]} was added
0N/A * to the selection. A return value of {@code true} indicates the
0N/A * path was added to the selection. A return value of {@code false}
0N/A * indicates the path is no longer selected.
0N/A *
0N/A * @param index the index of the path to test
0N/A * @return {@code true} if the path was added to the selection,
0N/A * {@code false} otherwise
0N/A * @throws IllegalArgumentException if index is outside the range of
0N/A * {@code getPaths}
0N/A * @see #getPaths
0N/A *
0N/A * @since 1.3
0N/A */
0N/A public boolean isAddedPath(int index) {
0N/A if (paths == null || index < 0 || index >= paths.length) {
0N/A throw new IllegalArgumentException("index is beyond range of added paths identified by TreeSelectionEvent");
0N/A }
0N/A return areNew[index];
0N/A }
0N/A
0N/A /**
0N/A * Returns the path that was previously the lead path.
0N/A */
0N/A public TreePath getOldLeadSelectionPath() {
0N/A return oldLeadSelectionPath;
0N/A }
0N/A
0N/A /**
0N/A * Returns the current lead path.
0N/A */
0N/A public TreePath getNewLeadSelectionPath() {
0N/A return newLeadSelectionPath;
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the receiver, but with the source being newSource.
0N/A */
0N/A public Object cloneWithSource(Object newSource) {
0N/A // Fix for IE bug - crashing
0N/A return new TreeSelectionEvent(newSource, paths,areNew,
0N/A oldLeadSelectionPath,
0N/A newLeadSelectionPath);
0N/A }
0N/A}