jdk/src/share/classes/javax/swing/JTree.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5950 4beeac5abfed
child 10878 978071ed312e
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5950
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    23
 * questions.
2
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) {
5950
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1989
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        if(path == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            return false;
5950
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1992
        Object  value;
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1993
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1994
        do{
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1995
            value = expandedState.get(path);
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1996
            if(value == null || !((Boolean)value).booleanValue())
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1997
                return false;
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1998
        } while( (path=path.getParentPath())!=null );
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  1999
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * Returns true if the node at the specified display row is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     * expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     * @return true if the node is currently expanded, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
    public boolean isExpanded(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            TreePath         path = tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            if(path != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2018
                Boolean value = expandedState.get(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                return (value != null && value.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * Returns true if the value identified by path is currently collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * this will return false if any of the values in path are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * not being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * @param path  the <code>TreePath</code> to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * @return true if any of the nodes in the node's path are collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     *               false if all nodes in the path are expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    public boolean isCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        return !isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * Returns true if the node at the specified display row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * @return true if the node is currently collapsed, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
    public boolean isCollapsed(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        return !isExpanded(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * Ensures that the node identified by path is currently viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * @param path  the <code>TreePath</code> to make visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    public void makeVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            if(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                expandPath(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * Returns true if the value identified by path is currently viewable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * which means it is either the root or all of its parents are expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * Otherwise, this method returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * @return true if the node is viewable, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    public boolean isVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
            if(parentPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                return isExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            // Root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * Returns the <code>Rectangle</code> that the specified node will be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * into. Returns <code>null</code> if any component in the path is hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * (under a collapsed parent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * Note:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * This method returns a valid rectangle, even if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     * node is not currently displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * @param path the <code>TreePath</code> identifying the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * @return the <code>Rectangle</code> the node is drawn in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
    public Rectangle getPathBounds(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        TreeUI                   tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            return tree.getPathBounds(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * Returns the <code>Rectangle</code> that the node at the specified row is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * drawn in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * @param row  the row to be drawn, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * @return the <code>Rectangle</code> the node is drawn in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    public Rectangle getRowBounds(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        return getPathBounds(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * Makes sure all the path components in path are expanded (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * for the last path component) and scrolls so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * node identified by the path is displayed. Only works when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * <code>JTree</code> is contained in a <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * @param path  the <code>TreePath</code> identifying the node to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     *          bring into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
    public void scrollPathToVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
            makeVisible(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            Rectangle          bounds = getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            if(bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                scrollRectToVisible(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                    ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
        }
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
     * Scrolls the item identified by row until it is displayed. The minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     * of amount of scrolling necessary to bring the row into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * is performed. Only works when this <code>JTree</code> is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * @param row  an integer specifying the row to scroll, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
    public void scrollRowToVisible(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        scrollPathToVisible(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     * Returns the path for the specified row.  If <code>row</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     * not visible, or a {@code TreeUI} has not been set, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     * @param row  an integer specifying a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * @return the <code>TreePath</code> to the specified node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     *          <code>null</code> if <code>row < 0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     *          or <code>row >= getRowCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
    public TreePath getPathForRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            return tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * Returns the row that displays the node identified by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * @return an integer specifying the display row, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *         row in the display, or -1 if any of the elements in path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     *         are hidden under a collapsed parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
    public int getRowForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            return tree.getRowForPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * expanded and viewable. If the last item in the path is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * leaf, this will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
    public void expandPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        // Only expand if not leaf!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        TreeModel          model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        if(path != null && model != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
           !model.isLeaf(path.getLastPathComponent())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            setExpandedState(path, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * Ensures that the node in the specified row is expanded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * If <code>row</code> is < 0 or >= <code>getRowCount</code> this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
    public void expandRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        expandPath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * collapsed and viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    public void collapsePath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        setExpandedState(path, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     * Ensures that the node in the specified row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     * If <code>row</code> is < 0 or >= <code>getRowCount</code> this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    public void collapseRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
        collapsePath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * Returns the path for the node at the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * @return  the <code>TreePath</code> for the node at that location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
    public TreePath getPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        TreePath          closestPath = getClosestPathForLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        if(closestPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
            Rectangle       pathBounds = getPathBounds(closestPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            if(pathBounds != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
               x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
               y >= pathBounds.y && y < (pathBounds.y + pathBounds.height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                return closestPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     * Returns the row for the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     * @return the row corresponding to the location, or -1 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     *         location is not within the bounds of a displayed cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * @see #getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    public int getRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        return getRowForPath(getPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * no nodes are currently viewable, or there is no model, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * <code>null</code>, otherwise it always returns a valid path.  To test if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * the node is exactly at x, y, get the node's bounds and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     * @return  the <code>TreePath</code> for the node closest to that location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     *          <code>null</code> if nothing is viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     * @see #getPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     * @see #getPathBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
    public TreePath getClosestPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
            return tree.getClosestPathForLocation(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     * Returns the row to the node that is closest to x,y.  If no nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
     * are viewable or there is no model, returns -1. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     * it always returns a valid row.  To test if the returned object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     * exactly at x, y, get the bounds for the node at the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     * row and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * @return the row closest to the location, -1 if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     *         viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * @see #getRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * @see #getRowBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    public int getClosestRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        return getRowForPath(getClosestPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     * Returns true if the tree is being edited. The item that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     * edited can be obtained using <code>getSelectionPath</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
     * @return true if the user is currently editing a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
     * @see #getSelectionPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    public boolean isEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            return tree.isEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * Ends the current editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     * (The <code>DefaultTreeCellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * object saves any edits that are currently in progress on a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * Other implementations may operate differently.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * Has no effect if the tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * <b>Note:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * To make edit-saves automatic whenever the user changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * their position in the tree, use {@link #setInvokesStopCellEditing}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * @return true if editing was in progress and is now stopped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     *              false if editing was not in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    public boolean stopEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            return tree.stopEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
     * Cancels the current editing session. Has no effect if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     * tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    public void  cancelEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            tree.cancelEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * Selects the node identified by the specified path and initiates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * editing.  The edit-attempt fails if the <code>CellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * editing for the specified item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
    public void startEditingAtPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
            tree.startEditingAtPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     * Returns the path to the element that is currently being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     * @return  the <code>TreePath</code> for the node being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    public TreePath getEditingPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            return tree.getEditingPath(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    // Following are primarily convenience methods for mapping from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    // row based selections to path selections.  Sometimes it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
    // easier to deal with these than paths (mouse downs, key downs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    // usually just deal with index based selections).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    // Since row based selections require a UI many of these won't work
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    // without one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * Sets the tree's selection model. When a <code>null</code> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * specified an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * <code>selectionModel</code> is used, which does not allow selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * @param selectionModel the <code>TreeSelectionModel</code> to use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     *          or <code>null</code> to disable selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * @see TreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     *  description: The tree's selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    public void setSelectionModel(TreeSelectionModel selectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        if(selectionModel == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            selectionModel = EmptySelectionModel.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        TreeSelectionModel         oldValue = this.selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        if (this.selectionModel != null && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            this.selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
           this.selectionModel.removeTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
           selectionModel.addTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        this.selectionModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        if (selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            this.selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                           this.selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                    AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                    Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
     * Returns the model for selections. This should always return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     * non-<code>null</code> value. If you don't want to allow anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
     * to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     * set the selection model to <code>null</code>, which forces an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
     * selection model to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     * @see #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
    public TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * Returns the paths (inclusive) between the specified rows. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     * the specified indices are within the viewable set of rows, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     * bound the viewable set of rows, then the indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
     * constrained by the viewable set of rows. If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
     * indices are not within the viewable set of rows, or do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
     * bound the viewable set of rows, then an empty array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
     * returned. For example, if the row count is {@code 10}, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     * method is invoked with {@code -1, 20}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * indices are constrained to the viewable set of rows, and this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * treated as if invoked with {@code 0, 9}. On the other hand, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * this were invoked with {@code -10, -1}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * indices do not bound the viewable set of rows, and an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     * array is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * getPathBetweenRows(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     * {@code getPathBetweenRows(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * An empty array is returned if the row count is {@code 0}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * the specified indices do not bound the viewable set of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * @param index0 the first index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * @param index1 the last index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * @return the paths (inclusive) between the specified row indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
    protected TreePath[] getPathBetweenRows(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        TreeUI           tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            int rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            if (rowCount > 0 && !((index0 < 0 && index1 < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                                  (index0 >= rowCount && index1 >= rowCount))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                index0 = Math.min(rowCount - 1, Math.max(index0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                index1 = Math.min(rowCount - 1, Math.max(index1, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                int minIndex = Math.min(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                int maxIndex = Math.max(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                TreePath[] selection = new TreePath[
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                        maxIndex - minIndex + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                for(int counter = minIndex; counter <= maxIndex; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                    selection[counter - minIndex] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                            tree.getPathForRow(this, counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        return new TreePath[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * Selects the rows in the specified interval (inclusive). If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * the viewable set of rows, then the specified rows are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * the selection is cleared. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * specified indices bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     * invoked with {@code -10, -1}, then the specified indices do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * bound the viewable set of rows, and the selection is cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * setSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * {@code setSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * @param index0 the first index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * @param index1 the last index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    public void setSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        this.getSelectionModel().setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
     * Adds the specified rows (inclusive) to the selection. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     * specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     * the viewable set of rows, then the specified indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * constrained by the viewable set of rows. If the indices are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     * within the viewable set of rows, or do not bound the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * set of rows, then the selection is unchanged. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * the row count is {@code 10}, and this method is invoked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * {@code -1, 20}, then the specified indices bounds the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * range, and this is treated as if invoked with {@code 0, 9}. On
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * the other hand, if this were invoked with {@code -10, -1}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * the specified indices do not bound the viewable set of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * addSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * {@code addSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * @param index0 the first index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * @param index1 the last index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
    public void addSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            this.getSelectionModel().addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * Removes the specified rows (inclusive) from the selection. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * the viewable set of rows, then the specified indices are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * the selection is unchanged. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * specified range bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * invoked with {@code -10, -1}, then the specified range does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * bound the viewable set of rows, and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * removeSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     * {@code removeSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * @param index0 the first row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * @param index1 the last row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
    public void removeSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
     * Removes the node identified by the specified path from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    public void removeSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
        this.getSelectionModel().removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     * Removes the nodes identified by the specified paths from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * @param paths an array of <code>TreePath</code> objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     *              specifies the nodes to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    public void removeSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
        this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * Removes the row at the index <code>row</code> from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * @param row  the row to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    public void removeSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        int[]             rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
        removeSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * Removes the rows that are selected at each of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * @param rows  an array of ints specifying display rows, where 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     *             the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    public void removeSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
        TreeUI             ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
            for(int counter = 0; counter < numRows; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
            removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     * Clears the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
     * Returns true if the selection is currently empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
     * @return true if the selection is currently empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
    public boolean isSelectionEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
        return getSelectionModel().isSelectionEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     * Adds a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
     * @param tel a TreeExpansionListener that will be notified when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
     *            a tree node is expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
    public void addTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        if (settingUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            uiTreeExpansionListener = tel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
        listenerList.add(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * Removes a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     * @param tel the <code>TreeExpansionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
    public void removeTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        listenerList.remove(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
        if (uiTreeExpansionListener == tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            uiTreeExpansionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     * Returns an array of all the <code>TreeExpansionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
     * to this JTree with addTreeExpansionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
     * @return all of the <code>TreeExpansionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    public TreeExpansionListener[] getTreeExpansionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2704
        return listenerList.getListeners(TreeExpansionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
     * Adds a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     * @param tel a <code>TreeWillExpandListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     *            when a tree node will be expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
    public void addTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
        listenerList.add(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     * Removes a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     * @param tel the <code>TreeWillExpandListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
    public void removeTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        listenerList.remove(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * Returns an array of all the <code>TreeWillExpandListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     * to this JTree with addTreeWillExpandListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * @return all of the <code>TreeWillExpandListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
    public TreeWillExpandListener[] getTreeWillExpandListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2736
        return listenerList.getListeners(TreeWillExpandListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     public void fireTreeExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            uiTreeExpansionListener.treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
                    treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     *          collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
    public void fireTreeCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            uiTreeExpansionListener.treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                    treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     public void fireTreeWillExpand(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                    treeWillExpand(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
                    treeWillCollapse(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
     * Adds a listener for <code>TreeSelection</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
     * @param tsl the <code>TreeSelectionListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     *            when a node is selected or deselected (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     *            selection")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
    public void addTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
        listenerList.add(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
           && selectionRedirector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     * Removes a <code>TreeSelection</code> listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * @param tsl the <code>TreeSelectionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    public void removeTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
        listenerList.remove(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
        if(listenerList.getListenerCount(TreeSelectionListener.class) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
           && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
            selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
            selectionRedirector = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * Returns an array of all the <code>TreeSelectionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     * to this JTree with addTreeSelectionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * @return all of the <code>TreeSelectionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
    public TreeSelectionListener[] getTreeSelectionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2893
        return listenerList.getListeners(TreeSelectionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * @param e the <code>TreeSelectionEvent</code> to be fired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     *          generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     *          <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     *          when a node is selected or deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
    protected void fireValueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            // TreeSelectionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            if (listeners[i]==TreeSelectionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
                // e = new ListSelectionEvent(this, firstIndex, lastIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
                ((TreeSelectionListener)listeners[i+1]).valueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     * Sent when the tree has changed enough that we need to resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * the bounds, but not enough that we need to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     * expanded node set (e.g nodes were expanded or collapsed, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * nodes were inserted into the tree). You should never have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * invoke this, the UI will invoke this as it needs to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
    public void treeDidChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     * Sets the number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     * This will only work if the tree is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * <code>JScrollPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     * and will adjust the preferred size and size of that scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
     * @param newCount the number of rows to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     *  description: The number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
    public void setVisibleRowCount(int newCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
        int                 oldCount = visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        visibleRowCount = newCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
                           visibleRowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
     * Returns the number of rows that are displayed in the display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
     * @return the number of rows displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
    public int getVisibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
        return visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
     * Expands the root path, assuming the current TreeModel has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
    private void expandRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
        TreeModel              model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
        if(model != null && model.getRoot() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            expandPath(new TreePath(model.getRoot()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
     * Returns the TreePath to the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
     * begins with a prefix. To handle the conversion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
     * <code>TreePath</code> into a String, <code>convertValueToText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
     * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
     * @param prefix the string to test for a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
     * @param startingRow the row for starting the search
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
     * @param bias the search direction, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
     * Position.Bias.Forward or Position.Bias.Backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
     * @return the TreePath of the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
     * starts with the prefix; otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
     * @exception IllegalArgumentException if prefix is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
     * or startingRow is out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
    public TreePath getNextMatch(String prefix, int startingRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                                 Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
        int max = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
        if (prefix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
        if (startingRow < 0 || startingRow >= max) {
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
        prefix = prefix.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
        // start search from the next/previous element froom the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
        // selected element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
        int increment = (bias == Position.Bias.Forward) ? 1 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
        int row = startingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
            TreePath path = getPathForRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            String text = convertValueToText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                path.getLastPathComponent(), isRowSelected(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
                isExpanded(row), true, row, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
            if (text.toUpperCase().startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
                return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            row = (row + increment + max) % max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
        } while (row != startingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
    private void writeObject(ObjectOutputStream s) throws IOException {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3027
        Vector<Object> values = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
        // Save the cellRenderer, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
        if(cellRenderer != null && cellRenderer instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            values.addElement("cellRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            values.addElement(cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
        // Save the cellEditor, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        if(cellEditor != null && cellEditor instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            values.addElement("cellEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
            values.addElement(cellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
        // Save the treeModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
        if(treeModel != null && treeModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
            values.addElement("treeModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            values.addElement(treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
        // Save the selectionModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
        if(selectionModel != null && selectionModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
            values.addElement("selectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            values.addElement(selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        Object      expandedData = getArchivableExpandedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
        if(expandedData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
            values.addElement("expandedState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
            values.addElement(expandedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
        s.writeObject(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
        // Create an instance of expanded state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3074
        expandedState = new Hashtable<TreePath, Boolean>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3075
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3076
        expandedStack = new Stack<Stack<TreePath>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        Vector          values = (Vector)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
        int             indexCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
        int             maxCounter = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
           equals("cellRenderer")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
            cellRenderer = (TreeCellRenderer)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
           equals("cellEditor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
            cellEditor = (TreeCellEditor)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
           equals("treeModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
            treeModel = (TreeModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
           equals("selectionModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
            selectionModel = (TreeSelectionModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
           equals("expandedState")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
            unarchiveExpandedState(values.elementAt(++indexCounter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
        // Reinstall the redirector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
        // Listener to TreeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
            treeModelListener = createTreeModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
            if(treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
                treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * Returns an object that can be archived indicating what nodes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * expanded and what aren't. The objects from the model are NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * written out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
    private Object getArchivableExpandedState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
        TreeModel       model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
        if(model != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3129
            Enumeration<TreePath> paths = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
            if(paths != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3132
                Vector<Object> state = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
                while(paths.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3135
                    TreePath path = paths.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
                    Object     archivePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                        archivePath = getModelIndexsForPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
                    } catch (Error error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                        archivePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                    if(archivePath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
                        state.addElement(archivePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
                        state.addElement(expandedState.get(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
                return state;
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 null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
     * Updates the expanded state of nodes in the tree based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
     * previously archived state <code>state</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
    private void unarchiveExpandedState(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
        if(state instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            Vector          paths = (Vector)state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            for(int counter = paths.size() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
                Boolean        eState = (Boolean)paths.elementAt(counter--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
                TreePath       path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
                    path = getPathForIndexs((int[])paths.elementAt(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
                    if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
                        expandedState.put(path, eState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
                } catch (Error error) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
     * Returns an array of integers specifying the indexs of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
     * components in the <code>path</code>. If <code>path</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
     * the root, this will return an empty array.  If <code>path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     * is <code>null</code>, <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
    private int[] getModelIndexsForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
            TreeModel   model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
            int         count = path.getPathCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
            int[]       indexs = new int[count - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            Object      parent = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
            for(int counter = 1; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
                indexs[counter - 1] = model.getIndexOfChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                                   (parent, path.getPathComponent(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
                parent = path.getPathComponent(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                if(indexs[counter - 1] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
            return indexs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
     * Returns a <code>TreePath</code> created by obtaining the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
     * for each of the indices in <code>indexs</code>. If <code>indexs</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
     * or the <code>TreeModel</code> is <code>null</code>, it will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
    private TreePath getPathForIndexs(int[] indexs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
        if(indexs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        TreeModel    model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        if(model == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
        int          count = indexs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
        Object       parent = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        TreePath     parentPath = new TreePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        for(int counter = 0; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            parent = model.getChild(parent, indexs[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            parentPath = parentPath.pathByAddingChild(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
        return parentPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
     * <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
     * that does not allow anything to be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
    protected static class EmptySelectionModel extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
              DefaultTreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
         * The single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
        protected static final EmptySelectionModel sharedInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
            new EmptySelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
         * Returns the single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
         * @return single instance of {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
        static public EmptySelectionModel sharedInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
            return sharedInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
         * @param paths the paths to select; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        public void setSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
         * @param paths the paths to add to the selection; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
        public void addSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
         * @param paths the paths to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
        public void removeSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
         * @param mode the selection mode; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
        public void setSelectionMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
         * @param mapper the {@code RowMapper} instance; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        public void setRowMapper(RowMapper mapper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        public void addTreeSelectionListener(TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        public void removeTreeSelectionListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
                TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
        public void addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
        public void removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     * Handles creating a new <code>TreeSelectionEvent</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     * <code>JTree</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     * source and passing it off to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
    protected class TreeSelectionRedirector implements Serializable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
                    TreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
         * Invoked by the <code>TreeSelectionModel</code> when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
         * selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
         * @param e the <code>TreeSelectionEvent</code> generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
         *              <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
        public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
            TreeSelectionEvent       newE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
            newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            fireValueChanged(newE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
    } // End of class JTree.TreeSelectionRedirector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
    // Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * Returns the preferred display size of a <code>JTree</code>. The height is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     * determined from <code>getVisibleRowCount</code> and the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * is the current preferred width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * @return a <code>Dimension</code> object containing the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        int                 width = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
        int                 visRows = getVisibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
        int                 height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        if(isFixedRowHeight())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
            height = visRows * getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
            TreeUI          ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
            if (ui != null && visRows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                int rc = ui.getRowCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
                if (rc >= visRows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                    Rectangle bounds = getRowBounds(visRows - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                        height = bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                else if (rc > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                    Rectangle bounds = getRowBounds(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                        height = bounds.height * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            if (height == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                height = 16 * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * Returns the amount to increment when scrolling. The amount is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     * the height of the first displayed row that isn't completely in view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * or, if it is totally displayed, the height of the next row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * scrolling direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     *          greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * @see JScrollBar#setUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                                          int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
        if(orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
            Rectangle       rowBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
            int             firstIndex = getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                                         (0, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
            if(firstIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                rowBounds = getRowBounds(firstIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
                if(rowBounds.y != visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
                    if(direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                        // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
                        return Math.max(0, (visibleRect.y - rowBounds.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
                    return (rowBounds.y + rowBounds.height - visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                if(direction < 0) { // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
                    if(firstIndex != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
                        rowBounds = getRowBounds(firstIndex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
                        return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                    return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
        return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
     * Returns the amount for a block increment, which is the height or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
     * width of <code>visibleRect</code>, based on <code>orientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     *          greater than zero for down/right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     * @return the "block" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * @see JScrollBar#setBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                                           int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
        return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
            visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     * Returns false to indicate that the width of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * determine the width of the table, unless the preferred width of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     * the tree is smaller than the viewports width.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * @return whether the tree should track the width of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
    public boolean getScrollableTracksViewportWidth() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3498
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3499
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3500
            return parent.getWidth() > getPreferredSize().width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
     * Returns false to indicate that the height of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
     * determine the height of the table, unless the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
     * of the tree is smaller than the viewports height.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
     * @return whether the tree should track the height of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
    public boolean getScrollableTracksViewportHeight() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3515
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3516
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3517
            return parent.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
     * Sets the expanded state of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
     * If <code>state</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
     * true, all parents of <code>path</code> and path are marked as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
     * expanded. If <code>state</code> is false, all parents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * <code>path</code> are marked EXPANDED, but <code>path</code> itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * is marked collapsed.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * This will fail if a <code>TreeWillExpandListener</code> vetos it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
    protected void setExpandedState(TreePath path, boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
            // Make sure all parents of path are expanded.
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3534
            Stack<TreePath> stack;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3535
            TreePath parentPath = path.getParentPath();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
            if (expandedStack.size() == 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3538
                stack = new Stack<TreePath>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
            else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3541
                stack = expandedStack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
                while(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
                    if(isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                        parentPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                        stack.push(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
                        parentPath = parentPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
                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
  3555
                    parentPath = stack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
                    if(!isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
                            fireTreeWillExpand(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
                        } catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
                            // Expand vetoed!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
                        expandedState.put(parentPath, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                        fireTreeExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
                        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                            ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                                              fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                if (expandedStack.size() < TEMP_STACK_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                    stack.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                    expandedStack.push(stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
            if(!state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                // collapse last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
                if(cValue != null && ((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
                        fireTreeWillCollapse(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
                    expandedState.put(path, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
                    fireTreeCollapsed(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
                    if (removeDescendantSelectedPaths(path, false) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
                        !isPathSelected(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
                        // A descendant was selected, select the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
                        addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
                                    fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
                // Expand last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
                if(cValue == null || !((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
                        fireTreeWillExpand(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
                    expandedState.put(path, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
                    fireTreeExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                                          fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
            }
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
     * Returns an <code>Enumeration</code> of <code>TreePaths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
     * that have been expanded that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
     * are descendants of <code>parent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
    protected Enumeration<TreePath>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
        getDescendantToggledPaths(TreePath parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
        if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3635
        Vector<TreePath> descendants = new Vector<TreePath>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3636
        Enumeration<TreePath> nodes = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
        while(nodes.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3639
            TreePath path = nodes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
            if(parent.isDescendant(path))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
                descendants.addElement(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
        return descendants.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
     * Removes any descendants of the <code>TreePaths</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
     * <code>toRemove</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
     * that have been expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
     * @param toRemove an enumeration of the paths to remove; a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
     *        {@code null} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     * @throws ClassCastException if {@code toRemove} contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     *         element that is not a {@code TreePath}; {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
     *         values are ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
     protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
         removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
         if(toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
             while(toRemove.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3662
                 Enumeration descendants = getDescendantToggledPaths
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3663
                         (toRemove.nextElement());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
                 if(descendants != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
                     while(descendants.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
                         expandedState.remove(descendants.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
             }
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
      * Clears the cache of toggled tree paths. This does NOT send out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
      * any <code>TreeExpansionListener</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     protected void clearToggledPaths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
         expandedState.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
      * Creates and returns an instance of <code>TreeModelHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
      * The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
      * object is responsible for updating the expanded state when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
      * <code>TreeModel</code> changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
      * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
      * For more information on what expanded state means, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
      * <a href=#jtree_description>JTree description</a> above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
     protected TreeModelListener createTreeModelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
         return new TreeModelHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
     * Removes any paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
     * <code>path</code>. If <code>includePath</code> is true and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
     * <code>path</code> is selected, it will be removed from the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
     * @return true if a descendant was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
    protected boolean removeDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
                                                    boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
        TreePath[]    toRemove = getDescendantSelectedPaths(path, includePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
        if (toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
            getSelectionModel().removeSelectionPaths(toRemove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
     * Returns an array of paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
     * <code>path</code>. The returned array may contain <code>null</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
    private TreePath[] getDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
                                                  boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
        TreeSelectionModel   sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
        TreePath[]           selPaths = (sm != null) ? sm.getSelectionPaths() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
                                        null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
        if(selPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
            boolean        shouldRemove = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
            for(int counter = selPaths.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
                if(selPaths[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
                   path.isDescendant(selPaths[counter]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
                   (!path.equals(selPaths[counter]) || includePath))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
                    shouldRemove = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
                    selPaths[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
            if(!shouldRemove) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                selPaths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
            return selPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
     * Removes any paths from the selection model that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
     * the nodes identified by in <code>e</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
    void removeDescendantSelectedPaths(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
        TreePath            pPath = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
        Object[]            oldChildren = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
        TreeSelectionModel  sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
        if (sm != null && pPath != null && oldChildren != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
            oldChildren.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
            for (int counter = oldChildren.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
                 counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
                // Might be better to call getDescendantSelectedPaths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
                // numerous times, then push to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                removeDescendantSelectedPaths(pPath.pathByAddingChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                                              (oldChildren[counter]), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
    }
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
      * Listens to the model and updates the <code>expandedState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
      * accordingly when nodes are removed, or changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
    protected class TreeModelHandler implements TreeModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
        public void treeNodesChanged(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
        public void treeNodesInserted(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
        public void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
            // NOTE: If I change this to NOT remove the descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
            // and update BasicTreeUIs treeStructureChanged method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
            // to update descendants in response to a treeStructureChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
            // event, all the children of the event won't collapse!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
            TreePath            parent = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
            if (parent.getPathCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
                // New root, remove everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
                clearToggledPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
                if(treeModel.getRoot() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
                   !treeModel.isLeaf(treeModel.getRoot())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                    // Mark the root as expanded, if it isn't a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
                    expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
            else if(expandedState.get(parent) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
                Vector<TreePath>    toRemove = new Vector<TreePath>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
                boolean             isExpanded = isExpanded(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
                toRemove.addElement(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
                if(isExpanded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
                    TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                    if(model == null || model.isLeaf
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
                       (parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
                        collapsePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
                        expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
            removeDescendantSelectedPaths(parent, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
        public void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
            TreePath            parent = e.getTreePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
            Object[]            children = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
            if(children == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            TreePath            rPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
            Vector<TreePath>    toRemove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                = new Vector<TreePath>(Math.max(1, children.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
            for(int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                rPath = parent.pathByAddingChild(children[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                if(expandedState.get(rPath) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                    toRemove.addElement(rPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
            if(toRemove.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
            TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
            if(model == null || model.isLeaf(parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
                expandedState.remove(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
            removeDescendantSelectedPaths(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
     * <code>DynamicUtilTreeNode</code> can wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
     * vectors/hashtables/arrays/strings and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
     * create the appropriate children tree nodes as necessary. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
     * dynamic in that it will only create the children as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
    public static class DynamicUtilTreeNode extends DefaultMutableTreeNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
         * Does the this <code>JTree</code> have children?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
         * This property is currently not implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
        protected boolean            hasChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
        /** Value to create children with. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
        protected Object             childValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        /** Have the children been loaded yet? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
        protected boolean            loadedChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
         * Adds to parent all the children in <code>children</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
         * If <code>children</code> is an array or vector all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
         * elements are added is children, otherwise if <code>children</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
         * is a hashtable all the key/value pairs are added in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
         * <code>Enumeration</code> returns them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
        public static void createChildren(DefaultMutableTreeNode parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                                          Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
            if(children instanceof Vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
                Vector          childVector = (Vector)children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
                for(int counter = 0, maxCounter = childVector.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
                    parent.add(new DynamicUtilTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
                               (childVector.elementAt(counter),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                                childVector.elementAt(counter)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
            else if(children instanceof Hashtable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
                Hashtable           childHT = (Hashtable)children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
                Enumeration         keys = childHT.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
                Object              aKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                while(keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                    aKey = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
                    parent.add(new DynamicUtilTreeNode(aKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                                                       childHT.get(aKey)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
            else if(children instanceof Object[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                Object[]             childArray = (Object[])children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
                for(int counter = 0, maxCounter = childArray.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
                    parent.add(new DynamicUtilTreeNode(childArray[counter],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
                                                       childArray[counter]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
         * Creates a node with the specified object as its value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
         * with the specified children. For the node to allow children,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
         * the children-object must be an array of objects, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
         * <code>Vector</code>, or a <code>Hashtable</code> -- even
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
         * if empty. Otherwise, the node is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
         * allowed to have children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
         * @param value  the <code>Object</code> that is the value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
         *              new node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
         * @param children an array of <code>Object</code>s, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
         *              <code>Vector</code>, or a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
         *              used to create the child nodes; if any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
         *              object is specified, or if the value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
         *              <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
         *              then the node is not allowed to have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
        public DynamicUtilTreeNode(Object value, Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
            super(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
            loadedChildren = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
            childValue = children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
            if(children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                if(children instanceof Vector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                else if(children instanceof Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                else if(children instanceof Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                    setAllowsChildren(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
            }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
         * Returns true if this node allows children. Whether the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
         * allows children depends on how it was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
         * @return true if this node allows children, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
         * @see #JTree.DynamicUtilTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
        public boolean isLeaf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
            return !getAllowsChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
         * Returns the number of child nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
         * @return the number of child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
        public int getChildCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
            return super.getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
         * Loads the children based on <code>childValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
         * If <code>childValue</code> is a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
         * or array each element is added as a child,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
         * if <code>childValue</code> is a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
         * each key/value pair is added in the order that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
         * <code>Enumeration</code> returns the keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
        protected void loadChildren() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
            loadedChildren = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
            createChildren(this, childValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
        public TreeNode getChildAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
            return super.getChildAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
        public Enumeration children() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
            return super.children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
            if (!rowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                rowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
        } else if (propertyName == "scrollsOnExpand") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            if (!scrollsOnExpandSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
                setScrollsOnExpand(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                scrollsOnExpandSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
        } else if (propertyName == "showsRootHandles") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
            if (!showsRootHandlesSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
                setShowsRootHandles(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
                showsRootHandlesSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
     * Returns a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
     * @return  a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
        String rootVisibleString = (rootVisible ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
        String showsRootHandlesString = (showsRootHandles ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
                                         "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
        String editableString = (editable ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                                 "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
        String largeModelString = (largeModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
        String invokesStopCellEditingString = (invokesStopCellEditing ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                                               "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
        String scrollsOnExpandString = (scrollsOnExpand ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                                        "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
        ",editable=" + editableString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
        ",invokesStopCellEditing=" + invokesStopCellEditingString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
        ",largeModel=" + largeModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
        ",rootVisible=" + rootVisibleString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
        ",scrollsOnExpand=" + scrollsOnExpandString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
        ",showsRootHandles=" + showsRootHandlesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
        ",toggleClickCount=" + toggleClickCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
        ",visibleRowCount=" + visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
     * Gets the AccessibleContext associated with this JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
     * For JTrees, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
     * AccessibleJTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
     * A new AccessibleJTree instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
     * @return an AccessibleJTree that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
     *         AccessibleContext of this JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
            accessibleContext = new AccessibleJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
     * <code>JTree</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
     * Java Accessibility API appropriate to tree user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
    protected class AccessibleJTree extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
            implements AccessibleSelection, TreeSelectionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
                       TreeModelListener, TreeExpansionListener  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
        TreePath   leadSelectionPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
        Accessible leadSelectionAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
        public AccessibleJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            // Add a tree model listener for JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
                model.addTreeModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            JTree.this.addTreeExpansionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
            JTree.this.addTreeSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
            leadSelectionPath = JTree.this.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            leadSelectionAccessible = (leadSelectionPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
                    ? new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
                                              leadSelectionPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
                                              JTree.this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                    : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
         * Tree Selection Listener value change method. Used to fire the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
         * property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
         * @param e ListSelectionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
        public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
            // Fixes 4546503 - JTree is sending incorrect active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
            // descendant events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
            TreePath oldLeadSelectionPath = e.getOldLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            leadSelectionPath = e.getNewLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            if (oldLeadSelectionPath != leadSelectionPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
                Accessible oldLSA = leadSelectionAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
                leadSelectionAccessible = (leadSelectionPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
                        ? new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
                                                  leadSelectionPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
                                                  null) // parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                        : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
                                   oldLSA, leadSelectionAccessible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
                               Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
         * Fire a visible data property change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
         * A 'visible' data property is one that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
         * something about the way the component appears on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
         * display, where that appearance isn't bound to any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
         * property. It notifies screen readers  that the visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
         * appearance of the component has changed, so they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
         * notify the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
        public void fireVisibleDataPropertyChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
                              Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
        // Fire the visible data changes for the model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
        public void treeNodesChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
        public void treeNodesInserted(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
         * @param e  a Tree node(s) removal event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
        public  void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
         * Tree Model structure change change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
        public  void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
         * Tree Collapsed notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
         * @param e  a TreeExpansionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        public  void treeCollapsed(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
                    AccessibleState.EXPANDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
                    AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
         * Tree Model Expansion notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
        public  void treeExpanded(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
                // TIGER - 4839971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
                    AccessibleState.COLLAPSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
                    AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
        private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
            Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
            if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4248
                return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
        private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
            // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
            // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
            // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
            TreePath path = new TreePath(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
            if (JTree.this.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
                TreeCellRenderer r = JTree.this.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                TreeUI ui = JTree.this.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
                if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                    int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                    int lsr = JTree.this.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                    boolean hasFocus = JTree.this.isFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                                       && (lsr == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                    boolean selected = JTree.this.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                    boolean expanded = JTree.this.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                    return r.getTreeCellRendererComponent(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                        model.getRoot(), selected, expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                        model.isLeaf(model.getRoot()), row, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
        // Overridden methods from AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
            return AccessibleRole.TREE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
         * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
         * @param p point in local coordinates of this <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            TreePath path = getClosestPathForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                // JTree.this is NOT the parent; parent will get computed later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
                return new AccessibleJTreeNode(JTree.this, path, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
         * Returns the number of top-level children nodes of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
         * JTree.  Each of these nodes may in turn have children nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
         * @return the number of accessible children nodes in the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
                return 1;    // the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
            // return the root's first set of children count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
            return model.getChildCount(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
         * Return the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
         * @param i zero-based index of child
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
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
                if (i == 0) {    // return the root node Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
                    Object[] objPath = { model.getRoot() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
                    return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
            // return Accessible for one of root's child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            int count = model.getChildCount(model.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
            if (i < 0 || i >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
            Object obj = model.getChild(model.getRoot(), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
            Object[] objPath = { model.getRoot(), obj };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
            TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
            return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
         * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
         * @return the index of this object in its parent.  Since a JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
         * top-level object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
            // didn't ever need to override this...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
            return super.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
         * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
         * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
            Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
            rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
            TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
         * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
         * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
         * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
         * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
         * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
         * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
                rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
                if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
                    return new AccessibleJTreeNode(JTree.this, childPath, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
         * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
         * @param i the zero-based index of the child in this Accessible object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                rootPath[0] = treeModel.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
                return JTree.this.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
         * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
         * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
         * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
         * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
           TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
           if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
               if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
                   Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
                   TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
                   JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
         * Removes the specified selected item in the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
                    Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
                    JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
         * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
         * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
            int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
            for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
                removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
         * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
         * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
                Object[] objPath = {model.getRoot()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
                TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
                JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
         * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
         * <code>JTree</code> child.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
         * Java Accessibility API appropriate to tree nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
        protected class AccessibleJTreeNode extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
            implements Accessible, AccessibleComponent, AccessibleSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
            AccessibleAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
            private JTree tree = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
            private TreeModel treeModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
            private Object obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
            private TreePath path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
            private Accessible accessibleParent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            private int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            private boolean isLeaf = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
             *  Constructs an AccessibleJTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
            public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
                tree = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
                path = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
                accessibleParent = ap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
                treeModel = t.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
                obj = p.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
                if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
                    isLeaf = treeModel.isLeaf(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
            private TreePath getChildTreePath(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                    return new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
             * Get the AccessibleContext associated with this tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
             * In the implementation of the Java Accessibility API for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
             * this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
             * AccessibleContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
                Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
                if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4571
                    return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
                // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
                // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
                // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
                if (tree.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
                    TreeCellRenderer r = tree.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
                    if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
                    TreeUI ui = tree.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
                    if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
                        int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
                        boolean selected = tree.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
                        boolean expanded = tree.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
                        boolean hasFocus = false; // how to tell?? -PK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
                        return r.getTreeCellRendererComponent(tree, obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
                            selected, expanded, isLeaf, row, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
             /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
              * Get the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
              *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
              * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
              * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
             public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
             * Set the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
             * @param s the new localized name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
            // *** should check tooltip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
             * Get the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
             * @return the localized description of the object; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
             * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
             * Set the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
             * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
             * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
             * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
             * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
                AccessibleStateSet states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
                    states = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
                    states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
                // need to test here, 'cause the underlying component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
                // is a cellRenderer, which is never showing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
                if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
                    states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
                } else if (states.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
                    states.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
                if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
                    states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
                } else if (states.contains(AccessibleState.VISIBLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
                    states.remove(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
                if (tree.isPathSelected(path)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
                    states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
                if (path == getLeadSelectionPath()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
                    states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
                if (!isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
                    states.add(AccessibleState.EXPANDABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
                if (tree.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
                    states.add(AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
                    states.add(AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
                if (tree.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
                    states.add(AccessibleState.EDITABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
                return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
             * Get the Accessible parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
             * @return the Accessible parent of this object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
             * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
                // someone wants to know, so we need to create our parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
                // if we don't have one (hey, we're a talented kid!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
                    if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
                        Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
                        if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
                            index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
                        Object[] objParentPath = new Object[objPath.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
                        java.lang.System.arraycopy(objPath, 0, objParentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
                                                   0, objPath.length-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
                        TreePath parentPath = new TreePath(objParentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
                        accessibleParent = new AccessibleJTreeNode(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
                                                                   parentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
                    } else if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
                        accessibleParent = tree; // we're the top!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
                        index = 0; // we're an only child!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
                return 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
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
             * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
             * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
                // index is invalid 'till we have an accessibleParent...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
                    getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
                Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
                if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
                    Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
                    if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
                        index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
             * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
                return treeModel.getChildCount(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
             * Return the specified Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
             * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
                    TreePath childPath = new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
                    return new AccessibleJTreeNode(JTree.this, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
             * Gets the locale of the component. If the component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
             * a locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
             * @return This component's locale. If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
             * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
             * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
             * If the Component does not have its own locale and has not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
             * been added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
             * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                    return tree.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
             * Add a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
             * @param l  The PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
             * Remove a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
             * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
             * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
             * @param l  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
             * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
             * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
             * Get the AccessibleComponent associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
             * AccessibleComponent interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
             * Get the AccessibleSelection associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
             * @return the AccessibleSelection, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
                if (ac != null && isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
                    return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
                    return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
             * Get the AccessibleText associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
             * @return the AccessibleText, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
                    return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
             * Get the AccessibleValue associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
             * @return the AccessibleValue, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
                    return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
             * Get the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
             * Set the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
             * @param c the new Color for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
            }
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
             * Get the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
                Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
                Rectangle parentBounds = tree.getVisibleRect();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5115
                return pathBounds != null && parentBounds != null &&
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5116
                        parentBounds.intersects(pathBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
            public void setVisible(boolean b) {
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 boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
                return (tree.isShowing() && isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
                if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
                    Point treeLocation = tree.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
                    Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
                    if (treeLocation != null && pathBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
                        Point nodeLocation = new Point(pathBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
                                                       pathBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                        nodeLocation.translate(treeLocation.x, treeLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
                        return nodeLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
                    }
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
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
            protected Point getLocationInJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
                Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
            public void setLocation(Point p) {
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 Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
                Accessible parent = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
                    if (parent instanceof AccessibleJTreeNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
                        Point parentLoc = ((AccessibleJTreeNode) parent).getLocationInJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
                        if (parentLoc != null && r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
                            r.translate(-parentLoc.x, -parentLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
                            return null;        // not visible!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
                return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
                return getBounds().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
             * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
             * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
             * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
             * @param p point in local coordinates of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
             *    <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
             * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
             *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
             * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
             * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
             * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
            public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
                       count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
                return 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
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
             * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
             * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
             * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
             * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
             * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
             * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
            public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
                    return null;        // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
                for (int j = 0; j < childCount && i >= count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
                    TreePath childPath = getChildTreePath(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
                        if (count == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
                            return new AccessibleJTreeNode(tree, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
                            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
             * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
             * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
             * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
            public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
                    return false;       // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
                    return tree.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
             * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
             * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
             * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
             * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
             * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
            public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
             * Removes the specified selected item in the object from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
             * object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
             * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
             * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
            public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
                       JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
             * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
             * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
            public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
                    removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
             * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
             * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
            public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
                   int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
                   TreePath path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
                   for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
                       path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
        // AccessibleAction methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
             * Returns the number of accessible actions available in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
             * tree node.  If this node is not a leaf, there is at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
             * one action (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
             * @return the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
            public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
                        return (aa.getAccessibleActionCount() + (isLeaf ? 0 : 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
                return 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
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
             * Return a description of the specified action of the tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
             * If this node is not a leaf, there is at least one action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
             * description (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
             * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
             * @return a description of the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
            public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
                    // TIGER - 4766636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
                    return AccessibleAction.TOGGLE_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
                        return aa.getAccessibleActionDescription(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
             * Perform the specified Action on the tree node.  If this node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
             * is not a leaf, there is at least one action which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
             * done (toggle expand), in addition to any available on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
             * object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
             * @param i zero-based index of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
             * @return true if the the action was performed; else false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
            public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
                    if (JTree.this.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
                        JTree.this.collapsePath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                        JTree.this.expandPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
                        return aa.doAccessibleAction(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
        } // inner class AccessibleJTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
    }  // inner class AccessibleJTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
} // End of class JTree