jdk/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java
author aeremeev
Mon, 14 Jul 2014 18:44:50 +0400
changeset 25775 6a6fd62bc6d5
parent 25565 ce603b34c98d
child 25784 656f7d3eef5f
permissions -rw-r--r--
8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7 Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 4394
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: 4394
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: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
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.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.TreeUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.text.Position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
20097
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18133
diff changeset
    45
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 20097
diff changeset
    52
 * The basic L&F for a hierarchical data structure.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Shannon Hickey (drag and drop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class BasicTreeUI extends TreeUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final StringBuilder BASELINE_COMPONENT_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        new StringBuilder("Tree.baselineComponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Old actions forward to an instance of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static private final Actions SHARED_ACTION = new Actions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    66
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    67
     * The collapsed icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    68
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    transient protected Icon        collapsedIcon;
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    70
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    71
     * The expanded icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
    72
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    transient protected Icon        expandedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      * Color used to draw hash marks.  If <code>null</code> no hash marks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
      * will be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Color hashColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /** Distance between left margin and where vertical dashes will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      * drawn. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected int               leftChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /** Distance to add to leftChildIndent to determine where cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      * contents will be drawn. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected int               rightChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** Total distance that will be indented.  The sum of leftChildIndent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      * and rightChildIndent. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected int               totalChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /** Minimum preferred size. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected Dimension         preferredMinSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /** Index of the row that was last selected. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected int               lastSelectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /** Component that we're going to be drawing into. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected JTree             tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /** Renderer that is being used to do the actual cell drawing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    transient protected TreeCellRenderer   currentCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /** Set to true if the renderer that is currently in the tree was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * created by this instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    protected boolean           createdRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /** Editor for the tree. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    transient protected TreeCellEditor     cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /** Set to true if editor that is currently in the tree was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * created by this instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected boolean           createdCellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /** Set to false when editing and shouldSelectCell() returns true meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * the node should be selected before editing, used in completeEditing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected boolean           stopEditingInCompleteEditing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /** Used to paint the TreeCellRenderer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected CellRendererPane  rendererPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /** Size needed to completely display all the nodes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected Dimension         preferredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /** Is the preferredSize valid? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    protected boolean           validCachedPreferredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /** Object responsible for handling sizing and expanded issues. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // WARNING: Be careful with the bounds held by treeState. They are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // always in terms of left-to-right. They get mapped to right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // by the various methods of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    protected AbstractLayoutCache  treeState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /** Used for minimizing the drawing of vertical lines. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected Hashtable<TreePath,Boolean> drawingCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /** True if doing optimizations for a largeModel. Subclasses that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * don't support this may wish to override createLayoutCache to not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * return a FixedHeightLayoutCache instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected boolean           largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /** Reponsible for telling the TreeState the size needed for a node. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    protected AbstractLayoutCache.NodeDimensions     nodeDimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /** Used to determine what to display. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected TreeModel         treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   148
    /** Model maintaining the selection. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected TreeSelectionModel treeSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /** How much the depth should be offset to properly calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * x locations. This is based on whether or not the root is visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * and if the root handles are visible. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected int               depthOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // Following 4 ivars are only valid when editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /** When editing, this will be the Component that is doing the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      * editing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected Component         editingComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /** Path that is being edited. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    protected TreePath          editingPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /** Row that is being edited. Should only be referenced if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * editingComponent is not null. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected int               editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /** Set to true if the editor has a different size than the renderer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    protected boolean           editorHasDifferentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /** Row correspondin to lead path. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private int                 leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /** If true, the property change event for LEAD_SELECTION_PATH_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * or ANCHOR_SELECTION_PATH_PROPERTY will not generate a repaint. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private boolean             ignoreLAChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /** Indicates the orientation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private boolean             leftToRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    // Cached listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private PropertyChangeListener selectionModelPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private MouseListener mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private FocusListener focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private KeyListener keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /** Used for large models, listens for moved/resized events and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * updates the validCachedPreferredSize bit accordingly. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private ComponentListener   componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /** Listens for CellEditor events. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private CellEditorListener  cellEditorListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /** Updates the display when the selection changes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private TreeSelectionListener treeSelectionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /** Is responsible for updating the display based on model events. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private TreeModelListener treeModelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /** Updates the treestate as the nodes expand. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private TreeExpansionListener treeExpansionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /** UI property indicating whether to paint lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private boolean paintLines = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /** UI property for painting dashed lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private boolean lineTypeDashed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * The time factor to treate the series of typed alphanumeric key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * as prefix for first letter navigation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private long timeFactor = 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * A temporary variable for communication between startEditingOnRelease
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * and startEditing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private MouseEvent releaseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   219
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   220
     * Constructs a new instance of {@code BasicTreeUI}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   221
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   222
     * @param x a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   223
     * @return a new instance of {@code BasicTreeUI}
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   224
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return new BasicTreeUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        map.put(new Actions(Actions.SELECT_PREVIOUS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        map.put(new Actions(Actions.SELECT_PREVIOUS_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        map.put(new Actions(Actions.SELECT_PREVIOUS_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        map.put(new Actions(Actions.SELECT_NEXT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        map.put(new Actions(Actions.SELECT_NEXT_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        map.put(new Actions(Actions.SELECT_NEXT_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        map.put(new Actions(Actions.SELECT_CHILD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        map.put(new Actions(Actions.SELECT_CHILD_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        map.put(new Actions(Actions.SELECT_PARENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        map.put(new Actions(Actions.SELECT_PARENT_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        map.put(new Actions(Actions.SCROLL_UP_CHANGE_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        map.put(new Actions(Actions.SCROLL_UP_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        map.put(new Actions(Actions.SCROLL_UP_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        map.put(new Actions(Actions.SCROLL_DOWN_CHANGE_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        map.put(new Actions(Actions.SCROLL_DOWN_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        map.put(new Actions(Actions.SCROLL_DOWN_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        map.put(new Actions(Actions.SELECT_FIRST));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        map.put(new Actions(Actions.SELECT_FIRST_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        map.put(new Actions(Actions.SELECT_FIRST_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        map.put(new Actions(Actions.SELECT_LAST));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        map.put(new Actions(Actions.SELECT_LAST_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        map.put(new Actions(Actions.SELECT_LAST_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        map.put(new Actions(Actions.TOGGLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        map.put(new Actions(Actions.CANCEL_EDITING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        map.put(new Actions(Actions.START_EDITING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        map.put(new Actions(Actions.SELECT_ALL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        map.put(new Actions(Actions.CLEAR_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        map.put(new Actions(Actions.SCROLL_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        map.put(new Actions(Actions.SCROLL_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        map.put(new Actions(Actions.SCROLL_LEFT_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        map.put(new Actions(Actions.SCROLL_RIGHT_EXTEND_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        map.put(new Actions(Actions.SCROLL_RIGHT_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        map.put(new Actions(Actions.SCROLL_LEFT_CHANGE_LEAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        map.put(new Actions(Actions.EXPAND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        map.put(new Actions(Actions.COLLAPSE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        map.put(new Actions(Actions.MOVE_SELECTION_TO_PARENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        map.put(new Actions(Actions.ADD_TO_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        map.put(new Actions(Actions.TOGGLE_AND_ANCHOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        map.put(new Actions(Actions.EXTEND_TO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        map.put(new Actions(Actions.MOVE_SELECTION_TO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        map.put(TransferHandler.getCutAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        map.put(TransferHandler.getCopyAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        map.put(TransferHandler.getPasteAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   294
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   295
     * Constructs a new instance of {@code BasicTreeUI}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   296
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public BasicTreeUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   301
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   302
     * Returns the hash color.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   303
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   304
     * @return the hash color
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   305
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected Color getHashColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return hashColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   310
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   311
     * Sets the hash color.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   312
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   313
     * @param color the hash color
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   314
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    protected void setHashColor(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        hashColor = color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   319
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   320
     * Sets the left child indent.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   321
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   322
     * @param newAmount the left child indent
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   323
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public void setLeftChildIndent(int newAmount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        leftChildIndent = newAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        totalChildIndent = leftChildIndent + rightChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if(treeState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   332
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   333
     * Returns the left child indent.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   334
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   335
     * @return the left child indent
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   336
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public int getLeftChildIndent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return leftChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   341
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   342
     * Sets the right child indent.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   343
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   344
     * @param newAmount the right child indent
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   345
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public void setRightChildIndent(int newAmount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        rightChildIndent = newAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        totalChildIndent = leftChildIndent + rightChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if(treeState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   354
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   355
     * Returns the right child indent.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   356
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   357
     * @return the right child indent
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   358
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public int getRightChildIndent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return rightChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   363
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   364
     * Sets the expanded icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   365
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   366
     * @param newG the expanded icon
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   367
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void setExpandedIcon(Icon newG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        expandedIcon = newG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   372
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   373
     * Returns the expanded icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   374
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   375
     * @return the expanded icon
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   376
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public Icon getExpandedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return expandedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   381
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   382
     * Sets the collapsed icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   383
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   384
     * @param newG the collapsed icon
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   385
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public void setCollapsedIcon(Icon newG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        collapsedIcon = newG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   390
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   391
     * Returns the collapsed icon.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   392
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   393
     * @return the collapsed icon
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   394
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public Icon getCollapsedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return collapsedIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    // Methods for configuring the behavior of the tree. None of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    // push the value to the JTree instance. You should really only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    // call these methods on the JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Updates the componentListener, if necessary.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   407
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   408
     * @param largeModel the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    protected void setLargeModel(boolean largeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if(getRowHeight() < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            largeModel = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if(this.largeModel != largeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            this.largeModel = largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            treeState = createLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            configureLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            updateLayoutCacheExpandedNodesIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   423
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   424
     * Returns {@code true} if large model is set.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   425
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   426
     * @return {@code true} if large model is set
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   427
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    protected boolean isLargeModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return largeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Sets the row height, this is forwarded to the treeState.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   434
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   435
     * @param rowHeight the row height
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    protected void setRowHeight(int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            setLargeModel(tree.isLargeModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            treeState.setRowHeight(rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   446
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   447
     * Returns the row height.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   448
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   449
     * @return the row height
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   450
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    protected int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return (tree == null) ? -1 : tree.getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   456
     * Sets the {@code TreeCellRenderer} to {@code tcr}. This invokes
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   457
     * {@code updateRenderer}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   458
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   459
     * @param tcr the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    protected void setCellRenderer(TreeCellRenderer tcr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        updateRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   471
     * Return {@code currentCellRenderer}, which will either be the trees
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   472
     * renderer, or {@code defaultCellRenderer}, which ever wasn't null.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   473
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   474
     * @return an instance of {@code TreeCellRenderer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    protected TreeCellRenderer getCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return currentCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   481
     * Sets the {@code TreeModel}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   482
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   483
     * @param model the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    protected void setModel(TreeModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if(treeModel != null && treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            treeModel.removeTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        treeModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if(treeModelListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            treeState.setModel(model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            updateLayoutCacheExpandedNodesIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   501
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   502
     * Returns the tree model.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   503
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   504
     * @return the tree model
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   505
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    protected TreeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Sets the root to being visible.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   512
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   513
     * @param newValue the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    protected void setRootVisible(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        updateDepthOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            treeState.setRootVisible(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   525
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   526
     * Returns {@code true} if the tree root is visible.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   527
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   528
     * @return {@code true} if the tree root is visible
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   529
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    protected boolean isRootVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return (tree != null) ? tree.isRootVisible() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Determines whether the node handles are to be displayed.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   536
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   537
     * @param newValue the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    protected void setShowsRootHandles(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        updateDepthOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   548
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   549
     * Returns {@code true} if the root handles are to be displayed.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   550
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   551
     * @return {@code true} if the root handles are to be displayed
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   552
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    protected boolean getShowsRootHandles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return (tree != null) ? tree.getShowsRootHandles() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * Sets the cell editor.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   559
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   560
     * @param editor the new cell editor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    protected void setCellEditor(TreeCellEditor editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        updateCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   566
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   567
     * Returns an instance of {@code TreeCellEditor}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   568
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   569
     * @return an instance of {@code TreeCellEditor}
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   570
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    protected TreeCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return (tree != null) ? tree.getCellEditor() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Configures the receiver to allow, or not allow, editing.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   577
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   578
     * @param newValue the new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    protected void setEditable(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        updateCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   584
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   585
     * Returns {@code true} if the tree is editable.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   586
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   587
     * @return {@code true} if the tree is editable
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   588
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    protected boolean isEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return (tree != null) ? tree.isEditable() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Resets the selection model. The appropriate listener are installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * on the model.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   596
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   597
     * @param newLSM new selection model
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    protected void setSelectionModel(TreeSelectionModel newLSM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if(selectionModelPropertyChangeListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
           treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            treeSelectionModel.removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                              (selectionModelPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if(treeSelectionListener != null && treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            treeSelectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                               (treeSelectionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        treeSelectionModel = newLSM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if(treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if(selectionModelPropertyChangeListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                treeSelectionModel.addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                              (selectionModelPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if(treeSelectionListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                treeSelectionModel.addTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                   (treeSelectionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if(treeState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                treeState.setSelectionModel(treeSelectionModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        else if(treeState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            treeState.setSelectionModel(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            tree.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   625
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   626
     * Returns the tree selection model.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   627
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   628
     * @return the tree selection model
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   629
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    protected TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return treeSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    // TreeUI methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
      * Returns the Rectangle enclosing the label portion that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      * last item in path will be drawn into.  Will return null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
      * any component in path is currently valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public Rectangle getPathBounds(JTree tree, TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if(tree != null && treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return getPathBounds(path, tree.getInsets(), new Rectangle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private Rectangle getPathBounds(TreePath path, Insets insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                    Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        bounds = treeState.getBounds(path, bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                bounds.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                bounds.x = tree.getWidth() - (bounds.x + bounds.width) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                        insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            bounds.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
      * Returns the path for passed in row.  If row is not visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
      * null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public TreePath getPathForRow(JTree tree, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return (treeState != null) ? treeState.getPathForRow(row) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
      * Returns the row that the last item identified in path is visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
      * at.  Will return -1 if any of the elements in path are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
      * currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public int getRowForPath(JTree tree, TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return (treeState != null) ? treeState.getRowForPath(path) : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      * Returns the number of rows that are being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    public int getRowCount(JTree tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        return (treeState != null) ? treeState.getRowCount() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
      * there is nothing currently visible this will return null, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
      * it'll always return a valid path.  If you need to test if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
      * returned object is exactly at x, y you should get the bounds for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
      * the returned path and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    public TreePath getClosestPathForLocation(JTree tree, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if(tree != null && treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            // TreeState doesn't care about the x location, hence it isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            // adjusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            y -= tree.getInsets().top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            return treeState.getPathClosestTo(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return null;
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
      * Returns true if the tree is being edited.  The item that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
      * edited can be returned by getEditingPath().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public boolean isEditing(JTree tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return (editingComponent != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
      * Stops the current editing session.  This has no effect if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
      * tree isn't being edited.  Returns true if the editor allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
      * editing session to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public boolean stopEditing(JTree tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if(editingComponent != null && cellEditor.stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            completeEditing(false, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      * Cancels the current editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public void cancelEditing(JTree tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if(editingComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            completeEditing(false, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
      * Selects the last item in path and tries to edit it.  Editing will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
      * fail if the CellEditor won't allow it for the selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public void startEditingAtPath(JTree tree, TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        tree.scrollPathToVisible(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if(path != null && tree.isVisible(path))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            startEditing(path, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * Returns the path to the element that is being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public TreePath getEditingPath(JTree tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return editingPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    // Install methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if ( c == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            throw new NullPointerException( "null component passed to BasicTreeUI.installUI()" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        tree = (JTree)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        prepareForUIInstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        // Boilerplate install block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        installComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        completeUIInstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   776
     * Invoked after the {@code tree} instance variable has been
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * set, but before any defaults/listeners have been installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    protected void prepareForUIInstall() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        drawingCache = new Hashtable<TreePath,Boolean>(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        // Data member initializations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        leftToRight = BasicGraphicsUtils.isLeftToRight(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        stopEditingInCompleteEditing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        lastSelectedRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        leadRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        preferredSize = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        largeModel = tree.isLargeModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if(getRowHeight() <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            largeModel = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        setModel(tree.getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * Invoked from installUI after all the defaults/listeners have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    protected void completeUIInstall() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        // Custom install code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        this.setShowsRootHandles(tree.getShowsRootHandles());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        updateRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        updateDepthOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        setSelectionModel(tree.getSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        // Create, if necessary, the TreeState instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        treeState = createLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        configureLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   817
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   818
     * Installs default properties.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   819
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if(tree.getBackground() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
           tree.getBackground() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            tree.setBackground(UIManager.getColor("Tree.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if(getHashColor() == null || getHashColor() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            setHashColor(UIManager.getColor("Tree.hash"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        if (tree.getFont() == null || tree.getFont() instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            tree.setFont( UIManager.getFont("Tree.font") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        // JTree's original row height is 16.  To correctly display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        // contents on Linux we should have set it to 18, Windows 19 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        // Solaris 20.  As these values vary so much it's too hard to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        // be backward compatable and try to update the row height, we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        // therefor NOT going to adjust the row height based on font.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        // developer changes the font, it's there responsibility to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        // the row height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        setExpandedIcon( (Icon)UIManager.get( "Tree.expandedIcon" ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        setCollapsedIcon( (Icon)UIManager.get( "Tree.collapsedIcon" ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        setLeftChildIndent(((Integer)UIManager.get("Tree.leftChildIndent")).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                           intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        setRightChildIndent(((Integer)UIManager.get("Tree.rightChildIndent")).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                           intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        LookAndFeel.installProperty(tree, "rowHeight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                    UIManager.get("Tree.rowHeight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        largeModel = (tree.isLargeModel() && tree.getRowHeight() > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        Object scrollsOnExpand = UIManager.get("Tree.scrollsOnExpand");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (scrollsOnExpand != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            LookAndFeel.installProperty(tree, "scrollsOnExpand", scrollsOnExpand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        paintLines = UIManager.getBoolean("Tree.paintLines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        lineTypeDashed = UIManager.getBoolean("Tree.lineTypeDashed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        Long l = (Long)UIManager.get("Tree.timeFactor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        timeFactor = (l!=null) ? l.longValue() : 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        Object showsRootHandles = UIManager.get("Tree.showsRootHandles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        if (showsRootHandles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            LookAndFeel.installProperty(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    JTree.SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   869
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   870
     * Registers listeners.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   871
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        if ( (propertyChangeListener = createPropertyChangeListener())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
             != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            tree.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if ( (mouseListener = createMouseListener()) != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            tree.addMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            if (mouseListener instanceof MouseMotionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                tree.addMouseMotionListener((MouseMotionListener)mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if ((focusListener = createFocusListener()) != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            tree.addFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if ((keyListener = createKeyListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            tree.addKeyListener(keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if((treeExpansionListener = createTreeExpansionListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            tree.addTreeExpansionListener(treeExpansionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        if((treeModelListener = createTreeModelListener()) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
           treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            treeModel.addTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        if((selectionModelPropertyChangeListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            createSelectionModelPropertyChangeListener()) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
           treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            treeSelectionModel.addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                (selectionModelPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        if((treeSelectionListener = createTreeSelectionListener()) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
           treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            treeSelectionModel.addTreeSelectionListener(treeSelectionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        TransferHandler th = tree.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        if (th == null || th instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            tree.setTransferHandler(defaultTransferHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            // default TransferHandler doesn't support drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            // so we don't want drop handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            if (tree.getDropTarget() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                tree.setDropTarget(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        LookAndFeel.installProperty(tree, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   920
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   921
     * Registers keyboard actions.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   922
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        InputMap km = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        SwingUtilities.replaceUIInputMap(tree, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                         km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        km = getInputMap(JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        SwingUtilities.replaceUIInputMap(tree, JComponent.WHEN_FOCUSED, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        LazyActionMap.installLazyActionMap(tree, BasicTreeUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                                           "Tree.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            return (InputMap)DefaultLookup.get(tree, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                               "Tree.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        else if (condition == JComponent.WHEN_FOCUSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            InputMap keyMap = (InputMap)DefaultLookup.get(tree, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                                                      "Tree.focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            InputMap rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            if (tree.getComponentOrientation().isLeftToRight() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                  ((rtlKeyMap = (InputMap)DefaultLookup.get(tree, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                  "Tree.focusInputMap.RightToLeft")) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                return keyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                rtlKeyMap.setParent(keyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                return rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * Intalls the subcomponents of the tree, which is the renderer pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if ((rendererPane = createCellRendererPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            tree.add( rendererPane );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    // Create methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   973
     * Creates an instance of {@code NodeDimensions} that is able to determine
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * the size of a given node in the tree.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   975
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   976
     * @return an instance of {@code NodeDimensions}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    protected AbstractLayoutCache.NodeDimensions createNodeDimensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        return new NodeDimensionsHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * Creates a listener that is responsible that updates the UI based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * how the tree changes.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   985
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
   986
     * @return an instance of the {@code PropertyChangeListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * Creates the listener responsible for updating the selection based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * mouse events.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1002
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1003
     * @return an instance of the {@code MouseListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    protected MouseListener createMouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * Creates a listener that is responsible for updating the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * when focus is lost/gained.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1012
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1013
     * @return an instance of the {@code FocusListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    protected FocusListener createFocusListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1020
     * Creates the listener responsible for getting key events from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * the tree.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1022
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1023
     * @return an instance of the {@code KeyListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    protected KeyListener createKeyListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * Creates the listener responsible for getting property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * events from the selection model.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1032
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1033
     * @return an instance of the {@code PropertyChangeListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    protected PropertyChangeListener createSelectionModelPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * Creates the listener that updates the display based on selection change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * methods.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1042
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1043
     * @return an instance of the {@code TreeSelectionListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    protected TreeSelectionListener createTreeSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * Creates a listener to handle events from the current editor.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1051
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1052
     * @return an instance of the {@code CellEditorListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    protected CellEditorListener createCellEditorListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * Creates and returns a new ComponentHandler. This is used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * the large model to mark the validCachedPreferredSize as invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * when the component moves.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1062
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1063
     * @return an instance of the {@code ComponentListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    protected ComponentListener createComponentListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        return new ComponentHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * Creates and returns the object responsible for updating the treestate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * when nodes expanded state changes.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1072
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1073
     * @return an instance of the {@code TreeExpansionListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    protected TreeExpansionListener createTreeExpansionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * Creates the object responsible for managing what is expanded, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * well as the size of nodes.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1082
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1083
     * @return the object responsible for managing what is expanded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    protected AbstractLayoutCache createLayoutCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if(isLargeModel() && getRowHeight() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            return new FixedHeightLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return new VariableHeightLayoutCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * Returns the renderer pane that renderer components are placed in.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1094
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1095
     * @return an instance of the {@code CellRendererPane}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    protected CellRendererPane createCellRendererPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        return new CellRendererPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1102
     * Creates a default cell editor.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1103
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1104
     * @return a default cell editor
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1105
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    protected TreeCellEditor createDefaultCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        if(currentCellRenderer != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
           (currentCellRenderer instanceof DefaultTreeCellRenderer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            DefaultTreeCellEditor editor = new DefaultTreeCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                        (tree, (DefaultTreeCellRenderer)currentCellRenderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        return new DefaultTreeCellEditor(tree, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1118
     * Returns the default cell renderer that is used to do the
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1119
     * stamping of each node.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1120
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1121
     * @return an instance of {@code TreeCellRenderer}
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1122
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    protected TreeCellRenderer createDefaultCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        return new DefaultTreeCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * Returns a listener that can update the tree when the model changes.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1129
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1130
     * @return an instance of the {@code TreeModelListener}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    protected TreeModelListener createTreeModelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    // Uninstall methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        prepareForUIUninstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        uninstallComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        completeUIUninstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1153
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1154
     * Invoked before unstallation of UI.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1155
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    protected void prepareForUIUninstall() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1159
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1160
     * Uninstalls UI.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1161
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    protected void completeUIUninstall() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        if(createdRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            tree.setCellRenderer(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        if(createdCellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            tree.setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        cellEditor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        currentCellRenderer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        rendererPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        componentListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        mouseListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        focusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        keyListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        setSelectionModel(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        treeState = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        drawingCache = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        selectionModelPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        tree = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        treeModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        treeSelectionModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        treeSelectionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        treeExpansionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1188
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1189
     * Uninstalls default properties.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1190
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        if (tree.getTransferHandler() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            tree.setTransferHandler(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1197
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1198
     * Unregisters listeners.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1199
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        if(componentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            tree.removeComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            tree.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        if (mouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            tree.removeMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            if (mouseListener instanceof MouseMotionListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                tree.removeMouseMotionListener((MouseMotionListener)mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (focusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            tree.removeFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        if (keyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            tree.removeKeyListener(keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        if(treeExpansionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            tree.removeTreeExpansionListener(treeExpansionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        if(treeModel != null && treeModelListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            treeModel.removeTreeModelListener(treeModelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        if(selectionModelPropertyChangeListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
           treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            treeSelectionModel.removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                (selectionModelPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        if(treeSelectionListener != null && treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            treeSelectionModel.removeTreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                               (treeSelectionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1237
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1238
     * Unregisters keyboard actions.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1239
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        SwingUtilities.replaceUIActionMap(tree, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        SwingUtilities.replaceUIInputMap(tree, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        SwingUtilities.replaceUIInputMap(tree, JComponent.WHEN_FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * Uninstalls the renderer pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    protected void uninstallComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        if(rendererPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            tree.remove(rendererPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * Recomputes the right margin, and invalidates any tree states
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    private void redoTheLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        if (treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        Component renderer = (Component)lafDefaults.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                BASELINE_COMPONENT_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            TreeCellRenderer tcr = createDefaultCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            renderer = tcr.getTreeCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                    tree, "a", false, false, false, -1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            lafDefaults.put(BASELINE_COMPONENT_KEY, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        int rowHeight = tree.getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        int baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        if (rowHeight > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            baseline = renderer.getBaseline(Integer.MAX_VALUE, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            Dimension pref = renderer.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            baseline = renderer.getBaseline(pref.width, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        return baseline + tree.getInsets().top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    // Painting routines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        if (tree != c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            throw new InternalError("incorrect component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        // Should never happen if installed for a UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if(treeState == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        Rectangle        paintBounds = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        Insets           insets = tree.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        TreePath         initialPath = getClosestPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                                       (tree, 0, paintBounds.y);
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1329
        Enumeration<?>   paintingEnumerator = treeState.getVisiblePathsFrom
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                              (initialPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        int              row = treeState.getRowForPath(initialPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        int              endY = paintBounds.y + paintBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        drawingCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        if(initialPath != null && paintingEnumerator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            TreePath   parentPath = initialPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            // Draw the lines, knobs, and rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            // Find each parent and have them draw a line to their last child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            parentPath = parentPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            while(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                drawingCache.put(parentPath, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                parentPath = parentPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            boolean         done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            // Information for the node being rendered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            boolean         isExpanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            boolean         hasBeenExpanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            boolean         isLeaf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            Rectangle       boundsBuffer = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            Rectangle       bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            TreePath        path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            boolean         rootVisible = isRootVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            while(!done && paintingEnumerator.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                path = (TreePath)paintingEnumerator.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                if(path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                    isLeaf = treeModel.isLeaf(path.getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    if(isLeaf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                        isExpanded = hasBeenExpanded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                        isExpanded = treeState.getExpandedState(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                        hasBeenExpanded = tree.hasBeenExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    bounds = getPathBounds(path, insets, boundsBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                    if(bounds == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                        // This will only happen if the model changes out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                        // from under us (usually in another thread).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                        // Swing isn't multithreaded, but I'll put this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                        // check in anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    // See if the vertical line to the parent has been drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                    parentPath = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    if(parentPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                        if(drawingCache.get(parentPath) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                            paintVerticalPartOfLeg(g, paintBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                                                   insets, parentPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                            drawingCache.put(parentPath, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                        paintHorizontalPartOfLeg(g, paintBounds, insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                                                 bounds, path, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                                                 isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                                                 hasBeenExpanded, isLeaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                    else if(rootVisible && row == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        paintHorizontalPartOfLeg(g, paintBounds, insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                                                 bounds, path, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                                                 isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                                                 hasBeenExpanded, isLeaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    if(shouldPaintExpandControl(path, row, isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                                                hasBeenExpanded, isLeaf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                        paintExpandControl(g, paintBounds, insets, bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                                           path, row, isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                                           hasBeenExpanded, isLeaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                    paintRow(g, paintBounds, insets, bounds, path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                                 row, isExpanded, hasBeenExpanded, isLeaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    if((bounds.y + bounds.height) >= endY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        paintDropLine(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        // Empty out the renderer pane, allowing renderers to be gc'ed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        rendererPane.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        drawingCache.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1421
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1422
     * Tells if a {@code DropLocation} should be indicated by a line between
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1423
     * nodes. This is meant for {@code javax.swing.DropMode.INSERT} and
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1424
     * {@code javax.swing.DropMode.ON_OR_INSERT} drop modes.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1425
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1426
     * @param loc a {@code DropLocation}
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1427
     * @return {@code true} if the drop location should be shown as a line
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1428
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1429
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1430
    protected boolean isDropLine(JTree.DropLocation loc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        return loc != null && loc.getPath() != null && loc.getChildIndex() != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1434
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1435
     * Paints the drop line.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1436
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1437
     * @param g {@code Graphics} object to draw on
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1438
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1439
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1440
    protected void paintDropLine(Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        JTree.DropLocation loc = tree.getDropLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        if (!isDropLine(loc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        Color c = UIManager.getColor("Tree.dropLineColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            Rectangle rect = getDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            g.fillRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1454
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1455
     * Returns a unbounding box for the drop line.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1456
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1457
     * @param loc a {@code DropLocation}
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1458
     * @return bounding box for the drop line
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1459
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1460
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1461
    protected Rectangle getDropLineRect(JTree.DropLocation loc) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1462
        Rectangle rect;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        TreePath path = loc.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        int index = loc.getChildIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        boolean ltr = leftToRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        Insets insets = tree.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        if (tree.getRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            rect = new Rectangle(insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                                 insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                                 tree.getWidth() - insets.left - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                                 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            TreeModel model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            Object root = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            if (path.getLastPathComponent() == root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    && index >= model.getChildCount(root)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                rect = tree.getRowBounds(tree.getRowCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                rect.y = rect.y + rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                Rectangle xRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                if (!tree.isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                    xRect = tree.getRowBounds(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                } else if (model.getChildCount(root) == 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    xRect = tree.getRowBounds(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    xRect.x += totalChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                    xRect.width -= totalChildIndent + totalChildIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                    TreePath lastChildPath = path.pathByAddingChild(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                        model.getChild(root, model.getChildCount(root) - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                    xRect = tree.getPathBounds(lastChildPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                rect.x = xRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                rect.width = xRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                rect = tree.getPathBounds(path.pathByAddingChild(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    model.getChild(path.getLastPathComponent(), index)));
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
        if (rect.y != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            rect.y--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        if (!ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            rect.x = rect.x + rect.width - 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        rect.width = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        rect.height = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * Paints the horizontal part of the leg. The receiver should
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1521
     * NOT modify {@code clipBounds}, or {@code insets}.<p>
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1522
     * NOTE: {@code parentRow} can be -1 if the root is not visible.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1523
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1524
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1525
     * @param clipBounds a clipped rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1526
     * @param insets insets
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1527
     * @param bounds a bounding rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1528
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1529
     * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1530
     * @param isExpanded {@code true} if the path is expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1531
     * @param hasBeenExpanded {@code true} if the path has been expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1532
     * @param isLeaf {@code true} if the path is leaf
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                                            Insets insets, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                                            TreePath path, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                                            boolean isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                                            boolean hasBeenExpanded, boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                                            isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        if (!paintLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        // Don't paint the legs for the root'ish node if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        int depth = path.getPathCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        if((depth == 0 || (depth == 1 && !isRootVisible())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
           !getShowsRootHandles()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        int clipLeft = clipBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        int clipRight = clipBounds.x + clipBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        int clipTop = clipBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        int clipBottom = clipBounds.y + clipBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        int lineY = bounds.y + bounds.height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            int leftX = bounds.x - getRightChildIndent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            int nodeX = bounds.x - getHorizontalLegBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            if(lineY >= clipTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                    && lineY < clipBottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    && nodeX >= clipLeft
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                    && leftX < clipRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    && leftX < nodeX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                g.setColor(getHashColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                paintHorizontalLine(g, tree, lineY, leftX, nodeX - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            int nodeX = bounds.x + bounds.width + getHorizontalLegBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            int rightX = bounds.x + bounds.width + getRightChildIndent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            if(lineY >= clipTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    && lineY < clipBottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    && rightX >= clipLeft
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    && nodeX < clipRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                    && nodeX < rightX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                g.setColor(getHashColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                paintHorizontalLine(g, tree, lineY, nodeX, rightX - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * Paints the vertical part of the leg. The receiver should
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1588
     * NOT modify {@code clipBounds}, {@code insets}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1589
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1590
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1591
     * @param clipBounds a clipped rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1592
     * @param insets insets
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1593
     * @param path a tree path
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                                          Insets insets, TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        if (!paintLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        int depth = path.getPathCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        if (depth == 0 && !getShowsRootHandles() && !isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        int lineX = getRowX(-1, depth + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            lineX = lineX - getRightChildIndent() + insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            lineX = tree.getWidth() - lineX - insets.right +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                    getRightChildIndent() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        int clipLeft = clipBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        int clipRight = clipBounds.x + (clipBounds.width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        if (lineX >= clipLeft && lineX <= clipRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            int clipTop = clipBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            int clipBottom = clipBounds.y + clipBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            Rectangle parentBounds = getPathBounds(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            Rectangle lastChildBounds = getPathBounds(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                                                     getLastChildPath(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            if(lastChildBounds == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                // This shouldn't happen, but if the model is modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                // in another thread it is possible for this to happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                // Swing isn't multithreaded, but I'll add this check in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                // anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            int       top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            if(parentBounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                top = Math.max(insets.top + getVerticalLegBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                               clipTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                top = Math.max(parentBounds.y + parentBounds.height +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                               getVerticalLegBuffer(), clipTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            if(depth == 0 && !isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                TreeModel      model = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                if(model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    Object        root = model.getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                    if(model.getChildCount(root) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                        parentBounds = getPathBounds(tree, path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                                  pathByAddingChild(model.getChild(root, 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                        if(parentBounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                            top = Math.max(insets.top + getVerticalLegBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                                           parentBounds.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                                           parentBounds.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            int bottom = Math.min(lastChildBounds.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                                  (lastChildBounds.height / 2), clipBottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            if (top <= bottom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                g.setColor(getHashColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                paintVerticalLine(g, tree, lineX, top, bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * Paints the expand (toggle) part of a row. The receiver should
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1668
     * NOT modify {@code clipBounds}, or {@code insets}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1669
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1670
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1671
     * @param clipBounds a clipped rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1672
     * @param insets insets
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1673
     * @param bounds a bounding rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1674
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1675
     * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1676
     * @param isExpanded {@code true} if the path is expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1677
     * @param hasBeenExpanded {@code true} if the path has been expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1678
     * @param isLeaf {@code true} if the row is leaf
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    protected void paintExpandControl(Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                      Rectangle clipBounds, Insets insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                                      Rectangle bounds, TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                                      int row, boolean isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                                      boolean hasBeenExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                                      boolean isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        Object       value = path.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        // Draw icons if not a leaf and either hasn't been loaded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        // or the model child count is > 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        if (!isLeaf && (!hasBeenExpanded ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                        treeModel.getChildCount(value) > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            int middleXOfKnob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                middleXOfKnob = bounds.x - getRightChildIndent() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                middleXOfKnob = bounds.x + bounds.width + getRightChildIndent() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            int middleYOfKnob = bounds.y + (bounds.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            if (isExpanded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                Icon expandedIcon = getExpandedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                if(expandedIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                  drawCentered(tree, g, expandedIcon, middleXOfKnob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                               middleYOfKnob );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                Icon collapsedIcon = getCollapsedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                if(collapsedIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                  drawCentered(tree, g, collapsedIcon, middleXOfKnob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                               middleYOfKnob);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * Paints the renderer part of a row. The receiver should
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1717
     * NOT modify {@code clipBounds}, or {@code insets}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1718
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1719
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1720
     * @param clipBounds a clipped rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1721
     * @param insets insets
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1722
     * @param bounds a bounding rectangle
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1723
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1724
     * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1725
     * @param isExpanded {@code true} if the path is expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1726
     * @param hasBeenExpanded {@code true} if the path has been expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1727
     * @param isLeaf {@code true} if the path is leaf
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    protected void paintRow(Graphics g, Rectangle clipBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                            Insets insets, Rectangle bounds, TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                            int row, boolean isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                            boolean hasBeenExpanded, boolean isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        // Don't paint the renderer if editing this row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        if(editingComponent != null && editingRow == row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        int leadIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        if(tree.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            leadIndex = getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            leadIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        component = currentCellRenderer.getTreeCellRendererComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                      (tree, path.getLastPathComponent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                       tree.isRowSelected(row), isExpanded, isLeaf, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                       (leadIndex == row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                                    bounds.width, bounds.height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1757
     * Returns {@code true} if the expand (toggle) control should be drawn for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * the specified row.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1759
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1760
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1761
     * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1762
     * @param isExpanded {@code true} if the path is expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1763
     * @param hasBeenExpanded {@code true} if the path has been expanded
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1764
     * @param isLeaf {@code true} if the row is leaf
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1765
     * @return {@code true} if the expand (toggle) control should be drawn
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1766
     *         for the specified row
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
    protected boolean shouldPaintExpandControl(TreePath path, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                                               boolean isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                                               boolean hasBeenExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                                               boolean isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        if(isLeaf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        int              depth = path.getPathCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        if((depth == 0 || (depth == 1 && !isRootVisible())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
           !getShowsRootHandles())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * Paints a vertical line.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1785
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1786
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1787
     * @param c a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1788
     * @param x an X coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1789
     * @param top an Y1 coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1790
     * @param bottom an Y2 coordinate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
    protected void paintVerticalLine(Graphics g, JComponent c, int x, int top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                                    int bottom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        if (lineTypeDashed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            drawDashedVerticalLine(g, x, top, bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            g.drawLine(x, top, x, bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * Paints a horizontal line.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1803
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1804
     * @param g a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1805
     * @param c a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1806
     * @param y an Y coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1807
     * @param left an X1 coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1808
     * @param right an X2 coordinate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    protected void paintHorizontalLine(Graphics g, JComponent c, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                                      int left, int right) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        if (lineTypeDashed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            drawDashedHorizontalLine(g, y, left, right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            g.drawLine(left, y, right, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * The vertical element of legs between nodes starts at the bottom of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * parent node by default.  This method makes the leg start below that.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1822
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1823
     * @return the vertical leg buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    protected int getVerticalLegBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * The horizontal element of legs between nodes starts at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * right of the left-hand side of the child node by default.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * method makes the leg end before that.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1833
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1834
     * @return the horizontal leg buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    protected int getHorizontalLegBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    private int findCenteredX(int x, int iconWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        return leftToRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
               ? x - (int)Math.ceil(iconWidth / 2.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
               : x - (int)Math.floor(iconWidth / 2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    // Generic painting methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1850
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1851
     * Draws the {@code icon} centered at (x,y).
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1852
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1853
     * @param c a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1854
     * @param graphics a graphics context
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1855
     * @param icon an icon
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1856
     * @param x an X coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1857
     * @param y an Y coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1858
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    protected void drawCentered(Component c, Graphics graphics, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                                int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        icon.paintIcon(c, graphics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                      findCenteredX(x, icon.getIconWidth()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                      y - icon.getIconHeight() / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    // This method is slow -- revisit when Java2D is ready.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    // assumes x1 <= x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        // Drawing only even coordinates helps join line segments so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        // appear as one line.  This can be defeated by translating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        // Graphics by an odd amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        x1 += (x1 % 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        for (int x = x1; x <= x2; x+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
    // This method is slow -- revisit when Java2D is ready.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    // assumes y1 <= y2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        // Drawing only even coordinates helps join line segments so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        // appear as one line.  This can be defeated by translating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        // Graphics by an odd amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        y1 += (y1 % 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        for (int y = y1; y <= y2; y+=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            g.drawLine(x, y, x, y);
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
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    // Various local methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * Returns the location, along the x-axis, to render a particular row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * at. The return value does not include any Insets specified on the JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * This does not check for the validity of the row or depth, it is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * to be correct and will not throw an Exception if the row or depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * doesn't match that of the tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * @param row Row to return x location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     * @param depth Depth of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * @return amount to indent the given row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    protected int getRowX(int row, int depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        return totalChildIndent * (depth + depthOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * Makes all the nodes that are expanded in JTree expanded in LayoutCache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * This invokes updateExpandedDescendants with the root path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    protected void updateLayoutCacheExpandedNodes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        if(treeModel != null && treeModel.getRoot() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            updateExpandedDescendants(new TreePath(treeModel.getRoot()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    private void updateLayoutCacheExpandedNodesIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        if (treeModel != null && treeModel.getRoot() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            TreePath rootPath = new TreePath(treeModel.getRoot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            if (tree.isExpanded(rootPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                updateLayoutCacheExpandedNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                treeState.setExpandedState(rootPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1933
     * Updates the expanded state of all the descendants of {@code path}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * by getting the expanded descendants from the tree and forwarding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * to the tree state.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1936
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1937
     * @param path a tree path
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
    protected void updateExpandedDescendants(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            treeState.setExpandedState(path, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1944
            Enumeration<?> descendants = tree.getExpandedDescendants(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            if(descendants != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                while(descendants.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                    path = (TreePath)descendants.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                    treeState.setExpandedState(path, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            }
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  1952
            updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1958
     * Returns a path to the last child of {@code parent}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1959
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1960
     * @param parent a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  1961
     * @return a path to the last child of {@code parent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    protected TreePath getLastChildPath(TreePath parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        if(treeModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            int         childCount = treeModel.getChildCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                (parent.getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            if(childCount > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                return parent.pathByAddingChild(treeModel.getChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                           (parent.getLastPathComponent(), childCount - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * Updates how much each depth should be offset by.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    protected void updateDepthOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        if(isRootVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            if(getShowsRootHandles())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                depthOffset = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                depthOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        else if(!getShowsRootHandles())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            depthOffset = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            depthOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
      * Updates the cellEditor based on the editability of the JTree that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
      * we're contained in.  If the tree is editable but doesn't have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
      * cellEditor, a basic one will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
    protected void updateCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        TreeCellEditor        newEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        if(tree == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
            newEditor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            if(tree.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                newEditor = tree.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                if(newEditor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                    newEditor = createDefaultCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                    if(newEditor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                        tree.setCellEditor(newEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                        createdCellEditor = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                newEditor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        if(newEditor != cellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            if(cellEditor != null && cellEditorListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                cellEditor.removeCellEditorListener(cellEditorListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            cellEditor = newEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            if(cellEditorListener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                cellEditorListener = createCellEditorListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            if(newEditor != null && cellEditorListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                newEditor.addCellEditorListener(cellEditorListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            createdCellEditor = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
      * Messaged from the tree we're in when the renderer has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    protected void updateRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            TreeCellRenderer      newCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            newCellRenderer = tree.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            if(newCellRenderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                tree.setCellRenderer(createDefaultCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                createdRenderer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                createdRenderer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                currentCellRenderer = newCellRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                if(createdCellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                    tree.setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
            createdRenderer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            currentCellRenderer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        updateCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * Resets the TreeState instance based on the tree we're providing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * look and feel for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    protected void configureLayoutCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        if(treeState != null && tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            if(nodeDimensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                nodeDimensions = createNodeDimensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            treeState.setNodeDimensions(nodeDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            treeState.setRootVisible(tree.isRootVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
            treeState.setRowHeight(tree.getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            treeState.setSelectionModel(getSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            // Only do this if necessary, may loss state if call with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
            // same model as it currently has.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
            if(treeState.getModel() != tree.getModel())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                treeState.setModel(tree.getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
            updateLayoutCacheExpandedNodesIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            // Create a listener to update preferred size when bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            // changes, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            if(isLargeModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                if(componentListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                    componentListener = createComponentListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                    if(componentListener != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                        tree.addComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            else if(componentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                tree.removeComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                componentListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        else if(componentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            tree.removeComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            componentListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * Marks the cached size as being invalid, and messages the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * tree with <code>treeDidChange</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
    protected void updateSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        validCachedPreferredSize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        tree.treeDidChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
    private void updateSize0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        validCachedPreferredSize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        tree.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * Updates the <code>preferredSize</code> instance variable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * which is returned from <code>getPreferredSize()</code>.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * For left to right orientations, the size is determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * current AbstractLayoutCache. For RTL orientations, the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * becomes the width minus the minimum x position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    protected void updateCachedPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        if(treeState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            Insets               i = tree.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            if(isLargeModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                Rectangle            visRect = tree.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                if (visRect.x == 0 && visRect.y == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                        visRect.width == 0 && visRect.height == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                        tree.getVisibleRowCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                    // The tree doesn't have a valid bounds yet. Calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                    // based on visible row count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    visRect.width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                    visRect.height = tree.getRowHeight() *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                            tree.getVisibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                    visRect.x -= i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                    visRect.y -= i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                }
15333
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2132
                // we should consider a non-visible area above
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2133
                Component component = SwingUtilities.getUnwrappedParent(tree);
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2134
                if (component instanceof JViewport) {
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2135
                    component = component.getParent();
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2136
                    if (component instanceof JScrollPane) {
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2137
                        JScrollPane pane = (JScrollPane) component;
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2138
                        JScrollBar bar = pane.getHorizontalScrollBar();
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2139
                        if ((bar != null) && bar.isVisible()) {
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2140
                            int height = bar.getHeight();
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2141
                            visRect.y -= height;
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2142
                            visRect.height += height;
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2143
                        }
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2144
                    }
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  2145
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                preferredSize.width = treeState.getPreferredWidth(visRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                preferredSize.width = treeState.getPreferredWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            preferredSize.height = treeState.getPreferredHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            preferredSize.width += i.left + i.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            preferredSize.height += i.top + i.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        validCachedPreferredSize = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2159
     * Messaged from the {@code VisibleTreeNode} after it has been expanded.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2160
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2161
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2162
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    protected void pathWasExpanded(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            tree.fireTreeExpanded(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2170
     * Messaged from the {@code VisibleTreeNode} after it has collapsed.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2171
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2172
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2173
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
    protected void pathWasCollapsed(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            tree.fireTreeCollapsed(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2181
     * Ensures that the rows identified by {@code beginRow} through
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2182
     * {@code endRow} are visible.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2183
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2184
     * @param beginRow the begin row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2185
     * @param endRow the end row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2186
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    protected void ensureRowsAreVisible(int beginRow, int endRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        if(tree != null && beginRow >= 0 && endRow < getRowCount(tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            boolean scrollVert = DefaultLookup.getBoolean(tree, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                              "Tree.scrollsHorizontallyAndVertically", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
            if(beginRow == endRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                Rectangle     scrollBounds = getPathBounds(tree, getPathForRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                                                           (tree, beginRow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                if(scrollBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                    if (!scrollVert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                        scrollBounds.x = tree.getVisibleRect().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                        scrollBounds.width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                    tree.scrollRectToVisible(scrollBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                Rectangle   beginRect = getPathBounds(tree, getPathForRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                                                      (tree, beginRow));
11499
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2206
                if (beginRect != null) {
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2207
                    Rectangle   visRect = tree.getVisibleRect();
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2208
                    Rectangle   testRect = beginRect;
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2209
                    int         beginY = beginRect.y;
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2210
                    int         maxY = beginY + visRect.height;
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2211
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2212
                    for(int counter = beginRow + 1; counter <= endRow; counter++) {
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2213
                            testRect = getPathBounds(tree,
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2214
                                    getPathForRow(tree, counter));
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2215
                        if (testRect == null) {
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2216
                            return;
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2217
                        }
11499
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2218
                        if((testRect.y + testRect.height) > maxY)
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2219
                                counter = endRow;
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2220
                            }
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2221
                        tree.scrollRectToVisible(new Rectangle(visRect.x, beginY, 1,
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2222
                                                      testRect.y + testRect.height-
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  2223
                                                      beginY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2229
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2230
     * Sets the preferred minimum size.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2231
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2232
     * @param newSize the new preferred size
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2233
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    public void setPreferredMinSize(Dimension newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        preferredMinSize = newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2238
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2239
     * Returns the minimum preferred size.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2240
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2241
     * @return the minimum preferred size
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2242
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    public Dimension getPreferredMinSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        if(preferredMinSize == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
        return new Dimension(preferredMinSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2249
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2250
     * Returns the preferred size to properly display the tree,
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2251
     * this is a cover method for {@code getPreferredSize(c, true)}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2252
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2253
     * @param c a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2254
     * @return the preferred size to represent the tree in the component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2255
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        return getPreferredSize(c, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2260
    /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2261
     * Returns the preferred size to represent the tree in
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2262
     * <I>c</I>.  If <I>checkConsistency</I> is {@code true}
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2263
     * <b>checkConsistency</b> is messaged first.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2264
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2265
     * @param c a component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2266
     * @param checkConsistency if {@code true} consistency is checked
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2267
     * @return the preferred size to represent the tree in the component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2268
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    public Dimension getPreferredSize(JComponent c,
8374
d262ac869cda 6956842: BasicTreeUI.getPreferredSize(JComp c) is delegated to getPreferredSize(c, true) not (c, false)
alexp
parents: 5506
diff changeset
  2270
                                      boolean checkConsistency) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        Dimension       pSize = this.getPreferredMinSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        if(!validCachedPreferredSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            updateCachedPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            if(pSize != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                return new Dimension(Math.max(pSize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                                              preferredSize.width),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                              Math.max(pSize.height, preferredSize.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            return new Dimension(preferredSize.width, preferredSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        else if(pSize != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
            return pSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
            return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
      * Returns the minimum size for this component.  Which will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
      * the min preferred size or 0, 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        if(this.getPreferredMinSize() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
            return this.getPreferredMinSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
      * Returns the maximum size for this component, which will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
      * preferred size if the instance is currently in a JTree, or 0, 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        if(tree != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
            return getPreferredSize(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        if(this.getPreferredMinSize() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            return this.getPreferredMinSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        return new Dimension(0, 0);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * Messages to stop the editing session. If the UI the receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * is providing the look and feel for returns true from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * <code>getInvokesStopCellEditing</code>, stopCellEditing will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * invoked on the current editor. Then completeEditing will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * be messaged with false, true, false to cancel any lingering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    protected void completeEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        /* If should invoke stopCellEditing, try that */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        if(tree.getInvokesStopCellEditing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
           stopEditingInCompleteEditing && editingComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            cellEditor.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        /* Invoke cancelCellEditing, this will do nothing if stopCellEditing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
           was successful. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        completeEditing(false, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2331
     * Stops the editing session. If {@code messageStop} is {@code true} the editor
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2332
     * is messaged with {@code stopEditing}, if {@code messageCancel}
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2333
     * is {@code true} the editor is messaged with {@code cancelEditing}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2334
     * If {@code messageTree} is {@code true} the {@code treeModel} is messaged
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2335
     * with {@code valueForPathChanged}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2336
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2337
     * @param messageStop message to stop editing
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2338
     * @param messageCancel message to cancel editing
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2339
     * @param messageTree message to tree
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2340
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    protected void completeEditing(boolean messageStop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                                   boolean messageCancel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                                   boolean messageTree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        if(stopEditingInCompleteEditing && editingComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            Component             oldComponent = editingComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            TreePath              oldPath = editingPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            TreeCellEditor        oldEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
            Object                newValue = oldEditor.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            Rectangle             editingBounds = getPathBounds(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                                                                editingPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
            boolean               requestFocus = (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                                   (tree.hasFocus() || SwingUtilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                                    findFocusOwner(editingComponent) != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
            editingComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            editingPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            if(messageStop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                oldEditor.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            else if(messageCancel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                oldEditor.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            tree.remove(oldComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            if(editorHasDifferentSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                treeState.invalidatePathBounds(oldPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            }
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2366
            else if (editingBounds != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                editingBounds.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                editingBounds.width = tree.getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                tree.repaint(editingBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            if(requestFocus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                tree.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            if(messageTree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                treeModel.valueForPathChanged(oldPath, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
    // cover method for startEditing that allows us to pass extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
    // information into that method via a class variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    private boolean startEditingOnRelease(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                                          MouseEvent event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                                          MouseEvent releaseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        this.releaseEvent = releaseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            return startEditing(path, event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            this.releaseEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2392
     * Will start editing for node if there is a {@code cellEditor} and
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2393
     * {@code shouldSelectCell} returns {@code true}.<p>
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2394
     * This assumes that path is valid and visible.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2395
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2396
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2397
     * @param event a mouse event
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2398
     * @return {@code true} if the editing is successful
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2399
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
    protected boolean startEditing(TreePath path, MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        if (isEditing(tree) && tree.getInvokesStopCellEditing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
                               !stopEditing(tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
        completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        if(cellEditor != null && tree.isPathEditable(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
            int           row = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
            if(cellEditor.isCellEditable(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
                editingComponent = cellEditor.getTreeCellEditorComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
                      (tree, path.getLastPathComponent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                       tree.isPathSelected(path), tree.isExpanded(path),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                       treeModel.isLeaf(path.getLastPathComponent()), row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
                Rectangle           nodeBounds = getPathBounds(tree, path);
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2415
                if (nodeBounds == null) {
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2416
                    return false;
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2417
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                editingRow = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                Dimension editorSize = editingComponent.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
                // Only allow odd heights if explicitly set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                if(editorSize.height != nodeBounds.height &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                   getRowHeight() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                    editorSize.height = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                if(editorSize.width != nodeBounds.width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                   editorSize.height != nodeBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                    // Editor wants different width or height, invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                    // treeState and relayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                    editorHasDifferentSize = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                    treeState.invalidatePathBounds(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                    // To make sure x/y are updated correctly, fetch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                    // the bounds again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                    nodeBounds = getPathBounds(tree, path);
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2438
                    if (nodeBounds == null) {
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2439
                        return false;
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  2440
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                    editorHasDifferentSize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
                tree.add(editingComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                editingComponent.setBounds(nodeBounds.x, nodeBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
                                           nodeBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                                           nodeBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
                editingPath = path;
20097
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18133
diff changeset
  2449
                AWTAccessor.getComponentAccessor().revalidateSynchronously(editingComponent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                editingComponent.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                if(cellEditor.shouldSelectCell(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                    stopEditingInCompleteEditing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                    tree.setSelectionRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                    stopEditingInCompleteEditing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
                Component focusedComponent = SwingUtilities2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
                                 compositeRequestFocus(editingComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
                boolean selectAll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  2461
                if(event != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                    /* Find the component that will get forwarded all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
                       mouse events until mouseReleased. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
                    Point          componentPoint = SwingUtilities.convertPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                        (tree, new Point(event.getX(), event.getY()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                         editingComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                    /* Create an instance of BasicTreeMouseListener to handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                       passing the mouse/motion events to the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                       component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                    // We really want similar behavior to getMouseEventTarget,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                    // but it is package private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                    Component activeComponent = SwingUtilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
                                    getDeepestComponentAt(editingComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                                       componentPoint.x, componentPoint.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
                    if (activeComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                        MouseInputHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
                            new MouseInputHandler(tree, activeComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
                                                  event, focusedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                        if (releaseEvent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
                            handler.mouseReleased(releaseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
                        selectAll = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
                if (selectAll && focusedComponent instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                    ((JTextField)focusedComponent).selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                editingComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
    // Following are primarily for handling mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2504
     * If the {@code mouseX} and {@code mouseY} are in the
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2505
     * expand/collapse region of the {@code row}, this will toggle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     * the row.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2507
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2508
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2509
     * @param mouseX an X coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2510
     * @param mouseY an Y coordinate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
    protected void checkForClickInExpandControl(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                                                int mouseX, int mouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
      if (isLocationInExpandControl(path, mouseX, mouseY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
          handleExpandControlClick(path, mouseX, mouseY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2520
     * Returns {@code true} if {@code mouseX} and {@code mouseY} fall
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * in the area of row that is used to expand/collapse the node and
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2522
     * the node at {@code row} does not represent a leaf.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2523
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2524
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2525
     * @param mouseX an X coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2526
     * @param mouseY an Y coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2527
     * @return {@code true} if the mouse cursor fall in the area of row that
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2528
     *         is used to expand/collapse the node and the node is not a leaf.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
    protected boolean isLocationInExpandControl(TreePath path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                                                int mouseX, int mouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        if(path != null && !treeModel.isLeaf(path.getLastPathComponent())){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            int                     boxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
            Insets                  i = tree.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            if(getExpandedIcon() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                boxWidth = getExpandedIcon().getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                boxWidth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
            int boxLeftX = getRowX(tree.getRowForPath(path),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                                   path.getPathCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
                boxLeftX = boxLeftX + i.left - getRightChildIndent() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
                boxLeftX = tree.getWidth() - boxLeftX - i.right + getRightChildIndent() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
            boxLeftX = findCenteredX(boxLeftX, boxWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            return (mouseX >= boxLeftX && mouseX < (boxLeftX + boxWidth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * Messaged when the user clicks the particular row, this invokes
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2559
     * {@code toggleExpandState}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2560
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2561
     * @param path a tree path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2562
     * @param mouseX an X coordinate
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2563
     * @param mouseY an Y coordinate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    protected void handleExpandControlClick(TreePath path, int mouseX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
                                            int mouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        toggleExpandState(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * Expands path if it is not expanded, or collapses row if it is expanded.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2572
     * If expanding a path and {@code JTree} scrolls on expand,
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2573
     * {@code ensureRowsAreVisible} is invoked to scroll as many of the children
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2574
     * to visible as possible (tries to scroll to last visible descendant of path).
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2575
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2576
     * @param path a tree path
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
    protected void toggleExpandState(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
        if(!tree.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            int       row = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            tree.expandPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            if(row != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
                if(tree.getScrollsOnExpand())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
                    ensureRowsAreVisible(row, row + treeState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                                         getVisibleChildCount(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                    ensureRowsAreVisible(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            tree.collapsePath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2599
     * Returning {@code true} signifies a mouse event on the node should toggle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     * the selection of only the row under mouse.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2601
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2602
     * @param event a mouse event
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2603
     * @return {@code true} if a mouse event on the node should toggle the selection
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
    protected boolean isToggleSelectionEvent(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        return (SwingUtilities.isLeftMouseButton(event) &&
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  2607
                BasicGraphicsUtils.isMenuShortcutKeyDown(event));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2611
     * Returning {@code true} signifies a mouse event on the node should select
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * from the anchor point.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2613
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2614
     * @param event a mouse event
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2615
     * @return {@code true} if a mouse event on the node should select
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2616
     *         from the anchor point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    protected boolean isMultiSelectEvent(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
        return (SwingUtilities.isLeftMouseButton(event) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
                event.isShiftDown());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2624
     * Returning {@code true} indicates the row under the mouse should be toggled
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2625
     * based on the event. This is invoked after {@code checkForClickInExpandControl},
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2626
     * implying the location is not in the expand (toggle) control.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2627
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2628
     * @param event a mouse event
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2629
     * @return {@code true} if the row under the mouse should be toggled
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    protected boolean isToggleEvent(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        if(!SwingUtilities.isLeftMouseButton(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        int           clickCount = tree.getToggleClickCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
        if(clickCount <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
        return ((event.getClickCount() % clickCount) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2644
     * Messaged to update the selection based on a {@code MouseEvent} over a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * particular row. If the event is a toggle selection event, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * row is either selected, or deselected. If the event identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * a multi selection event, the selection is updated from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     * anchor point. Otherwise the row is selected, and if the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * specified a toggle event the row is expanded/collapsed.
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2650
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2651
     * @param path the selected path
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2652
     * @param event the mouse event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
    protected void selectPathForEvent(TreePath path, MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        /* Adjust from the anchor point. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
        if(isMultiSelectEvent(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
            TreePath    anchor = getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            int         anchorRow = (anchor == null) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
                                    getRowForPath(tree, anchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
            if(anchorRow == -1 || tree.getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
                      getSelectionMode() == TreeSelectionModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
                      SINGLE_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
                tree.setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
                int          row = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
                TreePath     lastAnchorPath = anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                if (isToggleSelectionEvent(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                    if (tree.isRowSelected(anchorRow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                        tree.addSelectionInterval(anchorRow, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                        tree.removeSelectionInterval(anchorRow, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                        tree.addSelectionInterval(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                } else if(row < anchorRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                    tree.setSelectionInterval(row, anchorRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                    tree.setSelectionInterval(anchorRow, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                lastSelectedRow = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                setAnchorSelectionPath(lastAnchorPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
                setLeadSelectionPath(path);
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
        // Should this event toggle the selection of this row?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        /* Control toggles just this node. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
        else if(isToggleSelectionEvent(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            if(tree.isPathSelected(path))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
                tree.removeSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
                tree.addSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            lastSelectedRow = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
            setAnchorSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
            setLeadSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
        /* Otherwise set the selection to just this interval. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
        else if(SwingUtilities.isLeftMouseButton(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
            tree.setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
            if(isToggleEvent(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                toggleExpandState(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
    /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2710
     * Returns {@code true} if the node at {@code row} is a leaf.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2711
     *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2712
     * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2713
     * @return {@code true} if the node at {@code row} is a leaf
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
    protected boolean isLeaf(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        TreePath          path = getPathForRow(tree, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
        if(path != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            return treeModel.isLeaf(path.getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
        // Have to return something here...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    // The following selection methods (lead/anchor) are covers for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
    // methods in JTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
    private void setAnchorSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
        ignoreLAChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            tree.setAnchorSelectionPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
        } finally{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            ignoreLAChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
    private TreePath getAnchorSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
        return tree.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
    private void setLeadSelectionPath(TreePath newPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
        setLeadSelectionPath(newPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
    private void setLeadSelectionPath(TreePath newPath, boolean repaint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
        Rectangle       bounds = repaint ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
                            getPathBounds(tree, getLeadSelectionPath()) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        ignoreLAChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
            tree.setLeadSelectionPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            ignoreLAChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        leadRow = getRowForPath(tree, newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2757
        if (repaint) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2758
            if (bounds != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2759
                tree.repaint(getRepaintPathBounds(bounds));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2760
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            bounds = getPathBounds(tree, newPath);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2762
            if (bounds != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2763
                tree.repaint(getRepaintPathBounds(bounds));
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2764
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2768
    private Rectangle getRepaintPathBounds(Rectangle bounds) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2769
        if (UIManager.getBoolean("Tree.repaintWholeRow")) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2770
           bounds.x = 0;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2771
           bounds.width = tree.getWidth();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2772
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2773
        return bounds;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2774
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
  2775
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
    private TreePath getLeadSelectionPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
        return tree.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2780
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2781
     * Updates the lead row of the selection.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2782
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2783
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2784
    protected void updateLeadSelectionRow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        leadRow = getRowForPath(tree, getLeadSelectionPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2788
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2789
     * Returns the lead row of the selection.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2790
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2791
     * @return selection lead row
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2792
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2793
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  2794
    protected int getLeadSelectionRow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
        return leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     * Extends the selection from the anchor to make <code>newLead</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     * the lead of the selection. This does not scroll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    private void extendSelection(TreePath newLead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
        TreePath           aPath = getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
        int                aRow = (aPath == null) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
                                  getRowForPath(tree, aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        int                newIndex = getRowForPath(tree, newLead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
        if(aRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            tree.setSelectionRow(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            if(aRow < newIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                tree.setSelectionInterval(aRow, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                tree.setSelectionInterval(newIndex, aRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
            setLeadSelectionPath(newLead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * Invokes <code>repaint</code> on the JTree for the passed in TreePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     * <code>path</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
    private void repaintPath(TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
        if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
            Rectangle bounds = getPathBounds(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
            if (bounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
                tree.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * Updates the TreeState in response to nodes expanding/collapsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    public class TreeExpansionHandler implements TreeExpansionListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2840
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
         * Called whenever an item in the tree has been expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        public void treeExpanded(TreeExpansionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            getHandler().treeExpanded(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
         * Called whenever an item in the tree has been collapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        public void treeCollapsed(TreeExpansionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
            getHandler().treeCollapsed(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
    } // BasicTreeUI.TreeExpansionHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     * Updates the preferred size when scrolling (if necessary).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    public class ComponentHandler extends ComponentAdapter implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                 ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        /** Timer used when inside a scrollpane and the scrollbar is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
         * adjusting. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
        protected Timer                timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
        /** ScrollBar that is being adjusted. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
        protected JScrollBar           scrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
        public void componentMoved(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
            if(timer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                JScrollPane   scrollPane = getScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                if(scrollPane == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                    scrollBar = scrollPane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                    if(scrollBar == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                        !scrollBar.getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                        // Try the horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
                        if((scrollBar = scrollPane.getHorizontalScrollBar())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                            != null && scrollBar.getValueIsAdjusting())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                            startTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                            updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                        startTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
         * Creates, if necessary, and starts a Timer to check if need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
         * resize the bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
        protected void startTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
            if(timer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                timer = new Timer(200, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                timer.setRepeats(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            timer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
        /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2908
         * Returns the {@code JScrollPane} housing the {@code JTree},
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2909
         * or null if one isn't found.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2910
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  2911
         * @return the {@code JScrollPane} housing the {@code JTree}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        protected JScrollPane getScrollPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
            Component       c = tree.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
            while(c != null && !(c instanceof JScrollPane))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            if(c instanceof JScrollPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
                return (JScrollPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
         * Public as a result of Timer. If the scrollBar is null, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
         * not adjusting, this stops the timer and updates the sizing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
        public void actionPerformed(ActionEvent ae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
            if(scrollBar == null || !scrollBar.getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
                if(timer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
                    timer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
                updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
                timer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                scrollBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
    } // End of BasicTreeUI.ComponentHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * Forwards all TreeModel events to the TreeState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
    public class TreeModelHandler implements TreeModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2944
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        public void treeNodesChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
            getHandler().treeNodesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        public void treeNodesInserted(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            getHandler().treeNodesInserted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
        public void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
            getHandler().treeNodesRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
        public void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            getHandler().treeStructureChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
    } // End of BasicTreeUI.TreeModelHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
     * Listens for changes in the selection model and updates the display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
     * accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
    public class TreeSelectionHandler implements TreeSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2973
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
         * Messaged when the selection changes in the tree we're displaying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
         * for.  Stops editing, messages super and displays the changed paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
        public void valueChanged(TreeSelectionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            getHandler().valueChanged(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
    }// End of BasicTreeUI.TreeSelectionHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
     * Listener responsible for getting cell editing events and updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
     * the tree accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
    public class CellEditorHandler implements CellEditorListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2994
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
        /** Messaged when editing has stopped in the tree. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
        public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
            getHandler().editingStopped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
        /** Messaged when editing has been canceled in the tree. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
        public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            getHandler().editingCanceled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
    } // BasicTreeUI.CellEditorHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3012
     * This is used to get multiple key down events to appropriately generate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
    public class KeyHandler extends KeyAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3017
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
        // Also note these fields aren't use anymore, nor does Handler have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
        // the old functionality. This behavior worked around an old bug
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
        // in JComponent that has long since been fixed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
        /** Key code that is being generated for. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
        protected Action              repeatKeyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        /** Set to true while keyPressed is active. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
        protected boolean            isKeyDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
         * Invoked when a key has been typed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
         * Moves the keyboard focus to the first element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
         * whose first letter matches the alphanumeric key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
         * pressed by the user. Subsequent same key presses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
         * move the keyboard focus to the next object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
         * starts with the same letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
            getHandler().keyTyped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
        public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            getHandler().keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
        public void keyReleased(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
            getHandler().keyReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
    } // End of BasicTreeUI.KeyHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     * Repaints the lead selection row when focus is lost/gained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
    public class FocusHandler implements FocusListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3059
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
         * Invoked when focus is activated on the tree we're in, redraws the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
         * lead row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
         * Invoked when focus is activated on the tree we're in, redraws the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
         * lead row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
    } // End of class BasicTreeUI.FocusHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * Class responsible for getting size of node, method is forwarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * to BasicTreeUI method. X location does not include insets, that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     * handled in getPathBounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
    // This returns locations that don't include any Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
    public class NodeDimensionsHandler extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
                 AbstractLayoutCache.NodeDimensions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
         * Responsible for getting the size of a particular node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
        public Rectangle getNodeDimensions(Object value, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
                                           int depth, boolean expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
                                           Rectangle size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
            // Return size of editing component, if editing and asking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
            // for editing row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
            if(editingComponent != null && editingRow == row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
                Dimension        prefSize = editingComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
                                              getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
                int              rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
                if(rh > 0 && rh != prefSize.height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
                    prefSize.height = rh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
                if(size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
                    size.x = getRowX(row, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
                    size.width = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
                    size.height = prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
                    size = new Rectangle(getRowX(row, depth), 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
                                         prefSize.width, prefSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
            // Not editing, use renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
            if(currentCellRenderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
                Component          aComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
                aComponent = currentCellRenderer.getTreeCellRendererComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
                    (tree, value, tree.isRowSelected(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
                     expanded, treeModel.isLeaf(value), row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
                     false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
                if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
                    // Only ever removed when UI changes, this is OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
                    rendererPane.add(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
                    aComponent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
                Dimension        prefSize = aComponent.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
                if(size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
                    size.x = getRowX(row, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
                    size.width = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
                    size.height = prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
                    size = new Rectangle(getRowX(row, depth), 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
                                         prefSize.width, prefSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
        /**
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3146
         * Returns amount to indent the given row.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3147
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3148
         * @param row a row
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3149
         * @param depth a depth
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3150
         * @return amount to indent the given row
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
        protected int getRowX(int row, int depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            return BasicTreeUI.this.getRowX(row, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
    } // End of class BasicTreeUI.NodeDimensionsHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     * TreeMouseListener is responsible for updating the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
     * based on mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
    public class MouseHandler extends MouseAdapter implements MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
 {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3165
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
         * Invoked when a mouse button has been pressed on a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
         * Invoked when the mouse button has been moved on a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
         * (with no buttons no down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
            getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
    } // End of BasicTreeUI.MouseHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
     * PropertyChangeListener for the tree. Updates the appropriate
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3198
     * variable, or TreeState, based on what changes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
    public class PropertyChangeHandler implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
                       PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3203
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
            getHandler().propertyChange(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    } // End of BasicTreeUI.PropertyChangeHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
     * Listener on the TreeSelectionModel, resets the row selection if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     * any of the properties of the model change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
    public class SelectionModelPropertyChangeHandler implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
                      PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  3221
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
            getHandler().propertyChange(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
    } // End of BasicTreeUI.SelectionModelPropertyChangeHandler
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>TreeTraverseAction</code> is the action used for left/right keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * Will toggle the expandedness of a node, as well as potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * incrementing the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3237
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
    public class TreeTraverseAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
        /** Determines direction to traverse, 1 means expand, -1 means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
          * collapse. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
        protected int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
        /** True if the selection is reset, false means only the lead path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
         * changes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
        private boolean changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3246
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3247
         * Constructs a new instance of {@code TreeTraverseAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3248
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3249
         * @param direction the direction
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3250
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3251
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
        public TreeTraverseAction(int direction, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
            this(direction, name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
        private TreeTraverseAction(int direction, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
                                   boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
            this.changeSelection = changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
            if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
                SHARED_ACTION.traverse(tree, BasicTreeUI.this, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
                                       changeSelection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                                             tree.isEnabled()); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
    } // BasicTreeUI.TreeTraverseAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
    /** TreePageAction handles page up and page down events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
      */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3276
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
    public class TreePageAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
        /** Specifies the direction to adjust the selection by. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
        protected int         direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
        /** True indicates should set selection from anchor path. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
        private boolean       addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
        private boolean       changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3284
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3285
         * Constructs a new instance of {@code TreePageAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3286
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3287
         * @param direction the direction
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3288
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3289
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
        public TreePageAction(int direction, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            this(direction, name, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        private TreePageAction(int direction, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                               boolean addToSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                               boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
            this.addToSelection = addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
            this.changeSelection = changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
            if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
                SHARED_ACTION.page(tree, BasicTreeUI.this, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                                   addToSelection, changeSelection);
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
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                                             tree.isEnabled()); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
    } // BasicTreeUI.TreePageAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
    /** TreeIncrementAction is used to handle up/down actions.  Selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
      * is moved up or down based on direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
      */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3318
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
    public class TreeIncrementAction extends AbstractAction  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        /** Specifies the direction to adjust the selection by. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
        protected int         direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        /** If true the new item is added to the selection, if false the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
         * selection is reset. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
        private boolean       addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
        private boolean       changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3327
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3328
         * Constructs a new instance of {@code TreeIncrementAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3329
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3330
         * @param direction the direction
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3331
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3332
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
        public TreeIncrementAction(int direction, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
            this(direction, name, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
        private TreeIncrementAction(int direction, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
                                   boolean addToSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
                                    boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
            this.addToSelection = addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
            this.changeSelection = changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
            if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
                SHARED_ACTION.increment(tree, BasicTreeUI.this, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
                                        addToSelection, changeSelection);
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
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
                                             tree.isEnabled()); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
    } // End of class BasicTreeUI.TreeIncrementAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
      * TreeHomeAction is used to handle end/home actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
      * Scrolls either the first or last cell to be visible based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
      * direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
      */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3362
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
    public class TreeHomeAction extends AbstractAction {
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3364
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3365
         * The direction.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3366
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
        protected int            direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
        /** Set to true if append to selection. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
        private boolean          addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        private boolean          changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3372
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3373
         * Constructs a new instance of {@code TreeHomeAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3374
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3375
         * @param direction the direction
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3376
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3377
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
        public TreeHomeAction(int direction, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
            this(direction, name, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
        private TreeHomeAction(int direction, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
                               boolean addToSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                               boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
            this.changeSelection = changeSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
            this.addToSelection = addToSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                SHARED_ACTION.home(tree, BasicTreeUI.this, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
                                   addToSelection, changeSelection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
                                             tree.isEnabled()); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
    } // End of class BasicTreeUI.TreeHomeAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
      * For the first selected row expandedness will be toggled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
      */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3406
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
    public class TreeToggleAction extends AbstractAction {
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3408
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3409
         * Constructs a new instance of {@code TreeToggleAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3410
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3411
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3412
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
        public TreeToggleAction(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                SHARED_ACTION.toggle(tree, BasicTreeUI.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
                                             tree.isEnabled()); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
    } // End of class BasicTreeUI.TreeToggleAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * ActionListener that invokes cancelEditing when action performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3431
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
    public class TreeCancelEditingAction extends AbstractAction {
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3433
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3434
         * Constructs a new instance of {@code TreeCancelEditingAction}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3435
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3436
         * @param name the name of action
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3437
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
        public TreeCancelEditingAction(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
            if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                SHARED_ACTION.cancelEditing(tree, BasicTreeUI.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
        public boolean isEnabled() { return (tree != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
                                             tree.isEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                                             isEditing(tree)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
    } // End of class BasicTreeUI.TreeCancelEditingAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
      * MouseInputHandler handles passing all mouse events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
      * including mouse motion events, until the mouse is released to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
      * the destination it is constructed with. It is assumed all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
      * events are currently target at source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
    public class MouseInputHandler extends Object implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
                     MouseInputListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
        /** Source that events are coming from. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
        protected Component        source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        /** Destination that receives all events. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
        protected Component        destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
        private Component          focusComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
        private boolean            dispatchedEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3469
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3470
         * Constructs a new instance of {@code MouseInputHandler}.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3471
         *
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3472
         * @param source a source component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3473
         * @param destination a destination component
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3474
         * @param event a mouse event
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3475
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
        public MouseInputHandler(Component source, Component destination,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                                      MouseEvent event){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
            this(source, destination, event, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
        MouseInputHandler(Component source, Component destination,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
                          MouseEvent event, Component focusComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
            this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            this.destination = destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
            this.source.addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            this.source.addMouseMotionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
            SwingUtilities2.setSkipClickCount(destination,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
                                              event.getClickCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
            /* Dispatch the editing event! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
            destination.dispatchEvent(SwingUtilities.convertMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                                          (source, event, destination));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
            this.focusComponent = focusComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
            if(destination != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
                dispatchedEvent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
                destination.dispatchEvent(SwingUtilities.convertMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
                                          (source, e, destination));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
            if(destination != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
                destination.dispatchEvent(SwingUtilities.convertMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
                                          (source, e, destination));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
            removeFromSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            if (!SwingUtilities.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                removeFromSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            if (!SwingUtilities.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
                removeFromSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
            if(destination != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
                dispatchedEvent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
                destination.dispatchEvent(SwingUtilities.convertMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
                                          (source, e, destination));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
            removeFromSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
25775
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3539
        /**
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3540
         * Removes an event from the source.
6a6fd62bc6d5 8050009: Fix doclint warnings from javax.swing.plaf.basic package, 7 of 7
aeremeev
parents: 25565
diff changeset
  3541
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
        protected void removeFromSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
            if(source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
                source.removeMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
                source.removeMouseMotionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
                if (focusComponent != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                      focusComponent == destination && !dispatchedEvent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                      (focusComponent instanceof JTextField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                    ((JTextField)focusComponent).selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
            source = destination = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
    } // End of class BasicTreeUI.MouseInputHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
    private static final TransferHandler defaultTransferHandler = new TreeTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21982
diff changeset
  3559
    @SuppressWarnings("serial") // JDK-implementation class
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3560
    static class TreeTransferHandler extends TransferHandler implements UIResource, Comparator<TreePath> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
        private JTree tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
         * Create a Transferable to use as the source for a data transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
         * @param c  The component holding the data to be transfered.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
         *  argument is provided to enable sharing of TransferHandlers by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
         *  multiple components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
         * @return  The representation of the data to be transfered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
        protected Transferable createTransferable(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
            if (c instanceof JTree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                tree = (JTree) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                TreePath[] paths = tree.getSelectionPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
                if (paths == null || paths.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3582
                StringBuilder plainStr = new StringBuilder();
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3583
                StringBuilder htmlStr = new StringBuilder();
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3584
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3585
                htmlStr.append("<html>\n<body>\n<ul>\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
                TreeModel model = tree.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                TreePath lastPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
                TreePath[] displayPaths = getDisplayOrderPaths(paths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3591
                for (TreePath path : displayPaths) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
                    Object node = path.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
                    boolean leaf = model.isLeaf(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
                    String label = getDisplayString(path, true, leaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3596
                    plainStr.append(label + "\n");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3597
                    htmlStr.append("  <li>" + label + "\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
                // remove the last newline
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3601
                plainStr.deleteCharAt(plainStr.length() - 1);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3602
                htmlStr.append("</ul>\n</body>\n</html>");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
                tree = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23715
diff changeset
  3606
                return new BasicTransferable(plainStr.toString(), htmlStr.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3612
        public int compare(TreePath o1, TreePath o2) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3613
            int row1 = tree.getRowForPath(o1);
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3614
            int row2 = tree.getRowForPath(o2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
            return row1 - row2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
        String getDisplayString(TreePath path, boolean selected, boolean leaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
            int row = tree.getRowForPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
            boolean hasFocus = tree.getLeadSelectionRow() == row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
            Object node = path.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            return tree.convertValueToText(node, selected, tree.isExpanded(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
                                           leaf, row, hasFocus);
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
         * Selection paths are in selection order.  The conversion to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
         * HTML requires display order.  This method resorts the paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
         * to be in the display order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
        TreePath[] getDisplayOrderPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
            // sort the paths to display order rather than selection order
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3633
            ArrayList<TreePath> selOrder = new ArrayList<TreePath>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3634
            for (TreePath path : paths) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3635
                selOrder.add(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
            Collections.sort(selOrder, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
            int n = selOrder.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
            TreePath[] displayPaths = new TreePath[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
            for (int i = 0; i < n; i++) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3641
                displayPaths[i] = selOrder.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
            return displayPaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
        public int getSourceActions(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
            return COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
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
    private class Handler implements CellEditorListener, FocusListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
                  KeyListener, MouseListener, MouseMotionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
                  PropertyChangeListener, TreeExpansionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                  TreeModelListener, TreeSelectionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
                  BeforeDrag {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
        // KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
        private String prefix = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
        private String typedString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
        private long lastTime = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
         * Invoked when a key has been typed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
         * Moves the keyboard focus to the first element whose prefix matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
         * sequence of alphanumeric keys pressed by the user with delay less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
         * than value of <code>timeFactor</code> property (or 1000 milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
         * if it is not defined). Subsequent same key presses move the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
         * focus to the next object that starts with the same letter until another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
         * key is pressed, then it is treated as the prefix with appropriate number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
         * of the same letters followed by first typed another letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
            // handle first letter navigation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
            if(tree != null && tree.getRowCount()>0 && tree.hasFocus() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
               tree.isEnabled()) {
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  3680
                if (e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
                    isNavigationKey(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
                boolean startingFromSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                char c = e.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
                long time = e.getWhen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
                int startingRow = tree.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
                if (time - lastTime < timeFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
                    typedString += c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
                    if((prefix.length() == 1) && (c == prefix.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
                        // Subsequent same key presses move the keyboard focus to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
                        // object that starts with the same letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
                        startingRow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
                        prefix = typedString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
                    startingRow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
                    typedString = "" + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
                    prefix = typedString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
                lastTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
                if (startingRow < 0 || startingRow >= tree.getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
                    startingFromSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
                    startingRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
                TreePath path = tree.getNextMatch(prefix, startingRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
                                                  Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
                if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
                    tree.setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
                    int row = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
                    ensureRowsAreVisible(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
                } else if (startingFromSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
                    path = tree.getNextMatch(prefix, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
                                             Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
                    if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
                        tree.setSelectionPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
                        int row = getRowForPath(tree, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
                        ensureRowsAreVisible(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
         * Invoked when a key has been pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
         * Checks to see if the key event is a navigation key to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
         * dispatching these keys for the first letter navigation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
        public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
            if (tree != null && isNavigationKey(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                prefix = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
                typedString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                lastTime = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
        public void keyReleased(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
         * Returns whether or not the supplied key event maps to a key that is used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
         * navigation.  This is used for optimizing key input by only passing non-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
         * navigation keys to the first letter navigation mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
        private boolean isNavigationKey(KeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
            InputMap inputMap = tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
            KeyStroke key = KeyStroke.getKeyStrokeForEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  3754
            return inputMap != null && inputMap.get(key) != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
            if (event.getSource() == treeSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                treeSelectionModel.resetRowSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
            else if(event.getSource() == tree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
                String              changeName = event.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
                if (changeName == JTree.LEAD_SELECTION_PATH_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
                    if (!ignoreLAChange) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  3770
                        updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
                        repaintPath((TreePath)event.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
                        repaintPath((TreePath)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
                else if (changeName == JTree.ANCHOR_SELECTION_PATH_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
                    if (!ignoreLAChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
                        repaintPath((TreePath)event.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
                        repaintPath((TreePath)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
                if(changeName == JTree.CELL_RENDERER_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
                    setCellRenderer((TreeCellRenderer)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
                    redoTheLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
                else if(changeName == JTree.TREE_MODEL_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
                    setModel((TreeModel)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
                else if(changeName == JTree.ROOT_VISIBLE_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
                    setRootVisible(((Boolean)event.getNewValue()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
                                   booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
                else if(changeName == JTree.SHOWS_ROOT_HANDLES_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
                    setShowsRootHandles(((Boolean)event.getNewValue()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
                                        booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
                else if(changeName == JTree.ROW_HEIGHT_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
                    setRowHeight(((Integer)event.getNewValue()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
                                 intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
                else if(changeName == JTree.CELL_EDITOR_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                    setCellEditor((TreeCellEditor)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
                else if(changeName == JTree.EDITABLE_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
                    setEditable(((Boolean)event.getNewValue()).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
                else if(changeName == JTree.LARGE_MODEL_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
                    setLargeModel(tree.isLargeModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
                else if(changeName == JTree.SELECTION_MODEL_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
                    setSelectionModel(tree.getSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
                else if(changeName == "font") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
                    completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
                    if(treeState != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
                        treeState.invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                else if (changeName == "componentOrientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
                    if (tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                        leftToRight = BasicGraphicsUtils.isLeftToRight(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
                        redoTheLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                        tree.treeDidChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
                        InputMap km = getInputMap(JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
                        SwingUtilities.replaceUIInputMap(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
                                                JComponent.WHEN_FOCUSED, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                } else if ("dropLocation" == changeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                    JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                    repaintDropLocation(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                    repaintDropLocation(tree.getDropLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
        private void repaintDropLocation(JTree.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
            if (loc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
            Rectangle r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
            if (isDropLine(loc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
                r = getDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
                r = tree.getPathBounds(loc.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
                tree.repaint(r);
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
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
        // MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
        // Whether or not the mouse press (which is being considered as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
        // of a drag sequence) also caused the selection change to be fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
        // processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
        private boolean dragPressDidSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
        // Set to true when a drag gesture has been fully recognized and DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
        // begins. Use this to ignore further mouse events which could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
        // delivered if DnD is cancelled (via ESCAPE for example)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
        private boolean dragStarted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
        // The path over which the press occurred and the press event itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
        private TreePath pressedPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        private MouseEvent pressedEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
        // Used to detect whether the press event causes a selection change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        // If it does, we won't try to start editing on the release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        private boolean valueChangedOnPress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
        private boolean isActualPath(TreePath path, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
            if (path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
            Rectangle bounds = getPathBounds(tree, path);
11499
f486e3ec76e6 6505523: NullPointerException in BasicTreeUI when a node is removed by expansion listener
alexsch
parents: 9035
diff changeset
  3882
            if (bounds == null || y > (bounds.y + bounds.height)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
            return (x >= bounds.x) && (x <= (bounds.x + bounds.width));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
         * Invoked when a mouse button has been pressed on a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
            if (SwingUtilities2.shouldIgnore(e, tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
            // if we can't stop any ongoing editing, do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
            if (isEditing(tree) && tree.getInvokesStopCellEditing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
                                && !stopEditing(tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
            completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
            pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
            if (tree.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                mousePressedDND(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                SwingUtilities2.adjustFocus(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                handleSelection(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
        private void mousePressedDND(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
            pressedEvent = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
            boolean grabFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
            dragStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
            valueChangedOnPress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
            // if we have a valid path and this is a drag initiating event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
            if (isActualPath(pressedPath, e.getX(), e.getY()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
                    DragRecognitionSupport.mousePressed(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                dragPressDidSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  3936
                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                    // do nothing for control - will be handled on release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                    // or when drag starts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                } else if (!e.isShiftDown() && tree.isPathSelected(pressedPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                    // clicking on something that's already selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                    // and need to make it the lead now
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                    setAnchorSelectionPath(pressedPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                    setLeadSelectionPath(pressedPath, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
                dragPressDidSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                // could be a drag initiating event - don't grab focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                grabFocus = 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
            if (grabFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                SwingUtilities2.adjustFocus(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
            handleSelection(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
        void handleSelection(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
            if(pressedPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                Rectangle bounds = getPathBounds(tree, pressedPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  3965
                if (bounds == null || e.getY() >= (bounds.y + bounds.height)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                // Preferably checkForClickInExpandControl could take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                // the Event to do this it self!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
                if(SwingUtilities.isLeftMouseButton(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
                    checkForClickInExpandControl(pressedPath, e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
                int x = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
                // Perhaps they clicked the cell itself. If so,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
                // select it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
                if (x >= bounds.x && x < (bounds.x + bounds.width)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                    if (tree.getDragEnabled() || !startEditing(pressedPath, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
                        selectPathForEvent(pressedPath, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
        public void dragStarting(MouseEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
            dragStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  3990
            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                tree.addSelectionPath(pressedPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                setAnchorSelectionPath(pressedPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                setLeadSelectionPath(pressedPath, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
            pressedEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
            pressedPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
            if (SwingUtilities2.shouldIgnore(e, tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
            if (tree.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                DragRecognitionSupport.mouseDragged(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
         * Invoked when the mouse button has been moved on a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
         * (with no buttons no down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
            if (SwingUtilities2.shouldIgnore(e, tree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
            if (tree.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                mouseReleasedDND(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
            pressedEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
            pressedPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
        private void mouseReleasedDND(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
            MouseEvent me = DragRecognitionSupport.mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
            if (me != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
                SwingUtilities2.adjustFocus(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
                if (!dragPressDidSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
                    handleSelection(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
            if (!dragStarted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                // Note: We don't give the tree a chance to start editing if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                // mouse press caused a selection change. Otherwise the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                // tree cell editor will start editing on EVERY press and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                // release. If it turns out that this affects some editors, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                // can always parameterize this with a client property. ex:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                // if (pressedPath != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                //         (Boolean.TRUE == tree.getClientProperty("Tree.DnD.canEditOnValueChange") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                //          !valueChangedOnPress) && ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                if (pressedPath != null && !valueChangedOnPress &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
                        isActualPath(pressedPath, pressedEvent.getX(), pressedEvent.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
                    startEditingOnRelease(pressedPath, pressedEvent, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
            if(tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
                Rectangle                 pBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
                pBounds = getPathBounds(tree, tree.getLeadSelectionPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
                if(pBounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
                    tree.repaint(getRepaintPathBounds(pBounds));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
                pBounds = getPathBounds(tree, getLeadSelectionPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
                if(pBounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
                    tree.repaint(getRepaintPathBounds(pBounds));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
            focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        // CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
        public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
            completeEditing(false, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
        /** Messaged when editing has been canceled in the tree. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
        public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
            completeEditing(false, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
        // TreeSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
        public void valueChanged(TreeSelectionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
            valueChangedOnPress = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            // Stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
            completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
            // Make sure all the paths are visible, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
            // PENDING: This should be tweaked when isAdjusting is added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            if(tree.getExpandsSelectedPaths() && treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
                TreePath[]           paths = treeSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
                                         .getSelectionPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
                if(paths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
                    for(int counter = paths.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
                        counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
                        TreePath path = paths[counter].getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
                        boolean expand = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
                        while (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
                            // Indicates this path isn't valid anymore,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
                            // we shouldn't attempt to expand it then.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
                            if (treeModel.isLeaf(path.getLastPathComponent())){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
                                expand = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
                                path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                                path = path.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
                        if (expand) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
                            tree.makeVisible(paths[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            TreePath oldLead = getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
            lastSelectedRow = tree.getMinSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
            TreePath lead = tree.getSelectionModel().getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
            setAnchorSelectionPath(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
            setLeadSelectionPath(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
            TreePath[]       changedPaths = event.getPaths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
            Rectangle        nodeBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
            Rectangle        visRect = tree.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
            boolean          paintPaths = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
            int              nWidth = tree.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
            if(changedPaths != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
                int              counter, maxCounter = changedPaths.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
                if(maxCounter > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
                    tree.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
                    paintPaths = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
                    for (counter = 0; counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
                        nodeBounds = getPathBounds(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
                                                   changedPaths[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
                        if(nodeBounds != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
                           visRect.intersects(nodeBounds))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
                            tree.repaint(0, nodeBounds.y, nWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
                                         nodeBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
            if(paintPaths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
                nodeBounds = getPathBounds(tree, oldLead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
                if(nodeBounds != null && visRect.intersects(nodeBounds))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
                    tree.repaint(0, nodeBounds.y, nWidth, nodeBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
                nodeBounds = getPathBounds(tree, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
                if(nodeBounds != null && visRect.intersects(nodeBounds))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
                    tree.repaint(0, nodeBounds.y, nWidth, nodeBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        // TreeExpansionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
        public void treeExpanded(TreeExpansionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
            if(event != null && tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
                TreePath      path = event.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
                updateExpandedDescendants(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
        public void treeCollapsed(TreeExpansionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
            if(event != null && tree != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
                TreePath        path = event.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
                completeEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
                if(path != null && tree.isVisible(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
                    treeState.setExpandedState(path, false);
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  4188
                    updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
        // TreeModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        public void treeNodesChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
            if(treeState != null && e != null) {
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 15333
diff changeset
  4199
                TreePath parentPath = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
                int[] indices = e.getChildIndices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
                if (indices == null || indices.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
                    // The root has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
                    treeState.treeNodesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
                else if (treeState.isExpanded(parentPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
                    // Changed nodes are visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
                    // Find the minimum index, we only need paint from there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
                    // down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
                    int minIndex = indices[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
                    for (int i = indices.length - 1; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
                        minIndex = Math.min(indices[i], minIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
                    Object minChild = treeModel.getChild(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
                            parentPath.getLastPathComponent(), minIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
                    TreePath minPath = parentPath.pathByAddingChild(minChild);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
                    Rectangle minBounds = getPathBounds(tree, minPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
                    // Forward to the treestate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
                    treeState.treeNodesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
                    // Mark preferred size as bogus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
                    updateSize0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
                    // And repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
                    Rectangle newMinBounds = getPathBounds(tree, minPath);
14655
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  4227
                    if (minBounds == null || newMinBounds == null) {
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  4228
                        return;
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  4229
                    }
d524ae0f511e 6671481: NPE at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection
alexsch
parents: 11499
diff changeset
  4230
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
                    if (indices.length == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
                            newMinBounds.height == minBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
                        tree.repaint(0, minBounds.y, tree.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
                                     minBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
                        tree.repaint(0, minBounds.y, tree.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
                                     tree.getHeight() - minBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
                    // Nodes that changed aren't visible.  No need to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
                    treeState.treeNodesChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
        public void treeNodesInserted(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
            if(treeState != null && e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
                treeState.treeNodesInserted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  4252
                updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 15333
diff changeset
  4254
                TreePath       path = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
                if(treeState.isExpanded(path)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                    // PENDING(sky): Need a method in TreeModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
                    // that can return the count, getChildIndices allocs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
                    // a new array!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
                    int[]      indices = e.getChildIndices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
                    int        childCount = treeModel.getChildCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                                            (path.getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                    if(indices != null && (childCount - indices.length) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                        updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
        public void treeNodesRemoved(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
            if(treeState != null && e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                treeState.treeNodesRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  4277
                updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 15333
diff changeset
  4279
                TreePath       path = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                if(treeState.isExpanded(path) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
                   treeModel.getChildCount(path.getLastPathComponent()) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
        public void treeStructureChanged(TreeModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
            if(treeState != null && e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                treeState.treeStructureChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3977
diff changeset
  4291
                updateLeadSelectionRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
18133
41b4b144eaff 8013571: TreeModelEvent doesn't accept "null" for root as Javadoc specifies.
malenkov
parents: 15333
diff changeset
  4293
                TreePath       pPath = SwingUtilities2.getTreePath(e, getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
                if (pPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
                    pPath = pPath.getParentPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
                if(pPath == null || treeState.isExpanded(pPath))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                    updateSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
            }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
        private static final String SELECT_PREVIOUS = "selectPrevious";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
        private static final String SELECT_PREVIOUS_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                             "selectPreviousChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
        private static final String SELECT_PREVIOUS_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                             "selectPreviousExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
        private static final String SELECT_NEXT = "selectNext";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
        private static final String SELECT_NEXT_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                                    "selectNextChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
        private static final String SELECT_NEXT_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                                    "selectNextExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
        private static final String SELECT_CHILD = "selectChild";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
        private static final String SELECT_CHILD_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
                                    "selectChildChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        private static final String SELECT_PARENT = "selectParent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
        private static final String SELECT_PARENT_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
                                    "selectParentChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
        private static final String SCROLL_UP_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
                                    "scrollUpChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
        private static final String SCROLL_UP_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
                                    "scrollUpChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
        private static final String SCROLL_UP_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
                                    "scrollUpExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
        private static final String SCROLL_DOWN_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
                                    "scrollDownChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
        private static final String SCROLL_DOWN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
                                    "scrollDownExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
        private static final String SCROLL_DOWN_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
                                    "scrollDownChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
        private static final String SELECT_FIRST = "selectFirst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
        private static final String SELECT_FIRST_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
                                    "selectFirstChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
        private static final String SELECT_FIRST_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
                                    "selectFirstExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
        private static final String SELECT_LAST = "selectLast";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
        private static final String SELECT_LAST_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
                                    "selectLastChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
        private static final String SELECT_LAST_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
                                    "selectLastExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
        private static final String TOGGLE = "toggle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
        private static final String CANCEL_EDITING = "cancel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
        private static final String START_EDITING = "startEditing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
        private static final String SELECT_ALL = "selectAll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
        private static final String CLEAR_SELECTION = "clearSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
        private static final String SCROLL_LEFT = "scrollLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
        private static final String SCROLL_RIGHT = "scrollRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
        private static final String SCROLL_LEFT_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
                                    "scrollLeftExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
        private static final String SCROLL_RIGHT_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
                                    "scrollRightExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
        private static final String SCROLL_RIGHT_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
                                    "scrollRightChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
        private static final String SCROLL_LEFT_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
                                    "scrollLeftChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
        private static final String EXPAND = "expand";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
        private static final String COLLAPSE = "collapse";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
        private static final String MOVE_SELECTION_TO_PARENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
                                    "moveSelectionToParent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
        // add the lead item to the selection without changing lead or anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
        private static final String ADD_TO_SELECTION = "addToSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
        // toggle the selected state of the lead item and move the anchor to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
        private static final String TOGGLE_AND_ANCHOR = "toggleAndAnchor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
        // extend the selection to the lead item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
        private static final String EXTEND_TO = "extendTo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
        // move the anchor to the lead and ensure only that item is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
        private static final String MOVE_SELECTION_TO = "moveSelectionTo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
        Actions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
            super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
        public boolean isEnabled(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
            if (o instanceof JTree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
                if (getName() == CANCEL_EDITING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
                    return ((JTree)o).isEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
            JTree tree = (JTree)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
            BasicTreeUI ui = (BasicTreeUI)BasicLookAndFeel.getUIOfType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
                             tree.getUI(), BasicTreeUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
            if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
            if (key == SELECT_PREVIOUS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                increment(tree, ui, -1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            else if (key == SELECT_PREVIOUS_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                increment(tree, ui, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
            else if (key == SELECT_PREVIOUS_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
                increment(tree, ui, -1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
            else if (key == SELECT_NEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
                increment(tree, ui, 1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
            else if (key == SELECT_NEXT_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
                increment(tree, ui, 1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            else if (key == SELECT_NEXT_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
                increment(tree, ui, 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
            else if (key == SELECT_CHILD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
                traverse(tree, ui, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
            else if (key == SELECT_CHILD_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
                traverse(tree, ui, 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            else if (key == SELECT_PARENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                traverse(tree, ui, -1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
            else if (key == SELECT_PARENT_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                traverse(tree, ui, -1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
            else if (key == SCROLL_UP_CHANGE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
                page(tree, ui, -1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
            else if (key == SCROLL_UP_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                page(tree, ui, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
            else if (key == SCROLL_UP_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                page(tree, ui, -1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
            else if (key == SCROLL_DOWN_CHANGE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                page(tree, ui, 1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
            else if (key == SCROLL_DOWN_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
                page(tree, ui, 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
            else if (key == SCROLL_DOWN_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
                page(tree, ui, 1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
            else if (key == SELECT_FIRST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
                home(tree, ui, -1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
            else if (key == SELECT_FIRST_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
                home(tree, ui, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
            else if (key == SELECT_FIRST_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
                home(tree, ui, -1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
            else if (key == SELECT_LAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
                home(tree, ui, 1, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
            else if (key == SELECT_LAST_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
                home(tree, ui, 1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
            else if (key == SELECT_LAST_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
                home(tree, ui, 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
            else if (key == TOGGLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
                toggle(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
            else if (key == CANCEL_EDITING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
                cancelEditing(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
            else if (key == START_EDITING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
                startEditing(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
            else if (key == SELECT_ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
                selectAll(tree, ui, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            else if (key == CLEAR_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
                selectAll(tree, ui, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
            else if (key == ADD_TO_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
                if (ui.getRowCount(tree) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
                    int lead = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
                    if (!tree.isRowSelected(lead)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
                        TreePath aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
                        tree.addSelectionRow(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
                        ui.setAnchorSelectionPath(aPath);
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
            else if (key == TOGGLE_AND_ANCHOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
                if (ui.getRowCount(tree) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
                    int lead = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
                    TreePath lPath = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
                    if (!tree.isRowSelected(lead)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
                        tree.addSelectionRow(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
                        tree.removeSelectionRow(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
                        ui.setLeadSelectionPath(lPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
                    ui.setAnchorSelectionPath(lPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
            else if (key == EXTEND_TO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
                extendSelection(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
            else if (key == MOVE_SELECTION_TO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
                if (ui.getRowCount(tree) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
                    int lead = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
                    tree.setSelectionInterval(lead, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
            else if (key == SCROLL_LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
                scroll(tree, ui, SwingConstants.HORIZONTAL, -10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
            else if (key == SCROLL_RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
                scroll(tree, ui, SwingConstants.HORIZONTAL, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
            else if (key == SCROLL_LEFT_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                scrollChangeSelection(tree, ui, -1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
            else if (key == SCROLL_RIGHT_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
                scrollChangeSelection(tree, ui, 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            else if (key == SCROLL_RIGHT_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
                scrollChangeSelection(tree, ui, 1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
            else if (key == SCROLL_LEFT_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
                scrollChangeSelection(tree, ui, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
            else if (key == EXPAND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
                expand(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
            else if (key == COLLAPSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
                collapse(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
            else if (key == MOVE_SELECTION_TO_PARENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
                moveSelectionToParent(tree, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
        private void scrollChangeSelection(JTree tree, BasicTreeUI ui,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
                           int direction, boolean addToSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
                           boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            int           rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
            if((rowCount = ui.getRowCount(tree)) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
                ui.treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
                TreePath          newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                Rectangle         visRect = tree.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
                if (direction == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
                    newPath = ui.getClosestPathForLocation(tree, visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
                                                        visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
                    visRect.x = Math.max(0, visRect.x - visRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
                    visRect.x = Math.min(Math.max(0, tree.getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
                                   visRect.width), visRect.x + visRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
                    newPath = ui.getClosestPathForLocation(tree, visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
                                                 visRect.y + visRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
                // Scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
                tree.scrollRectToVisible(visRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
                // select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
                if (addToSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
                    ui.extendSelection(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
                else if(changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
                    tree.setSelectionPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
                    ui.setLeadSelectionPath(newPath, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
        private void scroll(JTree component, BasicTreeUI ui, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
                            int amount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
            Rectangle visRect = component.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
            Dimension size = component.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
            if (direction == SwingConstants.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
                visRect.x += amount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
                visRect.x = Math.max(0, visRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
                visRect.x = Math.min(Math.max(0, size.width - visRect.width),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
                                     visRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
                visRect.y += amount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
                visRect.y = Math.max(0, visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
                visRect.y = Math.min(Math.max(0, size.width - visRect.height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
                                     visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
            component.scrollRectToVisible(visRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
        private void extendSelection(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
            if (ui.getRowCount(tree) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
                int       lead = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
                if (lead != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
                    TreePath      leadP = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
                    TreePath      aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
                    int           aRow = ui.getRowForPath(tree, aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
                    if(aRow == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
                        aRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
                    tree.setSelectionInterval(aRow, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
                    ui.setLeadSelectionPath(leadP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
                    ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
        private void selectAll(JTree tree, BasicTreeUI ui, boolean selectAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
            int                   rowCount = ui.getRowCount(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
            if(rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
                if(selectAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
                    if (tree.getSelectionModel().getSelectionMode() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
                            TreeSelectionModel.SINGLE_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
                        int lead = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
                        if (lead != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
                            tree.setSelectionRow(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
                        } else if (tree.getMinSelectionRow() == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
                            tree.setSelectionRow(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
                            ui.ensureRowsAreVisible(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
                    TreePath      lastPath = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
                    TreePath      aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
                    if(lastPath != null && !tree.isVisible(lastPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
                        lastPath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
                    tree.setSelectionInterval(0, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
                    if(lastPath != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
                        ui.setLeadSelectionPath(lastPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
                    if(aPath != null && tree.isVisible(aPath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
                        ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
                    TreePath      lastPath = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
                    TreePath      aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                    tree.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                    ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
                    ui.setLeadSelectionPath(lastPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
        private void startEditing(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
            TreePath   lead = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
            int        editRow = (lead != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
                                     ui.getRowForPath(tree, lead) : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
            if(editRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
                tree.startEditingAtPath(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
        private void cancelEditing(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
            tree.cancelEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
        private void toggle(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
            int            selRow = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
            if(selRow != -1 && !ui.isLeaf(selRow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
                TreePath aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
                TreePath lPath = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
                ui.toggleExpandState(ui.getPathForRow(tree, selRow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
                ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
                ui.setLeadSelectionPath(lPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
        private void expand(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
            int selRow = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            tree.expandRow(selRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
        private void collapse(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
            int selRow = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
            tree.collapseRow(selRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
        private void increment(JTree tree, BasicTreeUI ui, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
                               boolean addToSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
                               boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
            // disable moving of lead unless in discontiguous mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
            if (!addToSelection && !changeSelection &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
                    tree.getSelectionModel().getSelectionMode() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
                        TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
                changeSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
            int              rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
            if(ui.treeSelectionModel != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
                  (rowCount = tree.getRowCount()) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
                int                  selIndex = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
                int                  newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
                if(selIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
                    if(direction == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
                        newIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
                        newIndex = rowCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
                    /* Aparently people don't like wrapping;( */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
                    newIndex = Math.min(rowCount - 1, Math.max
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
                                        (0, (selIndex + direction)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
                if(addToSelection && ui.treeSelectionModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
                        getSelectionMode() != TreeSelectionModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
                        SINGLE_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
                    ui.extendSelection(tree.getPathForRow(newIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
                else if(changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
                    tree.setSelectionInterval(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
                    ui.setLeadSelectionPath(tree.getPathForRow(newIndex),true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
                ui.ensureRowsAreVisible(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
                ui.lastSelectedRow = newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
        private void traverse(JTree tree, BasicTreeUI ui, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
                              boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
            // disable moving of lead unless in discontiguous mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
            if (!changeSelection &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
                    tree.getSelectionModel().getSelectionMode() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
                        TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
                changeSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
            int                rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
            if((rowCount = tree.getRowCount()) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
                int               minSelIndex = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
                int               newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
                if(minSelIndex == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
                    newIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
                    /* Try and expand the node, otherwise go to next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
                       node. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
                    if(direction == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
                        TreePath minSelPath = ui.getPathForRow(tree, minSelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
                        int childCount = tree.getModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
                            getChildCount(minSelPath.getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
                        newIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
                        if (!ui.isLeaf(minSelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
                            if (!tree.isExpanded(minSelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
                                ui.toggleExpandState(minSelPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
                            else if (childCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
                                newIndex = Math.min(minSelIndex + 1, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
                    /* Try to collapse node. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
                        if(!ui.isLeaf(minSelIndex) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
                           tree.isExpanded(minSelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
                            ui.toggleExpandState(ui.getPathForRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
                                              (tree, minSelIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
                            newIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
                            TreePath         path = ui.getPathForRow(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
                                                                  minSelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
                            if(path != null && path.getPathCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
                                newIndex = ui.getRowForPath(tree, path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
                                                         getParentPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
                            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
                                newIndex = -1;
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
                if(newIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
                    if(changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
                        tree.setSelectionInterval(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
                        ui.setLeadSelectionPath(ui.getPathForRow(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
                                                    tree, newIndex), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
                    ui.ensureRowsAreVisible(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
        private void moveSelectionToParent(JTree tree, BasicTreeUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
            int selRow = ui.getLeadSelectionRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
            TreePath path = ui.getPathForRow(tree, selRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
            if (path != null && path.getPathCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
                int  newIndex = ui.getRowForPath(tree, path.getParentPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
                if (newIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
                    tree.setSelectionInterval(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
                    ui.ensureRowsAreVisible(newIndex, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
        private void page(JTree tree, BasicTreeUI ui, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
                          boolean addToSelection, boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
            // disable moving of lead unless in discontiguous mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
            if (!addToSelection && !changeSelection &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
                    tree.getSelectionModel().getSelectionMode() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
                        TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
                changeSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
            int           rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
            if((rowCount = ui.getRowCount(tree)) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
                           ui.treeSelectionModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
                Dimension         maxSize = tree.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                TreePath          lead = ui.getLeadSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                TreePath          newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                Rectangle         visRect = tree.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
                if(direction == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
                    // up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
                    newPath = ui.getClosestPathForLocation(tree, visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
                                                         visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
                    if(newPath.equals(lead)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                        visRect.y = Math.max(0, visRect.y - visRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
                        newPath = tree.getClosestPathForLocation(visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                                                                 visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                    // down
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                    visRect.y = Math.min(maxSize.height, visRect.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                                         visRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
                    newPath = tree.getClosestPathForLocation(visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
                                                             visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                    if(newPath.equals(lead)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
                        visRect.y = Math.min(maxSize.height, visRect.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
                                             visRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
                        newPath = tree.getClosestPathForLocation(visRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
                                                                 visRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
                Rectangle            newRect = ui.getPathBounds(tree, newPath);
14656
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4865
                if (newRect != null) {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4866
                    newRect.x = visRect.x;
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4867
                    newRect.width = visRect.width;
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4868
                    if(direction == -1) {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4869
                        newRect.height = visRect.height;
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4870
                    }
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4871
                    else {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4872
                        newRect.y -= (visRect.height - newRect.height);
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4873
                        newRect.height = visRect.height;
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4874
                    }
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4875
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4876
                    if(addToSelection) {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4877
                        ui.extendSelection(newPath);
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4878
                    }
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4879
                    else if(changeSelection) {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4880
                        tree.setSelectionPath(newPath);
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4881
                    }
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4882
                    else {
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4883
                        ui.setLeadSelectionPath(newPath, true);
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4884
                    }
6d8446e5b460 8003830: NPE at BasicTreeUI$Actions.page:4470
alexsch
parents: 14655
diff changeset
  4885
                    tree.scrollRectToVisible(newRect);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
15333
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4890
        private void home(JTree tree, final BasicTreeUI ui, int direction,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
                          boolean addToSelection, boolean changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
            // disable moving of lead unless in discontiguous mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
            if (!addToSelection && !changeSelection &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
                    tree.getSelectionModel().getSelectionMode() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
                        TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
                changeSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
15333
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4900
            final int rowCount = ui.getRowCount(tree);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
            if (rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
                if(direction == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
                    ui.ensureRowsAreVisible(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
                    if (addToSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
                        TreePath        aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                        int             aRow = (aPath == null) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
                                        ui.getRowForPath(tree, aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
                        if (aRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
                            tree.setSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
                            tree.setSelectionInterval(0, aRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
                            ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
                            ui.setLeadSelectionPath(ui.getPathForRow(tree, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
                    else if(changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
                        tree.setSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
                        ui.setLeadSelectionPath(ui.getPathForRow(tree, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
                                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
                    ui.ensureRowsAreVisible(rowCount - 1, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
                    if (addToSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
                        TreePath        aPath = ui.getAnchorSelectionPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
                        int             aRow = (aPath == null) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
                                        ui.getRowForPath(tree, aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
                        if (aRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
                            tree.setSelectionInterval(rowCount - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
                                                      rowCount -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
                            tree.setSelectionInterval(aRow, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
                            ui.setAnchorSelectionPath(aPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
                            ui.setLeadSelectionPath(ui.getPathForRow(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
                                                               rowCount -1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
                    else if(changeSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
                        tree.setSelectionInterval(rowCount - 1, rowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
                        ui.setLeadSelectionPath(ui.getPathForRow(tree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
                                                          rowCount - 1), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
                    }
15333
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4952
                    if (ui.isLargeModel()){
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4953
                        SwingUtilities.invokeLater(new Runnable() {
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4954
                            public void run() {
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4955
                                ui.ensureRowsAreVisible(rowCount - 1, rowCount - 1);
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4956
                            }
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4957
                        });
56b81ef28fb4 8003400: JTree scrolling problem when using large model in WindowsLookAndFeel
malenkov
parents: 14656
diff changeset
  4958
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
} // End of class BasicTreeUI