< prev index next >

src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java

Print this page

        

*** 44,62 **** * to be able to track row changes you may wish to become a listener * for expansion events on the tree and test for changes from there. * <p>resetRowSelection is called from any of the methods that update * the selected paths. If you subclass any of these methods to * filter what is allowed to be selected, be sure and message ! * <code>resetRowSelection</code> if you do not message super. * * <strong>Warning:</strong> * 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 JavaBeans&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.JTree * * @author Scott Violet --- 44,62 ---- * to be able to track row changes you may wish to become a listener * for expansion events on the tree and test for changes from there. * <p>resetRowSelection is called from any of the methods that update * the selected paths. If you subclass any of these methods to * filter what is allowed to be selected, be sure and message ! * {@code resetRowSelection} if you do not message super. * * <strong>Warning:</strong> * 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 JavaBeans&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.JTree * * @author Scott Violet
*** 95,105 **** protected int leadIndex; /** Lead row. */ protected int leadRow; /** Used to make sure the paths are unique, will contain all the paths ! * in <code>selection</code>. */ private Hashtable<TreePath, Boolean> uniquePaths; private Hashtable<TreePath, Boolean> lastPaths; private TreePath[] tempPaths; --- 95,105 ---- protected int leadIndex; /** Lead row. */ protected int leadRow; /** Used to make sure the paths are unique, will contain all the paths ! * in {@code selection}. */ private Hashtable<TreePath, Boolean> uniquePaths; private Hashtable<TreePath, Boolean> lastPaths; private TreePath[] tempPaths;
*** 136,154 **** /** * Sets the selection model, which must be one of SINGLE_TREE_SELECTION, * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. If mode * is not one of the defined value, ! * <code>DISCONTIGUOUS_TREE_SELECTION</code> is assumed. * <p>This may change the selection if the current selection is not valid * for the new mode. For example, if three TreePaths are ! * selected when the mode is changed to <code>SINGLE_TREE_SELECTION</code>, * only one TreePath will remain selected. It is up to the particular * implementation to decide what TreePath remains selected. * <p> * Setting the mode to something other than the defined types will ! * result in the mode becoming <code>DISCONTIGUOUS_TREE_SELECTION</code>. */ public void setSelectionMode(int mode) { int oldMode = selectionMode; selectionMode = validateSelectionMode(mode); --- 136,154 ---- /** * Sets the selection model, which must be one of SINGLE_TREE_SELECTION, * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. If mode * is not one of the defined value, ! * {@code DISCONTIGUOUS_TREE_SELECTION} is assumed. * <p>This may change the selection if the current selection is not valid * for the new mode. For example, if three TreePaths are ! * selected when the mode is changed to {@code SINGLE_TREE_SELECTION}, * only one TreePath will remain selected. It is up to the particular * implementation to decide what TreePath remains selected. * <p> * Setting the mode to something other than the defined types will ! * result in the mode becoming {@code DISCONTIGUOUS_TREE_SELECTION}. */ public void setSelectionMode(int mode) { int oldMode = selectionMode; selectionMode = validateSelectionMode(mode);
*** 164,185 **** && mode != TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) ? TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION : mode; } /** ! * Returns the selection mode, one of <code>SINGLE_TREE_SELECTION</code>, ! * <code>DISCONTIGUOUS_TREE_SELECTION</code> or ! * <code>CONTIGUOUS_TREE_SELECTION</code>. */ public int getSelectionMode() { return selectionMode; } /** * Sets the selection to path. If this represents a change, then ! * the TreeSelectionListeners are notified. If <code>path</code> is ! * null, this has the same effect as invoking <code>clearSelection</code>. * * @param path new path to select */ public void setSelectionPath(TreePath path) { if(path == null) --- 164,185 ---- && mode != TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) ? TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION : mode; } /** ! * Returns the selection mode, one of {@code SINGLE_TREE_SELECTION}, ! * {@code DISCONTIGUOUS_TREE_SELECTION} or ! * {@code CONTIGUOUS_TREE_SELECTION}. */ public int getSelectionMode() { return selectionMode; } /** * Sets the selection to path. If this represents a change, then ! * the TreeSelectionListeners are notified. If {@code path} is ! * null, this has the same effect as invoking {@code clearSelection}. * * @param path new path to select */ public void setSelectionPath(TreePath path) { if(path == null)
*** 299,309 **** } /** * Adds path to the current selection. If path is not currently * in the selection the TreeSelectionListeners are notified. This has ! * no effect if <code>path</code> is null. * * @param path the new path to add to the current selection */ public void addSelectionPath(TreePath path) { if(path != null) { --- 299,309 ---- } /** * Adds path to the current selection. If path is not currently * in the selection the TreeSelectionListeners are notified. This has ! * no effect if {@code path} is null. * * @param path the new path to add to the current selection */ public void addSelectionPath(TreePath path) { if(path != null) {
*** 316,333 **** /** * Adds paths to the current selection. If any of the paths in * paths are not currently in the selection the TreeSelectionListeners * are notified. This has ! * no effect if <code>paths</code> is null. ! * <p>The lead path is set to the last element in <code>paths</code>. ! * <p>If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code>, * and adding the new paths would make the selection discontiguous. ! * Then two things can result: if the TreePaths in <code>paths</code> * are contiguous, then the selection becomes these TreePaths, * otherwise the TreePaths aren't contiguous and the selection becomes ! * the first TreePath in <code>paths</code>. * * @param paths the new path to add to the current selection */ public void addSelectionPaths(TreePath[] paths) { int newPathLength = ((paths == null) ? 0 : paths.length); --- 316,333 ---- /** * Adds paths to the current selection. If any of the paths in * paths are not currently in the selection the TreeSelectionListeners * are notified. This has ! * no effect if {@code paths} is null. ! * <p>The lead path is set to the last element in {@code paths}. ! * <p>If the selection mode is {@code CONTIGUOUS_TREE_SELECTION}, * and adding the new paths would make the selection discontiguous. ! * Then two things can result: if the TreePaths in {@code paths} * are contiguous, then the selection becomes these TreePaths, * otherwise the TreePaths aren't contiguous and the selection becomes ! * the first TreePath in {@code paths}. * * @param paths the new path to add to the current selection */ public void addSelectionPaths(TreePath[] paths) { int newPathLength = ((paths == null) ? 0 : paths.length);
*** 422,432 **** } /** * Removes path from the selection. If path is in the selection * The TreeSelectionListeners are notified. This has no effect if ! * <code>path</code> is null. * * @param path the path to remove from the selection */ public void removeSelectionPath(TreePath path) { if(path != null) { --- 422,432 ---- } /** * Removes path from the selection. If path is in the selection * The TreeSelectionListeners are notified. This has no effect if ! * {@code path} is null. * * @param path the path to remove from the selection */ public void removeSelectionPath(TreePath path) { if(path != null) {
*** 438,448 **** } /** * Removes paths from the selection. If any of the paths in paths * are in the selection the TreeSelectionListeners are notified. ! * This has no effect if <code>paths</code> is null. * * @param paths the paths to remove from the selection */ public void removeSelectionPaths(TreePath[] paths) { if (paths != null && selection != null && paths.length > 0) { --- 438,448 ---- } /** * Removes paths from the selection. If any of the paths in paths * are in the selection the TreeSelectionListeners are notified. ! * This has no effect if {@code paths} is null. * * @param paths the paths to remove from the selection */ public void removeSelectionPaths(TreePath[] paths) { if (paths != null && selection != null && paths.length > 0) {
*** 541,551 **** public int getSelectionCount() { return (selection == null) ? 0 : selection.length; } /** ! * Returns true if the path, <code>path</code>, * is in the current selection. */ public boolean isPathSelected(TreePath path) { return (path != null) ? (uniquePaths.get(path) != null) : false; } --- 541,551 ---- public int getSelectionCount() { return (selection == null) ? 0 : selection.length; } /** ! * Returns true if the path, {@code path}, * is in the current selection. */ public boolean isPathSelected(TreePath path) { return (path != null) ? (uniquePaths.get(path) != null) : false; }
*** 603,613 **** /** * Returns an array of all the tree selection listeners * registered on this model. * ! * @return all of this model's <code>TreeSelectionListener</code>s * or an empty * array if no tree selection listeners are currently registered * * @see #addTreeSelectionListener * @see #removeTreeSelectionListener --- 603,613 ---- /** * Returns an array of all the tree selection listeners * registered on this model. * ! * @return all of this model's {@code TreeSelectionListener}s * or an empty * array if no tree selection listeners are currently registered * * @see #addTreeSelectionListener * @see #removeTreeSelectionListener
*** 650,665 **** * <code><em>Foo</em>Listener</code>s are registered using the * <code>add<em>Foo</em>Listener</code> method. * * <p> * ! * You can specify the <code>listenerType</code> argument * with a class literal, * such as * <code><em>Foo</em>Listener.class</code>. * For example, you can query a ! * <code>DefaultTreeSelectionModel</code> <code>m</code> * for its tree selection listeners with the following code: * * <pre>TreeSelectionListener[] tsls = (TreeSelectionListener[])(m.getListeners(TreeSelectionListener.class));</pre> * * If no such listeners exist, this method returns an empty array. --- 650,665 ---- * <code><em>Foo</em>Listener</code>s are registered using the * <code>add<em>Foo</em>Listener</code> method. * * <p> * ! * You can specify the {@code listenerType} argument * with a class literal, * such as * <code><em>Foo</em>Listener.class</code>. * For example, you can query a ! * {@code DefaultTreeSelectionModel m} * for its tree selection listeners with the following code: * * <pre>TreeSelectionListener[] tsls = (TreeSelectionListener[])(m.getListeners(TreeSelectionListener.class));</pre> * * If no such listeners exist, this method returns an empty array.
*** 668,680 **** * @param listenerType the type of listeners requested * @return an array of all objects registered as * <code><em>Foo</em>Listener</code>s on this component, * or an empty array if no such * listeners have been added ! * @exception ClassCastException if <code>listenerType</code> * doesn't specify a class or interface that implements ! * <code>java.util.EventListener</code> * * @see #getTreeSelectionListeners * @see #getPropertyChangeListeners * * @since 1.3 --- 668,680 ---- * @param listenerType the type of listeners requested * @return an array of all objects registered as * <code><em>Foo</em>Listener</code>s on this component, * or an empty array if no such * listeners have been added ! * @exception ClassCastException if {@code listenerType} * doesn't specify a class or interface that implements ! * {@code java.util.EventListener} * * @see #getTreeSelectionListeners * @see #getPropertyChangeListeners * * @since 1.3
*** 750,760 **** public int getMaxSelectionRow() { return listSelectionModel.getMaxSelectionIndex(); } /** ! * Returns true if the row identified by <code>row</code> is selected. */ public boolean isRowSelected(int row) { return listSelectionModel.isSelectedIndex(row); } --- 750,760 ---- public int getMaxSelectionRow() { return listSelectionModel.getMaxSelectionIndex(); } /** ! * Returns true if the row identified by {@code row} is selected. */ public boolean isRowSelected(int row) { return listSelectionModel.isSelectedIndex(row); }
*** 763,773 **** * be invoked when the mapping from TreePaths to integers has changed * (for example, a node has been expanded). * <p>You do not normally have to call this, JTree and its associated * Listeners will invoke this for you. If you are implementing your own * View class, then you will have to invoke this. ! * <p>This will invoke <code>insureRowContinuity</code> to make sure * the currently selected TreePaths are still valid based on the * selection mode. */ public void resetRowSelection() { listSelectionModel.clearSelection(); --- 763,773 ---- * be invoked when the mapping from TreePaths to integers has changed * (for example, a node has been expanded). * <p>You do not normally have to call this, JTree and its associated * Listeners will invoke this for you. If you are implementing your own * View class, then you will have to invoke this. ! * <p>This will invoke {@code insureRowContinuity} to make sure * the currently selected TreePaths are still valid based on the * selection mode. */ public void resetRowSelection() { listSelectionModel.clearSelection();
*** 851,863 **** changeSupport.removePropertyChangeListener(listener); } /** * Returns an array of all the property change listeners ! * registered on this <code>DefaultTreeSelectionModel</code>. * ! * @return all of this model's <code>PropertyChangeListener</code>s * or an empty * array if no property change listeners are currently registered * * @see #addPropertyChangeListener * @see #removePropertyChangeListener --- 851,863 ---- changeSupport.removePropertyChangeListener(listener); } /** * Returns an array of all the property change listeners ! * registered on this {@code DefaultTreeSelectionModel}. * ! * @return all of this model's {@code PropertyChangeListener}s * or an empty * array if no property change listeners are currently registered * * @see #addPropertyChangeListener * @see #removePropertyChangeListener
*** 870,889 **** } return changeSupport.getPropertyChangeListeners(); } /** ! * Makes sure the currently selected <code>TreePath</code>s are valid * for the current selection mode. ! * If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code> ! * and a <code>RowMapper</code> exists, this will make sure all * the rows are contiguous, that is, when sorted all the rows are * in order with no gaps. * If the selection isn't contiguous, the selection is * reset to contain the first set, when sorted, of contiguous rows. * <p> ! * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and * more than one TreePath is selected, the selection is reset to * contain the first path currently selected. */ protected void insureRowContinuity() { if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION && --- 870,889 ---- } return changeSupport.getPropertyChangeListeners(); } /** ! * Makes sure the currently selected {@code TreePath}s are valid * for the current selection mode. ! * If the selection mode is {@code CONTIGUOUS_TREE_SELECTION} ! * and a {@code RowMapper} exists, this will make sure all * the rows are contiguous, that is, when sorted all the rows are * in order with no gaps. * If the selection isn't contiguous, the selection is * reset to contain the first set, when sorted, of contiguous rows. * <p> ! * If the selection mode is {@code SINGLE_TREE_SELECTION} and * more than one TreePath is selected, the selection is reset to * contain the first path currently selected. */ protected void insureRowContinuity() { if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION &&
*** 968,983 **** } return true; } /** ! * Used to test if a particular set of <code>TreePath</code>s can ! * be added. This will return true if <code>paths</code> is null (or * empty), or this object has no RowMapper, or nothing is currently selected, ! * or the selection mode is <code>DISCONTIGUOUS_TREE_SELECTION</code>, or * adding the paths to the current selection still results in a ! * contiguous set of <code>TreePath</code>s. * * @param paths array of {@code TreePaths} to check * @return whether the particular set of {@code TreePaths} can be added */ protected boolean canPathsBeAdded(TreePath[] paths) { --- 968,983 ---- } return true; } /** ! * Used to test if a particular set of {@code TreePath}s can ! * be added. This will return true if {@code paths} is null (or * empty), or this object has no RowMapper, or nothing is currently selected, ! * or the selection mode is {@code DISCONTIGUOUS_TREE_SELECTION}, or * adding the paths to the current selection still results in a ! * contiguous set of {@code TreePath}s. * * @param paths array of {@code TreePaths} to check * @return whether the particular set of {@code TreePaths} can be added */ protected boolean canPathsBeAdded(TreePath[] paths) {
< prev index next >