jdk/src/java.desktop/share/classes/javax/swing/JTree.java
author darcy
Fri, 03 Apr 2015 10:41:34 -0700
changeset 29894 3e16b51732f5
parent 29250 f9edd0824de6
child 31657 6b5f36a9a3c0
permissions -rw-r--r--
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}} Reviewed-by: alexsch
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    transient protected TreeModel        treeModel;
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    transient protected TreeSelectionModel selectionModel;
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    transient protected TreeCellRenderer  cellRenderer;
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
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   192
    transient private 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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    transient protected TreeCellEditor          cellEditor;
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    transient protected TreeModelListener       treeModelListener;
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
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   286
    transient private 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>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public final static String        CELL_RENDERER_PROPERTY = "cellRenderer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /** Bound property name for <code>treeModel</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public final static String        TREE_MODEL_PROPERTY = "model";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /** Bound property name for <code>rootVisible</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public final static String        ROOT_VISIBLE_PROPERTY = "rootVisible";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /** Bound property name for <code>showsRootHandles</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public final static String        SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /** Bound property name for <code>rowHeight</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public final static String        ROW_HEIGHT_PROPERTY = "rowHeight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /** Bound property name for <code>cellEditor</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public final static String        CELL_EDITOR_PROPERTY = "cellEditor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /** Bound property name for <code>editable</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public final static String        EDITABLE_PROPERTY = "editable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /** Bound property name for <code>largeModel</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public final static String        LARGE_MODEL_PROPERTY = "largeModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /** Bound property name for selectionModel. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public final static String        SELECTION_MODEL_PROPERTY = "selectionModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /** Bound property name for <code>visibleRowCount</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public final static String        VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /** Bound property name for <code>messagesStopCellEditing</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public final static String        INVOKES_STOP_CELL_EDITING_PROPERTY = "invokesStopCellEditing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /** Bound property name for <code>scrollsOnExpand</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public final static String        SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /** Bound property name for <code>toggleClickCount</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public final static String        TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount";
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 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public final static String        LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath";
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 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public final static String        ANCHOR_SELECTION_PATH_PROPERTY = "anchorSelectionPath";
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 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public final static String        EXPANDS_SELECTED_PATHS_PROPERTY = "expandsSelectedPaths";
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();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    assert checkOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                    location = new DropLocation(p, getPathForRow(row), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                    location = new DropLocation(p, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                        model.getIndexOfChild(parent.getLastPathComponent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                                              child.getLastPathComponent()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                } else if (checkOn || !model.isLeaf(root)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    location = new DropLocation(p, rootPath, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    location = new DropLocation(p, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                assert false : "Unexpected drop mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        if (outside || row != expandRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            cancelDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        if (!outside && row != expandRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            if (isCollapsed(row)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                expandRow = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                startDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * In some cases, the component may need to use it's internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        Object retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        DropLocation treeLocation = (DropLocation)location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        if (dropMode == DropMode.USE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            if (treeLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                if (!forDrop && state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                    setSelectionPaths(((TreePath[][])state)[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                    setAnchorSelectionPath(((TreePath[][])state)[1][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                    setLeadSelectionPath(((TreePath[][])state)[1][1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                if (dropLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                    TreePath[] paths = getSelectionPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                    if (paths == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                        paths = new TreePath[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                    retVal = new TreePath[][] {paths,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                            {getAnchorSelectionPath(), getLeadSelectionPath()}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                    retVal = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                setSelectionPath(treeLocation.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        DropLocation old = dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        dropLocation = treeLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        firePropertyChange("dropLocation", old, dropLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Called to indicate to this component that DnD is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * Allows for us to cancel the expand timer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    void dndDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        cancelDropTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        dropTimer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * Returns the location that this component should visually indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * as the drop location during a DnD operation over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * or {@code null} if no location is to currently be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     * This method is not meant for querying the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * from a {@code TransferHandler}, as the drop location is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * set after the {@code TransferHandler}'s <code>canImport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * has returned and has allowed for the location to be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * When this property changes, a property change event with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     * name "dropLocation" is fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * @return the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * @see TransferHandler#canImport(TransferHandler.TransferSupport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    public final DropLocation getDropLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        return dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    private void startDropTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        if (dropTimer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            dropTimer = new TreeTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        dropTimer.start();
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 cancelDropTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        if (dropTimer != null && dropTimer.isRunning()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            expandRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            dropTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * Returns <code>isEditable</code>. This is invoked from the UI before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * editing begins to insure that the given path can be edited. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * is provided as an entry point for subclassers to add filtered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * editing without having to resort to creating a new editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  1525
     * @param path a {@code TreePath} identifying a node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * @return true if every parent node and the node itself is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * @see #isEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    public boolean isPathEditable(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        return isEditable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * method in order to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * renderer's tips to be used if it has text set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * NOTE: For <code>JTree</code> to properly display tooltips of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * renderers, <code>JTree</code> must be a registered component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * <code>ToolTipManager</code>.  This can be done by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * <code>ToolTipManager.sharedInstance().registerComponent(tree)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * This is not done automatically!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * @param event the <code>MouseEvent</code> that initiated the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     *          <code>ToolTip</code> display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * @return a string containing the  tooltip or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     *          if <code>event</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        if(event != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            Point p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            int selRow = getRowForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            TreeCellRenderer       r = getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            if(selRow != -1 && r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                TreePath     path = getPathForRow(selRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                Object       lastPath = path.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                Component    rComponent = r.getTreeCellRendererComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    (this, lastPath, isRowSelected(selRow),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                     isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                     true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                if(rComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                    MouseEvent      newEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                    Rectangle       pathBounds = getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    p.translate(-pathBounds.x, -pathBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                    newEvent = new MouseEvent(rComponent, event.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                                          event.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                                              event.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                                              p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                                              event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                                              event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                                              event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                                              event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                                              MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                    tip = ((JComponent)rComponent).getToolTipText(newEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        // No tip from the renderer get our own tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        if (tip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            tip = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * Called by the renderers to convert the specified value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * text. This implementation returns <code>value.toString</code>, ignoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * all other arguments. To control the conversion, subclass this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     * method and use any of the arguments you need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     * @param value the <code>Object</code> to convert to text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * @param selected true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * @param expanded true if the node is expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * @param leaf  true if the node is a leaf node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * @param row  an integer specifying the node's display row, where 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     *             the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * @param hasFocus true if the node has the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @return the <code>String</code> representation of the node's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    public String convertValueToText(Object value, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                                     boolean expanded, boolean leaf, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                                     boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        if(value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            String sValue = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            if (sValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                return sValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    // The following are convenience methods that get forwarded to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    // current TreeUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * Returns the number of viewable nodes. A node is viewable if all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * parents are expanded. The root is only included in this count if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     * {@code isRootVisible()} is {@code true}. This returns {@code 0} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     * the UI has not been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * @return the number of viewable nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        TreeUI            tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            return tree.getRowCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * Selects the node identified by the specified path. If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * component of the path is hidden (under a collapsed node), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     * <code>getExpandsSelectedPaths</code> is true it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
     * exposed (made viewable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
     * @param path the <code>TreePath</code> specifying the node to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    public void setSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        getSelectionModel().setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     * Selects the nodes identified by the specified array of paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * If any component in any of the paths is hidden (under a collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * node), and <code>getExpandsSelectedPaths</code> is true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * it is exposed (made viewable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     * @param paths an array of <code>TreePath</code> objects that specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *          the nodes to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    public void setSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        getSelectionModel().setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * Sets the path identifies as the lead. The lead may not be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * The lead is not maintained by <code>JTree</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * rather the UI will update it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * @param newPath  the new lead path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     *  description: Lead selection path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    public void setLeadSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        TreePath          oldValue = leadPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        leadPath = newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);
24187
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1682
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1683
        // Fire the active descendant property change here since the
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1684
        // 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
  1685
        // selection changed and node focus changed
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1686
        if (accessibleContext != null){
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1687
            ((AccessibleJTree)accessibleContext).
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1688
                fireActiveDescendantPropertyChange(oldValue, newPath);
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  1689
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * Sets the path identified as the anchor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * The anchor is not maintained by <code>JTree</code>, rather the UI will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * update it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @param newPath  the new anchor path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     *  description: Anchor selection path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    public void setAnchorSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        TreePath          oldValue = anchorPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        anchorPath = newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Selects the node at the specified row in the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * @param row  the row to select, where 0 is the first row in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     *             the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public void setSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        int[]             rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        setSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * Selects the nodes corresponding to each of the specified rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * 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
  1727
     * &lt; 0 or &gt;= <code>getRowCount</code>, it will be ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * If none of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * in <code>rows</code> are valid rows, the selection will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * be cleared. That is it will be as if <code>clearSelection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @param rows  an array of ints specifying the rows to select,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     *              where 0 indicates the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    public void setSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        TreeUI               ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            for(int counter = 0; counter < numRows; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * Adds the node identified by the specified <code>TreePath</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * to the current selection. If any component of the path isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * viewable, and <code>getExpandsSelectedPaths</code> is true it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * made viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * Note that <code>JTree</code> does not allow duplicate nodes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * exist as children under the same parent -- each sibling must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * a unique object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * @param path the <code>TreePath</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    public void addSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        getSelectionModel().addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * Adds each path in the array of paths to the current selection. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * any component of any of the paths isn't viewable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * <code>getExpandsSelectedPaths</code> is true, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * made viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * Note that <code>JTree</code> does not allow duplicate nodes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * exist as children under the same parent -- each sibling must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * a unique object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * @param paths an array of <code>TreePath</code> objects that specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     *          the nodes to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    public void addSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        getSelectionModel().addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * Adds the path at the specified row to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * @param row  an integer specifying the row of the node to add,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     *             where 0 is the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    public void addSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        int[]      rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        addSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * Adds the paths at each of the specified rows to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * @param rows  an array of ints specifying the rows to add,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     *              where 0 indicates the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    public void addSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        TreeUI             ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            for(int counter = 0; counter < numRows; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * Returns the last path component of the selected path. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * a convenience method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * {@code getSelectionModel().getSelectionPath().getLastPathComponent()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * This is typically only useful if the selection has one path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * @return the last path component of the selected path, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     *         <code>null</code> if nothing is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * @see TreePath#getLastPathComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    public Object getLastSelectedPathComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        TreePath     selPath = getSelectionModel().getSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        if(selPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            return selPath.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * Returns the path identified as the lead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * @return path identified as the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    public TreePath getLeadSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        return leadPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * Returns the path identified as the anchor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * @return path identified as the anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
    public TreePath getAnchorSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        return anchorPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * Returns the path to the first selected node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * @return the <code>TreePath</code> for the first selected node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     *          or <code>null</code> if nothing is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    public TreePath getSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        return getSelectionModel().getSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * Returns the paths of all selected values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @return an array of <code>TreePath</code> objects indicating the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *         nodes, or <code>null</code> if nothing is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    public TreePath[] getSelectionPaths() {
10878
978071ed312e 7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents: 7668
diff changeset
  1866
        TreePath[] selectionPaths = getSelectionModel().getSelectionPaths();
978071ed312e 7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents: 7668
diff changeset
  1867
978071ed312e 7080203: JTree.getSelectionPaths() now returns empty array instead of null
rupashka
parents: 7668
diff changeset
  1868
        return (selectionPaths != null && selectionPaths.length > 0) ? selectionPaths : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * Returns all of the currently selected rows. This method is simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * forwarded to the <code>TreeSelectionModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     * If nothing is selected <code>null</code> or an empty array will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     * be returned, based on the <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * @return an array of integers that identifies all currently selected rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     *         where 0 is the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    public int[] getSelectionRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        return getSelectionModel().getSelectionRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * Returns the number of nodes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * @return the number of nodes selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
    public int getSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        return selectionModel.getSelectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * Returns the smallest selected row. If the selection is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * none of the selected paths are viewable, {@code -1} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * @return the smallest selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    public int getMinSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        return getSelectionModel().getMinSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * Returns the largest selected row. If the selection is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * none of the selected paths are viewable, {@code -1} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * @return the largest selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    public int getMaxSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        return getSelectionModel().getMaxSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * Returns the row index corresponding to the lead path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * @return an integer giving the row index of the lead path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     *          where 0 is the first row in the display; or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     *          if <code>leadPath</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    public int getLeadSelectionRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        TreePath leadPath = getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        if (leadPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            return getRowForPath(leadPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * Returns true if the item identified by the path is currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * @param path a <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * @return true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    public boolean isPathSelected(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        return getSelectionModel().isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * Returns true if the node identified by row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * @param row  an integer specifying a display row, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     *             row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * @return true if the node is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
    public boolean isRowSelected(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        return getSelectionModel().isRowSelected(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * Returns an <code>Enumeration</code> of the descendants of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * path <code>parent</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * are currently expanded. If <code>parent</code> is not currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * expanded, this will return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * If you expand/collapse nodes while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * iterating over the returned <code>Enumeration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * this may not return all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * the expanded paths, or may return paths that are no longer expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * @param parent  the path which is to be examined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * @return an <code>Enumeration</code> of the descendents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     *          <code>parent</code>, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     *          <code>parent</code> is not currently expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    public Enumeration<TreePath> getExpandedDescendants(TreePath parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        if(!isExpanded(parent))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1970
        Enumeration<TreePath> toggledPaths = expandedState.keys();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1971
        Vector<TreePath> elements = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        TreePath          path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        Object            value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        if(toggledPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            while(toggledPaths.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1977
                path = toggledPaths.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                value = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                // Add the path if it is expanded, a descendant of parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                // and it is visible (all parents expanded). This is rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                // expensive!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                if(path != parent && value != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                   ((Boolean)value).booleanValue() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                   parent.isDescendant(path) && isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                    if (elements == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  1986
                        elements = new Vector<TreePath>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                    elements.addElement(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        if (elements == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            Set<TreePath> empty = Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            return Collections.enumeration(empty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * Returns true if the node identified by the path has ever been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * expanded.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2002
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2003
     * @param path a {@code TreePath} identifying a node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * @return true if the <code>path</code> has ever been expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    public boolean hasBeenExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        return (path != null && expandedState.get(path) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * Returns true if the node identified by the path is currently expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * @param path  the <code>TreePath</code> specifying the node to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * @return false if any of the nodes in the node's path are collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *               true if all nodes in the path are expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    public boolean isExpanded(TreePath path) {
5950
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2018
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        if(path == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            return false;
5950
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2021
        Object  value;
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2022
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2023
        do{
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2024
            value = expandedState.get(path);
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2025
            if(value == null || !((Boolean)value).booleanValue())
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2026
                return false;
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2027
        } while( (path=path.getParentPath())!=null );
4beeac5abfed 6684401: JTree isExpanded should not call itself recursively
alexp
parents: 5506
diff changeset
  2028
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * Returns true if the node at the specified display row is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * @return true if the node is currently expanded, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
    public boolean isExpanded(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            TreePath         path = tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
            if(path != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2047
                Boolean value = expandedState.get(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                return (value != null && value.booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * Returns true if the value identified by path is currently collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * this will return false if any of the values in path are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * not being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * @param path  the <code>TreePath</code> to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * @return true if any of the nodes in the node's path are collapsed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     *               false if all nodes in the path are expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    public boolean isCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        return !isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * Returns true if the node at the specified display row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * @param row  the row to check, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * @return true if the node is currently collapsed, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    public boolean isCollapsed(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        return !isExpanded(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * Ensures that the node identified by path is currently viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * @param path  the <code>TreePath</code> to make visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    public void makeVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            if(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                expandPath(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * Returns true if the value identified by path is currently viewable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * which means it is either the root or all of its parents are expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * Otherwise, this method returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2099
     * @param path {@code TreePath} identifying a node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * @return true if the node is viewable, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    public boolean isVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            TreePath        parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            if(parentPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                return isExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            // Root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * Returns the <code>Rectangle</code> that the specified node will be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * into. Returns <code>null</code> if any component in the path is hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * (under a collapsed parent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * Note:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * This method returns a valid rectangle, even if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * node is not currently displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * @param path the <code>TreePath</code> identifying the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * @return the <code>Rectangle</code> the node is drawn in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    public Rectangle getPathBounds(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        TreeUI                   tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            return tree.getPathBounds(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * Returns the <code>Rectangle</code> that the node at the specified row is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * drawn in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     * @param row  the row to be drawn, where 0 is the first row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     *             display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     * @return the <code>Rectangle</code> the node is drawn in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    public Rectangle getRowBounds(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        return getPathBounds(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * Makes sure all the path components in path are expanded (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * for the last path component) and scrolls so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * node identified by the path is displayed. Only works when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * <code>JTree</code> is contained in a <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * @param path  the <code>TreePath</code> identifying the node to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     *          bring into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    public void scrollPathToVisible(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            makeVisible(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            Rectangle          bounds = getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            if(bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                scrollRectToVisible(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                    ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     * Scrolls the item identified by row until it is displayed. The minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * of amount of scrolling necessary to bring the row into view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * is performed. Only works when this <code>JTree</code> is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * @param row  an integer specifying the row to scroll, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    public void scrollRowToVisible(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        scrollPathToVisible(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     * Returns the path for the specified row.  If <code>row</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * not visible, or a {@code TreeUI} has not been set, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * @param row  an integer specifying a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @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
  2191
     *          <code>null</code> if <code>row &lt; 0</code>
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 18133
diff changeset
  2192
     *          or <code>row &gt;= getRowCount()</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    public TreePath getPathForRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            return tree.getPathForRow(this, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * Returns the row that displays the node identified by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @return an integer specifying the display row, where 0 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     *         row in the display, or -1 if any of the elements in path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     *         are hidden under a collapsed parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    public int getRowForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
            return tree.getRowForPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * expanded and viewable. If the last item in the path is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * leaf, this will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    public void expandPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        // Only expand if not leaf!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        TreeModel          model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
        if(path != null && model != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
           !model.isLeaf(path.getLastPathComponent())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            setExpandedState(path, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * Ensures that the node in the specified row is expanded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * <p>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 18133
diff changeset
  2240
     * If <code>row</code> is &lt; 0 or &gt;= <code>getRowCount</code> this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    public void expandRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        expandPath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * Ensures that the node identified by the specified path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * collapsed and viewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    public void collapsePath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        setExpandedState(path, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * Ensures that the node in the specified row is collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * <p>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 18133
diff changeset
  2263
     * If <code>row</code> is &lt; 0 or &gt;= <code>getRowCount</code> this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     * @param row  an integer specifying a display row, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     *             first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    public void collapseRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        collapsePath(getPathForRow(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     * Returns the path for the node at the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * @return  the <code>TreePath</code> for the node at that location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    public TreePath getPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        TreePath          closestPath = getClosestPathForLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        if(closestPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            Rectangle       pathBounds = getPathBounds(closestPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
            if(pathBounds != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
               x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
               y >= pathBounds.y && y < (pathBounds.y + pathBounds.height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                return closestPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * Returns the row for the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
     * @return the row corresponding to the location, or -1 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
     *         location is not within the bounds of a displayed cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
     * @see #getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
    public int getRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        return getRowForPath(getPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * no nodes are currently viewable, or there is no model, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * <code>null</code>, otherwise it always returns a valid path.  To test if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * the node is exactly at x, y, get the node's bounds and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * @return  the <code>TreePath</code> for the node closest to that location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     *          <code>null</code> if nothing is viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * @see #getPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     * @see #getPathBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    public TreePath getClosestPathForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            return tree.getClosestPathForLocation(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * Returns the row to the node that is closest to x,y.  If no nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * are viewable or there is no model, returns -1. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * it always returns a valid row.  To test if the returned object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     * exactly at x, y, get the bounds for the node at the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * row and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * @param x an integer giving the number of pixels horizontally from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     *          the left edge of the display area, minus any left margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * @param y an integer giving the number of pixels vertically from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     *          the top of the display area, minus any top margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * @return the row closest to the location, -1 if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     *         viewable or there is no model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * @see #getRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * @see #getRowBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    public int getClosestRowForLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        return getRowForPath(getClosestPathForLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * Returns true if the tree is being edited. The item that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     * edited can be obtained using <code>getSelectionPath</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
     * @return true if the user is currently editing a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
     * @see #getSelectionPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    public boolean isEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            return tree.isEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * Ends the current editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * (The <code>DefaultTreeCellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * object saves any edits that are currently in progress on a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * Other implementations may operate differently.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * Has no effect if the tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * <b>Note:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * To make edit-saves automatic whenever the user changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * their position in the tree, use {@link #setInvokesStopCellEditing}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * @return true if editing was in progress and is now stopped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     *              false if editing was not in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    public boolean stopEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            return tree.stopEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     * Cancels the current editing session. Has no effect if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * tree isn't being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
    public void  cancelEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            tree.cancelEditing(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * Selects the node identified by the specified path and initiates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * editing.  The edit-attempt fails if the <code>CellEditor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     * editing for the specified item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    public void startEditingAtPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            tree.startEditingAtPath(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * Returns the path to the element that is currently being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     * @return  the <code>TreePath</code> for the node being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    public TreePath getEditingPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        TreeUI                  tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            return tree.getEditingPath(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    // Following are primarily convenience methods for mapping from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    // row based selections to path selections.  Sometimes it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    // easier to deal with these than paths (mouse downs, key downs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    // usually just deal with index based selections).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    // Since row based selections require a UI many of these won't work
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
    // without one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * Sets the tree's selection model. When a <code>null</code> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * specified an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     * <code>selectionModel</code> is used, which does not allow selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
     * @param selectionModel the <code>TreeSelectionModel</code> to use,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
     *          or <code>null</code> to disable selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
     * @see TreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
     *  description: The tree's selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    public void setSelectionModel(TreeSelectionModel selectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        if(selectionModel == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            selectionModel = EmptySelectionModel.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        TreeSelectionModel         oldValue = this.selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        if (this.selectionModel != null && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            this.selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
           this.selectionModel.removeTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
           selectionModel.addTreeSelectionListener((TreeSelectionListener)accessibleContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        this.selectionModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        if (selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            this.selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
        firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                           this.selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                    AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
                    Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * Returns the model for selections. This should always return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * non-<code>null</code> value. If you don't want to allow anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * set the selection model to <code>null</code>, which forces an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * selection model to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2493
     * @return the model for selections
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * @see #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
    public TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * Returns the paths (inclusive) between the specified rows. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * the specified indices are within the viewable set of rows, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * bound the viewable set of rows, then the indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * constrained by the viewable set of rows. If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * indices are not within the viewable set of rows, or do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     * bound the viewable set of rows, then an empty array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
     * returned. For example, if the row count is {@code 10}, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
     * method is invoked with {@code -1, 20}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
     * indices are constrained to the viewable set of rows, and this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
     * treated as if invoked with {@code 0, 9}. On the other hand, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
     * this were invoked with {@code -10, -1}, then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
     * indices do not bound the viewable set of rows, and an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
     * array is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
     * getPathBetweenRows(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     * {@code getPathBetweenRows(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * An empty array is returned if the row count is {@code 0}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * the specified indices do not bound the viewable set of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * @param index0 the first index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * @param index1 the last index in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * @return the paths (inclusive) between the specified row indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
    protected TreePath[] getPathBetweenRows(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
        TreeUI           tree = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
        if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            int rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            if (rowCount > 0 && !((index0 < 0 && index1 < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                                  (index0 >= rowCount && index1 >= rowCount))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                index0 = Math.min(rowCount - 1, Math.max(index0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                index1 = Math.min(rowCount - 1, Math.max(index1, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                int minIndex = Math.min(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
                int maxIndex = Math.max(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                TreePath[] selection = new TreePath[
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                        maxIndex - minIndex + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
                for(int counter = minIndex; counter <= maxIndex; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                    selection[counter - minIndex] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
                            tree.getPathForRow(this, counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
        return new TreePath[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * Selects the rows in the specified interval (inclusive). If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * the viewable set of rows, then the specified rows are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * the selection is cleared. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * specified indices bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * invoked with {@code -10, -1}, then the specified indices do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * bound the viewable set of rows, and the selection is cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * setSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * {@code setSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * @param index0 the first index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * @param index1 the last index in the range to select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    public void setSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
        this.getSelectionModel().setSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * Adds the specified rows (inclusive) to the selection. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * the viewable set of rows, then the specified indices are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * constrained by the viewable set of rows. If the indices are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * within the viewable set of rows, or do not bound the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * set of rows, then the selection is unchanged. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * the row count is {@code 10}, and this method is invoked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * {@code -1, 20}, then the specified indices bounds the viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * range, and this is treated as if invoked with {@code 0, 9}. On
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     * the other hand, if this were invoked with {@code -10, -1}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     * the specified indices do not bound the viewable set of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * addSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * {@code addSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * @param index0 the first index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * @param index1 the last index in the range to add to the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
    public void addSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            this.getSelectionModel().addSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     * Removes the specified rows (inclusive) from the selection. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
     * the specified indices are within the viewable set of rows, or bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
     * the viewable set of rows, then the specified indices are constrained by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
     * the viewable set of rows. If the specified indices are not within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * viewable set of rows, or do not bound the viewable set of rows, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * the selection is unchanged. For example, if the row count is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * 10}, and this method is invoked with {@code -1, 20}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     * specified range bounds the viewable range, and this is treated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * if invoked with {@code 0, 9}. On the other hand, if this were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     * invoked with {@code -10, -1}, then the specified range does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * bound the viewable set of rows, and the selection is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     * The parameters are not order dependent. That is, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * removeSelectionInterval(x, y)} is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     * {@code removeSelectionInterval(y, x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * @param index0 the first row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
     * @param index1 the last row to remove from the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
    public void removeSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        TreePath[]         paths = getPathBetweenRows(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        if (paths != null && paths.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
            this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     * Removes the node identified by the specified path from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * @param path  the <code>TreePath</code> identifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
    public void removeSelectionPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
        this.getSelectionModel().removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * Removes the nodes identified by the specified paths from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     * current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * @param paths an array of <code>TreePath</code> objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     *              specifies the nodes to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    public void removeSelectionPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        this.getSelectionModel().removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     * Removes the row at the index <code>row</code> from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     * @param row  the row to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
    public void removeSelectionRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        int[]             rows = { row };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        removeSelectionRows(rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     * Removes the rows that are selected at each of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     * rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
     * @param rows  an array of ints specifying display rows, where 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     *             the first row in the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
    public void removeSelectionRows(int[] rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        TreeUI             ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
        if(ui != null && rows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            int                  numRows = rows.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            TreePath[]           paths = new TreePath[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            for(int counter = 0; counter < numRows; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                paths[counter] = ui.getPathForRow(this, rows[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            removeSelectionPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * Clears the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        getSelectionModel().clearSelection();
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
     * Returns true if the selection is currently empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     * @return true if the selection is currently empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
    public boolean isSelectionEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        return getSelectionModel().isSelectionEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     * Adds a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     * @param tel a TreeExpansionListener that will be notified when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     *            a tree node is expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
    public void addTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
        if (settingUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            uiTreeExpansionListener = tel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
        listenerList.add(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     * Removes a listener for <code>TreeExpansion</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     * @param tel the <code>TreeExpansionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    public void removeTreeExpansionListener(TreeExpansionListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
        listenerList.remove(TreeExpansionListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        if (uiTreeExpansionListener == tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
            uiTreeExpansionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     * Returns an array of all the <code>TreeExpansionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * to this JTree with addTreeExpansionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     * @return all of the <code>TreeExpansionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
    public TreeExpansionListener[] getTreeExpansionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2735
        return listenerList.getListeners(TreeExpansionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * Adds a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * @param tel a <code>TreeWillExpandListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     *            when a tree node will be expanded or collapsed (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     *            expansion")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
    public void addTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
        listenerList.add(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * Removes a listener for <code>TreeWillExpand</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     * @param tel the <code>TreeWillExpandListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
    public void removeTreeWillExpandListener(TreeWillExpandListener tel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        listenerList.remove(TreeWillExpandListener.class, tel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     * Returns an array of all the <code>TreeWillExpandListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     * to this JTree with addTreeWillExpandListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     * @return all of the <code>TreeWillExpandListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
    public TreeWillExpandListener[] getTreeWillExpandListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2767
        return listenerList.getListeners(TreeWillExpandListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     *          expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     public void fireTreeExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            uiTreeExpansionListener.treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                    treeExpanded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     *          collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
    public void fireTreeCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        if (uiTreeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            uiTreeExpansionListener.treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            if (listeners[i]==TreeExpansionListener.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                listeners[i + 1] != uiTreeExpansionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                ((TreeExpansionListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                    treeCollapsed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     *          expanded
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2839
     * @throws ExpandVetoException if the expansion is prevented from occurring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     public void fireTreeWillExpand(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                    treeWillExpand(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     * is lazily created using the <code>path</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
     * @param path the <code>TreePath</code> indicating the node that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
     *          expanded
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  2866
     * @throws ExpandVetoException if the collapse is prevented from occurring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
        TreeExpansionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
            if (listeners[i]==TreeWillExpandListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                    e = new TreeExpansionEvent(this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                ((TreeWillExpandListener)listeners[i+1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                    treeWillCollapse(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     * Adds a listener for <code>TreeSelection</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * @param tsl the <code>TreeSelectionListener</code> that will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     *            when a node is selected or deselected (a "negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     *            selection")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    public void addTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
        listenerList.add(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
           && selectionRedirector == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     * Removes a <code>TreeSelection</code> listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     * @param tsl the <code>TreeSelectionListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
    public void removeTreeSelectionListener(TreeSelectionListener tsl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        listenerList.remove(TreeSelectionListener.class,tsl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
        if(listenerList.getListenerCount(TreeSelectionListener.class) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
           && selectionRedirector != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
            selectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
                (selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            selectionRedirector = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
     * Returns an array of all the <code>TreeSelectionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     * to this JTree with addTreeSelectionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     * @return all of the <code>TreeSelectionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
    public TreeSelectionListener[] getTreeSelectionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  2926
        return listenerList.getListeners(TreeSelectionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * notification on this event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     * @param e the <code>TreeSelectionEvent</code> to be fired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     *          generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     *          <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     *          when a node is selected or deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
    protected void fireValueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
            // TreeSelectionEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
            if (listeners[i]==TreeSelectionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
                // if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
                // e = new ListSelectionEvent(this, firstIndex, lastIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
                ((TreeSelectionListener)listeners[i+1]).valueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
     * Sent when the tree has changed enough that we need to resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
     * the bounds, but not enough that we need to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
     * expanded node set (e.g nodes were expanded or collapsed, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
     * nodes were inserted into the tree). You should never have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
     * invoke this, the UI will invoke this as it needs to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
    public void treeDidChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
     * Sets the number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
     * This will only work if the tree is contained in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
     * <code>JScrollPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
     * and will adjust the preferred size and size of that scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
     * @param newCount the number of rows to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
     *  description: The number of rows that are to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
    public void setVisibleRowCount(int newCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
        int                 oldCount = visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
        visibleRowCount = newCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
        firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                           visibleRowCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
            ((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
     * Returns the number of rows that are displayed in the display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
     * @return the number of rows displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
    public int getVisibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
        return visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
     * Expands the root path, assuming the current TreeModel has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
    private void expandRoot() {
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3005
        TreeModel   model = getModel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
        if(model != null && model.getRoot() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
            expandPath(new TreePath(model.getRoot()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * Returns the TreePath to the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * begins with a prefix. To handle the conversion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * <code>TreePath</code> into a String, <code>convertValueToText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * @param prefix the string to test for a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * @param startingRow the row for starting the search
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * @param bias the search direction, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * Position.Bias.Forward or Position.Bias.Backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * @return the TreePath of the next tree element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * starts with the prefix; otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * @exception IllegalArgumentException if prefix is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     * or startingRow is out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
    public TreePath getNextMatch(String prefix, int startingRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
                                 Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
        int max = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
        if (prefix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
        if (startingRow < 0 || startingRow >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
        prefix = prefix.toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        // start search from the next/previous element froom the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
        // selected element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
        int increment = (bias == Position.Bias.Forward) ? 1 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
        int row = startingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
            TreePath path = getPathForRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            String text = convertValueToText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
                path.getLastPathComponent(), isRowSelected(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                isExpanded(row), true, row, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            if (text.toUpperCase().startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
                return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
            row = (row + increment + max) % max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
        } while (row != startingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
    private void writeObject(ObjectOutputStream s) throws IOException {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3059
        Vector<Object> values = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        // Save the cellRenderer, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
        if(cellRenderer != null && cellRenderer instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            values.addElement("cellRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            values.addElement(cellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
        // Save the cellEditor, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
        if(cellEditor != null && cellEditor instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
            values.addElement("cellEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
            values.addElement(cellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
        // Save the treeModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
        if(treeModel != null && treeModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            values.addElement("treeModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
            values.addElement(treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
        // Save the selectionModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        if(selectionModel != null && selectionModel instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
            values.addElement("selectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
            values.addElement(selectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
        Object      expandedData = getArchivableExpandedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
        if(expandedData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
            values.addElement("expandedState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
            values.addElement(expandedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
        s.writeObject(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
        throws IOException, ClassNotFoundException {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3102
        ObjectInputStream.GetField f = s.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3103
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3104
        rootVisible = f.get("rootVisible", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3105
        rowHeight = f.get("rowHeight", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3106
        rowHeightSet = f.get("rowHeightSet", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3107
        showsRootHandles = f.get("showsRootHandles", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3108
        showsRootHandlesSet = f.get("showsRootHandlesSet", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3109
        editable = f.get("editable", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3110
        largeModel = f.get("largeModel", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3111
        visibleRowCount = f.get("visibleRowCount", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3112
        invokesStopCellEditing = f.get("invokesStopCellEditing", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3113
        scrollsOnExpand = f.get("scrollsOnExpand", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3114
        scrollsOnExpandSet = f.get("scrollsOnExpandSet", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3115
        toggleClickCount = f.get("toggleClickCount", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3116
        leadPath = (TreePath) f.get("leadPath", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3117
        anchorPath = (TreePath) f.get("anchorPath", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3118
        expandsSelectedPaths = f.get("expandsSelectedPaths", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3119
        settingUI = f.get("settingUI", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3120
        boolean newDragEnabled = f.get("dragEnabled", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3121
        checkDragEnabled(newDragEnabled);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3122
        dragEnabled = newDragEnabled;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3123
        DropMode newDropMode = (DropMode) f.get("dropMode",
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3124
                DropMode.USE_SELECTION);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3125
        checkDropMode(newDropMode);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3126
        dropMode = newDropMode;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3127
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3128
        expandRow = f.get("expandRow", -1);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25568
diff changeset
  3129
        dropTimer = (TreeTimer) f.get("dropTimer", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
        // Create an instance of expanded state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3133
        expandedState = new Hashtable<TreePath, Boolean>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3134
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3135
        expandedStack = new Stack<Stack<TreePath>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3137
        Vector<?>          values = (Vector)s.readObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
        int             indexCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
        int             maxCounter = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
           equals("cellRenderer")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
            cellRenderer = (TreeCellRenderer)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
           equals("cellEditor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
            cellEditor = (TreeCellEditor)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
           equals("treeModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            treeModel = (TreeModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
           equals("selectionModel")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
            selectionModel = (TreeSelectionModel)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
           equals("expandedState")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            unarchiveExpandedState(values.elementAt(++indexCounter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
        // Reinstall the redirector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        if(listenerList.getListenerCount(TreeSelectionListener.class) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            selectionRedirector = new TreeSelectionRedirector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
            selectionModel.addTreeSelectionListener(selectionRedirector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
        // Listener to TreeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
            treeModelListener = createTreeModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            if(treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
                treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     * Returns an object that can be archived indicating what nodes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     * expanded and what aren't. The objects from the model are NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
     * written out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
    private Object getArchivableExpandedState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
        TreeModel       model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
        if(model != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3188
            Enumeration<TreePath> paths = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
            if(paths != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3191
                Vector<Object> state = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                while(paths.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3194
                    TreePath path = paths.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                    Object     archivePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
                        archivePath = getModelIndexsForPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
                    } catch (Error error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
                        archivePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
                    if(archivePath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
                        state.addElement(archivePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
                        state.addElement(expandedState.get(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
                return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
     * Updates the expanded state of nodes in the tree based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
     * previously archived state <code>state</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
    private void unarchiveExpandedState(Object state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
        if(state instanceof Vector) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3219
            Vector<?>          paths = (Vector)state;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
            for(int counter = paths.size() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
                Boolean        eState = (Boolean)paths.elementAt(counter--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
                TreePath       path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
                    path = getPathForIndexs((int[])paths.elementAt(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                    if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                        expandedState.put(path, eState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                } catch (Error error) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * Returns an array of integers specifying the indexs of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * components in the <code>path</code>. If <code>path</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * the root, this will return an empty array.  If <code>path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * is <code>null</code>, <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
    private int[] getModelIndexsForPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
            TreeModel   model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
            int         count = path.getPathCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
            int[]       indexs = new int[count - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
            Object      parent = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
            for(int counter = 1; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                indexs[counter - 1] = model.getIndexOfChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                                   (parent, path.getPathComponent(counter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                parent = path.getPathComponent(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
                if(indexs[counter - 1] < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
            return indexs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
     * Returns a <code>TreePath</code> created by obtaining the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
     * for each of the indices in <code>indexs</code>. If <code>indexs</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
     * or the <code>TreeModel</code> is <code>null</code>, it will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
    private TreePath getPathForIndexs(int[] indexs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
        if(indexs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        TreeModel    model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
        if(model == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        int          count = indexs.length;
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3275
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
        Object       parent = model.getRoot();
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3277
        if (parent == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3278
            return null;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3279
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
        TreePath     parentPath = new TreePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
        for(int counter = 0; counter < count; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            parent = model.getChild(parent, indexs[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            parentPath = parentPath.pathByAddingChild(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
        return parentPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
     * <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
     * that does not allow anything to be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
     * 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
  3299
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3303
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
    protected static class EmptySelectionModel extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
              DefaultTreeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
         * The single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        protected static final EmptySelectionModel sharedInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
            new EmptySelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
         * Returns the single instance of {@code EmptySelectionModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
         * @return single instance of {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
        static public EmptySelectionModel sharedInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
            return sharedInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
         * @param paths the paths to select; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        public void setSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
         * @param paths the paths to add to the selection; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
        public void addSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
         * @param paths the paths to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        public void removeSelectionPaths(TreePath[] paths) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
         * @param mode the selection mode; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
        public void setSelectionMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
         * @param mapper the {@code RowMapper} instance; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
        public void setRowMapper(RowMapper mapper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
        public void addTreeSelectionListener(TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
        public void removeTreeSelectionListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                TreeSelectionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
         * @param listener the listener to add; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
        public void addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
         * This is overriden to do nothing; {@code EmptySelectionModel}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
         * does not allow a selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
         * @param listener the listener to remove; this is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
         * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
        public void removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                                PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
     * Handles creating a new <code>TreeSelectionEvent</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
     * <code>JTree</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
     * source and passing it off to all the listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
     * 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
  3421
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3425
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
    protected class TreeSelectionRedirector implements Serializable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
                    TreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
         * Invoked by the <code>TreeSelectionModel</code> when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
         * selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
         * @param e the <code>TreeSelectionEvent</code> generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
         *              <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
        public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
            TreeSelectionEvent       newE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
            newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
            fireValueChanged(newE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
    } // End of class JTree.TreeSelectionRedirector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
    // Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * Returns the preferred display size of a <code>JTree</code>. The height is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * determined from <code>getVisibleRowCount</code> and the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     * is the current preferred width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     * @return a <code>Dimension</code> object containing the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
        int                 width = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
        int                 visRows = getVisibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        int                 height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
        if(isFixedRowHeight())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
            height = visRows * getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
            TreeUI          ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
            if (ui != null && visRows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
                int rc = ui.getRowCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                if (rc >= visRows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
                    Rectangle bounds = getRowBounds(visRows - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                        height = bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
                else if (rc > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                    Rectangle bounds = getRowBounds(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                    if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                        height = bounds.height * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            if (height == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
                height = 16 * visRows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     * Returns the amount to increment when scrolling. The amount is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * the height of the first displayed row that isn't completely in view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     * or, if it is totally displayed, the height of the next row in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * scrolling direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     *          greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
     * @see JScrollBar#setUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
                                          int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
        if(orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
            Rectangle       rowBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
            int             firstIndex = getClosestRowForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
                                         (0, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
            if(firstIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
                rowBounds = getRowBounds(firstIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
                if(rowBounds.y != visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
                    if(direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
                        // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                        return Math.max(0, (visibleRect.y - rowBounds.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
                    return (rowBounds.y + rowBounds.height - visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
                if(direction < 0) { // UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                    if(firstIndex != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
                        rowBounds = getRowBounds(firstIndex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
                        return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                    return rowBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
        return 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
     * Returns the amount for a block increment, which is the height or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
     * width of <code>visibleRect</code>, based on <code>orientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
     *          or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
     *          greater than zero for down/right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * @return the "block" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * @see JScrollBar#setBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                                           int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
        return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
            visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
     * Returns false to indicate that the width of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
     * determine the width of the table, unless the preferred width of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
     * the tree is smaller than the viewports width.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     * @return whether the tree should track the width of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
    public boolean getScrollableTracksViewportWidth() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3562
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3563
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3564
            return parent.getWidth() > getPreferredSize().width;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     * Returns false to indicate that the height of the viewport does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     * determine the height of the table, unless the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     * of the tree is smaller than the viewports height.  In other words:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     * ensure that the tree is never smaller than its viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
     * @return whether the tree should track the height of the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
    public boolean getScrollableTracksViewportHeight() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3579
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3580
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4278
diff changeset
  3581
            return parent.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
     * Sets the expanded state of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
     * If <code>state</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
     * true, all parents of <code>path</code> and path are marked as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
     * expanded. If <code>state</code> is false, all parents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
     * <code>path</code> are marked EXPANDED, but <code>path</code> itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
     * is marked collapsed.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     * 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
  3594
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3595
     * @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
  3596
     * @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
  3597
     *              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
  3598
     *              but {@code path} itself is marked collapsed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
    protected void setExpandedState(TreePath path, boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
        if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
            // Make sure all parents of path are expanded.
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3603
            Stack<TreePath> stack;
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3604
            TreePath parentPath = path.getParentPath();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
            if (expandedStack.size() == 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3607
                stack = new Stack<TreePath>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
            else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3610
                stack = expandedStack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
                while(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                    if(isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                        parentPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
                        stack.push(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
                        parentPath = parentPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
                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
  3624
                    parentPath = stack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
                    if(!isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
                            fireTreeWillExpand(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
                        } catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
                            // Expand vetoed!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
                        expandedState.put(parentPath, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                        fireTreeExpanded(parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
                            ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
                                              fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
                if (expandedStack.size() < TEMP_STACK_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
                    stack.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
                    expandedStack.push(stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
            if(!state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
                // collapse last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
                if(cValue != null && ((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
                        fireTreeWillCollapse(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
                    expandedState.put(path, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
                    fireTreeCollapsed(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
                    if (removeDescendantSelectedPaths(path, false) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
                        !isPathSelected(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
                        // A descendant was selected, select the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
                        addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
                                    fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                // Expand last path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
                Object          cValue = expandedState.get(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
                if(cValue == null || !((Boolean)cValue).booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
                        fireTreeWillExpand(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
                    catch (ExpandVetoException eve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
                    expandedState.put(path, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                    fireTreeExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
                    if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
                        ((AccessibleJTree)accessibleContext).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                                          fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
    /**
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3694
     * Returns an {@code Enumeration} of {@code TreePaths}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
     * that have been expanded that
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3696
     * are descendants of {@code parent}.
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3697
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3698
     * @param parent a path
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3699
     * @return the {@code Enumeration} of {@code TreePaths}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
    protected Enumeration<TreePath>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
        getDescendantToggledPaths(TreePath parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
        if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3707
        Vector<TreePath> descendants = new Vector<TreePath>();
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3708
        Enumeration<TreePath> nodes = expandedState.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
        while(nodes.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3711
            TreePath path = nodes.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
            if(parent.isDescendant(path))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
                descendants.addElement(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
        return descendants.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
     * Removes any descendants of the <code>TreePaths</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
     * <code>toRemove</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
     * that have been expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     * @param toRemove an enumeration of the paths to remove; a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
     *        {@code null} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     * @throws ClassCastException if {@code toRemove} contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
     *         element that is not a {@code TreePath}; {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     *         values are ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
     protected void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
         removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
         if(toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
             while(toRemove.hasMoreElements()) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3734
                 Enumeration<?> descendants = getDescendantToggledPaths
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  3735
                         (toRemove.nextElement());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
                 if(descendants != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                     while(descendants.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
                         expandedState.remove(descendants.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
      * Clears the cache of toggled tree paths. This does NOT send out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
      * any <code>TreeExpansionListener</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
     protected void clearToggledPaths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
         expandedState.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
      * Creates and returns an instance of <code>TreeModelHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
      * The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
      * object is responsible for updating the expanded state when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
      * <code>TreeModel</code> changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
      * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
      * For more information on what expanded state means, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
      * <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
  3762
      *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3763
      * @return the instance of {@code TreeModelHandler}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
     protected TreeModelListener createTreeModelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
         return new TreeModelHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
     * Removes any paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
     * <code>path</code>. If <code>includePath</code> is true and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
     * <code>path</code> is selected, it will be removed from the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3774
     * @param path a path
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3775
     * @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
  3776
     *                    it will be removed from the selection.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
     * @return true if a descendant was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
    protected boolean removeDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
                                                    boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
        TreePath[]    toRemove = getDescendantSelectedPaths(path, includePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
        if (toRemove != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            getSelectionModel().removeSelectionPaths(toRemove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
     * Returns an array of paths in the selection that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
     * <code>path</code>. The returned array may contain <code>null</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
    private TreePath[] getDescendantSelectedPaths(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
                                                  boolean includePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
        TreeSelectionModel   sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
        TreePath[]           selPaths = (sm != null) ? sm.getSelectionPaths() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
                                        null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
        if(selPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
            boolean        shouldRemove = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
            for(int counter = selPaths.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                if(selPaths[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
                   path.isDescendant(selPaths[counter]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
                   (!path.equals(selPaths[counter]) || includePath))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                    shouldRemove = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                    selPaths[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
            if(!shouldRemove) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
                selPaths = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            return selPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
     * Removes any paths from the selection model that are descendants of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
     * the nodes identified by in <code>e</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
    void removeDescendantSelectedPaths(TreeModelEvent e) {
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 11268
diff changeset
  3825
        TreePath            pPath = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
        Object[]            oldChildren = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
        TreeSelectionModel  sm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        if (sm != null && pPath != null && oldChildren != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
            oldChildren.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
            for (int counter = oldChildren.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                 counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                // Might be better to call getDescendantSelectedPaths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
                // numerous times, then push to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
                removeDescendantSelectedPaths(pPath.pathByAddingChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
                                              (oldChildren[counter]), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
      * Listens to the model and updates the <code>expandedState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
      * accordingly when nodes are removed, or changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
    protected class TreeModelHandler implements TreeModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        public void treeNodesChanged(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
        public void treeNodesInserted(TreeModelEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
        public void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
            // NOTE: If I change this to NOT remove the descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
            // and update BasicTreeUIs treeStructureChanged method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
            // to update descendants in response to a treeStructureChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
            // 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
  3859
            TreePath            parent = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
            if(parent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
            if (parent.getPathCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
                // New root, remove everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
                clearToggledPaths();
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3867
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3868
              Object treeRoot = treeModel.getRoot();
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3869
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3870
              if(treeRoot != null &&
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  3871
                !treeModel.isLeaf(treeRoot)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
                    // Mark the root as expanded, if it isn't a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
                    expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
            else if(expandedState.get(parent) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                Vector<TreePath>    toRemove = new Vector<TreePath>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                boolean             isExpanded = isExpanded(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
                toRemove.addElement(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
                if(isExpanded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
                    TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
                    if(model == null || model.isLeaf
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                       (parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
                        collapsePath(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                        expandedState.put(parent, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
            removeDescendantSelectedPaths(parent, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
        public void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
            if(e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 11268
diff changeset
  3899
            TreePath            parent = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
            Object[]            children = e.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
            if(children == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
            TreePath            rPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
            Vector<TreePath>    toRemove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
                = new Vector<TreePath>(Math.max(1, children.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            for(int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
                rPath = parent.pathByAddingChild(children[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
                if(expandedState.get(rPath) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
                    toRemove.addElement(rPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
            if(toRemove.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
                removeDescendantToggledPaths(toRemove.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
            TreeModel         model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
            if(model == null || model.isLeaf(parent.getLastPathComponent()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                expandedState.remove(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
            removeDescendantSelectedPaths(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
     * <code>DynamicUtilTreeNode</code> can wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
     * vectors/hashtables/arrays/strings and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
     * create the appropriate children tree nodes as necessary. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
     * dynamic in that it will only create the children as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
     * 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
  3938
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3942
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
    public static class DynamicUtilTreeNode extends DefaultMutableTreeNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
         * Does the this <code>JTree</code> have children?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
         * This property is currently not implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
        protected boolean            hasChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
        /** Value to create children with. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
        protected Object             childValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
        /** Have the children been loaded yet? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
        protected boolean            loadedChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
         * Adds to parent all the children in <code>children</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
         * If <code>children</code> is an array or vector all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
         * elements are added is children, otherwise if <code>children</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
         * is a hashtable all the key/value pairs are added in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
         * <code>Enumeration</code> returns them.
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3960
         *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3961
         * @param parent the parent node
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  3962
         * @param children the children
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
        public static void createChildren(DefaultMutableTreeNode parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
                                          Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
            if(children instanceof Vector) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3967
                Vector<?>          childVector = (Vector)children;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                for(int counter = 0, maxCounter = childVector.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
                    parent.add(new DynamicUtilTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
                               (childVector.elementAt(counter),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
                                childVector.elementAt(counter)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
            else if(children instanceof Hashtable) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3976
                Hashtable<?,?>           childHT = (Hashtable)children;
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  3977
                Enumeration<?>         keys = childHT.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
                Object              aKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                while(keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
                    aKey = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                    parent.add(new DynamicUtilTreeNode(aKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                                                       childHT.get(aKey)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
            else if(children instanceof Object[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                Object[]             childArray = (Object[])children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                for(int counter = 0, maxCounter = childArray.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                    counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                    parent.add(new DynamicUtilTreeNode(childArray[counter],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                                                       childArray[counter]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
         * Creates a node with the specified object as its value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
         * with the specified children. For the node to allow children,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
         * the children-object must be an array of objects, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
         * <code>Vector</code>, or a <code>Hashtable</code> -- even
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
         * if empty. Otherwise, the node is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
         * allowed to have children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
         * @param value  the <code>Object</code> that is the value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
         *              new node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
         * @param children an array of <code>Object</code>s, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
         *              <code>Vector</code>, or a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
         *              used to create the child nodes; if any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
         *              object is specified, or if the value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
         *              <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
         *              then the node is not allowed to have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
        public DynamicUtilTreeNode(Object value, Object children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
            super(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
            loadedChildren = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
            childValue = children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
            if(children != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
                if(children instanceof Vector)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
                else if(children instanceof Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                else if(children instanceof Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                    setAllowsChildren(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
                    setAllowsChildren(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
                setAllowsChildren(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
         * Returns true if this node allows children. Whether the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
         * allows children depends on how it was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
         * @return true if this node allows children, false otherwise
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
  4036
         * @see JTree.DynamicUtilTreeNode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
        public boolean isLeaf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
            return !getAllowsChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
         * Returns the number of child nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
         * @return the number of child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
        public int getChildCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
            return super.getChildCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
         * Loads the children based on <code>childValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
         * If <code>childValue</code> is a <code>Vector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
         * or array each element is added as a child,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
         * if <code>childValue</code> is a <code>Hashtable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
         * each key/value pair is added in the order that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
         * <code>Enumeration</code> returns the keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
        protected void loadChildren() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
            loadedChildren = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
            createChildren(this, childValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        public TreeNode getChildAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
            return super.getChildAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
         * Subclassed to load the children, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
         */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4078
        public Enumeration<TreeNode> children() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
            if(!loadedChildren)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
                loadChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
            return super.children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
            if (!rowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
                rowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        } else if (propertyName == "scrollsOnExpand") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
            if (!scrollsOnExpandSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
                setScrollsOnExpand(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                scrollsOnExpandSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
        } else if (propertyName == "showsRootHandles") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            if (!showsRootHandlesSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
                setShowsRootHandles(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
                showsRootHandlesSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
     * Returns a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
     * @return  a string representation of this <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
        String rootVisibleString = (rootVisible ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
        String showsRootHandlesString = (showsRootHandles ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
                                         "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
        String editableString = (editable ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
                                 "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
        String largeModelString = (largeModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
        String invokesStopCellEditingString = (invokesStopCellEditing ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
                                               "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
        String scrollsOnExpandString = (scrollsOnExpand ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
                                        "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
        ",editable=" + editableString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
        ",invokesStopCellEditing=" + invokesStopCellEditingString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
        ",largeModel=" + largeModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
        ",rootVisible=" + rootVisibleString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
        ",scrollsOnExpand=" + scrollsOnExpandString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
        ",showsRootHandles=" + showsRootHandlesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
        ",toggleClickCount=" + toggleClickCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
        ",visibleRowCount=" + visibleRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
     * Gets the AccessibleContext associated with this JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
     * For JTrees, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
     * AccessibleJTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
     * A new AccessibleJTree instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
     * @return an AccessibleJTree that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
     *         AccessibleContext of this JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
            accessibleContext = new AccessibleJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
     * <code>JTree</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
     * Java Accessibility API appropriate to tree user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
     * 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
  4173
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  4177
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
    protected class AccessibleJTree extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
            implements AccessibleSelection, TreeSelectionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
                       TreeModelListener, TreeExpansionListener  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
        TreePath   leadSelectionPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
        Accessible leadSelectionAccessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4185
        /**
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4186
         * Constructs {@code AccessibleJTree}
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4187
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        public AccessibleJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
            // Add a tree model listener for JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
                model.addTreeModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
            JTree.this.addTreeExpansionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
            JTree.this.addTreeSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
            leadSelectionPath = JTree.this.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
            leadSelectionAccessible = (leadSelectionPath != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
                    ? new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
                                              leadSelectionPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
                                              JTree.this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
                    : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
         * Tree Selection Listener value change method. Used to fire the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
         * property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
         * @param e ListSelectionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
        public void valueChanged(TreeSelectionEvent e) {
24187
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4212
             firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4213
                                Boolean.valueOf(false), Boolean.valueOf(true));
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4214
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
         * Fire a visible data property change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
         * A 'visible' data property is one that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
         * something about the way the component appears on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
         * display, where that appearance isn't bound to any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
         * property. It notifies screen readers  that the visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
         * appearance of the component has changed, so they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
         * notify the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
        public void fireVisibleDataPropertyChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
                              Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
        // Fire the visible data changes for the model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
        public void treeNodesChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
        public void treeNodesInserted(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
         * Tree Model Node change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
         * @param e  a Tree node(s) removal event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        public  void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
         * Tree Model structure change change notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
         * @param e  a Tree Model event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
        public  void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
           fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
         * Tree Collapsed notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
         * @param e  a TreeExpansionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
        public  void treeCollapsed(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
                    AccessibleState.EXPANDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
                    AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
         * Tree Model Expansion notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
         * @param e  a Tree node insertion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
        public  void treeExpanded(TreeExpansionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
            fireVisibleDataPropertyChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
            TreePath path = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                // TIGER - 4839971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                // Set parent to null so AccessibleJTreeNode computes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
                // its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                AccessibleJTreeNode node = new AccessibleJTreeNode(JTree.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                                                                   path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                PropertyChangeEvent pce = new PropertyChangeEvent(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
                    AccessibleState.COLLAPSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                    AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                                   null, pce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
24187
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4315
        /**
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4316
        *  Fire an active descendant property change notification.
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4317
        *  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
  4318
        *  tree, and table, which may have transient children.
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4319
        *  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
  4320
        *  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
  4321
        *
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4322
        * @param oldPath - lead path of previous active child
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4323
        * @param newPath - lead path of current active child
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4324
        *
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4325
        */
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4326
        void fireActiveDescendantPropertyChange(TreePath oldPath, TreePath newPath){
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4327
            if(oldPath != newPath){
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4328
                Accessible oldLSA = (oldPath != null)
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4329
                                    ? new AccessibleJTreeNode(JTree.this,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4330
                                                              oldPath,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4331
                                                              null)
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4332
                                    : null;
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4333
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4334
                Accessible newLSA = (newPath != null)
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4335
                                    ? new AccessibleJTreeNode(JTree.this,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4336
                                                              newPath,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4337
                                                              null)
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
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4340
                                                                oldLSA, newLSA);
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4341
            }
971bf0a51f75 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event
asaha
parents: 23010
diff changeset
  4342
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
        private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
            Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
            if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4347
                return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
        private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
            // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
            // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
            }
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4361
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4362
            Object treeRoot = model.getRoot();
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4363
            if (treeRoot == null) {
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4364
                return null;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4365
            }
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4366
            TreePath path = new TreePath(treeRoot);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
            if (JTree.this.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
                TreeCellRenderer r = JTree.this.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
                TreeUI ui = JTree.this.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
                if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
                    int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
                    int lsr = JTree.this.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
                    boolean hasFocus = JTree.this.isFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
                                       && (lsr == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
                    boolean selected = JTree.this.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
                    boolean expanded = JTree.this.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
                    return r.getTreeCellRendererComponent(JTree.this,
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4379
                        treeRoot, selected, expanded,
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4380
                        model.isLeaf(treeRoot), row, hasFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
        // Overridden methods from AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
            return AccessibleRole.TREE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
         * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
         * @param p point in local coordinates of this <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
            TreePath path = getClosestPathForLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
            if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
                // JTree.this is NOT the parent; parent will get computed later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
                return new AccessibleJTreeNode(JTree.this, path, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
         * Returns the number of top-level children nodes of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
         * JTree.  Each of these nodes may in turn have children nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
         * @return the number of accessible children nodes in the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                return 1;    // the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4433
            Object treeRoot = model.getRoot();
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4434
            if (treeRoot == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4435
                return 0;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4436
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            // return the root's first set of children count
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4438
            return model.getChildCount(treeRoot);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
         * Return the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
            if (model == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
            }
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4452
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4453
            Object treeRoot = model.getRoot();
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4454
            if (treeRoot == null) {
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4455
                return null;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4456
            }
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4457
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
            if (isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
                if (i == 0) {    // return the root node Accessible
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4460
                    Object[] objPath = { treeRoot };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
                    return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
            // return Accessible for one of root's child nodes
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4469
            int count = model.getChildCount(treeRoot);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
            if (i < 0 || i >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
            }
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4473
            Object obj = model.getChild(treeRoot, i);
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4474
            if (obj == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4475
                return null;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4476
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4477
            Object[] objPath = {treeRoot, obj };
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4478
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
            TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            return new AccessibleJTreeNode(JTree.this, path, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
         * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
         * @return the index of this object in its parent.  Since a JTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
         * top-level object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
            // didn't ever need to override this...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
            return super.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
         * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
         * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
         * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
            Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
            rootPath[0] = treeModel.getRoot();
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4517
            if (rootPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4518
                return 0;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4519
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
            TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
            if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
         * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
         * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
         * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
         * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
         * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
         * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
                rootPath[0] = treeModel.getRoot();
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4542
                if (rootPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4543
                    return null;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4544
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                if (JTree.this.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
                    return new AccessibleJTreeNode(JTree.this, childPath, JTree.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
         * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
         * @param i the zero-based index of the child in this Accessible object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
            // The JTree can have only one accessible child, the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
            if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
                Object[] rootPath = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
                rootPath[0] = treeModel.getRoot();
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4564
                if (rootPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4565
                    return false;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4566
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
                TreePath childPath = new TreePath(rootPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
                return JTree.this.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
         * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
         * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
         * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
         * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
           TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
           if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
               if (i == 0) {
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4587
                    Object[] objPath = {model.getRoot()};
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4588
                    if (objPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4589
                        return;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4590
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
                   TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
                   JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
         * Removes the specified selected item in the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
         * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
                    Object[] objPath = {model.getRoot()};
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4609
                    if (objPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4610
                        return;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4611
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
                    TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
                    JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
         * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
         * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
            int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
            for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
                removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
         * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
         * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
            TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
                Object[] objPath = {model.getRoot()};
29250
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4637
                if (objPath[0] == null)
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4638
                    return;
f9edd0824de6 8068518: IllegalArgumentException in JTree.AccessibleJTree
van
parents: 28059
diff changeset
  4639
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
                TreePath path = new TreePath(objPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
                JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
         * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
         * <code>JTree</code> child.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
         * Java Accessibility API appropriate to tree nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
        protected class AccessibleJTreeNode extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
            implements Accessible, AccessibleComponent, AccessibleSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
            AccessibleAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
            private JTree tree = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
            private TreeModel treeModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            private Object obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
            private TreePath path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
            private Accessible accessibleParent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
            private int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
            private boolean isLeaf = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
            /**
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4663
             * Constructs an AccessibleJTreeNode
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4664
             *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4665
             * @param t an instance of {@code JTree}
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4666
             * @param p an instance of {@code TreePath}
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  4667
             * @param ap an instance of {@code Accessible}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
            public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
                tree = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
                path = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
                accessibleParent = ap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
                treeModel = t.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
                obj = p.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
                if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
                    isLeaf = treeModel.isLeaf(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
            private TreePath getChildTreePath(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
                    return new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
             * Get the AccessibleContext associated with this tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
             * In the implementation of the Java Accessibility API for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
             * this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
             * AccessibleContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
                Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
                if (c instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  4711
                    return c.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
                // is the object visible?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
                // if so, get row, selected, focus & leaf state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
                // and then get the renderer component and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
                if (tree.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
                    TreeCellRenderer r = tree.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
                    if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
                    TreeUI ui = tree.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
                    if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
                        int row = ui.getRowForPath(JTree.this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                        boolean selected = tree.isPathSelected(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
                        boolean expanded = tree.isExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
                        boolean hasFocus = false; // how to tell?? -PK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
                        return r.getTreeCellRendererComponent(tree, obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
                            selected, expanded, isLeaf, row, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
             /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
              * Get the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
              *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
              * @return the localized name of the object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
              * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
             public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
             * Set the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
             * @param s the new localized name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
            // *** should check tooltip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
             * Get the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
             * @return the localized description of the object; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
             * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
             * Set the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
             * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
             * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
             * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
             * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
             * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
                AccessibleStateSet states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                    states = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                    states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
                // need to test here, 'cause the underlying component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
                // is a cellRenderer, which is never showing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
                if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
                    states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
                } else if (states.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                    states.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                    states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                } else if (states.contains(AccessibleState.VISIBLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                    states.remove(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                if (tree.isPathSelected(path)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                    states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
                if (path == getLeadSelectionPath()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                    states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
                if (!isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
                    states.add(AccessibleState.EXPANDABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
                if (tree.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
                    states.add(AccessibleState.EXPANDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
                    states.add(AccessibleState.COLLAPSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
                if (tree.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
                    states.add(AccessibleState.EDITABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
                return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
             * Get the Accessible parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
             * @return the Accessible parent of this object; null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
             * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
                // someone wants to know, so we need to create our parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
                // if we don't have one (hey, we're a talented kid!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
                    if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
                        Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
                        if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
                            index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
                        Object[] objParentPath = new Object[objPath.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
                        java.lang.System.arraycopy(objPath, 0, objParentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
                                                   0, objPath.length-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
                        TreePath parentPath = new TreePath(objParentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
                        accessibleParent = new AccessibleJTreeNode(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
                                                                   parentPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
                                                                   null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
                    } else if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
                        accessibleParent = tree; // we're the top!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
                        index = 0; // we're an only child!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
                        this.setAccessibleParent(accessibleParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
                return accessibleParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
             * Get the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
             * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
                // index is invalid 'till we have an accessibleParent...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
                if (accessibleParent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
                    getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
                Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
                if (objPath.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
                    Object objParent = objPath[objPath.length-2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
                    if (treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
                        index = treeModel.getIndexOfChild(objParent, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
             * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
                return treeModel.getChildCount(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
             * Return the specified Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
             * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
                // Tree nodes can't be so complex that they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
                // two sets of children -> we're ignoring that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
                if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
                    Object childObj = treeModel.getChild(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
                    Object[] objPath = path.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
                    Object[] objChildPath = new Object[objPath.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
                    java.lang.System.arraycopy(objPath, 0, objChildPath, 0, objPath.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
                    objChildPath[objChildPath.length-1] = childObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
                    TreePath childPath = new TreePath(objChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
                    return new AccessibleJTreeNode(JTree.this, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
             * Gets the locale of the component. If the component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
             * a locale, then the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
             * @return This component's locale. If this component does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
             * a locale, the locale of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
             * @exception IllegalComponentStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
             * If the Component does not have its own locale and has not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
             * been added to a containment hierarchy such that the locale can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
             * determined from the containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
                    return tree.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
             * Add a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
             * @param l  The PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
             * Remove a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
             * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
             * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
             * @param l  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
             * Get the AccessibleAction associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
             * AccessibleAction interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
             * Get the AccessibleComponent associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
             * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
             * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
             * AccessibleComponent interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
             * Get the AccessibleSelection associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
             * @return the AccessibleSelection, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
                if (ac != null && isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
                    return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
                    return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
             * Get the AccessibleText associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
             * @return the AccessibleText, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
                    return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
             * Get the AccessibleValue associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
             * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
             * @return the AccessibleValue, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
                    return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
             * Get the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
             * Set the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
             * @param c the new Color for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
             * Get the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
             * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
                Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
                Rectangle parentBounds = tree.getVisibleRect();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5255
                return pathBounds != null && parentBounds != null &&
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
  5256
                        parentBounds.intersects(pathBounds);
2
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 void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
                return (tree.isShowing() && isVisible());
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 boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
                if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
                    Point treeLocation = tree.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                    Rectangle pathBounds = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                    if (treeLocation != null && pathBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                        Point nodeLocation = new Point(pathBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                                                       pathBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                        nodeLocation.translate(treeLocation.x, treeLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                        return nodeLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  5299
            /**
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  5300
             * Returns the relative location of the node
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  5301
             *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  5302
             * @return the relative location of the node
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 24187
diff changeset
  5303
             */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
            protected Point getLocationInJTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
                Rectangle r = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
                if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
                    return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
                Rectangle r = tree.getPathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
                Accessible parent = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
                    if (parent instanceof AccessibleJTreeNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
                        Point parentLoc = ((AccessibleJTreeNode) parent).getLocationInJTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
                        if (parentLoc != null && r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
                            r.translate(-parentLoc.x, -parentLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
                            return null;        // not visible!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
                return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
                return getBounds().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
             * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
             * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
             * Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
             * @param p point in local coordinates of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
             *    <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
             * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
             *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 10878
diff changeset
  5388
            @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
        // AccessibleSelection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
             * Returns the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
             * If no items are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
             * @return the number of items currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
            public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
                       count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
                return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
             * Returns an Accessible representing the specified selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
             * in the object.  If there isn't a selection, or there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
             * fewer items selected than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
             * value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
             * @param i the zero-based index of selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
             * @return an Accessible containing the selected item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
            public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
                    return null;        // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
                for (int j = 0; j < childCount && i >= count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
                    TreePath childPath = getChildTreePath(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
                    if (tree.isPathSelected(childPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
                        if (count == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
                            return new AccessibleJTreeNode(tree, childPath, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
                            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
             * Returns true if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
             * @param i the zero-based index of the child in this Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
             * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
            public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
                if (i < 0 || i >= childCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
                    return false;       // out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
                    TreePath childPath = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
                    return tree.isPathSelected(childPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
             * Adds the specified selected item in the object to the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
             * selection.  If the object supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
             * the specified item is added to any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
             * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
             * specified item is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
            public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5523
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
             * Removes the specified selected item in the object from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
             * object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
             * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5527
             * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5528
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5529
             * @param i the zero-based index of selectable items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5530
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
            public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5532
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5534
                   if (i >= 0 && i < getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
                       TreePath path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
                       JTree.this.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
             * Clears the selection in the object, so that nothing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
             * object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
            public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
                int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
                for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
                    removeAccessibleSelection(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
             * Causes every selected item in the object to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
             * if the object supports multiple selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
            public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
               TreeModel model = JTree.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
               if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
                   int childCount = getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
                   TreePath path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
                   for (int i = 0; i < childCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
                       path = getChildTreePath(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
                       JTree.this.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
        // AccessibleAction methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
             * Returns the number of accessible actions available in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
             * tree node.  If this node is not a leaf, there is at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
             * one action (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
             * @return the number of Actions in this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
            public int getAccessibleActionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
                        return (aa.getAccessibleActionCount() + (isLeaf ? 0 : 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
                return isLeaf ? 0 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
             * Return a description of the specified action of the tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
             * If this node is not a leaf, there is at least one action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
             * description (toggle expand), in addition to any available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
             * on the object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
             * @param i zero-based index of the actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
             * @return a description of the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
            public String getAccessibleActionDescription(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
                    // TIGER - 4766636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
                    return AccessibleAction.TOGGLE_EXPAND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
                        return aa.getAccessibleActionDescription(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
             * Perform the specified Action on the tree node.  If this node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
             * is not a leaf, there is at least one action which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
             * done (toggle expand), in addition to any available on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
             * object behind the TreeCellRenderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
             * @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
  5622
             * @return true if the action was performed; else false.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
            public boolean doAccessibleAction(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
                if (i < 0 || i >= getAccessibleActionCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
                    if (JTree.this.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
                        JTree.this.collapsePath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
                        JTree.this.expandPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
                } else if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
                    AccessibleAction aa = ac.getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
                    if (aa != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
                        return aa.doAccessibleAction(i - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
        } // inner class AccessibleJTreeNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
    }  // inner class AccessibleJTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
} // End of class JTree