2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 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 0N/A * Default implementation of TreeSelectionModel. Listeners are notified 0N/A * the paths in the selection change, not the rows. In order 0N/A * to be able to track row changes you may wish to become a listener 0N/A * for expansion events on the tree and test for changes from there. 0N/A * <p>resetRowSelection is called from any of the methods that update 0N/A * the selected paths. If you subclass any of these methods to 0N/A * filter what is allowed to be selected, be sure and message 0N/A * <code>resetRowSelection</code> if you do not message super. 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 * @see javax.swing.JTree 0N/A * @author Scott Violet 0N/A /** Property name for selectionMode. */ 0N/A /** Used to messaged registered listeners. */ 0N/A /** Paths that are currently selected. Will be null if nothing is 0N/A * currently selected. */ 0N/A /** Event listener list. */ 0N/A /** Provides a row for a given path. */ 0N/A /** Handles maintaining the list selection model. The RowMapper is used 0N/A * to map from a TreePath to a row, and the value is then placed here. */ 0N/A /** Mode for the selection, will be either SINGLE_TREE_SELECTION, 0N/A * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. 0N/A /** Last path that was added. */ 0N/A /** Index of the lead path in selection. */ 0N/A /** Used to make sure the paths are unique, will contain all the paths 0N/A * in <code>selection</code>. 0N/A * Creates a new instance of DefaultTreeSelectionModel that is 0N/A * empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION. 0N/A * Sets the RowMapper instance. This instance is used to determine 0N/A * the row for a particular TreePath. 0N/A * Returns the RowMapper instance that is able to map a TreePath to a 0N/A * Sets the selection model, which must be one of SINGLE_TREE_SELECTION, 0N/A * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. If mode 0N/A * is not one of the defined value, 0N/A * <code>DISCONTIGUOUS_TREE_SELECTION</code> is assumed. 0N/A * <p>This may change the selection if the current selection is not valid 0N/A * for the new mode. For example, if three TreePaths are 0N/A * selected when the mode is changed to <code>SINGLE_TREE_SELECTION</code>, 0N/A * only one TreePath will remain selected. It is up to the particular 0N/A * implementation to decide what TreePath remains selected. 0N/A * Setting the mode to something other than the defined types will 0N/A * result in the mode becoming <code>DISCONTIGUOUS_TREE_SELECTION</code>. 0N/A * Returns the selection mode, one of <code>SINGLE_TREE_SELECTION</code>, 0N/A * <code>DISCONTIGUOUS_TREE_SELECTION</code> or 0N/A * <code>CONTIGUOUS_TREE_SELECTION</code>. 0N/A * Sets the selection to path. If this represents a change, then 0N/A * the TreeSelectionListeners are notified. If <code>path</code> is 0N/A * null, this has the same effect as invoking <code>clearSelection</code>. 0N/A * @param path new path to select 0N/A * Sets the selection. Whether the supplied paths are taken as the 0N/A * new selection depends upon the selection mode. If the supplied 0N/A * array is {@code null}, or empty, the selection is cleared. If 0N/A * the selection mode is {@code SINGLE_TREE_SELECTION}, only the 0N/A * first path in {@code pPaths} is used. If the selection 0N/A * mode is {@code CONTIGUOUS_TREE_SELECTION} and the supplied paths 0N/A * are not contiguous, then only the first path in {@code pPaths} is 0N/A * used. If the selection mode is 0N/A * {@code DISCONTIGUOUS_TREE_SELECTION}, then all paths are used. 0N/A * All {@code null} paths in {@code pPaths} are ignored. 0N/A * If this represents a change, all registered {@code 0N/A * TreeSelectionListener}s are notified. 0N/A * The lead path is set to the last unique path. 0N/A * The paths returned from {@code getSelectionPaths} are in the same 0N/A * order as those supplied to this method. 0N/A * @param pPaths the new selection 0N/A /* If single selection and more than one path, only allow 0N/A /* If contiguous selection and paths aren't contiguous, 0N/A only select the first path item. */ 0N/A /* Find the paths that are new. */ 0N/A /* Get the paths that were selected but no longer selected. */ 0N/A // No reason to do this now, but will still call it. 0N/A /* Notify of the change. */ 0N/A * Adds path to the current selection. If path is not currently 0N/A * in the selection the TreeSelectionListeners are notified. This has 0N/A * no effect if <code>path</code> is null. 0N/A * @param path the new path to add to the current selection 0N/A * Adds paths to the current selection. If any of the paths in 0N/A * paths are not currently in the selection the TreeSelectionListeners 0N/A * are notified. This has 0N/A * no effect if <code>paths</code> is null. 0N/A * <p>The lead path is set to the last element in <code>paths</code>. 0N/A * <p>If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code>, 0N/A * and adding the new paths would make the selection discontiguous. 0N/A * Then two things can result: if the TreePaths in <code>paths</code> 0N/A * are contiguous, then the selection becomes these TreePaths, 0N/A * otherwise the TreePaths aren't contiguous and the selection becomes 0N/A * the first TreePath in <code>paths</code>. 0N/A * @param paths the new path to add to the current selection 0N/A /* Determine the paths that aren't currently in the 0N/A /* And build the new selection. */ 0N/A /* Some of the paths in paths are already in 0N/A * Removes path from the selection. If path is in the selection 0N/A * The TreeSelectionListeners are notified. This has no effect if 0N/A * <code>path</code> is null. 0N/A * @param path the path to remove from the selection 0N/A * Removes paths from the selection. If any of the paths in paths 0N/A * are in the selection the TreeSelectionListeners are notified. 0N/A * This has no effect if <code>paths</code> is null. 0N/A * @param paths the paths to remove from the selection 0N/A /* Could probably do something more interesting here! */ 0N/A /* Find the paths that can be removed. */ 0N/A * Returns the first path in the selection. This is useful if there 0N/A * if only one item currently selected. 0N/A * Returns the selection. 0N/A * @return the selection 0N/A * Returns the number of paths that are selected. 0N/A * Returns true if the path, <code>path</code>, 0N/A * is in the current selection. 0N/A * Returns true if the selection is currently empty. 0N/A * Empties the current selection. If this represents a change in the 0N/A * current selection, the selection listeners are notified. 0N/A * Adds x to the list of listeners that are notified each time the 0N/A * set of selected TreePaths changes. 0N/A * @param x the new listener to be added 0N/A * Removes x from the list of listeners that are notified each time 0N/A * the set of selected TreePaths changes. 0N/A * @param x the listener to remove 0N/A * Returns an array of all the tree selection listeners 0N/A * registered on this model. 0N/A * @return all of this model's <code>TreeSelectionListener</code>s 0N/A * array if no tree selection listeners are currently registered 0N/A * @see #addTreeSelectionListener 0N/A * @see #removeTreeSelectionListener 0N/A * Notifies all listeners that are registered for 0N/A * tree selection events on this object. 0N/A * @see #addTreeSelectionListener 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // TreeSelectionEvent e = null; 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A // e = new ListSelectionEvent(this, firstIndex, lastIndex); 0N/A * Returns an array of all the objects currently registered 0N/A * as <code><em>Foo</em>Listener</code>s 0N/A * <code><em>Foo</em>Listener</code>s are registered using the 0N/A * <code>add<em>Foo</em>Listener</code> method. 0N/A * You can specify the <code>listenerType</code> argument 0N/A * with a class literal, 0N/A * <code><em>Foo</em>Listener.class</code>. 0N/A * For example, you can query a 0N/A * <code>DefaultTreeSelectionModel</code> <code>m</code> 0N/A * for its tree selection listeners with the following code: 0N/A * <pre>TreeSelectionListener[] tsls = (TreeSelectionListener[])(m.getListeners(TreeSelectionListener.class));</pre> 0N/A * If no such listeners exist, this method returns an empty array. 0N/A * @param listenerType the type of listeners requested; this parameter 0N/A * should specify an interface that descends from 0N/A * <code>java.util.EventListener</code> 0N/A * @return an array of all objects registered as 0N/A * <code><em>Foo</em>Listener</code>s on this component, 0N/A * or an empty array if no such 0N/A * listeners have been added 0N/A * @exception ClassCastException if <code>listenerType</code> 0N/A * doesn't specify a class or interface that implements 0N/A * <code>java.util.EventListener</code> 0N/A * @see #getTreeSelectionListeners 0N/A * @see #getPropertyChangeListeners 0N/A * Returns the selection in terms of rows. There is not 0N/A * necessarily a one-to-one mapping between the {@code TreePath}s 0N/A * returned from {@code getSelectionPaths} and this method. In 0N/A * particular, if a {@code TreePath} is not viewable (the {@code 0N/A * RowMapper} returns {@code -1} for the row corresponding to the 0N/A * {@code TreePath}), then the corresponding row is not included 0N/A * in the returned array. For example, if the selection consists 0N/A * of two paths, {@code A} and {@code B}, with {@code A} at row 0N/A * {@code 10}, and {@code B} not currently viewable, then this method 0N/A * returns an array with the single entry {@code 10}. 0N/A * @return the selection in terms of rows 0N/A // This is currently rather expensive. Needs 0N/A // to be better support from ListSelectionModel to speed this up. 0N/A * Returns the smallest value obtained from the RowMapper for the 0N/A * current set of selected TreePaths. If nothing is selected, 0N/A * or there is no RowMapper, this will return -1. 0N/A * Returns the largest value obtained from the RowMapper for the 0N/A * current set of selected TreePaths. If nothing is selected, 0N/A * or there is no RowMapper, this will return -1. 0N/A * Returns true if the row identified by <code>row</code> is selected. 0N/A * Updates this object's mapping from TreePath to rows. This should 0N/A * be invoked when the mapping from TreePaths to integers has changed 0N/A * (for example, a node has been expanded). 0N/A * <p>You do not normally have to call this, JTree and its associated 0N/A * Listeners will invoke this for you. If you are implementing your own 0N/A * View class, then you will have to invoke this. 0N/A * <p>This will invoke <code>insureRowContinuity</code> to make sure 0N/A * the currently selected TreePaths are still valid based on the 0N/A // Lead selection path doesn't have to be in the selection. 0N/A * Returns the lead selection index. That is the last index that was 0N/A * Returns the last path that was added. This may differ from the 0N/A * leadSelectionPath property maintained by the JTree. 0N/A * Adds a PropertyChangeListener to the listener list. 0N/A * The listener is registered for all properties. 0N/A * A PropertyChangeEvent will get fired when the selection mode 0N/A * @param listener the PropertyChangeListener to be added 0N/A * Removes a PropertyChangeListener from the listener list. 0N/A * This removes a PropertyChangeListener that was registered 0N/A * for all properties. 0N/A * @param listener the PropertyChangeListener to be removed 0N/A * Returns an array of all the property change listeners 0N/A * registered on this <code>DefaultTreeSelectionModel</code>. 0N/A * @return all of this model's <code>PropertyChangeListener</code>s 0N/A * array if no property change listeners are currently registered 0N/A * @see #addPropertyChangeListener 0N/A * @see #removePropertyChangeListener 0N/A * Makes sure the currently selected <code>TreePath</code>s are valid 0N/A * for the current selection mode. 0N/A * If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code> 0N/A * and a <code>RowMapper</code> exists, this will make sure all 0N/A * the rows are contiguous, that is, when sorted all the rows are 0N/A * in order with no gaps. 0N/A * If the selection isn't contiguous, the selection is 0N/A * reset to contain the first set, when sorted, of contiguous rows. 0N/A * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and 0N/A * more than one TreePath is selected, the selection is reset to 0N/A * contain the first path currently selected. 0N/A // find the actual selection pathes corresponded to the 0N/A // rows of the new selection 0N/A * Returns true if the paths are contiguous, 0N/A * or this object has no RowMapper. 0N/A * Used to test if a particular set of <code>TreePath</code>s can 0N/A * be added. This will return true if <code>paths</code> is null (or 0N/A * empty), or this object has no RowMapper, or nothing is currently selected, 0N/A * or the selection mode is <code>DISCONTIGUOUS_TREE_SELECTION</code>, or 0N/A * adding the paths to the current selection still results in a 0N/A * contiguous set of <code>TreePath</code>s. 0N/A * Returns true if the paths can be removed without breaking the 0N/A * continuity of the model. 0N/A * This is rather expensive. 0N/A /* Determine the rows for the removed entries. */ 0N/A /* Make sure they are contiguous. */ 1635N/A * Notifies listeners of a change in path. changePaths should contain 1635N/A * instances of PathPlaceHolder. 1635N/A * @deprecated As of JDK version 1.7 0N/A * Updates the leadIndex instance variable. 0N/A // Can use == here since we know leadPath came from 0N/A * This method is obsolete and its implementation is now a noop. It's 0N/A * still called by setSelectionPaths and addSelectionPaths, but only 0N/A * for backwards compatability. 0N/A * Returns a string that displays and identifies this 0N/A * object's properties. 0N/A * @return a String representation of this object 0N/A * Returns a clone of this object with the same selection. 0N/A * This method does not duplicate 0N/A * selection listeners and property listeners. 0N/A * @exception CloneNotSupportedException never thrown by instances of 0N/A // Serialization support. 0N/A // Save the rowMapper, if it implements Serializable 0N/A * Holds a path and whether or not it is new.