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