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