jdk/src/share/classes/javax/swing/tree/AbstractLayoutCache.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20458 f2423fb3fd19
child 22574 7f8ce0c8c20a
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2004, 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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Sets the <code>TreeSelectionModel</code> used to manage the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * selection to new LSM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param newLSM  the new <code>TreeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void setSelectionModel(TreeSelectionModel newLSM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if(treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            treeSelectionModel.setRowMapper(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        treeSelectionModel = newLSM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if(treeSelectionModel != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            treeSelectionModel.setRowMapper(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the model used to maintain the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return the <code>treeSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public TreeSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return treeSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns the preferred height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public int getPreferredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // Get the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        int           rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if(rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            Rectangle     bounds = getBounds(getPathForRow(rowCount - 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if(bounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                return bounds.y + bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns the preferred width for the passed in region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * The region is defined by the path closest to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <code>(bounds.x, bounds.y)</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * ends at <code>bounds.height + bounds.y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * If <code>bounds</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * the preferred width for all the nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * will be returned (and this may be a VERY expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * computation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param bounds the region being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the preferred width for the passed in region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public int getPreferredWidth(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int           rowCount = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if(rowCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // Get the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            TreePath      firstPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int           endY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if(bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                firstPath = getPathForRow(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                endY = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                firstPath = getPathClosestTo(bounds.x, bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                endY = bounds.height + bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            Enumeration   paths = getVisiblePathsFrom(firstPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if(paths != null && paths.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                Rectangle   pBounds = getBounds((TreePath)paths.nextElement(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                int         width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if(pBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    width = pBounds.x + pBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    if (pBounds.y >= endY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                while (pBounds != null && paths.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    pBounds = getBounds((TreePath)paths.nextElement(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                        pBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    if (pBounds != null && pBounds.y < endY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        width = Math.max(width, pBounds.x + pBounds.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        pBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    // Abstract methods that must be implemented to be concrete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      * Returns true if the value identified by row is currently expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public abstract boolean isExpanded(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns a rectangle giving the bounds needed to draw path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @param path     a <code>TreePath</code> specifying a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param placeIn  a <code>Rectangle</code> object giving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *          available space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return a <code>Rectangle</code> object specifying the space to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public abstract Rectangle getBounds(TreePath path, Rectangle placeIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      * Returns the path for passed in row.  If row is not visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      * <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      * @param row  the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      * @return the <code>TreePath</code> for the given row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public abstract TreePath getPathForRow(int row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * Returns the row that the last item identified in path is visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      * at.  Will return -1 if any of the elements in path are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * @param path the <code>TreePath</code> being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      * @return the row where the last item in path is visible or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      *         if any elements in path aren't currently visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public abstract int getRowForPath(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      * Returns the path to the node that is closest to x,y.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      * there is nothing currently visible this will return <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      * otherwise it'll always return a valid path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      * If you need to test if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      * returned object is exactly at x, y you should get the bounds for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
      * the returned path and test x, y against that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      * @param x the horizontal component of the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      * @param y the vertical component of the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      * @return the <code>TreePath</code> closest to the specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public abstract TreePath getPathClosestTo(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Returns an <code>Enumerator</code> that increments over the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * paths starting at the passed in location. The ordering of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * enumeration is based on how the paths are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * The first element of the returned enumeration will be path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * unless it isn't visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * in which case <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param path the starting location for the enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return the <code>Enumerator</code> starting at the desired location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public abstract Enumeration<TreePath> getVisiblePathsFrom(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Returns the number of visible children for row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param path  the path being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return the number of visible children for the specified path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public abstract int getVisibleChildCount(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Marks the path <code>path</code> expanded state to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <code>isExpanded</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param path  the path being expanded or collapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @param isExpanded true if the path should be expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public abstract void setExpandedState(TreePath path, boolean isExpanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Returns true if the path is expanded, and visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param path  the path being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return true if the path is expanded and visible, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public abstract boolean getExpandedState(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Number of rows being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return the number of rows being displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public abstract int getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Informs the <code>TreeState</code> that it needs to recalculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * all the sizes it is referencing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public abstract void invalidateSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Instructs the <code>LayoutCache</code> that the bounds for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * <code>path</code> are invalid, and need to be updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param path the path being updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public abstract void invalidatePathBounds(TreePath path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    // TreeModelListener methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    // AbstractTreeState does not directly become a TreeModelListener on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    // the model, it is up to some other object to forward these methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Invoked after a node (or a set of siblings) has changed in some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * way. The node(s) have not changed locations in the tree or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * altered their children arrays, but other attributes have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * changed and may affect presentation. Example: the name of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * file has changed, but it is in the same location in the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * system.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <p>e.path() returns the path the parent of the changed node(s).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param e  the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public abstract void treeNodesChanged(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <p>Invoked after nodes have been inserted into the tree.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <p>e.path() returns the parent of the new nodes</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>e.childIndices() returns the indices of the new nodes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * ascending order.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public abstract void treeNodesInserted(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p>Invoked after nodes have been removed from the tree.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * if a subtree is removed from the tree, this method may only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * invoked once for the root of the removed subtree, not once for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * each individual set of siblings removed.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>e.path() returns the former parent of the deleted nodes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public abstract void treeNodesRemoved(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * <p>Invoked after the tree has drastically changed structure from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * given node down.  If the path returned by <code>e.getPath()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * is of length one and the first element does not identify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * current root node the first element should become the new root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * of the tree.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <p>e.path() holds the path to the node.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * <p>e.childIndices() returns null.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @param e the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public abstract void treeStructureChanged(TreeModelEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    // RowMapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Returns the rows that the <code>TreePath</code> instances in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <code>path</code> are being displayed at.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * This method should return an array of the same length as that passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * in, and if one of the <code>TreePaths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * in <code>path</code> is not valid its entry in the array should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * be set to -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param paths the array of <code>TreePath</code>s being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return an array of the same length that is passed in containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *          the rows that each corresponding where each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *          <code>TreePath</code> is displayed; if <code>paths</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *          is <code>null</code>, <code>null</code> is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public int[] getRowsForPaths(TreePath[] paths) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if(paths == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        int               numPaths = paths.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int[]             rows = new int[numPaths];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        for(int counter = 0; counter < numPaths; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            rows[counter] = getRowForPath(paths[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    // Local methods that subclassers may wish to use that are primarly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    // convenience methods.
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
     * Returns, by reference in <code>placeIn</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * the size needed to represent <code>value</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * If <code>inPlace</code> is <code>null</code>, a newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <code>Rectangle</code> should be returned, otherwise the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * should be placed in <code>inPlace</code> and returned. This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * return <code>null</code> if there is no renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @param value the <code>value</code> to be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @param row  row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @param depth the depth of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param expanded true if row is expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @param placeIn  a <code>Rectangle</code> containing the size needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *          to represent <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return a <code>Rectangle</code> containing the node dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *          or <code>null</code> if node has no dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    protected Rectangle getNodeDimensions(Object value, int row, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                          boolean expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                          Rectangle placeIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        NodeDimensions            nd = getNodeDimensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if(nd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return nd.getNodeDimensions(value, row, depth, expanded, placeIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
      * Returns true if the height of each row is a fixed size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    protected boolean isFixedRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return (rowHeight > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Used by <code>AbstractLayoutCache</code> to determine the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * and x origin of a particular node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    static public abstract class NodeDimensions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         * Returns, by reference in bounds, the size and x origin to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         * place value at. The calling method is responsible for determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         * the Y location. If bounds is <code>null</code>, a newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         * <code>Rectangle</code> should be returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         * otherwise the value should be placed in bounds and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         * @param value the <code>value</code> to be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * @param row row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         * @param depth the depth of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * @param expanded true if row is expanded, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * @param bounds  a <code>Rectangle</code> containing the size needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         *              to represent <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * @return a <code>Rectangle</code> containing the node dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         *              or <code>null</code> if node has no dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        public abstract Rectangle getNodeDimensions(Object value, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                                    int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                                    boolean expanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                    Rectangle bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
}