jdk/src/share/classes/javax/swing/JTree.java
author alexp
Fri, 06 Nov 2009 22:40:58 +0300
changeset 4278 b7a976422d27
parent 3737 83fb4621a129
child 5449 21bec46ee9e3
permissions -rw-r--r--
6878399: public SwingUtilities.getParentViewport() is required Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1639
a97859015238 6785258: Update copyright year
xdono
parents: 1301
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.text.Position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.swing.SwingUtilities2.Section;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static sun.swing.SwingUtilities2.Section.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <a name="jtree_description">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A control that displays a set of hierarchical data as an outline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * You can find task-oriented documentation and examples of using trees in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">How to Use Trees</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * A specific node in a tree can be identified either by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>TreePath</code> (an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * that encapsulates a node and all of its ancestors), or by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * display row, where each row in the display area displays one node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * An <i>expanded</i> node is a non-leaf node (as identified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>TreeModel.isLeaf(node)</code> returning false) that will displays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * its children when all its ancestors are <i>expanded</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * A <i>collapsed</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * node is one which hides them. A <i>hidden</i> node is one which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * under a collapsed ancestor. All of a <i>viewable</i> nodes parents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * are expanded, but may or may not be displayed. A <i>displayed</i> node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * is both viewable and in the display area, where it can be seen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The following <code>JTree</code> methods use "visible" to mean "displayed":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <li><code>isRootVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <li><code>setRootVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <li><code>scrollPathToVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <li><code>scrollRowToVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <li><code>getVisibleRowCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <li><code>setVisibleRowCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * The next group of <code>JTree</code> methods use "visible" to mean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * "viewable" (under an expanded parent):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <li><code>isVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <li><code>makeVisible()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * If you are interested in knowing when the selection changes implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * the <code>TreeSelectionListener</code> interface and add the instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * using the method <code>addTreeSelectionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>valueChanged</code> will be invoked when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * selection changes, that is if the user clicks twice on the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * node <code>valueChanged</code> will only be invoked once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * If you are interested in detecting either double-click events or when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * a user clicks on a node, regardless of whether or not it was selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * we recommend you do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * final JTree tree = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * MouseListener ml = new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *     public void <b>mousePressed</b>(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *         int selRow = tree.getRowForLocation(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *         TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *         if(selRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *             if(e.getClickCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *                 mySingleClick(selRow, selPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *             else if(e.getClickCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *                 myDoubleClick(selRow, selPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * tree.addMouseListener(ml);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * NOTE: This example obtains both the path and row, but you only need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * get the one you're interested in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * To use <code>JTree</code> to display compound nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * (for example, nodes containing both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * a graphic icon and text), subclass {@link TreeCellRenderer} and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * {@link #setCellRenderer} to tell the tree to use it. To edit such nodes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * subclass {@link TreeCellEditor} and use {@link #setCellEditor}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * Like all <code>JComponent</code> classes, you can use {@link InputMap} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * {@link ActionMap}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * to associate an {@link Action} object with a {@link KeyStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * and execute the action under specified conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * description: A component that displays a set of hierarchical data as an outline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * @author Rob Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * @author Ray Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
public class JTree extends JComponent implements Scrollable, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final String uiClassID = "TreeUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * The model that defines the tree displayed by this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    transient protected TreeModel        treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Models the set of selected nodes in this tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    transient protected TreeSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * True if the root node is displayed, false if its children are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * the highest visible nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected boolean                    rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * The cell used to draw nodes. If <code>null</code>, the UI uses a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <code>cellRenderer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    transient protected TreeCellRenderer  cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Height to use for each display row. If this is <= 0 the renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * determines the height for each row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected int                         rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private boolean                       rowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Maps from <code>TreePath</code> to <code>Boolean</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * indicating whether or not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * particular path is expanded. This ONLY indicates whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * given path is expanded, and NOT if it is visible or not. That
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * information must be determined by visiting all the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * paths and seeing if they are visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   190
    transient private Hashtable<TreePath, Boolean> expandedState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * True if handles are displayed at the topmost level of the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * A handle is a small icon that displays adjacent to the node which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * allows the user to click once to expand or collapse the node. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * common interface shows a plus sign (+) for a node which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * expanded and a minus sign (-) for a node which can be collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Handles are always shown for nodes below the topmost level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * If the <code>rootVisible</code> setting specifies that the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * node is to be displayed, then that is the only node at the topmost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * level. If the root node is not displayed, then all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * children are at the topmost level of the tree. Handles are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * always displayed for nodes other than the topmost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * If the root node isn't visible, it is generally a good to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * this value true. Otherwise, the tree looks exactly like a list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * and users may not know that the "list entries" are actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * tree nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see #rootVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    protected boolean           showsRootHandles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private boolean             showsRootHandlesSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Creates a new event and passed it off the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>selectionListeners</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected transient TreeSelectionRedirector selectionRedirector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Editor for the entries.  Default is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * (tree is not editable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    transient protected TreeCellEditor          cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Is the tree editable? Default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    protected boolean                 editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Is this tree a large model? This is a code-optimization setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * A large model can be used when the cell height is the same for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * nodes. The UI will then cache very little information and instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * continually message the model. Without a large model the UI caches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * most of the information, resulting in fewer method calls to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * This value is only a suggestion to the UI. Not all UIs will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * take advantage of it. Default value is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected boolean                 largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Number of rows to make visible at one time. This value is used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * the <code>Scrollable</code> interface. It determines the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * size of the display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected int                     visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * If true, when editing is to be stopped by way of selection changing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * data in tree changing or other means <code>stopCellEditing</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * is invoked, and changes are saved. If false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <code>cancelCellEditing</code> is invoked, and changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * are discarded. Default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected boolean                 invokesStopCellEditing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * If true, when a node is expanded, as many of the descendants are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * scrolled to be visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    protected boolean                 scrollsOnExpand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private boolean                   scrollsOnExpandSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Number of mouse clicks before a node is expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    protected int                     toggleClickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Updates the <code>expandedState</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    transient protected TreeModelListener       treeModelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Used when <code>setExpandedState</code> is invoked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * will be a <code>Stack</code> of <code>Stack</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   284
    transient private Stack<Stack<TreePath>> expandedStack;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Lead selection path, may not be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private TreePath                  leadPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Anchor path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private TreePath                  anchorPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * True if paths in the selection should be expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private boolean                   expandsSelectedPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * This is set to true for the life of the <code>setUI</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private boolean                   settingUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /** If true, mouse presses on selections initiate a drag operation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private boolean dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * The drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private DropMode dropMode = DropMode.USE_SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * The drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private transient DropLocation dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * A subclass of <code>TransferHandler.DropLocation</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * a drop location for a <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public static final class DropLocation extends TransferHandler.DropLocation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        private final TreePath path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        private final int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        private DropLocation(Point p, TreePath path, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            super(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * Returns the index where the dropped data should be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * with respect to the path returned by <code>getPath()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * For drop modes <code>DropMode.USE_SELECTION</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * <code>DropMode.ON</code>, this index is unimportant (and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * always be <code>-1</code>) as the only interesting data is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * path over which the drop operation occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * For drop mode <code>DropMode.INSERT</code>, this index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * indicates the index at which the data should be inserted into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * the parent path represented by <code>getPath()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * <code>-1</code> indicates that the drop occurred over the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * parent itself, and in most cases should be treated as inserting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * into either the beginning or the end of the parent's list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * For <code>DropMode.ON_OR_INSERT</code>, this value will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         * an insert index, as described above, or <code>-1</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * the drop occurred over the path itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * @return the child index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * @see #getPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        public int getChildIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * Returns the path where dropped data should be placed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * Interpretation of this value depends on the drop mode set on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * component. If the drop mode is <code>DropMode.USE_SELECTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         * or <code>DropMode.ON</code>, the return value is the path in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * tree over which the data has been (or will be) dropped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         * <code>null</code> indicates that the drop is over empty space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         * not associated with a particular path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         * If the drop mode is <code>DropMode.INSERT</code>, the return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * refers to the path that should become the parent of the new data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * in which case <code>getChildIndex()</code> indicates where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * new item should be inserted into this parent path. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * <code>null</code> path indicates that no parent path has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         * determined, which can happen for multiple reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         *    <li>The tree has no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         *    <li>There is no root in the tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         *    <li>The root is collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         *    <li>The root is a leaf node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * It is up to the developer to decide if and how they wish to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         * the <code>null</code> case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * If the drop mode is <code>DropMode.ON_OR_INSERT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * <code>getChildIndex</code> can be used to determine whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * drop is on top of the path itself (<code>-1</code>) or the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * at which it should be inserted into the path (values other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * <code>-1</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * @return the drop path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * @see #getChildIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        public TreePath getPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * Returns a string representation of this drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * This method is intended to be used for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * and the content and format of the returned string may vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * @return a string representation of this drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return getClass().getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                   + "[dropPoint=" + getDropPoint() + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                   + "path=" + path + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                   + "childIndex=" + index + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * The row to expand during DnD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private int expandRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private class TreeTimer extends Timer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        public TreeTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            super(2000, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            setRepeats(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        public void fireActionPerformed(ActionEvent ae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            JTree.this.expandRow(expandRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * A timer to expand nodes during drop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private TreeTimer dropTimer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * When <code>addTreeExpansionListener</code> is invoked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * and <code>settingUI</code> is true, this ivar gets set to the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <code>Listener</code>. This listener is then notified first in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <code>fireTreeCollapsed</code> and <code>fireTreeExpanded</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p>This is an ugly workaround for a way to have the UI listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * get notified before other listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private transient TreeExpansionListener     uiTreeExpansionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Max number of stacks to keep around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private static int                TEMP_STACK_SIZE = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    // Bound property names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /** Bound property name for <code>cellRenderer</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public final static String        CELL_RENDERER_PROPERTY = "cellRenderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /** Bound property name for <code>treeModel</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public final static String        TREE_MODEL_PROPERTY = "model";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /** Bound property name for <code>rootVisible</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public final static String        ROOT_VISIBLE_PROPERTY = "rootVisible";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /** Bound property name for <code>showsRootHandles</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public final static String        SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /** Bound property name for <code>rowHeight</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public final static String        ROW_HEIGHT_PROPERTY = "rowHeight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /** Bound property name for <code>cellEditor</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    public final static String        CELL_EDITOR_PROPERTY = "cellEditor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /** Bound property name for <code>editable</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public final static String        EDITABLE_PROPERTY = "editable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /** Bound property name for <code>largeModel</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public final static String        LARGE_MODEL_PROPERTY = "largeModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /** Bound property name for selectionModel. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public final static String        SELECTION_MODEL_PROPERTY = "selectionModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /** Bound property name for <code>visibleRowCount</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public final static String        VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /** Bound property name for <code>messagesStopCellEditing</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public final static String        INVOKES_STOP_CELL_EDITING_PROPERTY = "invokesStopCellEditing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /** Bound property name for <code>scrollsOnExpand</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public final static String        SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /** Bound property name for <code>toggleClickCount</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public final static String        TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /** Bound property name for <code>leadSelectionPath</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @since 1.3 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public final static String        LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /** Bound property name for anchor selection path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @since 1.3 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public final static String        ANCHOR_SELECTION_PATH_PROPERTY = "anchorSelectionPath";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /** Bound property name for expands selected paths property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @since 1.3 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public final static String        EXPANDS_SELECTED_PATHS_PROPERTY = "expandsSelectedPaths";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Creates and returns a sample <code>TreeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Used primarily for beanbuilders to show something interesting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @return the default <code>TreeModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    protected static TreeModel getDefaultTreeModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        DefaultMutableTreeNode      root = new DefaultMutableTreeNode("JTree");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        DefaultMutableTreeNode      parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        parent = new DefaultMutableTreeNode("colors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        root.add(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        parent.add(new DefaultMutableTreeNode("blue"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        parent.add(new DefaultMutableTreeNode("violet"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        parent.add(new DefaultMutableTreeNode("red"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        parent.add(new DefaultMutableTreeNode("yellow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        parent = new DefaultMutableTreeNode("sports");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        root.add(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        parent.add(new DefaultMutableTreeNode("basketball"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        parent.add(new DefaultMutableTreeNode("soccer"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        parent.add(new DefaultMutableTreeNode("football"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        parent.add(new DefaultMutableTreeNode("hockey"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        parent = new DefaultMutableTreeNode("food");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        root.add(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        parent.add(new DefaultMutableTreeNode("hot dogs"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        parent.add(new DefaultMutableTreeNode("pizza"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        parent.add(new DefaultMutableTreeNode("ravioli"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        parent.add(new DefaultMutableTreeNode("bananas"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return new DefaultTreeModel(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Returns a <code>TreeModel</code> wrapping the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * If the object is:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <li>an array of <code>Object</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <li>a <code>Hashtable</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <li>a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * </ul>then a new root node is created with each of the incoming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * objects as children. Otherwise, a new root is created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * a value of {@code "root"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @param value  the <code>Object</code> used as the foundation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *          the <code>TreeModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @return a <code>TreeModel</code> wrapping the specified object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    protected static TreeModel createTreeModel(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        DefaultMutableTreeNode           root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if((value instanceof Object[]) || (value instanceof Hashtable) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
           (value instanceof Vector)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            root = new DefaultMutableTreeNode("root");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            DynamicUtilTreeNode.createChildren(root, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            root = new DynamicUtilTreeNode("root", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        return new DefaultTreeModel(root, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Returns a <code>JTree</code> with a sample model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * The default model used by the tree defines a leaf node as any node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * without children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public JTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        this(getDefaultTreeModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Returns a <code>JTree</code> with each element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * specified array as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * child of a new root node which is not displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * By default, the tree defines a leaf node as any node without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @param value  an array of <code>Object</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public JTree(Object[] value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        this(createTreeModel(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        this.setRootVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        this.setShowsRootHandles(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        expandRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Returns a <code>JTree</code> with each element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <code>Vector</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * child of a new root node which is not displayed. By default, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * tree defines a leaf node as any node without children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @param value  a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public JTree(Vector<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        this(createTreeModel(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        this.setRootVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        this.setShowsRootHandles(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        expandRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns a <code>JTree</code> created from a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * which does not display with root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * Each value-half of the key/value pairs in the <code>HashTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * becomes a child of the new root node. By default, the tree defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * a leaf node as any node without children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @param value  a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    public JTree(Hashtable<?,?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        this(createTreeModel(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        this.setRootVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        this.setShowsRootHandles(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        expandRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Returns a <code>JTree</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <code>TreeNode</code> as its root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * which displays the root node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * By default, the tree defines a leaf node as any node without children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @param root  a <code>TreeNode</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public JTree(TreeNode root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        this(root, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Returns a <code>JTree</code> with the specified <code>TreeNode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * as its root, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * displays the root node and which decides whether a node is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * leaf node in the specified manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @param root  a <code>TreeNode</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param asksAllowsChildren  if false, any node without children is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *              leaf node; if true, only nodes that do not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *              children are leaf nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @see DefaultTreeModel#asksAllowsChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public JTree(TreeNode root, boolean asksAllowsChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        this(new DefaultTreeModel(root, asksAllowsChildren));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Returns an instance of <code>JTree</code> which displays the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * -- the tree is created using the specified data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @param newModel  the <code>TreeModel</code> to use as the data model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    @ConstructorProperties({"model"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public JTree(TreeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        super();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   655
        expandedStack = new Stack<Stack<TreePath>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        toggleClickCount = 2;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   657
        expandedState = new Hashtable<TreePath, Boolean>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        rowHeight = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        visibleRowCount = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        rootVisible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        selectionModel = new DefaultTreeSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        cellRenderer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        scrollsOnExpand = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        expandsSelectedPaths = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        setModel(newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Returns the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @return the <code>TreeUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    public TreeUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return (TreeUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * Sets the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @param ui  the <code>TreeUI</code> L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    public void setUI(TreeUI ui) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   694
        if (this.ui != ui) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            settingUI = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            uiTreeExpansionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                settingUI = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Notification from the <code>UIManager</code> that the L&F has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        setUI((TreeUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        SwingUtilities.updateRendererOrEditorUI(getCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        SwingUtilities.updateRendererOrEditorUI(getCellEditor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * Returns the name of the L&F class that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @return the string "TreeUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * Returns the current <code>TreeCellRenderer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *  that is rendering each cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @return the <code>TreeCellRenderer</code> that is rendering each cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public TreeCellRenderer getCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        return cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Sets the <code>TreeCellRenderer</code> that will be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * draw each cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @param x  the <code>TreeCellRenderer</code> that is to render each cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *  description: The TreeCellRenderer that will be used to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *               each cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public void setCellRenderer(TreeCellRenderer x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        TreeCellRenderer oldValue = cellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        cellRenderer = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      * Determines whether the tree is editable. Fires a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      * change event if the new setting is different from the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      * setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
      * @param flag  a boolean value, true if the tree is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
      * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
      *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
      *  description: Whether the tree is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public void setEditable(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        boolean                 oldValue = this.editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        this.editable = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        firePropertyChange(EDITABLE_PROPERTY, oldValue, flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                (oldValue ? AccessibleState.EDITABLE : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                (flag ? AccessibleState.EDITABLE : null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Returns true if the tree is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @return true if the tree is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public boolean isEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        return editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * Sets the cell editor.  A <code>null</code> value implies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * tree cannot be edited.  If this represents a change in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * <code>cellEditor</code>, the <code>propertyChange</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * method is invoked on all listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @param cellEditor the <code>TreeCellEditor</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *  description: The cell editor. A null value implies the tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *               cannot be edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public void setCellEditor(TreeCellEditor cellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        TreeCellEditor        oldEditor = this.cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        this.cellEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        firePropertyChange(CELL_EDITOR_PROPERTY, oldEditor, cellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Returns the editor used to edit entries in the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @return the <code>TreeCellEditor</code> in use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *          or <code>null</code> if the tree cannot be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    public TreeCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        return cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Returns the <code>TreeModel</code> that is providing the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return the <code>TreeModel</code> that is providing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public TreeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        return treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Sets the <code>TreeModel</code> that will provide the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @param newModel the <code>TreeModel</code> that is to provide the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *  description: The TreeModel that will provide the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    public void setModel(TreeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        TreeModel oldModel = treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        if(treeModel != null && treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            treeModel.removeTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                treeModel.removeTreeModelListener((TreeModelListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (newModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                newModel.addTreeModelListener((TreeModelListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        treeModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        clearToggledPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            if(treeModelListener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                treeModelListener = createTreeModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            if(treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            // Mark the root as expanded, if it isn't a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            if(treeModel.getRoot() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
               !treeModel.isLeaf(treeModel.getRoot())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                expandedState.put(new TreePath(treeModel.getRoot()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                                  Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        firePropertyChange(TREE_MODEL_PROPERTY, oldModel, treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Returns true if the root node of the tree is displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @return true if the root node of the tree is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @see #rootVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    public boolean isRootVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        return rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * Determines whether or not the root node from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * the <code>TreeModel</code> is visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @param rootVisible true if the root node of the tree is to be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @see #rootVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *  description: Whether or not the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *               from the TreeModel is visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    public void setRootVisible(boolean rootVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        boolean                oldValue = this.rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        this.rootVisible = rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, this.rootVisible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Sets the value of the <code>showsRootHandles</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * which specifies whether the node handles should be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * The default value of this property depends on the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * used to create the <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Some look and feels might not support handles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @param newValue <code>true</code> if root handles should be displayed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *                 otherwise, <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @see #showsRootHandles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @see #getShowsRootHandles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *  description: Whether the node handles are to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *               displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    public void setShowsRootHandles(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        boolean                oldValue = showsRootHandles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        TreeModel              model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        showsRootHandles = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        showsRootHandlesSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                           showsRootHandles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Returns the value of the <code>showsRootHandles</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @return the value of the <code>showsRootHandles</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @see #showsRootHandles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    public boolean getShowsRootHandles()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        return showsRootHandles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * Sets the height of each cell, in pixels.  If the specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * is less than or equal to zero the current cell renderer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * queried for each row's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @param rowHeight the height of each cell, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *  description: The height of each cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    public void setRowHeight(int rowHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        int                oldValue = this.rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        this.rowHeight = rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        rowHeightSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, this.rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * Returns the height of each row.  If the returned value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * or equal to 0 the height for each row is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    public int getRowHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * Returns true if the height of each display row is a fixed size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @return true if the height of each row is a fixed size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public boolean isFixedRowHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        return (rowHeight > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Specifies whether the UI should use a large model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * (Not all UIs will implement this.) Fires a property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * for the LARGE_MODEL_PROPERTY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @param newValue true to suggest a large model to the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @see #largeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *  description: Whether the UI should use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *               large model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    public void setLargeModel(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        boolean                oldValue = largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        largeModel = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * Returns true if the tree is configured for a large model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * @return true if a large model is suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @see #largeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public boolean isLargeModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        return largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * Determines what happens when editing is interrupted by selecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * another node in the tree, a change in the tree's data, or by some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * other means. Setting this property to <code>true</code> causes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * changes to be automatically saved when editing is interrupted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @param newValue true means that <code>stopCellEditing</code> is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *        when editing is interrupted, and data is saved; false means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *        <code>cancelCellEditing</code> is invoked, and changes are lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     *  description: Determines what happens when editing is interrupted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *               selecting another node in the tree, a change in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *               tree's data, or some other means.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    public void setInvokesStopCellEditing(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        boolean                  oldValue = invokesStopCellEditing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        invokesStopCellEditing = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                           newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * Returns the indicator that tells what happens when editing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * interrupted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @return the indicator that tells what happens when editing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *         interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @see #setInvokesStopCellEditing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    public boolean getInvokesStopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return invokesStopCellEditing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * Sets the <code>scrollsOnExpand</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * which determines whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * tree might scroll to show previously hidden children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * If this property is <code>true</code> (the default),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * when a node expands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * the tree can use scrolling to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * the maximum possible number of the node's descendants visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * In some look and feels, trees might not need to scroll when expanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * those look and feels will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * @param newValue <code>false</code> to disable scrolling on expansion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *                 <code>true</code> to enable it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @see #getScrollsOnExpand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *  description: Indicates if a node descendant should be scrolled when expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    public void setScrollsOnExpand(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        boolean           oldValue = scrollsOnExpand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        scrollsOnExpand = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        scrollsOnExpandSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                           newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * Returns the value of the <code>scrollsOnExpand</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @return the value of the <code>scrollsOnExpand</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    public boolean getScrollsOnExpand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        return scrollsOnExpand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * Sets the number of mouse clicks before a node will expand or close.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * The default is two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *  description: Number of clicks before a node will expand/collapse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    public void setToggleClickCount(int clickCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        int         oldCount = toggleClickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        toggleClickCount = clickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                           clickCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * Returns the number of mouse clicks needed to expand or close a node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * @return number of mouse clicks before node is expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    public int getToggleClickCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        return toggleClickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * Configures the <code>expandsSelectedPaths</code> property. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * true, any time the selection is changed, either via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * <code>TreeSelectionModel</code>, or the cover methods provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * <code>JTree</code>, the <code>TreePath</code>s parents will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * expanded to make them visible (visible meaning the parent path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * expanded, not necessarily in the visible rectangle of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * <code>JTree</code>). If false, when the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * changes the nodes parent is not made visible (all its parents expanded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * This is useful if you wish to have your selection model maintain paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * that are not always visible (all parents expanded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @param newValue the new value for <code>expandsSelectedPaths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     *  description: Indicates whether changes to the selection should make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *               the parent of the path visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public void setExpandsSelectedPaths(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        boolean         oldValue = expandsSelectedPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        expandsSelectedPaths = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                           newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * Returns the <code>expandsSelectedPaths</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @return true if selection changes result in the parent path being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *         expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see #setExpandsSelectedPaths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    public boolean getExpandsSelectedPaths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        return expandsSelectedPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Turns on or off automatic drag handling. In order to enable automatic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * drag handling, this property should be set to {@code true}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * tree's {@code TransferHandler} needs to be {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * The default value of the {@code dragEnabled} property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * The job of honoring this property, and recognizing a user drag gesture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * lies with the look and feel implementation, and in particular, the tree's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * {@code TreeUI}. When automatic drag handling is enabled, most look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * feels (including those that subclass {@code BasicLookAndFeel}) begin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * drag and drop operation whenever the user presses the mouse button over
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * an item and then moves the mouse a few pixels. Setting this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * {@code true} can therefore have a subtle effect on how selections behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * If a look and feel is used that ignores this property, you can still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * begin a drag and drop operation by calling {@code exportAsDrag} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * tree's {@code TransferHandler}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * @param b whether or not to enable automatic drag handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *  description: determines whether automatic drag handling is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    public void setDragEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        dragEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * Returns whether or not automatic drag handling is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @return the value of the {@code dragEnabled} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * Sets the drop mode for this component. For backward compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * the default for this property is <code>DropMode.USE_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * Usage of one of the other modes is recommended, however, for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * improved user experience. <code>DropMode.ON</code>, for instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * offers similar behavior of showing items as selected, but does so without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * affecting the actual selection in the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * <code>JTree</code> supports the following drop modes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *    <li><code>DropMode.USE_SELECTION</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *    <li><code>DropMode.ON</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     *    <li><code>DropMode.INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *    <li><code>DropMode.ON_OR_INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * The drop mode is only meaningful if this component has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * <code>TransferHandler</code> that accepts drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * @param dropMode the drop mode to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * @throws IllegalArgumentException if the drop mode is unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     *         or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * @see #getDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    public final void setDropMode(DropMode dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        if (dropMode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            switch (dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    this.dropMode = dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for tree");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * Returns the drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @return the drop mode for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    public final DropMode getDropMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        return dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * Calculates a drop location in this component, representing where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * drop at the given point should insert data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * @param p the point to calculate a drop location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * @return the drop location, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    DropLocation dropLocationForPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        DropLocation location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        int row = getClosestRowForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        Rectangle bounds = getRowBounds(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        TreeModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        Object root = (model == null) ? null : model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        TreePath rootPath = (root == null) ? null : new TreePath(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1301
        TreePath child;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1302
        TreePath parent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        boolean outside = row == -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                          || p.y < bounds.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                          || p.y >= bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        switch(dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                if (outside) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    location = new DropLocation(p, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    location = new DropLocation(p, getPathForRow(row), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    if (root != null && !model.isLeaf(root) && isExpanded(rootPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                        location = new DropLocation(p, rootPath, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                        location = new DropLocation(p, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                boolean checkOn = dropMode == DropMode.ON_OR_INSERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                  || !model.isLeaf(getPathForRow(row).getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                Section section = SwingUtilities2.liesInVertical(bounds, p, checkOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                if(section == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                    child = getPathForRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    parent = child.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                } else if (section == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                    int index = row + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                    if (index >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                        if (model.isLeaf(root) || !isExpanded(rootPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                            location = new DropLocation(p, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                            parent = rootPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                            index = model.getChildCount(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                            location = new DropLocation(p, parent, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                    child = getPathForRow(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                    parent = child.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                    assert checkOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                    location = new DropLocation(p, getPathForRow(row), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                    location = new DropLocation(p, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                        model.getIndexOfChild(parent.getLastPathComponent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                                              child.getLastPathComponent()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                } else if (checkOn || !model.isLeaf(root)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    location = new DropLocation(p, rootPath, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    location = new DropLocation(p, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                assert false : "Unexpected drop mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        if (outside || row != expandRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            cancelDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        if (!outside && row != expandRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            if (isCollapsed(row)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                expandRow = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                startDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * In some cases, the component may need to use it's internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        Object retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        DropLocation treeLocation = (DropLocation)location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        if (dropMode == DropMode.USE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            if (treeLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                if (!forDrop && state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    setSelectionPaths(((TreePath[][])state)[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                    setAnchorSelectionPath(((TreePath[][])state)[1][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    setLeadSelectionPath(((TreePath[][])state)[1][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                if (dropLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                    TreePath[] paths = getSelectionPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                    if (paths == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                        paths = new TreePath[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    retVal = new TreePath[][] {paths,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                            {getAnchorSelectionPath(), getLeadSelectionPath()}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    retVal = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                setSelectionPath(treeLocation.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        DropLocation old = dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        dropLocation = treeLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        firePropertyChange("dropLocation", old, dropLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * Called to indicate to this component that DnD is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * Allows for us to cancel the expand timer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    void dndDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        cancelDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        dropTimer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * Returns the location that this component should visually indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * as the drop location during a DnD operation over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * or {@code null} if no location is to currently be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * This method is not meant for querying the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * from a {@code TransferHandler}, as the drop location is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * set after the {@code TransferHandler}'s <code>canImport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * has returned and has allowed for the location to be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * When this property changes, a property change event with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * name "dropLocation" is fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @return the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @see TransferHandler#canImport(TransferHandler.TransferSupport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    public final DropLocation getDropLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        return dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    private void startDropTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (dropTimer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            dropTimer = new TreeTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        dropTimer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    private void cancelDropTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        if (dropTimer != null && dropTimer.isRunning()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            expandRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            dropTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * Returns <code>isEditable</code>. This is invoked from the UI before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * editing begins to insure that the given path can be edited. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * is provided as an entry point for subclassers to add filtered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * editing without having to resort to creating a new editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @return true if every parent node and the node itself is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * @see #isEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    public boolean isPathEditable(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        return isEditable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * method in order to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * renderer's tips to be used if it has text set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * NOTE: For <code>JTree</code> to properly display tooltips of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * renderers, <code>JTree</code> must be a registered component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * <code>ToolTipManager</code>.  This can be done by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * <code>ToolTipManager.sharedInstance().registerComponent(tree)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * This is not done automatically!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * @param event the <code>MouseEvent</code> that initiated the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     *          <code>ToolTip</code> display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * @return a string containing the  tooltip or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     *          if <code>event</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        if(event != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            Point p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            int selRow = getRowForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            TreeCellRenderer       r = getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            if(selRow != -1 && r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                TreePath     path = getPathForRow(selRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                Object       lastPath = path.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                Component    rComponent = r.getTreeCellRendererComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                    (this, lastPath, isRowSelected(selRow),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                     isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                     true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                if(rComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                    MouseEvent      newEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                    Rectangle       pathBounds = getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                    p.translate(-pathBounds.x, -pathBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    newEvent = new MouseEvent(rComponent, event.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                                          event.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                                              event.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                                              p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                                              event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                                              event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                                              event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                                              event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                                              MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    tip = ((JComponent)rComponent).getToolTipText(newEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        // No tip from the renderer get our own tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        if (tip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            tip = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * Called by the renderers to convert the specified value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * text. This implementation returns <code>value.toString</code>, ignoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * all other arguments. To control the conversion, subclass this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * method and use any of the arguments you need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * @param value the <code>Object</code> to convert to text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * @param selected true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * @param expanded true if the node is expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * @param leaf  true if the node is a leaf node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * @param row  an integer specifying the node's display row, where 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     *             the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @param hasFocus true if the node has the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * @return the <code>String</code> representation of the node's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    public String convertValueToText(Object value, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                     boolean expanded, boolean leaf, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                     boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        if(value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            String sValue = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            if (sValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                return sValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    // The following are convenience methods that get forwarded to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    // current TreeUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * Returns the number of viewable nodes. A node is viewable if all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * parents are expanded. The root is only included in this count if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * {@code isRootVisible()} is {@code true}. This returns {@code 0} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * the UI has not been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * @return the number of viewable nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        TreeUI            tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            return tree.getRowCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * Selects the node identified by the specified path. If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * component of the path is hidden (under a collapsed node), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * <code>getExpandsSelectedPaths</code> is true it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     * exposed (made viewable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     * @param path the <code>TreePath</code> specifying the node to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    public void setSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        getSelectionModel().setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * Selects the nodes identified by the specified array of paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * If any component in any of the paths is hidden (under a collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * node), and <code>getExpandsSelectedPaths</code> is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * it is exposed (made viewable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * @param paths an array of <code>TreePath</code> objects that specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     *          the nodes to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    public void setSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        getSelectionModel().setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     * Sets the path identifies as the lead. The lead may not be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * The lead is not maintained by <code>JTree</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * rather the UI will update it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * @param newPath  the new lead path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *  description: Lead selection path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    public void setLeadSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        TreePath          oldValue = leadPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        leadPath = newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * Sets the path identified as the anchor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * The anchor is not maintained by <code>JTree</code>, rather the UI will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * update it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     * @param newPath  the new anchor path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     *  description: Anchor selection path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    public void setAnchorSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        TreePath          oldValue = anchorPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        anchorPath = newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * Selects the node at the specified row in the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * @param row  the row to select, where 0 is the first row in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     *             the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    public void setSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        int[]             rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        setSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * Selects the nodes corresponding to each of the specified rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * in the display. If a particular element of <code>rows</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * < 0 or >= <code>getRowCount</code>, it will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * If none of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * in <code>rows</code> are valid rows, the selection will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * be cleared. That is it will be as if <code>clearSelection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * @param rows  an array of ints specifying the rows to select,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     *              where 0 indicates the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    public void setSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        TreeUI               ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            for(int counter = 0; counter < numRows; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * Adds the node identified by the specified <code>TreePath</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * to the current selection. If any component of the path isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * viewable, and <code>getExpandsSelectedPaths</code> is true it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * made viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * Note that <code>JTree</code> does not allow duplicate nodes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * exist as children under the same parent -- each sibling must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * a unique object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * @param path the <code>TreePath</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    public void addSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        getSelectionModel().addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     * Adds each path in the array of paths to the current selection. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * any component of any of the paths isn't viewable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * <code>getExpandsSelectedPaths</code> is true, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * made viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * Note that <code>JTree</code> does not allow duplicate nodes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * exist as children under the same parent -- each sibling must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * a unique object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * @param paths an array of <code>TreePath</code> objects that specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     *          the nodes to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    public void addSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        getSelectionModel().addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * Adds the path at the specified row to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * @param row  an integer specifying the row of the node to add,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     *             where 0 is the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    public void addSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        int[]      rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        addSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * Adds the paths at each of the specified rows to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * @param rows  an array of ints specifying the rows to add,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     *              where 0 indicates the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    public void addSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        TreeUI             ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            for(int counter = 0; counter < numRows; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * Returns the last path component of the selected path. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * a convenience method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * {@code getSelectionModel().getSelectionPath().getLastPathComponent()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * This is typically only useful if the selection has one path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * @return the last path component of the selected path, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     *         <code>null</code> if nothing is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * @see TreePath#getLastPathComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    public Object getLastSelectedPathComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        TreePath     selPath = getSelectionModel().getSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        if(selPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
            return selPath.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * Returns the path identified as the lead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * @return path identified as the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    public TreePath getLeadSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        return leadPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * Returns the path identified as the anchor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * @return path identified as the anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    public TreePath getAnchorSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        return anchorPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * Returns the path to the first selected node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * @return the <code>TreePath</code> for the first selected node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     *          or <code>null</code> if nothing is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    public TreePath getSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        return getSelectionModel().getSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * Returns the paths of all selected values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * @return an array of <code>TreePath</code> objects indicating the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     *         nodes, or <code>null</code> if nothing is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    public TreePath[] getSelectionPaths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        return getSelectionModel().getSelectionPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * Returns all of the currently selected rows. This method is simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * forwarded to the <code>TreeSelectionModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * If nothing is selected <code>null</code> or an empty array will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * be returned, based on the <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     * @return an array of integers that identifies all currently selected rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     *         where 0 is the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    public int[] getSelectionRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        return getSelectionModel().getSelectionRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * Returns the number of nodes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * @return the number of nodes selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
    public int getSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        return selectionModel.getSelectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * Returns the smallest selected row. If the selection is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * none of the selected paths are viewable, {@code -1} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @return the smallest selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    public int getMinSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        return getSelectionModel().getMinSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * Returns the largest selected row. If the selection is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * none of the selected paths are viewable, {@code -1} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * @return the largest selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
    public int getMaxSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        return getSelectionModel().getMaxSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * Returns the row index corresponding to the lead path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * @return an integer giving the row index of the lead path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     *          where 0 is the first row in the display; or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     *          if <code>leadPath</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    public int getLeadSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        TreePath leadPath = getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        if (leadPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            return getRowForPath(leadPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     * Returns true if the item identified by the path is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * @param path a <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * @return true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
    public boolean isPathSelected(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        return getSelectionModel().isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * Returns true if the node identified by row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * @param row  an integer specifying a display row, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     *             row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * @return true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
    public boolean isRowSelected(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        return getSelectionModel().isRowSelected(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * Returns an <code>Enumeration</code> of the descendants of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * path <code>parent</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * are currently expanded. If <code>parent</code> is not currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * expanded, this will return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * If you expand/collapse nodes while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * iterating over the returned <code>Enumeration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * this may not return all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * the expanded paths, or may return paths that are no longer expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * @param parent  the path which is to be examined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * @return an <code>Enumeration</code> of the descendents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     *          <code>parent</code>, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     *          <code>parent</code> is not currently expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
    public Enumeration<TreePath> getExpandedDescendants(TreePath parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        if(!isExpanded(parent))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1943
        Enumeration<TreePath> toggledPaths = expandedState.keys();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1944
        Vector<TreePath> elements = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        TreePath          path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        Object            value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        if(toggledPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            while(toggledPaths.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1950
                path = toggledPaths.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                value = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                // Add the path if it is expanded, a descendant of parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                // and it is visible (all parents expanded). This is rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                // expensive!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                if(path != parent && value != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                   ((Boolean)value).booleanValue() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                   parent.isDescendant(path) && isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                    if (elements == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1959
                        elements = new Vector<TreePath>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                    elements.addElement(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        if (elements == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            Set<TreePath> empty = Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            return Collections.enumeration(empty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * Returns true if the node identified by the path has ever been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * @return true if the <code>path</code> has ever been expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    public boolean hasBeenExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        return (path != null && expandedState.get(path) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * Returns true if the node identified by the path is currently expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @param path  the <code>TreePath</code> specifying the node to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * @return false if any of the nodes in the node's path are collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     *               true if all nodes in the path are expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    public boolean isExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        if(path == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        // Is this node expanded?
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1993
        Boolean value = expandedState.get(path);
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1994
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1995
        if(value == null || !value.booleanValue())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        // It is, make sure its parent is also expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        if(parentPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            return isExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     * Returns true if the node at the specified display row is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * @return true if the node is currently expanded, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
    public boolean isExpanded(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            TreePath         path = tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            if(path != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2021
                Boolean value = expandedState.get(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                return (value != null && value.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * Returns true if the value identified by path is currently collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * this will return false if any of the values in path are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * not being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * @param path  the <code>TreePath</code> to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * @return true if any of the nodes in the node's path are collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     *               false if all nodes in the path are expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
    public boolean isCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        return !isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * Returns true if the node at the specified display row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * @return true if the node is currently collapsed, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    public boolean isCollapsed(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        return !isExpanded(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * Ensures that the node identified by path is currently viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * @param path  the <code>TreePath</code> to make visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
    public void makeVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            if(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                expandPath(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * Returns true if the value identified by path is currently viewable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * which means it is either the root or all of its parents are expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * Otherwise, this method returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * @return true if the node is viewable, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    public boolean isVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            if(parentPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                return isExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            // Root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * Returns the <code>Rectangle</code> that the specified node will be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * into. Returns <code>null</code> if any component in the path is hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * (under a collapsed parent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     * Note:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * This method returns a valid rectangle, even if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * node is not currently displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * @param path the <code>TreePath</code> identifying the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * @return the <code>Rectangle</code> the node is drawn in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
    public Rectangle getPathBounds(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        TreeUI                   tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            return tree.getPathBounds(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * Returns the <code>Rectangle</code> that the node at the specified row is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * drawn in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * @param row  the row to be drawn, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @return the <code>Rectangle</code> the node is drawn in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    public Rectangle getRowBounds(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        return getPathBounds(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * Makes sure all the path components in path are expanded (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     * for the last path component) and scrolls so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * node identified by the path is displayed. Only works when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * <code>JTree</code> is contained in a <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * @param path  the <code>TreePath</code> identifying the node to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     *          bring into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
    public void scrollPathToVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            makeVisible(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
            Rectangle          bounds = getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
            if(bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                scrollRectToVisible(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                    ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * Scrolls the item identified by row until it is displayed. The minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * of amount of scrolling necessary to bring the row into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * is performed. Only works when this <code>JTree</code> is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * @param row  an integer specifying the row to scroll, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    public void scrollRowToVisible(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        scrollPathToVisible(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     * Returns the path for the specified row.  If <code>row</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     * not visible, or a {@code TreeUI} has not been set, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     * @param row  an integer specifying a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * @return the <code>TreePath</code> to the specified node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     *          <code>null</code> if <code>row < 0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     *          or <code>row >= getRowCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    public TreePath getPathForRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            return tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * Returns the row that displays the node identified by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * @return an integer specifying the display row, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     *         row in the display, or -1 if any of the elements in path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     *         are hidden under a collapsed parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    public int getRowForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            return tree.getRowForPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * expanded and viewable. If the last item in the path is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * leaf, this will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    public void expandPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        // Only expand if not leaf!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        TreeModel          model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        if(path != null && model != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
           !model.isLeaf(path.getLastPathComponent())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            setExpandedState(path, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * Ensures that the node in the specified row is expanded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * If <code>row</code> is < 0 or >= <code>getRowCount</code> this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
    public void expandRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        expandPath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * collapsed and viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
    public void collapsePath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
        setExpandedState(path, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * Ensures that the node in the specified row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * If <code>row</code> is < 0 or >= <code>getRowCount</code> this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
    public void collapseRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        collapsePath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * Returns the path for the node at the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * @return  the <code>TreePath</code> for the node at that location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    public TreePath getPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        TreePath          closestPath = getClosestPathForLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
        if(closestPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            Rectangle       pathBounds = getPathBounds(closestPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
            if(pathBounds != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
               x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
               y >= pathBounds.y && y < (pathBounds.y + pathBounds.height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
                return closestPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     * Returns the row for the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * @return the row corresponding to the location, or -1 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     *         location is not within the bounds of a displayed cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * @see #getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
    public int getRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        return getRowForPath(getPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * no nodes are currently viewable, or there is no model, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * <code>null</code>, otherwise it always returns a valid path.  To test if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * the node is exactly at x, y, get the node's bounds and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     * @return  the <code>TreePath</code> for the node closest to that location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     *          <code>null</code> if nothing is viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     * @see #getPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * @see #getPathBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    public TreePath getClosestPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            return tree.getClosestPathForLocation(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     * Returns the row to the node that is closest to x,y.  If no nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     * are viewable or there is no model, returns -1. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * it always returns a valid row.  To test if the returned object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * exactly at x, y, get the bounds for the node at the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * row and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * @return the row closest to the location, -1 if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     *         viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * @see #getRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * @see #getRowBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
    public int getClosestRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        return getRowForPath(getClosestPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
     * Returns true if the tree is being edited. The item that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
     * edited can be obtained using <code>getSelectionPath</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
     * @return true if the user is currently editing a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * @see #getSelectionPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
    public boolean isEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            return tree.isEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * Ends the current editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * (The <code>DefaultTreeCellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * object saves any edits that are currently in progress on a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * Other implementations may operate differently.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * Has no effect if the tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * <b>Note:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     * To make edit-saves automatic whenever the user changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * their position in the tree, use {@link #setInvokesStopCellEditing}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     * @return true if editing was in progress and is now stopped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     *              false if editing was not in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    public boolean stopEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            return tree.stopEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     * Cancels the current editing session. Has no effect if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
     * tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    public void  cancelEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            tree.cancelEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * Selects the node identified by the specified path and initiates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * editing.  The edit-attempt fails if the <code>CellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * editing for the specified item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    public void startEditingAtPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            tree.startEditingAtPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     * Returns the path to the element that is currently being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * @return  the <code>TreePath</code> for the node being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
    public TreePath getEditingPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            return tree.getEditingPath(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    // Following are primarily convenience methods for mapping from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    // row based selections to path selections.  Sometimes it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    // easier to deal with these than paths (mouse downs, key downs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    // usually just deal with index based selections).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    // Since row based selections require a UI many of these won't work
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
    // without one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     * Sets the tree's selection model. When a <code>null</code> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * specified an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * <code>selectionModel</code> is used, which does not allow selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * @param selectionModel the <code>TreeSelectionModel</code> to use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     *          or <code>null</code> to disable selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * @see TreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     *  description: The tree's selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
    public void setSelectionModel(TreeSelectionModel selectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        if(selectionModel == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            selectionModel = EmptySelectionModel.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        TreeSelectionModel         oldValue = this.selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        if (this.selectionModel != null && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            this.selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
           this.selectionModel.removeTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
           selectionModel.addTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        this.selectionModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        if (selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            this.selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                           this.selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                    AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
                    Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     * Returns the model for selections. This should always return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
     * non-<code>null</code> value. If you don't want to allow anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     * to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     * set the selection model to <code>null</code>, which forces an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
     * selection model to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     * @see #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
    public TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
     * Returns the paths (inclusive) between the specified rows. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
     * the specified indices are within the viewable set of rows, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
     * bound the viewable set of rows, then the indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
     * constrained by the viewable set of rows. If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     * indices are not within the viewable set of rows, or do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * bound the viewable set of rows, then an empty array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * returned. For example, if the row count is {@code 10}, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * method is invoked with {@code -1, 20}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * indices are constrained to the viewable set of rows, and this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     * treated as if invoked with {@code 0, 9}. On the other hand, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * this were invoked with {@code -10, -1}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * indices do not bound the viewable set of rows, and an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * array is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * getPathBetweenRows(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * {@code getPathBetweenRows(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * An empty array is returned if the row count is {@code 0}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * the specified indices do not bound the viewable set of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * @param index0 the first index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     * @param index1 the last index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * @return the paths (inclusive) between the specified row indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    protected TreePath[] getPathBetweenRows(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        TreeUI           tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            int rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            if (rowCount > 0 && !((index0 < 0 && index1 < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                                  (index0 >= rowCount && index1 >= rowCount))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                index0 = Math.min(rowCount - 1, Math.max(index0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                index1 = Math.min(rowCount - 1, Math.max(index1, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                int minIndex = Math.min(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                int maxIndex = Math.max(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                TreePath[] selection = new TreePath[
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                        maxIndex - minIndex + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                for(int counter = minIndex; counter <= maxIndex; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                    selection[counter - minIndex] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                            tree.getPathForRow(this, counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
        return new TreePath[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * Selects the rows in the specified interval (inclusive). If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * the viewable set of rows, then the specified rows are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * the selection is cleared. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * specified indices bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * invoked with {@code -10, -1}, then the specified indices do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * bound the viewable set of rows, and the selection is cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * setSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * {@code setSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
     * @param index0 the first index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     * @param index1 the last index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
    public void setSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        this.getSelectionModel().setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * Adds the specified rows (inclusive) to the selection. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     * specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * the viewable set of rows, then the specified indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * constrained by the viewable set of rows. If the indices are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * within the viewable set of rows, or do not bound the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * set of rows, then the selection is unchanged. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * the row count is {@code 10}, and this method is invoked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * {@code -1, 20}, then the specified indices bounds the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * range, and this is treated as if invoked with {@code 0, 9}. On
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * the other hand, if this were invoked with {@code -10, -1}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * the specified indices do not bound the viewable set of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * addSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * {@code addSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     * @param index0 the first index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * @param index1 the last index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    public void addSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
            this.getSelectionModel().addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * Removes the specified rows (inclusive) from the selection. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * the viewable set of rows, then the specified indices are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * the selection is unchanged. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * specified range bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     * invoked with {@code -10, -1}, then the specified range does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * bound the viewable set of rows, and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * removeSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * {@code removeSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * @param index0 the first row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * @param index1 the last row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
    public void removeSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     * Removes the node identified by the specified path from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
    public void removeSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
        this.getSelectionModel().removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * Removes the nodes identified by the specified paths from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * @param paths an array of <code>TreePath</code> objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     *              specifies the nodes to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    public void removeSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
        this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * Removes the row at the index <code>row</code> from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     * @param row  the row to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
    public void removeSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        int[]             rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
        removeSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * Removes the rows that are selected at each of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * @param rows  an array of ints specifying display rows, where 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     *             the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    public void removeSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        TreeUI             ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
            for(int counter = 0; counter < numRows; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
            removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     * Clears the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
        getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     * Returns true if the selection is currently empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     * @return true if the selection is currently empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
    public boolean isSelectionEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
        return getSelectionModel().isSelectionEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
     * Adds a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
     * @param tel a TreeExpansionListener that will be notified when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
     *            a tree node is expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
    public void addTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
        if (settingUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            uiTreeExpansionListener = tel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
        listenerList.add(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
     * Removes a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * @param tel the <code>TreeExpansionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
    public void removeTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
        listenerList.remove(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
        if (uiTreeExpansionListener == tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
            uiTreeExpansionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
     * Returns an array of all the <code>TreeExpansionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
     * to this JTree with addTreeExpansionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     * @return all of the <code>TreeExpansionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
    public TreeExpansionListener[] getTreeExpansionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2707
        return listenerList.getListeners(TreeExpansionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     * Adds a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     * @param tel a <code>TreeWillExpandListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     *            when a tree node will be expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
    public void addTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
        listenerList.add(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     * Removes a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
     * @param tel the <code>TreeWillExpandListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
    public void removeTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        listenerList.remove(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * Returns an array of all the <code>TreeWillExpandListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * to this JTree with addTreeWillExpandListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * @return all of the <code>TreeWillExpandListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
    public TreeWillExpandListener[] getTreeWillExpandListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2739
        return listenerList.getListeners(TreeWillExpandListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     public void fireTreeExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            uiTreeExpansionListener.treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
                    treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     *          collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    public void fireTreeCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            uiTreeExpansionListener.treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
                    treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
     public void fireTreeWillExpand(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                    treeWillExpand(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
     public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                    treeWillCollapse(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     * Adds a listener for <code>TreeSelection</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     * @param tsl the <code>TreeSelectionListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
     *            when a node is selected or deselected (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
     *            selection")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
    public void addTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        listenerList.add(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
           && selectionRedirector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     * Removes a <code>TreeSelection</code> listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     * @param tsl the <code>TreeSelectionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
    public void removeTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
        listenerList.remove(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        if(listenerList.getListenerCount(TreeSelectionListener.class) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
           && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
            selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
            selectionRedirector = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * Returns an array of all the <code>TreeSelectionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * to this JTree with addTreeSelectionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     * @return all of the <code>TreeSelectionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
    public TreeSelectionListener[] getTreeSelectionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2896
        return listenerList.getListeners(TreeSelectionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     * @param e the <code>TreeSelectionEvent</code> to be fired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     *          generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     *          <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     *          when a node is selected or deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
    protected void fireValueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
            // TreeSelectionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
            if (listeners[i]==TreeSelectionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
                // e = new ListSelectionEvent(this, firstIndex, lastIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
                ((TreeSelectionListener)listeners[i+1]).valueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * Sent when the tree has changed enough that we need to resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * the bounds, but not enough that we need to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     * expanded node set (e.g nodes were expanded or collapsed, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     * nodes were inserted into the tree). You should never have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * invoke this, the UI will invoke this as it needs to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
    public void treeDidChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     * Sets the number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
     * This will only work if the tree is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * <code>JScrollPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     * and will adjust the preferred size and size of that scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * @param newCount the number of rows to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     *  description: The number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
    public void setVisibleRowCount(int newCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        int                 oldCount = visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        visibleRowCount = newCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
        firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
                           visibleRowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
            ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
     * Returns the number of rows that are displayed in the display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
     * @return the number of rows displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
    public int getVisibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
        return visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
     * Expands the root path, assuming the current TreeModel has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
    private void expandRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
        TreeModel              model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        if(model != null && model.getRoot() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            expandPath(new TreePath(model.getRoot()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
     * Returns the TreePath to the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
     * begins with a prefix. To handle the conversion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
     * <code>TreePath</code> into a String, <code>convertValueToText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
     * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
     * @param prefix the string to test for a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
     * @param startingRow the row for starting the search
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
     * @param bias the search direction, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
     * Position.Bias.Forward or Position.Bias.Backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
     * @return the TreePath of the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
     * starts with the prefix; otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
     * @exception IllegalArgumentException if prefix is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
     * or startingRow is out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
    public TreePath getNextMatch(String prefix, int startingRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                                 Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        int max = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
        if (prefix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
        if (startingRow < 0 || startingRow >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
        prefix = prefix.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
        // start search from the next/previous element froom the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
        // selected element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
        int increment = (bias == Position.Bias.Forward) ? 1 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
        int row = startingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
            TreePath path = getPathForRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
            String text = convertValueToText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
                path.getLastPathComponent(), isRowSelected(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
                isExpanded(row), true, row, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            if (text.toUpperCase().startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
            row = (row + increment + max) % max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
        } while (row != startingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
    private void writeObject(ObjectOutputStream s) throws IOException {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3030
        Vector<Object> values = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
        // Save the cellRenderer, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
        if(cellRenderer != null && cellRenderer instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            values.addElement("cellRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
            values.addElement(cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        // Save the cellEditor, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        if(cellEditor != null && cellEditor instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
            values.addElement("cellEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
            values.addElement(cellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
        // Save the treeModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
        if(treeModel != null && treeModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            values.addElement("treeModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            values.addElement(treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
        // Save the selectionModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
        if(selectionModel != null && selectionModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
            values.addElement("selectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
            values.addElement(selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
        Object      expandedData = getArchivableExpandedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
        if(expandedData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
            values.addElement("expandedState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
            values.addElement(expandedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
        s.writeObject(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
        // Create an instance of expanded state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3077
        expandedState = new Hashtable<TreePath, Boolean>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3078
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3079
        expandedStack = new Stack<Stack<TreePath>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
        Vector          values = (Vector)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
        int             indexCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
        int             maxCounter = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
           equals("cellRenderer")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
            cellRenderer = (TreeCellRenderer)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
           equals("cellEditor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
            cellEditor = (TreeCellEditor)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
           equals("treeModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            treeModel = (TreeModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
           equals("selectionModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
            selectionModel = (TreeSelectionModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
           equals("expandedState")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
            unarchiveExpandedState(values.elementAt(++indexCounter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
        // Reinstall the redirector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
        // Listener to TreeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
            treeModelListener = createTreeModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
            if(treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
                treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * Returns an object that can be archived indicating what nodes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     * expanded and what aren't. The objects from the model are NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * written out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
    private Object getArchivableExpandedState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        TreeModel       model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
        if(model != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3132
            Enumeration<TreePath> paths = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
            if(paths != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3135
                Vector<Object> state = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
                while(paths.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3138
                    TreePath path = paths.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                    Object     archivePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                        archivePath = getModelIndexsForPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                    } catch (Error error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
                        archivePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
                    if(archivePath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
                        state.addElement(archivePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
                        state.addElement(expandedState.get(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
                return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
     * Updates the expanded state of nodes in the tree based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
     * previously archived state <code>state</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
    private void unarchiveExpandedState(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
        if(state instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            Vector          paths = (Vector)state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
            for(int counter = paths.size() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
                Boolean        eState = (Boolean)paths.elementAt(counter--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
                TreePath       path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
                    path = getPathForIndexs((int[])paths.elementAt(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
                    if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
                        expandedState.put(path, eState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
                } catch (Error error) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     * Returns an array of integers specifying the indexs of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     * components in the <code>path</code>. If <code>path</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     * the root, this will return an empty array.  If <code>path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
     * is <code>null</code>, <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
    private int[] getModelIndexsForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            TreeModel   model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
            int         count = path.getPathCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
            int[]       indexs = new int[count - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
            Object      parent = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            for(int counter = 1; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                indexs[counter - 1] = model.getIndexOfChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                                   (parent, path.getPathComponent(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                parent = path.getPathComponent(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                if(indexs[counter - 1] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
            return indexs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     * Returns a <code>TreePath</code> created by obtaining the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * for each of the indices in <code>indexs</code>. If <code>indexs</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     * or the <code>TreeModel</code> is <code>null</code>, it will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
    private TreePath getPathForIndexs(int[] indexs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        if(indexs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
        TreeModel    model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
        if(model == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
        int          count = indexs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        Object       parent = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
        TreePath     parentPath = new TreePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
        for(int counter = 0; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            parent = model.getChild(parent, indexs[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
            parentPath = parentPath.pathByAddingChild(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
        return parentPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
     * <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
     * that does not allow anything to be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
    protected static class EmptySelectionModel extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
              DefaultTreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
         * The single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        protected static final EmptySelectionModel sharedInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
            new EmptySelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
         * Returns the single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
         * @return single instance of {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
        static public EmptySelectionModel sharedInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
            return sharedInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
         * @param paths the paths to select; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
        public void setSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
         * @param paths the paths to add to the selection; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
        public void addSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
         * @param paths the paths to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
        public void removeSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
         * @param mode the selection mode; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
        public void setSelectionMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
         * @param mapper the {@code RowMapper} instance; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        public void setRowMapper(RowMapper mapper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        public void addTreeSelectionListener(TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
        public void removeTreeSelectionListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        public void addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        public void removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     * Handles creating a new <code>TreeSelectionEvent</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
     * <code>JTree</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
     * source and passing it off to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
    protected class TreeSelectionRedirector implements Serializable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                    TreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
         * Invoked by the <code>TreeSelectionModel</code> when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
         * selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
         * @param e the <code>TreeSelectionEvent</code> generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
         *              <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
        public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            TreeSelectionEvent       newE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
            fireValueChanged(newE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
    } // End of class JTree.TreeSelectionRedirector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
    // Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     * Returns the preferred display size of a <code>JTree</code>. The height is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * determined from <code>getVisibleRowCount</code> and the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     * is the current preferred width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
     * @return a <code>Dimension</code> object containing the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        int                 width = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        int                 visRows = getVisibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
        int                 height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
        if(isFixedRowHeight())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
            height = visRows * getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
            TreeUI          ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            if (ui != null && visRows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                int rc = ui.getRowCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                if (rc >= visRows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                    Rectangle bounds = getRowBounds(visRows - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                        height = bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                else if (rc > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                    Rectangle bounds = getRowBounds(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                        height = bounds.height * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
            if (height == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
                height = 16 * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * Returns the amount to increment when scrolling. The amount is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * the height of the first displayed row that isn't completely in view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * or, if it is totally displayed, the height of the next row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * scrolling direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     *          greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * @see JScrollBar#setUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
                                          int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
        if(orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
            Rectangle       rowBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
            int             firstIndex = getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                                         (0, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            if(firstIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                rowBounds = getRowBounds(firstIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
                if(rowBounds.y != visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                    if(direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                        // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                        return Math.max(0, (visibleRect.y - rowBounds.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
                    return (rowBounds.y + rowBounds.height - visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
                if(direction < 0) { // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                    if(firstIndex != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
                        rowBounds = getRowBounds(firstIndex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                        return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
                    return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
        return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
     * Returns the amount for a block increment, which is the height or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
     * width of <code>visibleRect</code>, based on <code>orientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     *          greater than zero for down/right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     * @return the "block" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
     * @see JScrollBar#setBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
                                           int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
        return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
            visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * Returns false to indicate that the width of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     * determine the width of the table, unless the preferred width of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * the tree is smaller than the viewports width.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     * @return whether the tree should track the width of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
    public boolean getScrollableTracksViewportWidth() {
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 3737
diff changeset
  3501
        JViewport port = SwingUtilities.getParentViewport(this);
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
  3502
        if (port != null) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
  3503
            return port.getWidth() > getPreferredSize().width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
     * Returns false to indicate that the height of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
     * determine the height of the table, unless the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
     * of the tree is smaller than the viewports height.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
     * @return whether the tree should track the height of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
    public boolean getScrollableTracksViewportHeight() {
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 3737
diff changeset
  3518
        JViewport port = SwingUtilities.getParentViewport(this);
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
  3519
        if (port != null) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
  3520
            return port.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
     * Sets the expanded state of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * If <code>state</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * true, all parents of <code>path</code> and path are marked as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * expanded. If <code>state</code> is false, all parents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     * <code>path</code> are marked EXPANDED, but <code>path</code> itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
     * is marked collapsed.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
     * This will fail if a <code>TreeWillExpandListener</code> vetos it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
    protected void setExpandedState(TreePath path, boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
            // Make sure all parents of path are expanded.
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3537
            Stack<TreePath> stack;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3538
            TreePath parentPath = path.getParentPath();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
            if (expandedStack.size() == 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3541
                stack = new Stack<TreePath>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
            else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3544
                stack = expandedStack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                while(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                    if(isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                        parentPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
                        stack.push(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
                        parentPath = parentPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
                for(int counter = stack.size() - 1; counter >= 0; counter--) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3558
                    parentPath = stack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
                    if(!isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                            fireTreeWillExpand(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                        } catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                            // Expand vetoed!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                        expandedState.put(parentPath, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                        fireTreeExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
                        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                            ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                                              fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                if (expandedStack.size() < TEMP_STACK_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                    stack.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
                    expandedStack.push(stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
            if(!state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
                // collapse last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
                if(cValue != null && ((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
                        fireTreeWillCollapse(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
                    expandedState.put(path, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
                    fireTreeCollapsed(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
                    if (removeDescendantSelectedPaths(path, false) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
                        !isPathSelected(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
                        // A descendant was selected, select the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
                        addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
                                    fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
                // Expand last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
                if(cValue == null || !((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
                        fireTreeWillExpand(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                    expandedState.put(path, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                    fireTreeExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
                                          fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
     * Returns an <code>Enumeration</code> of <code>TreePaths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
     * that have been expanded that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
     * are descendants of <code>parent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
    protected Enumeration<TreePath>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
        getDescendantToggledPaths(TreePath parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
        if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3638
        Vector<TreePath> descendants = new Vector<TreePath>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3639
        Enumeration<TreePath> nodes = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        while(nodes.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3642
            TreePath path = nodes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
            if(parent.isDescendant(path))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
                descendants.addElement(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
        return descendants.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
     * Removes any descendants of the <code>TreePaths</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
     * <code>toRemove</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
     * that have been expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     * @param toRemove an enumeration of the paths to remove; a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
     *        {@code null} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
     * @throws ClassCastException if {@code toRemove} contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
     *         element that is not a {@code TreePath}; {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
     *         values are ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
     protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
         removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
         if(toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
             while(toRemove.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3665
                 Enumeration descendants = getDescendantToggledPaths
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3666
                         (toRemove.nextElement());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
                 if(descendants != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
                     while(descendants.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
                         expandedState.remove(descendants.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
      * Clears the cache of toggled tree paths. This does NOT send out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
      * any <code>TreeExpansionListener</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     protected void clearToggledPaths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
         expandedState.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
      * Creates and returns an instance of <code>TreeModelHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
      * The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
      * object is responsible for updating the expanded state when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
      * <code>TreeModel</code> changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
      * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
      * For more information on what expanded state means, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
      * <a href=#jtree_description>JTree description</a> above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
     protected TreeModelListener createTreeModelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
         return new TreeModelHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
     * Removes any paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
     * <code>path</code>. If <code>includePath</code> is true and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
     * <code>path</code> is selected, it will be removed from the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
     * @return true if a descendant was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
    protected boolean removeDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
                                                    boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
        TreePath[]    toRemove = getDescendantSelectedPaths(path, includePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
        if (toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
            getSelectionModel().removeSelectionPaths(toRemove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
     * Returns an array of paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
     * <code>path</code>. The returned array may contain <code>null</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
    private TreePath[] getDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
                                                  boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
        TreeSelectionModel   sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
        TreePath[]           selPaths = (sm != null) ? sm.getSelectionPaths() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
                                        null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
        if(selPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
            boolean        shouldRemove = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
            for(int counter = selPaths.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
                if(selPaths[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
                   path.isDescendant(selPaths[counter]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
                   (!path.equals(selPaths[counter]) || includePath))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                    shouldRemove = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                    selPaths[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
            if(!shouldRemove) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
                selPaths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            return selPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
     * Removes any paths from the selection model that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
     * the nodes identified by in <code>e</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
    void removeDescendantSelectedPaths(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
        TreePath            pPath = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
        Object[]            oldChildren = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
        TreeSelectionModel  sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
        if (sm != null && pPath != null && oldChildren != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
            oldChildren.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
            for (int counter = oldChildren.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                 counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                // Might be better to call getDescendantSelectedPaths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
                // numerous times, then push to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
                removeDescendantSelectedPaths(pPath.pathByAddingChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
                                              (oldChildren[counter]), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
      * Listens to the model and updates the <code>expandedState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
      * accordingly when nodes are removed, or changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
    protected class TreeModelHandler implements TreeModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
        public void treeNodesChanged(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
        public void treeNodesInserted(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
        public void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
            // NOTE: If I change this to NOT remove the descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
            // and update BasicTreeUIs treeStructureChanged method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            // to update descendants in response to a treeStructureChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
            // event, all the children of the event won't collapse!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            TreePath            parent = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            if (parent.getPathCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
                // New root, remove everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                clearToggledPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
                if(treeModel.getRoot() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
                   !treeModel.isLeaf(treeModel.getRoot())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
                    // Mark the root as expanded, if it isn't a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
                    expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
            else if(expandedState.get(parent) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
                Vector<TreePath>    toRemove = new Vector<TreePath>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                boolean             isExpanded = isExpanded(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
                toRemove.addElement(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                if(isExpanded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
                    TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                    if(model == null || model.isLeaf
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
                       (parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                        collapsePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
                        expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            removeDescendantSelectedPaths(parent, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
        public void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
            TreePath            parent = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
            Object[]            children = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            if(children == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
            TreePath            rPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
            Vector<TreePath>    toRemove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                = new Vector<TreePath>(Math.max(1, children.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
            for(int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                rPath = parent.pathByAddingChild(children[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                if(expandedState.get(rPath) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
                    toRemove.addElement(rPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
            if(toRemove.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
            TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
            if(model == null || model.isLeaf(parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
                expandedState.remove(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
            removeDescendantSelectedPaths(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
     * <code>DynamicUtilTreeNode</code> can wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
     * vectors/hashtables/arrays/strings and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
     * create the appropriate children tree nodes as necessary. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
     * dynamic in that it will only create the children as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
    public static class DynamicUtilTreeNode extends DefaultMutableTreeNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
         * Does the this <code>JTree</code> have children?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
         * This property is currently not implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        protected boolean            hasChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
        /** Value to create children with. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
        protected Object             childValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        /** Have the children been loaded yet? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        protected boolean            loadedChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
         * Adds to parent all the children in <code>children</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
         * If <code>children</code> is an array or vector all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
         * elements are added is children, otherwise if <code>children</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
         * is a hashtable all the key/value pairs are added in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
         * <code>Enumeration</code> returns them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
        public static void createChildren(DefaultMutableTreeNode parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
                                          Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
            if(children instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                Vector          childVector = (Vector)children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
                for(int counter = 0, maxCounter = childVector.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                    parent.add(new DynamicUtilTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
                               (childVector.elementAt(counter),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
                                childVector.elementAt(counter)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
            else if(children instanceof Hashtable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
                Hashtable           childHT = (Hashtable)children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                Enumeration         keys = childHT.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                Object              aKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                while(keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                    aKey = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
                    parent.add(new DynamicUtilTreeNode(aKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
                                                       childHT.get(aKey)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
            else if(children instanceof Object[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
                Object[]             childArray = (Object[])children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
                for(int counter = 0, maxCounter = childArray.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
                    parent.add(new DynamicUtilTreeNode(childArray[counter],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
                                                       childArray[counter]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
         * Creates a node with the specified object as its value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
         * with the specified children. For the node to allow children,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
         * the children-object must be an array of objects, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
         * <code>Vector</code>, or a <code>Hashtable</code> -- even
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
         * if empty. Otherwise, the node is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
         * allowed to have children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
         * @param value  the <code>Object</code> that is the value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
         *              new node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
         * @param children an array of <code>Object</code>s, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
         *              <code>Vector</code>, or a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
         *              used to create the child nodes; if any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
         *              object is specified, or if the value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
         *              <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
         *              then the node is not allowed to have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
        public DynamicUtilTreeNode(Object value, Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
            super(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
            loadedChildren = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
            childValue = children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
            if(children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                if(children instanceof Vector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                else if(children instanceof Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                else if(children instanceof Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                    setAllowsChildren(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                setAllowsChildren(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
         * Returns true if this node allows children. Whether the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
         * allows children depends on how it was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
         * @return true if this node allows children, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
         * @see #JTree.DynamicUtilTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
        public boolean isLeaf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
            return !getAllowsChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
         * Returns the number of child nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
         * @return the number of child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
        public int getChildCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
            return super.getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
         * Loads the children based on <code>childValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
         * If <code>childValue</code> is a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
         * or array each element is added as a child,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         * if <code>childValue</code> is a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
         * each key/value pair is added in the order that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
         * <code>Enumeration</code> returns the keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
        protected void loadChildren() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
            loadedChildren = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
            createChildren(this, childValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
        public TreeNode getChildAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
            return super.getChildAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
        public Enumeration children() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
            return super.children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
            if (!rowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
                rowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
        } else if (propertyName == "scrollsOnExpand") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            if (!scrollsOnExpandSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
                setScrollsOnExpand(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
                scrollsOnExpandSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
        } else if (propertyName == "showsRootHandles") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
            if (!showsRootHandlesSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
                setShowsRootHandles(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
                showsRootHandlesSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
     * Returns a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
     * @return  a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
        String rootVisibleString = (rootVisible ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
        String showsRootHandlesString = (showsRootHandles ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
                                         "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
        String editableString = (editable ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                                 "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
        String largeModelString = (largeModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
        String invokesStopCellEditingString = (invokesStopCellEditing ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                                               "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
        String scrollsOnExpandString = (scrollsOnExpand ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                                        "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
        ",editable=" + editableString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
        ",invokesStopCellEditing=" + invokesStopCellEditingString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
        ",largeModel=" + largeModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
        ",rootVisible=" + rootVisibleString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
        ",scrollsOnExpand=" + scrollsOnExpandString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
        ",showsRootHandles=" + showsRootHandlesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
        ",toggleClickCount=" + toggleClickCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
        ",visibleRowCount=" + visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
     * Gets the AccessibleContext associated with this JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
     * For JTrees, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
     * AccessibleJTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
     * A new AccessibleJTree instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
     * @return an AccessibleJTree that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
     *         AccessibleContext of this JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
            accessibleContext = new AccessibleJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
     * <code>JTree</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
     * Java Accessibility API appropriate to tree user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
    protected class AccessibleJTree extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            implements AccessibleSelection, TreeSelectionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
                       TreeModelListener, TreeExpansionListener  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
        TreePath   leadSelectionPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
        Accessible leadSelectionAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
        public AccessibleJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
            // Add a tree model listener for JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
                model.addTreeModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            JTree.this.addTreeExpansionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
            JTree.this.addTreeSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
            leadSelectionPath = JTree.this.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
            leadSelectionAccessible = (leadSelectionPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                    ? new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
                                              leadSelectionPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
                                              JTree.this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
                    : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
         * Tree Selection Listener value change method. Used to fire the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
         * property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
         * @param e ListSelectionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
        public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            // Fixes 4546503 - JTree is sending incorrect active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
            // descendant events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            TreePath oldLeadSelectionPath = e.getOldLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
            leadSelectionPath = e.getNewLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
            if (oldLeadSelectionPath != leadSelectionPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
                Accessible oldLSA = leadSelectionAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
                leadSelectionAccessible = (leadSelectionPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                        ? new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
                                                  leadSelectionPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
                                                  null) // parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
                        : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
                                   oldLSA, leadSelectionAccessible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
                               Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
         * Fire a visible data property change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
         * A 'visible' data property is one that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
         * something about the way the component appears on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
         * display, where that appearance isn't bound to any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
         * property. It notifies screen readers  that the visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
         * appearance of the component has changed, so they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
         * notify the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
        public void fireVisibleDataPropertyChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
                              Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
        // Fire the visible data changes for the model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        public void treeNodesChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
        public void treeNodesInserted(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
         * @param e  a Tree node(s) removal event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
        public  void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
         * Tree Model structure change change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
        public  void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
         * Tree Collapsed notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
         * @param e  a TreeExpansionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
        public  void treeCollapsed(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
                    AccessibleState.EXPANDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
                    AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
         * Tree Model Expansion notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
        public  void treeExpanded(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
                // TIGER - 4839971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
                    AccessibleState.COLLAPSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
                    AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
        private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
            Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
            if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4251
                return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
        private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
            // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
            // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
            // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
            TreePath path = new TreePath(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
            if (JTree.this.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                TreeCellRenderer r = JTree.this.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                TreeUI ui = JTree.this.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                    int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                    int lsr = JTree.this.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                    boolean hasFocus = JTree.this.isFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                                       && (lsr == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                    boolean selected = JTree.this.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                    boolean expanded = JTree.this.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                    return r.getTreeCellRendererComponent(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                        model.getRoot(), selected, expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                        model.isLeaf(model.getRoot()), row, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
        // Overridden methods from AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
            return AccessibleRole.TREE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
         * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
         * @param p point in local coordinates of this <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
            TreePath path = getClosestPathForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                // JTree.this is NOT the parent; parent will get computed later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                return new AccessibleJTreeNode(JTree.this, path, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
         * Returns the number of top-level children nodes of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
         * JTree.  Each of these nodes may in turn have children nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
         * @return the number of accessible children nodes in the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
                return 1;    // the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
            // return the root's first set of children count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
            return model.getChildCount(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
         * Return the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
                if (i == 0) {    // return the root node Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
                    Object[] objPath = { model.getRoot() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
                    return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
            // return Accessible for one of root's child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
            int count = model.getChildCount(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
            if (i < 0 || i >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
            Object obj = model.getChild(model.getRoot(), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
            Object[] objPath = { model.getRoot(), obj };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
            TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
            return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
         * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
         * @return the index of this object in its parent.  Since a JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
         * top-level object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
            // didn't ever need to override this...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
            return super.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
         * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
         * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
            rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
            TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
            if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
         * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
         * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
         * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
         * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
         * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
         * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
                rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
                if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
                    return new AccessibleJTreeNode(JTree.this, childPath, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
         * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
         * @param i the zero-based index of the child in this Accessible object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
                return JTree.this.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
         * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
         * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
         * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
         * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
           TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
           if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
               if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                   Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
                   TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
                   JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
         * Removes the specified selected item in the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
                    Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
                    JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
         * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
         * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
            int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
            for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
                removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
         * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
         * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
                Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
                TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
                JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
         * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
         * <code>JTree</code> child.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
         * Java Accessibility API appropriate to tree nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
        protected class AccessibleJTreeNode extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
            implements Accessible, AccessibleComponent, AccessibleSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
            AccessibleAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
            private JTree tree = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
            private TreeModel treeModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            private Object obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            private TreePath path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
            private Accessible accessibleParent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            private int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            private boolean isLeaf = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
             *  Constructs an AccessibleJTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
            public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
                tree = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
                path = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
                accessibleParent = ap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
                treeModel = t.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
                obj = p.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
                if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
                    isLeaf = treeModel.isLeaf(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
            private TreePath getChildTreePath(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
                    return new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
             * Get the AccessibleContext associated with this tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
             * In the implementation of the Java Accessibility API for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
             * this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
             * AccessibleContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
                Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
                if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4574
                    return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
                // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
                // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
                // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
                if (tree.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
                    TreeCellRenderer r = tree.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
                    if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
                    TreeUI ui = tree.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
                    if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
                        int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
                        boolean selected = tree.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
                        boolean expanded = tree.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
                        boolean hasFocus = false; // how to tell?? -PK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
                        return r.getTreeCellRendererComponent(tree, obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
                            selected, expanded, isLeaf, row, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
             /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
              * Get the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
              *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
              * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
              * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
             public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
             * Set the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
             * @param s the new localized name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
            // *** should check tooltip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
             * Get the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
             * @return the localized description of the object; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
             * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
             * Set the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
             * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
             * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
             * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
             * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
                AccessibleStateSet states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
                    states = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
                    states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
                // need to test here, 'cause the underlying component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
                // is a cellRenderer, which is never showing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
                if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
                    states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
                } else if (states.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
                    states.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
                if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
                    states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
                } else if (states.contains(AccessibleState.VISIBLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
                    states.remove(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
                if (tree.isPathSelected(path)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
                    states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
                if (path == getLeadSelectionPath()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
                    states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
                if (!isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
                    states.add(AccessibleState.EXPANDABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
                if (tree.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
                    states.add(AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
                    states.add(AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
                if (tree.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
                    states.add(AccessibleState.EDITABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
                return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
             * Get the Accessible parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
             * @return the Accessible parent of this object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
             * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
                // someone wants to know, so we need to create our parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
                // if we don't have one (hey, we're a talented kid!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
                    if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
                        Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
                        if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
                            index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
                        Object[] objParentPath = new Object[objPath.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
                        java.lang.System.arraycopy(objPath, 0, objParentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
                                                   0, objPath.length-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
                        TreePath parentPath = new TreePath(objParentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
                        accessibleParent = new AccessibleJTreeNode(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
                                                                   parentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
                    } else if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
                        accessibleParent = tree; // we're the top!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
                        index = 0; // we're an only child!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
                return accessibleParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
             * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
             * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
                // index is invalid 'till we have an accessibleParent...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
                    getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
                Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
                if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
                    Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
                    if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
                        index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
             * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
                return treeModel.getChildCount(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
             * Return the specified Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
             * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
                    TreePath childPath = new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
                    return new AccessibleJTreeNode(JTree.this, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
             * Gets the locale of the component. If the component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
             * a locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
             * @return This component's locale. If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
             * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
             * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
             * If the Component does not have its own locale and has not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
             * been added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
             * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
                    return tree.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
             * Add a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
             * @param l  The PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
             * Remove a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
             * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
             * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
             * @param l  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
             * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
             * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
             * Get the AccessibleComponent associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
             * AccessibleComponent interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
             * Get the AccessibleSelection associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
             * @return the AccessibleSelection, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
                if (ac != null && isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
                    return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
                    return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
             * Get the AccessibleText associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
             * @return the AccessibleText, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
                    return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
             * Get the AccessibleValue associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
             * @return the AccessibleValue, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
                    return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
             * Get the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
             * Set the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
             * @param c the new Color for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
             * Get the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
                Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
                Rectangle parentBounds = tree.getVisibleRect();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5118
                return pathBounds != null && parentBounds != null &&
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5119
                        parentBounds.intersects(pathBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
                return (tree.isShowing() && isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
                if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
                    Point treeLocation = tree.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
                    Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                    if (treeLocation != null && pathBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
                        Point nodeLocation = new Point(pathBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
                                                       pathBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
                        nodeLocation.translate(treeLocation.x, treeLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
                        return nodeLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
            protected Point getLocationInJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
                Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
                Accessible parent = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
                    if (parent instanceof AccessibleJTreeNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
                        Point parentLoc = ((AccessibleJTreeNode) parent).getLocationInJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
                        if (parentLoc != null && r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
                            r.translate(-parentLoc.x, -parentLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
                            return null;        // not visible!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
                return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
                return getBounds().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
             * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
             * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
             * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
             * @param p point in local coordinates of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
             *    <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
             * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
             *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
             * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
             * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
             * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
            public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
                       count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
                return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
             * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
             * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
             * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
             * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
             * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
             * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
            public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
                    return null;        // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
                for (int j = 0; j < childCount && i >= count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
                    TreePath childPath = getChildTreePath(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
                        if (count == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
                            return new AccessibleJTreeNode(tree, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
                            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
             * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
             * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
             * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
            public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
                    return false;       // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
                    return tree.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
             * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
             * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
             * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
             * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
             * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
            public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
             * Removes the specified selected item in the object from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
             * object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
             * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
             * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
            public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
                       JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
             * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
             * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
            public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
                    removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
             * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
             * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
            public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
                   int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                   TreePath path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
                   for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
                       path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
        // AccessibleAction methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
             * Returns the number of accessible actions available in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
             * tree node.  If this node is not a leaf, there is at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
             * one action (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
             * @return the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
            public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
                        return (aa.getAccessibleActionCount() + (isLeaf ? 0 : 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
                return isLeaf ? 0 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
             * Return a description of the specified action of the tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
             * If this node is not a leaf, there is at least one action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
             * description (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
             * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
             * @return a description of the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
            public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
                    // TIGER - 4766636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
                    return AccessibleAction.TOGGLE_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
                        return aa.getAccessibleActionDescription(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
             * Perform the specified Action on the tree node.  If this node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
             * is not a leaf, there is at least one action which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
             * done (toggle expand), in addition to any available on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
             * object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
             * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
             * @return true if the the action was performed; else false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
            public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                    if (JTree.this.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
                        JTree.this.collapsePath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
                        JTree.this.expandPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
                        return aa.doAccessibleAction(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
        } // inner class AccessibleJTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
    }  // inner class AccessibleJTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
} // End of class JTree