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