jdk/src/java.desktop/share/classes/javax/swing/ScrollPaneLayout.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
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: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.LayoutManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The layout manager used by <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>JScrollPaneLayout</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * responsible for nine components: a viewport, two scrollbars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * a row header, a column header, and four "corner" components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * 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: 5506
diff changeset
    51
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see JViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Hans Muller
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 24983
diff changeset
    59
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    61
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class ScrollPaneLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    implements LayoutManager, ScrollPaneConstants, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The scrollpane's viewport child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Default is an empty <code>JViewport</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @see JScrollPane#setViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected JViewport viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The scrollpane's vertical scrollbar child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Default is a <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @see JScrollPane#setVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected JScrollBar vsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The scrollpane's horizontal scrollbar child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Default is a <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @see JScrollPane#setHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected JScrollBar hsb;
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
     * The row header child.  Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see JScrollPane#setRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected JViewport rowHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The column header child.  Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see JScrollPane#setColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected JViewport colHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The component to display in the lower left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see JScrollPane#setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected Component lowerLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The component to display in the lower right corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see JScrollPane#setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected Component lowerRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * The component to display in the upper left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see JScrollPane#setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    protected Component upperLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The component to display in the upper right corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see JScrollPane#setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    protected Component upperRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The display policy for the vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * The default is <code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * This field is obsolete, please use the <code>JScrollPane</code> field instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see JScrollPane#setVerticalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected int vsbPolicy = VERTICAL_SCROLLBAR_AS_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * The display policy for the horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * The default is <code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * This field is obsolete, please use the <code>JScrollPane</code> field instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see JScrollPane#setHorizontalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected int hsbPolicy = HORIZONTAL_SCROLLBAR_AS_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * This method is invoked after the ScrollPaneLayout is set as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * LayoutManager of a <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * It initializes all of the internal fields that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * are ordinarily set by <code>addLayoutComponent</code>.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * ScrollPaneLayout mySPLayout = new ScrollPanelLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *     public void layoutContainer(Container p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *         super.layoutContainer(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *         // do some extra work here ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * scrollpane.setLayout(mySPLayout):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * </pre>
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 22574
diff changeset
   172
     *
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 22574
diff changeset
   173
     * @param sp an instance of the {@code JScrollPane}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void syncWithScrollPane(JScrollPane sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        viewport = sp.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        vsb = sp.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        hsb = sp.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        rowHead = sp.getRowHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        colHead = sp.getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        lowerLeft = sp.getCorner(LOWER_LEFT_CORNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        lowerRight = sp.getCorner(LOWER_RIGHT_CORNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        upperLeft = sp.getCorner(UPPER_LEFT_CORNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        upperRight = sp.getCorner(UPPER_RIGHT_CORNER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        vsbPolicy = sp.getVerticalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        hsbPolicy = sp.getHorizontalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Removes an existing component.  When a new component, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * the left corner, or vertical scrollbar, is added, the old one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * if it exists, must be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * This method returns <code>newC</code>. If <code>oldC</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * not equal to <code>newC</code> and is non-<code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * it will be removed from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param oldC the <code>Component</code> to replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param newC the <code>Component</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @return the <code>newC</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    protected Component addSingletonComponent(Component oldC, Component newC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if ((oldC != null) && (oldC != newC)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            oldC.getParent().remove(oldC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return newC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Adds the specified component to the layout. The layout is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * identified using one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <li>ScrollPaneConstants.VIEWPORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <li>ScrollPaneConstants.VERTICAL_SCROLLBAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <li>ScrollPaneConstants.HORIZONTAL_SCROLLBAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <li>ScrollPaneConstants.ROW_HEADER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <li>ScrollPaneConstants.COLUMN_HEADER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <li>ScrollPaneConstants.LOWER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <li>ScrollPaneConstants.LOWER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <li>ScrollPaneConstants.UPPER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <li>ScrollPaneConstants.UPPER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param s the component identifier
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   228
     * @param c the component to be added
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @exception IllegalArgumentException if <code>s</code> is an invalid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void addLayoutComponent(String s, Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (s.equals(VIEWPORT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            viewport = (JViewport)addSingletonComponent(viewport, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        else if (s.equals(VERTICAL_SCROLLBAR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            vsb = (JScrollBar)addSingletonComponent(vsb, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        else if (s.equals(HORIZONTAL_SCROLLBAR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            hsb = (JScrollBar)addSingletonComponent(hsb, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        else if (s.equals(ROW_HEADER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            rowHead = (JViewport)addSingletonComponent(rowHead, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        else if (s.equals(COLUMN_HEADER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            colHead = (JViewport)addSingletonComponent(colHead, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        else if (s.equals(LOWER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            lowerLeft = addSingletonComponent(lowerLeft, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        else if (s.equals(LOWER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            lowerRight = addSingletonComponent(lowerRight, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        else if (s.equals(UPPER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            upperLeft = addSingletonComponent(upperLeft, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        else if (s.equals(UPPER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            upperRight = addSingletonComponent(upperRight, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            throw new IllegalArgumentException("invalid layout key " + s);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Removes the specified component from the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param c the component to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void removeLayoutComponent(Component c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (c == viewport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            viewport = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        else if (c == vsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            vsb = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        else if (c == hsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            hsb = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        else if (c == rowHead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            rowHead = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        else if (c == colHead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            colHead = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        else if (c == lowerLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            lowerLeft = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        else if (c == lowerRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            lowerRight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        else if (c == upperLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            upperLeft = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        else if (c == upperRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            upperRight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Returns the vertical scrollbar-display policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return an integer giving the display policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #setVerticalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public int getVerticalScrollBarPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return vsbPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Sets the vertical scrollbar-display policy. The options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <li>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <li>ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <li>ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Note: Applications should use the <code>JScrollPane</code> version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * of this method.  It only exists for backwards compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * with the Swing 1.0.2 (and earlier) versions of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param x an integer giving the display policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @exception IllegalArgumentException if <code>x</code> is an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          vertical scroll bar policy, as listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public void setVerticalScrollBarPolicy(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        switch (x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        case VERTICAL_SCROLLBAR_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        case VERTICAL_SCROLLBAR_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        case VERTICAL_SCROLLBAR_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                vsbPolicy = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            throw new IllegalArgumentException("invalid verticalScrollBarPolicy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
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 the horizontal scrollbar-display policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @return an integer giving the display policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see #setHorizontalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public int getHorizontalScrollBarPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return hsbPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Sets the horizontal scrollbar-display policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * The options are:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <li>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <li>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <li>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Note: Applications should use the <code>JScrollPane</code> version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * of this method.  It only exists for backwards compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * with the Swing 1.0.2 (and earlier) versions of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param x an int giving the display policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @exception IllegalArgumentException if <code>x</code> is not a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *          horizontal scrollbar policy, as listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void setHorizontalScrollBarPolicy(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        switch (x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        case HORIZONTAL_SCROLLBAR_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        case HORIZONTAL_SCROLLBAR_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        case HORIZONTAL_SCROLLBAR_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                hsbPolicy = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            throw new IllegalArgumentException("invalid horizontalScrollBarPolicy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Returns the <code>JViewport</code> object that displays the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * scrollable contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @return the <code>JViewport</code> object that displays the scrollable contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @see JScrollPane#getViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public JViewport getViewport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Returns the <code>JScrollBar</code> object that handles horizontal scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @return the <code>JScrollBar</code> object that handles horizontal scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see JScrollPane#getHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public JScrollBar getHorizontalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return hsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns the <code>JScrollBar</code> object that handles vertical scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return the <code>JScrollBar</code> object that handles vertical scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see JScrollPane#getVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public JScrollBar getVerticalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return vsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Returns the <code>JViewport</code> object that is the row header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @return the <code>JViewport</code> object that is the row header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see JScrollPane#getRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public JViewport getRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return rowHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Returns the <code>JViewport</code> object that is the column header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @return the <code>JViewport</code> object that is the column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @see JScrollPane#getColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public JViewport getColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return colHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Returns the <code>Component</code> at the specified corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param key the <code>String</code> specifying the corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @return the <code>Component</code> at the specified corner, as defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *         {@link ScrollPaneConstants}; if <code>key</code> is not one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *          four corners, <code>null</code> is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see JScrollPane#getCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public Component getCorner(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (key.equals(LOWER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return lowerLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        else if (key.equals(LOWER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return lowerRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        else if (key.equals(UPPER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            return upperLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        else if (key.equals(UPPER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return upperRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * The preferred size of a <code>ScrollPane</code> is the size of the insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * plus the preferred size of the viewport, plus the preferred size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * the visible headers, plus the preferred size of the scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * that will appear given the current view and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * scrollbar displayPolicies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * <p>Note that the rowHeader is calculated as part of the preferred width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * and the colHeader is calculated as part of the preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param parent the <code>Container</code> that will be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @return a <code>Dimension</code> object specifying the preferred size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *         viewport and any scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see ViewportLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public Dimension preferredLayoutSize(Container parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        /* Sync the (now obsolete) policy fields with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         * JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        JScrollPane scrollPane = (JScrollPane)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        int prefWidth = insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int prefHeight = insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        /* Note that viewport.getViewSize() is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         * viewport.getView().getPreferredSize() modulo a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         * view or a view whose size was explicitly set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        Dimension extentSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        Dimension viewSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        Component view = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
412
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   495
        if (viewport != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            extentSize = viewport.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            view = viewport.getView();
412
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   498
            if (view != null) {
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   499
                viewSize = view.getPreferredSize();
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   500
            } else {
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   501
                viewSize = new Dimension(0, 0);
002786c2e5bb 6612531: api/javax_swing/ScrollPaneLayout/index.html#xxxLayoutSize (ScrollPaneLayout2024) throws NPE
mlapshin
parents: 2
diff changeset
   502
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        /* If there's a viewport add its preferredSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (extentSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            prefWidth += extentSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            prefHeight += extentSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        /* If there's a JScrollPane.viewportBorder, add its insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        Border viewportBorder = scrollPane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (viewportBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            Insets vpbInsets = viewportBorder.getBorderInsets(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            prefWidth += vpbInsets.left + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            prefHeight += vpbInsets.top + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        /* If a header exists and it's visible, factor its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * preferred size in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if ((rowHead != null) && rowHead.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            prefWidth += rowHead.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if ((colHead != null) && colHead.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            prefHeight += colHead.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        /* If a scrollbar is going to appear, factor its preferred size in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         * If the scrollbars policy is AS_NEEDED, this can be a little
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * tricky:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * - If the view is a Scrollable then scrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * and scrollableTracksViewportHeight can be used to effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * disable scrolling (if they're true) in their respective dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         * - Assuming that a scrollbar hasn't been disabled by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         * previous constraint, we need to decide if the scrollbar is going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         * to appear to correctly compute the JScrollPanes preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         * To do this we compare the preferredSize of the viewport (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * extentSize) to the preferredSize of the view.  Although we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         * not responsible for laying out the view we'll assume that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * JViewport will always give it its preferredSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if ((vsb != null) && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                prefWidth += vsb.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            else if ((viewSize != null) && (extentSize != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                boolean canScroll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                if (view instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    canScroll = !((Scrollable)view).getScrollableTracksViewportHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                if (canScroll && (viewSize.height > extentSize.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    prefWidth += vsb.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if ((hsb != null) && (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                prefHeight += hsb.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            else if ((viewSize != null) && (extentSize != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                boolean canScroll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                if (view instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    canScroll = !((Scrollable)view).getScrollableTracksViewportWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                if (canScroll && (viewSize.width > extentSize.width)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    prefHeight += hsb.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return new Dimension(prefWidth, prefHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * The minimum size of a <code>ScrollPane</code> is the size of the insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * plus minimum size of the viewport, plus the scrollpane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * viewportBorder insets, plus the minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * of the visible headers, plus the minimum size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * scrollbars whose displayPolicy isn't NEVER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @param parent the <code>Container</code> that will be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @return a <code>Dimension</code> object specifying the minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public Dimension minimumLayoutSize(Container parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        /* Sync the (now obsolete) policy fields with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         * JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        JScrollPane scrollPane = (JScrollPane)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        int minWidth = insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        int minHeight = insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        /* If there's a viewport add its minimumSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            Dimension size = viewport.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            minWidth += size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            minHeight += size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        /* If there's a JScrollPane.viewportBorder, add its insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        Border viewportBorder = scrollPane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (viewportBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            Insets vpbInsets = viewportBorder.getBorderInsets(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            minWidth += vpbInsets.left + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            minHeight += vpbInsets.top + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        /* If a header exists and it's visible, factor its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * minimum size in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if ((rowHead != null) && rowHead.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            Dimension size = rowHead.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            minWidth += size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            minHeight = Math.max(minHeight, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        if ((colHead != null) && colHead.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            Dimension size = colHead.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            minWidth = Math.max(minWidth, size.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            minHeight += size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        /* If a scrollbar might appear, factor its minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * size in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if ((vsb != null) && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            Dimension size = vsb.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            minWidth += size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            minHeight = Math.max(minHeight, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if ((hsb != null) && (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            Dimension size = hsb.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            minWidth = Math.max(minWidth, size.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            minHeight += size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        return new Dimension(minWidth, minHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Lays out the scrollpane. The positioning of components depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * the following constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * <li> The row header, if present and visible, gets its preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * width and the viewport's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <li> The column header, if present and visible, gets its preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * height and the viewport's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * <li> If a vertical scrollbar is needed, i.e. if the viewport's extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * height is smaller than its view height or if the <code>displayPolicy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * is ALWAYS, it's treated like the row header with respect to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * dimensions and is made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <li> If a horizontal scrollbar is needed, it is treated like the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * column header (see the paragraph above regarding the vertical scrollbar).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <li> If the scrollpane has a non-<code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * <code>viewportBorder</code>, then space is allocated for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <li> The viewport gets the space available after accounting for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * the previous constraints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <li> The corner components, if provided, are aligned with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * ends of the scrollbars and headers. If there is a vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * scrollbar, the right corners appear; if there is a horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * scrollbar, the lower corners appear; a row header gets left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * corners, and a column header gets upper corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @param parent the <code>Container</code> to lay out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public void layoutContainer(Container parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        /* Sync the (now obsolete) policy fields with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
         * JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        JScrollPane scrollPane = (JScrollPane)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        Rectangle availR = scrollPane.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        availR.x = availR.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        availR.x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        availR.y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        availR.width -= insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        availR.height -= insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        /* Get the scrollPane's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        boolean leftToRight = SwingUtilities.isLeftToRight(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        /* If there's a visible column header remove the space it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
         * needs from the top of availR.  The column header is treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
         * as if it were fixed height, arbitrary width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        Rectangle colHeadR = new Rectangle(0, availR.y, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if ((colHead != null) && (colHead.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            int colHeadHeight = Math.min(availR.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                                         colHead.getPreferredSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            colHeadR.height = colHeadHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            availR.y += colHeadHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            availR.height -= colHeadHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        /* If there's a visible row header remove the space it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         * from the left or right of availR.  The row header is treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         * as if it were fixed width, arbitrary height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        Rectangle rowHeadR = new Rectangle(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if ((rowHead != null) && (rowHead.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            int rowHeadWidth = Math.min(availR.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                        rowHead.getPreferredSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            rowHeadR.width = rowHeadWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            availR.width -= rowHeadWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if ( leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                rowHeadR.x = availR.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                availR.x += rowHeadWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                rowHeadR.x = availR.x + availR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        /* If there's a JScrollPane.viewportBorder, remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         * space it occupies for availR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        Border viewportBorder = scrollPane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        Insets vpbInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (viewportBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            vpbInsets = viewportBorder.getBorderInsets(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            availR.x += vpbInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            availR.y += vpbInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            availR.width -= vpbInsets.left + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            availR.height -= vpbInsets.top + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            vpbInsets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        /* At this point availR is the space available for the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         * and scrollbars. rowHeadR is correct except for its height and y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         * and colHeadR is correct except for its width and x.  Once we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * through computing the dimensions  of these three parts we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * go back and set the dimensions of rowHeadR.height, rowHeadR.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * colHeadR.width, colHeadR.x and the bounds for the corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * We'll decide about putting up scrollbars by comparing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * viewport views preferred size with the viewports extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * size (generally just its size).  Using the preferredSize is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * reasonable because layout proceeds top down - so we expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * the viewport to be laid out next.  And we assume that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * viewports layout manager will give the view it's preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * size.  One exception to this is when the view implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         * Scrollable and Scrollable.getViewTracksViewport{Width,Height}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         * methods return true.  If the view is tracking the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * width we don't bother with a horizontal scrollbar, similarly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         * if view.getViewTracksViewport(Height) is true we don't bother
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         * with a vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        Component view = (viewport != null) ? viewport.getView() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        Dimension viewPrefSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            (view != null) ? view.getPreferredSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                           : new Dimension(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        Dimension extentSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            (viewport != null) ? viewport.toViewCoordinates(availR.getSize())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                               : new Dimension(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        boolean viewTracksViewportWidth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        boolean viewTracksViewportHeight = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        boolean isEmpty = (availR.width < 0 || availR.height < 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        Scrollable sv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        // Don't bother checking the Scrollable methods if there is no room
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // for the viewport, we aren't going to show any scrollbars in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // case anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if (!isEmpty && view instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            sv = (Scrollable)view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            viewTracksViewportWidth = sv.getScrollableTracksViewportWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            viewTracksViewportHeight = sv.getScrollableTracksViewportHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            sv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        /* If there's a vertical scrollbar and we need one, allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
         * space for it (we'll make it visible later). A vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
         * scrollbar is considered to be fixed width, arbitrary height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        Rectangle vsbR = new Rectangle(0, availR.y - vpbInsets.top, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        boolean vsbNeeded;
25567
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents: 25201
diff changeset
   826
        if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            vsbNeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        else if (vsbPolicy == VERTICAL_SCROLLBAR_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            vsbNeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        else {  // vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            vsbNeeded = !viewTracksViewportHeight && (viewPrefSize.height > extentSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        if ((vsb != null) && vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            extentSize = viewport.toViewCoordinates(availR.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        /* If there's a horizontal scrollbar and we need one, allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
         * space for it (we'll make it visible later). A horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
         * scrollbar is considered to be fixed height, arbitrary width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        Rectangle hsbR = new Rectangle(availR.x - vpbInsets.left, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        boolean hsbNeeded;
25567
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents: 25201
diff changeset
   849
        if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            hsbNeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        else if (hsbPolicy == HORIZONTAL_SCROLLBAR_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            hsbNeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        else {  // hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            hsbNeeded = !viewTracksViewportWidth && (viewPrefSize.width > extentSize.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if ((hsb != null) && hsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            adjustForHSB(true, availR, hsbR, vpbInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            /* If we added the horizontal scrollbar then we've implicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
             * reduced  the vertical space available to the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
             * As a consequence we may have to add the vertical scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
             * if that hasn't been done so already.  Of course we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
             * don't bother with any of this if the vsbPolicy is NEVER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            if ((vsb != null) && !vsbNeeded &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                extentSize = viewport.toViewCoordinates(availR.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                vsbNeeded = viewPrefSize.height > extentSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                if (vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        /* Set the size of the viewport first, and then recheck the Scrollable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * methods. Some components base their return values for the Scrollable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * methods on the size of the Viewport, so that if we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * ask after resetting the bounds we may have gotten the wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            viewport.setBounds(availR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            if (sv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                extentSize = viewport.toViewCoordinates(availR.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                boolean oldHSBNeeded = hsbNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                boolean oldVSBNeeded = vsbNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                viewTracksViewportWidth = sv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                          getScrollableTracksViewportWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                viewTracksViewportHeight = sv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                          getScrollableTracksViewportHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                if (vsb != null && vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                    boolean newVSBNeeded = !viewTracksViewportHeight &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                                     (viewPrefSize.height > extentSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    if (newVSBNeeded != vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                        vsbNeeded = newVSBNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                        adjustForVSB(vsbNeeded, availR, vsbR, vpbInsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                                     leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                        extentSize = viewport.toViewCoordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                              (availR.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                if (hsb != null && hsbPolicy ==HORIZONTAL_SCROLLBAR_AS_NEEDED){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                    boolean newHSBbNeeded = !viewTracksViewportWidth &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                                       (viewPrefSize.width > extentSize.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                    if (newHSBbNeeded != hsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                        hsbNeeded = newHSBbNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        adjustForHSB(hsbNeeded, availR, hsbR, vpbInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        if ((vsb != null) && !vsbNeeded &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                            extentSize = viewport.toViewCoordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                         (availR.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                            vsbNeeded = viewPrefSize.height >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                                        extentSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                            if (vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                adjustForVSB(true, availR, vsbR, vpbInsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                             leftToRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                if (oldHSBNeeded != hsbNeeded ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    oldVSBNeeded != vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                    viewport.setBounds(availR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                    // You could argue that we should recheck the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                    // Scrollable methods again until they stop changing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    // but they might never stop changing, so we stop here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    // and don't do any additional checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        /* We now have the final size of the viewport: availR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         * Now fixup the header and scrollbar widths/heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        vsbR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        hsbR.width = availR.width + vpbInsets.left + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        rowHeadR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        rowHeadR.y = availR.y - vpbInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        colHeadR.width = availR.width + vpbInsets.left + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        colHeadR.x = availR.x - vpbInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        /* Set the bounds of the remaining components.  The scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * are made invisible if they're not needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (rowHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            rowHead.setBounds(rowHeadR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        if (colHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            colHead.setBounds(colHeadR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (vsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                if (colHead != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    UIManager.getBoolean("ScrollPane.fillUpperCorner"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    if ((leftToRight && upperRight == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        (!leftToRight && upperLeft == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                        // This is used primarily for GTK L&F, which needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        // extend the vertical scrollbar to fill the upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                        // corner near the column header.  Note that we skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                        // this step (and use the default behavior) if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                        // user has set a custom corner component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                        vsbR.y = colHeadR.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        vsbR.height += colHeadR.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                vsb.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                vsb.setBounds(vsbR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                vsb.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            if (hsbNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                if (rowHead != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    UIManager.getBoolean("ScrollPane.fillLowerCorner"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    if ((leftToRight && lowerLeft == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                        (!leftToRight && lowerRight == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                        // This is used primarily for GTK L&F, which needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                        // extend the horizontal scrollbar to fill the lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                        // corner near the row header.  Note that we skip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                        // this step (and use the default behavior) if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                        // user has set a custom corner component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                        if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                            hsbR.x = rowHeadR.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                        hsbR.width += rowHeadR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                hsb.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                hsb.setBounds(hsbR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                hsb.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (lowerLeft != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            lowerLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                hsbR.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                                leftToRight ? rowHeadR.width : vsbR.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                hsbR.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        if (lowerRight != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            lowerRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                                 hsbR.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                                 leftToRight ? vsbR.width : rowHeadR.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                 hsbR.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        if (upperLeft != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            upperLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                                colHeadR.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                leftToRight ? rowHeadR.width : vsbR.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                                colHeadR.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (upperRight != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            upperRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                                 colHeadR.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                                 leftToRight ? vsbR.width : rowHeadR.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                                 colHeadR.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * Adjusts the <code>Rectangle</code> <code>available</code> based on if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * the vertical scrollbar is needed (<code>wantsVSB</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * The location of the vsb is updated in <code>vsbR</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * the viewport border insets (<code>vpbInsets</code>) are used to offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * the vsb. This is only called when <code>wantsVSB</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * changed, eg you shouldn't invoke adjustForVSB(true) twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    private void adjustForVSB(boolean wantsVSB, Rectangle available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                              Rectangle vsbR, Insets vpbInsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                              boolean leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        int oldWidth = vsbR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if (wantsVSB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            int vsbWidth = Math.max(0, Math.min(vsb.getPreferredSize().width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                                                available.width));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            available.width -= vsbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            vsbR.width = vsbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            if( leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                vsbR.x = available.x + available.width + vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                vsbR.x = available.x - vpbInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                available.x += vsbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            available.width += oldWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Adjusts the <code>Rectangle</code> <code>available</code> based on if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * the horizontal scrollbar is needed (<code>wantsHSB</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * The location of the hsb is updated in <code>hsbR</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * the viewport border insets (<code>vpbInsets</code>) are used to offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * the hsb.  This is only called when <code>wantsHSB</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * changed, eg you shouldn't invoked adjustForHSB(true) twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    private void adjustForHSB(boolean wantsHSB, Rectangle available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                              Rectangle hsbR, Insets vpbInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        int oldHeight = hsbR.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        if (wantsHSB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            int hsbHeight = Math.max(0, Math.min(available.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                                              hsb.getPreferredSize().height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            available.height -= hsbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            hsbR.y = available.y + available.height + vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            hsbR.height = hsbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            available.height += oldHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * Returns the bounds of the border around the specified scroll pane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     *
24983
f5a6e2ed8c7d 8046596: fix doclint issues in swing classes, part 3 of 4
yan
parents: 22574
diff changeset
  1106
     * @param scrollpane an instance of the {@code JScrollPane}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @return the size and position of the viewport border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @deprecated As of JDK version Swing1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     *    replaced by <code>JScrollPane.getViewportBorderBounds()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    public Rectangle getViewportBorderBounds(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        return scrollpane.getViewportBorderBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * The UI resource version of <code>ScrollPaneLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    public static class UIResource extends ScrollPaneLayout implements javax.swing.plaf.UIResource {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
}