jdk/src/java.desktop/share/classes/javax/swing/tree/AbstractLayoutCache.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 25859 3317bb8137f4
child 33253 78e735319356
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 1998, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.TreeModelEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20169
diff changeset
    39
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
    45
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public abstract class AbstractLayoutCache implements RowMapper {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /** Object responsible for getting the size of a node. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected NodeDimensions     nodeDimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /** Model providing information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected TreeModel          treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /** Selection model. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected TreeSelectionModel treeSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * True if the root node is displayed, false if its children are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * the highest visible nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected boolean            rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    63
      * Height to use for each row.  If this is &lt;= 0 the renderer will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      * used to determine the height for each row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected int                rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Sets the renderer that is responsible for drawing nodes in the tree
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
    71
     * and which is therefore responsible for calculating the dimensions of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * individual nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param nd a <code>NodeDimensions</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void setNodeDimensions(NodeDimensions nd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.nodeDimensions = nd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Returns the object that renders nodes in the tree, and which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * responsible for calculating the dimensions of individual nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @return the <code>NodeDimensions</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public NodeDimensions getNodeDimensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return nodeDimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Sets the <code>TreeModel</code> that will provide the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param newModel the <code>TreeModel</code> that is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *          provide the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void setModel(TreeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        treeModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns the <code>TreeModel</code> that is providing the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return the <code>TreeModel</code> that is providing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public TreeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Determines whether or not the root node from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * the <code>TreeModel</code> is visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param rootVisible true if the root node of the tree is to be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #rootVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *  description: Whether or not the root node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *               from the TreeModel is visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void setRootVisible(boolean rootVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.rootVisible = rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns true if the root node of the tree is displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return true if the root node of the tree is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see #rootVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean isRootVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return rootVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Sets the height of each cell.  If the specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * is less than or equal to zero the current cell renderer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * queried for each row's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param rowHeight the height of each cell, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *  description: The height of each cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void setRowHeight(int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this.rowHeight = rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Returns the height of each row.  If the returned value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * or equal to 0 the height for each row is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * renderer.
24495
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   152
     *
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   153
     * @return the height of each row
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Sets the <code>TreeSelectionModel</code> used to manage the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * selection to new LSM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param newLSM  the new <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void setSelectionModel(TreeSelectionModel newLSM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if(treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            treeSelectionModel.setRowMapper(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        treeSelectionModel = newLSM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if(treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            treeSelectionModel.setRowMapper(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Returns the model used to maintain the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return the <code>treeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return treeSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns the preferred height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public int getPreferredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // Get the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        int           rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if(rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Rectangle     bounds = getBounds(getPathForRow(rowCount - 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if(bounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                return bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the preferred width for the passed in region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * The region is defined by the path closest to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <code>(bounds.x, bounds.y)</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * ends at <code>bounds.height + bounds.y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * If <code>bounds</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * the preferred width for all the nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * will be returned (and this may be a VERY expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * computation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param bounds the region being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return the preferred width for the passed in region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int getPreferredWidth(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int           rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if(rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            // Get the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            TreePath      firstPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            int           endY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if(bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                firstPath = getPathForRow(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                endY = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                firstPath = getPathClosestTo(bounds.x, bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                endY = bounds.height + bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 24495
diff changeset
   231
            Enumeration<TreePath> paths = getVisiblePathsFrom(firstPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if(paths != null && paths.hasMoreElements()) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 24495
diff changeset
   234
                Rectangle   pBounds = getBounds(paths.nextElement(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                int         width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if(pBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    width = pBounds.x + pBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    if (pBounds.y >= endY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                while (pBounds != null && paths.hasMoreElements()) {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 24495
diff changeset
   247
                    pBounds = getBounds(paths.nextElement(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                        pBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    if (pBounds != null && pBounds.y < endY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        width = Math.max(width, pBounds.x + pBounds.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        pBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // Abstract methods that must be implemented to be concrete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      * Returns true if the value identified by row is currently expanded.
24495
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   268
      *
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   269
      * @param path TreePath to check
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   270
      * @return whether TreePath is expanded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public abstract boolean isExpanded(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Returns a rectangle giving the bounds needed to draw path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param path     a <code>TreePath</code> specifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param placeIn  a <code>Rectangle</code> object giving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *          available space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return a <code>Rectangle</code> object specifying the space to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public abstract Rectangle getBounds(TreePath path, Rectangle placeIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      * Returns the path for passed in row.  If row is not visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      * <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * @param row  the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * @return the <code>TreePath</code> for the given row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public abstract TreePath getPathForRow(int row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      * Returns the row that the last item identified in path is visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      * at.  Will return -1 if any of the elements in path are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      * currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      * @param path the <code>TreePath</code> being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      * @return the row where the last item in path is visible or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      *         if any elements in path aren't currently visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public abstract int getRowForPath(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
      * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      * there is nothing currently visible this will return <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      * otherwise it'll always return a valid path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      * If you need to test if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      * returned object is exactly at x, y you should get the bounds for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      * the returned path and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      * @param x the horizontal component of the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      * @param y the vertical component of the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
      * @return the <code>TreePath</code> closest to the specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public abstract TreePath getPathClosestTo(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Returns an <code>Enumerator</code> that increments over the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * paths starting at the passed in location. The ordering of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * enumeration is based on how the paths are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * The first element of the returned enumeration will be path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * unless it isn't visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * in which case <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param path the starting location for the enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @return the <code>Enumerator</code> starting at the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public abstract Enumeration<TreePath> getVisiblePathsFrom(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Returns the number of visible children for row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param path  the path being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return the number of visible children for the specified path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public abstract int getVisibleChildCount(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Marks the path <code>path</code> expanded state to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <code>isExpanded</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param path  the path being expanded or collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param isExpanded true if the path should be expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public abstract void setExpandedState(TreePath path, boolean isExpanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns true if the path is expanded, and visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param path  the path being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return true if the path is expanded and visible, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public abstract boolean getExpandedState(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Number of rows being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return the number of rows being displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public abstract int getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Informs the <code>TreeState</code> that it needs to recalculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * all the sizes it is referencing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public abstract void invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Instructs the <code>LayoutCache</code> that the bounds for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <code>path</code> are invalid, and need to be updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param path the path being updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public abstract void invalidatePathBounds(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    // TreeModelListener methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    // AbstractTreeState does not directly become a TreeModelListener on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    // the model, it is up to some other object to forward these methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Invoked after a node (or a set of siblings) has changed in some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * way. The node(s) have not changed locations in the tree or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * altered their children arrays, but other attributes have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * changed and may affect presentation. Example: the name of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * file has changed, but it is in the same location in the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * system.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <p>e.path() returns the path the parent of the changed node(s).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param e  the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public abstract void treeNodesChanged(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <p>Invoked after nodes have been inserted into the tree.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <p>e.path() returns the parent of the new nodes</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>e.childIndices() returns the indices of the new nodes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * ascending order.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public abstract void treeNodesInserted(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>Invoked after nodes have been removed from the tree.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * if a subtree is removed from the tree, this method may only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * invoked once for the root of the removed subtree, not once for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * each individual set of siblings removed.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <p>e.path() returns the former parent of the deleted nodes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public abstract void treeNodesRemoved(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <p>Invoked after the tree has drastically changed structure from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * given node down.  If the path returned by <code>e.getPath()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * is of length one and the first element does not identify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * current root node the first element should become the new root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * of the tree.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * <p>e.path() holds the path to the node.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <p>e.childIndices() returns null.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public abstract void treeStructureChanged(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // RowMapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Returns the rows that the <code>TreePath</code> instances in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <code>path</code> are being displayed at.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * This method should return an array of the same length as that passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * in, and if one of the <code>TreePaths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * in <code>path</code> is not valid its entry in the array should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * be set to -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @param paths the array of <code>TreePath</code>s being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @return an array of the same length that is passed in containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *          the rows that each corresponding where each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *          <code>TreePath</code> is displayed; if <code>paths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *          is <code>null</code>, <code>null</code> is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public int[] getRowsForPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if(paths == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        int               numPaths = paths.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        int[]             rows = new int[numPaths];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        for(int counter = 0; counter < numPaths; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            rows[counter] = getRowForPath(paths[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return rows;
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
    // Local methods that subclassers may wish to use that are primarly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    // convenience methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Returns, by reference in <code>placeIn</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * the size needed to represent <code>value</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * If <code>inPlace</code> is <code>null</code>, a newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * <code>Rectangle</code> should be returned, otherwise the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * should be placed in <code>inPlace</code> and returned. This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * return <code>null</code> if there is no renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @param value the <code>value</code> to be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param row  row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param depth the depth of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @param expanded true if row is expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param placeIn  a <code>Rectangle</code> containing the size needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *          to represent <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return a <code>Rectangle</code> containing the node dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *          or <code>null</code> if node has no dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    protected Rectangle getNodeDimensions(Object value, int row, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                          boolean expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                          Rectangle placeIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        NodeDimensions            nd = getNodeDimensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if(nd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return nd.getNodeDimensions(value, row, depth, expanded, placeIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      * Returns true if the height of each row is a fixed size.
24495
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   504
      *
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 22574
diff changeset
   505
      * @return whether the height of each row is a fixed size
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    protected boolean isFixedRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return (rowHeight > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Used by <code>AbstractLayoutCache</code> to determine the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * and x origin of a particular node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   516
    public abstract static class NodeDimensions {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * Returns, by reference in bounds, the size and x origin to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         * place value at. The calling method is responsible for determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * the Y location. If bounds is <code>null</code>, a newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * <code>Rectangle</code> should be returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * otherwise the value should be placed in bounds and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * @param value the <code>value</code> to be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * @param row row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * @param depth the depth of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * @param expanded true if row is expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * @param bounds  a <code>Rectangle</code> containing the size needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         *              to represent <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * @return a <code>Rectangle</code> containing the node dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         *              or <code>null</code> if node has no dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public abstract Rectangle getNodeDimensions(Object value, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                                    int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                                    boolean expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                    Rectangle bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
}