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