jdk/src/java.desktop/share/classes/javax/swing/JScrollPane.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 25760 jdk/src/share/classes/javax/swing/JScrollPane.java@7955db32d6b0
child 33253 78e735319356
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.ComponentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.LayoutManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    43
import java.beans.PropertyChangeEvent;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    44
import java.beans.PropertyChangeListener;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    45
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Provides a scrollable view of a lightweight component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * A <code>JScrollPane</code> manages a viewport, optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * vertical and horizontal scroll bars, and optional row and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * column heading viewports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * You can find task-oriented documentation of <code>JScrollPane</code> in
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20451
diff changeset
    53
 *  <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html">How to Use Scroll Panes</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * a section in <em>The Java Tutorial</em>.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>JScrollPane</code> does not support heavyweight components.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
    56
 *
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20157
diff changeset
    57
 * <TABLE STYLE="FLOAT:RIGHT" BORDER="0" SUMMARY="layout">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *    <TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *    <TD ALIGN="CENTER">
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20157
diff changeset
    60
 *      <P STYLE="TEXT-ALIGN:CENTER"><IMG SRC="doc-files/JScrollPane-1.gif"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      alt="The following text describes this image."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20157
diff changeset
    62
 *      WIDTH="256" HEIGHT="248" STYLE="FLOAT:BOTTOM; BORDER:0px">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    </TD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *    </TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * </TABLE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The <code>JViewport</code> provides a window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * or &quot;viewport&quot; onto a data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * source -- for example, a text file. That data source is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * &quot;scrollable client&quot; (aka data model) displayed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <code>JViewport</code> view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * A <code>JScrollPane</code> basically consists of <code>JScrollBar</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * a <code>JViewport</code>, and the wiring between them,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * as shown in the diagram at right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * In addition to the scroll bars and viewport,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * a <code>JScrollPane</code> can have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * column header and a row header. Each of these is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>JViewport</code> object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * you specify with <code>setRowHeaderView</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * and <code>setColumnHeaderView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * The column header viewport automatically scrolls left and right, tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the left-right scrolling of the main viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * (It never scrolls vertically, however.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The row header acts in a similar fashion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Where two scroll bars meet, the row header meets the column header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * or a scroll bar meets one of the headers, both components stop short
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * of the corner, leaving a rectangular space which is, by default, empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * These spaces can potentially exist in any number of the four corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * In the previous diagram, the top right space is present and identified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * by the label "corner component".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Any number of these empty spaces can be replaced by using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <code>setCorner</code> method to add a component to a particular corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * (Note: The same component cannot be added to multiple corners.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * This is useful if there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * some extra decoration or function you'd like to add to the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * The size of each corner component is entirely determined by the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * headers and/or scroll bars that surround it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * A corner component will only be visible if there is an empty space in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * corner for it to exist in. For example, consider a component set into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * top right corner of a scroll pane with a column header. If the scroll pane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * vertical scrollbar is not present, perhaps because the view component hasn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * grown large enough to require it, then the corner component will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * shown (since there is no empty space in that corner created by the meeting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * of the header and vertical scroll bar). Forcing the scroll bar to always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * shown, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <code>setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS)</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * will ensure that the space for the corner component always exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * To add a border around the main viewport,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * you can use <code>setViewportBorder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * (Of course, you can also add a border around the whole scroll pane using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <code>setBorder</code>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * A common operation to want to do is to set the background color that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * be used if the main viewport view is smaller than the viewport, or is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * not opaque. This can be accomplished by setting the background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * of the viewport, via <code>scrollPane.getViewport().setBackground()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * The reason for setting the color of the viewport and not the scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * is that by default <code>JViewport</code> is opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * which, among other things, means it will completely fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * in its background using its background color.  Therefore when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <code>JScrollPane</code> draws its background the viewport will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * usually draw over it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * By default <code>JScrollPane</code> uses <code>ScrollPaneLayout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * to handle the layout of its child Components. <code>ScrollPaneLayout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * determines the size to make the viewport view in one of two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *   <li>If the view implements <code>Scrollable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *       a combination of <code>getPreferredScrollableViewportSize</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *       <code>getScrollableTracksViewportWidth</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *       <code>getScrollableTracksViewportHeight</code>is used, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *   <li><code>getPreferredSize</code> is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   149
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * @see JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * @see JViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * @see ScrollPaneLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * @see Scrollable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * @see Component#getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * @see #setViewportView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * @see #setRowHeaderView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * @see #setColumnHeaderView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @see #setViewportBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *     attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *     attribute: containerDelegate getViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *   description: A specialized container that manages a viewport, optional scrollbars and headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * @author Hans Muller
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
   170
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
   172
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
public class JScrollPane extends JComponent implements ScrollPaneConstants, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private Border viewportBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final String uiClassID = "ScrollPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * The display policy for the vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * The default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #setVerticalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected int verticalScrollBarPolicy = VERTICAL_SCROLLBAR_AS_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * The display policy for the horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * The default is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see #setHorizontalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    protected int horizontalScrollBarPolicy = HORIZONTAL_SCROLLBAR_AS_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * The scrollpane's viewport child.  Default is an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <code>JViewport</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #setViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    protected JViewport viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * The scrollpane's vertical scrollbar child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Default is a <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see #setVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    protected JScrollBar verticalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * The scrollpane's horizontal scrollbar child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Default is a <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #setHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected JScrollBar horizontalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The row header child.  Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see #setRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    protected JViewport rowHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * The column header child.  Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see #setColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    protected JViewport columnHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * The component to display in the lower left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected Component lowerLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * The component to display in the lower right corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected Component lowerRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * The component to display in the upper left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    protected Component upperLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * The component to display in the upper right corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Default is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    protected Component upperRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * State flag for mouse wheel scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private boolean wheelScrollState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Creates a <code>JScrollPane</code> that displays the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * component in a viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * whose view position can be controlled with a pair of scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * The scrollbar policies specify when the scrollbars are displayed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * For example, if <code>vsbPolicy</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <code>VERTICAL_SCROLLBAR_AS_NEEDED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * then the vertical scrollbar only appears if the view doesn't fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * vertically. The available policy settings are listed at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * {@link #setVerticalScrollBarPolicy} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * {@link #setHorizontalScrollBarPolicy}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #setViewportView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param view the component to display in the scrollpanes viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param vsbPolicy an integer that specifies the vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *          scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param hsbPolicy an integer that specifies the horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *          scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        setLayout(new ScrollPaneLayout.UIResource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        setVerticalScrollBarPolicy(vsbPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        setHorizontalScrollBarPolicy(hsbPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        setViewport(createViewport());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        setVerticalScrollBar(createVerticalScrollBar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        setHorizontalScrollBar(createHorizontalScrollBar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            setViewportView(view);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 466
diff changeset
   306
        setUIProperty("opaque",true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (!this.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            viewport.setViewPosition(new Point(Integer.MAX_VALUE, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Creates a <code>JScrollPane</code> that displays the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * contents of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * component, where both horizontal and vertical scrollbars appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * whenever the component's contents are larger than the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @see #setViewportView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param view the component to display in the scrollpane's viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public JScrollPane(Component view) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        this(view, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Creates an empty (no viewport view) <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * with specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * scrollbar policies. The available policy settings are listed at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * {@link #setVerticalScrollBarPolicy} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * {@link #setHorizontalScrollBarPolicy}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see #setViewportView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param vsbPolicy an integer that specifies the vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @param hsbPolicy an integer that specifies the horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *          scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public JScrollPane(int vsbPolicy, int hsbPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        this(null, vsbPolicy, hsbPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Creates an empty (no viewport view) <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * where both horizontal and vertical scrollbars appear when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public JScrollPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        this(null, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   358
     * Returns the look and feel (L&amp;F) object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @return the <code>ScrollPaneUI</code> object that renders this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                          component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public ScrollPaneUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return (ScrollPaneUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Sets the <code>ScrollPaneUI</code> object that provides the
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   376
     * look and feel (L&amp;F) for this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   378
     * @param ui the <code>ScrollPaneUI</code> L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see #getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public void setUI(ScrollPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Replaces the current <code>ScrollPaneUI</code> object with a version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * from the current default look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * To be called when the default look and feel changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see UIManager#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        setUI((ScrollPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   400
     * Returns the suffix used to construct the name of the L&amp;F class used to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * render this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return the string "ScrollPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *    hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
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
     * Sets the layout manager for this <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * This method overrides <code>setLayout</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <code>java.awt.Container</code> to ensure that only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <code>LayoutManager</code>s which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * are subclasses of <code>ScrollPaneLayout</code> can be used in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * <code>JScrollPane</code>. If <code>layout</code> is non-null, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * will invoke <code>syncWithScrollPane</code> on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @param layout the specified layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @exception ClassCastException if layout is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *                  <code>ScrollPaneLayout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see java.awt.Container#getLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @see java.awt.Container#setLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *    hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void setLayout(LayoutManager layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (layout instanceof ScrollPaneLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            super.setLayout(layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            ((ScrollPaneLayout)layout).syncWithScrollPane(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        else if (layout == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            super.setLayout(layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            String s = "layout of JScrollPane must be a ScrollPaneLayout";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            throw new ClassCastException(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Overridden to return true so that any calls to <code>revalidate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * on any descendants of this <code>JScrollPane</code> will cause the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * entire tree beginning with this <code>JScrollPane</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @see java.awt.Container#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see JComponent#revalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see JComponent#isValidateRoot
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 2658
diff changeset
   458
     * @see java.awt.Container#isValidateRoot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *    hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 2658
diff changeset
   463
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public boolean isValidateRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Returns the vertical scroll bar policy value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the <code>verticalScrollBarPolicy</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @see #setVerticalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public int getVerticalScrollBarPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return verticalScrollBarPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Determines when the vertical scrollbar appears in the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Legal values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <li><code>ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param policy one of the three values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @exception IllegalArgumentException if <code>policy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *                          is not one of the legal values shown above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see #getVerticalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * description: The scrollpane vertical scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *        enum: VERTICAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *              VERTICAL_SCROLLBAR_NEVER ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *              VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public void setVerticalScrollBarPolicy(int policy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        switch (policy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        case VERTICAL_SCROLLBAR_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        case VERTICAL_SCROLLBAR_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        case VERTICAL_SCROLLBAR_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            throw new IllegalArgumentException("invalid verticalScrollBarPolicy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        int old = verticalScrollBarPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        verticalScrollBarPolicy = policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        firePropertyChange("verticalScrollBarPolicy", old, policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Returns the horizontal scroll bar policy value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @return the <code>horizontalScrollBarPolicy</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #setHorizontalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public int getHorizontalScrollBarPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return horizontalScrollBarPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Determines when the horizontal scrollbar appears in the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * The options are:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <li><code>ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @param policy one of the three values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @exception IllegalArgumentException if <code>policy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *                          is not one of the legal values shown above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see #getHorizontalScrollBarPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * description: The scrollpane scrollbar policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *        enum: HORIZONTAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *              HORIZONTAL_SCROLLBAR_NEVER ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *              HORIZONTAL_SCROLLBAR_ALWAYS ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public void setHorizontalScrollBarPolicy(int policy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        switch (policy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        case HORIZONTAL_SCROLLBAR_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        case HORIZONTAL_SCROLLBAR_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        case HORIZONTAL_SCROLLBAR_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            throw new IllegalArgumentException("invalid horizontalScrollBarPolicy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        int old = horizontalScrollBarPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        horizontalScrollBarPolicy = policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        firePropertyChange("horizontalScrollBarPolicy", old, policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Returns the <code>Border</code> object that surrounds the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @return the <code>viewportBorder</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see #setViewportBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public Border getViewportBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return viewportBorder;
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
     * Adds a border around the viewport.  Note that the border isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * set on the viewport directly, <code>JViewport</code> doesn't support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * the <code>JComponent</code> border property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Similarly setting the <code>JScrollPane</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * viewport doesn't affect the <code>viewportBorder</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * The default value of this property is computed by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @param viewportBorder the border to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @see #getViewportBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @see #setViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * description: The border around the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public void setViewportBorder(Border viewportBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        Border oldValue = this.viewportBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        this.viewportBorder = viewportBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        firePropertyChange("viewportBorder", oldValue, viewportBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Returns the bounds of the viewport's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return a <code>Rectangle</code> object specifying the viewport border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public Rectangle getViewportBorderBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        Rectangle borderR = new Rectangle(getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        borderR.x = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        borderR.y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        borderR.width -= insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        borderR.height -= insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        boolean leftToRight = SwingUtilities.isLeftToRight(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        /* If there's a visible column header remove the space it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * needs from the top of borderR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        JViewport colHead = getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if ((colHead != null) && (colHead.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            int colHeadHeight = colHead.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            borderR.y += colHeadHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            borderR.height -= colHeadHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        /* If there's a visible row header remove the space it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * from the left of borderR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        JViewport rowHead = getRowHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if ((rowHead != null) && (rowHead.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            int rowHeadWidth = rowHead.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            if ( leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                borderR.x += rowHeadWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            borderR.width -= rowHeadWidth;
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 there's a visible vertical scrollbar remove the space it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * from the width of borderR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        JScrollBar vsb = getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if ((vsb != null) && (vsb.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            int vsbWidth = vsb.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if ( !leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                borderR.x += vsbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            borderR.width -= vsbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        /* If there's a visible horizontal scrollbar remove the space it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * from the height of borderR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        JScrollBar hsb = getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if ((hsb != null) && (hsb.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            borderR.height -= hsb.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return borderR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * By default <code>JScrollPane</code> creates scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * that are instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * of this class.  <code>Scrollbar</code> overrides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <code>getUnitIncrement</code> and <code>getBlockIncrement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * methods so that, if the viewport's view is a <code>Scrollable</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * the view is asked to compute these values. Unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * the unit/block increment have been explicitly set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   682
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see Scrollable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @see JScrollPane#createVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @see JScrollPane#createHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
   690
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    protected class ScrollBar extends JScrollBar implements UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * Set to true when the unit increment has been explicitly set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         * If this is false the viewport's view is obtained and if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         * is an instance of <code>Scrollable</code> the unit increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
         * from it is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        private boolean unitIncrementSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         * Set to true when the block increment has been explicitly set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         * If this is false the viewport's view is obtained and if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         * is an instance of <code>Scrollable</code> the block increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
         * from it is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        private boolean blockIncrementSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
         * Creates a scrollbar with the specified orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
         * The options are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * <li><code>ScrollPaneConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         * <li><code>ScrollPaneConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
         * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
         * @param orientation  an integer specifying one of the legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
         *      orientation values shown above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        public ScrollBar(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            super(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            this.putClientProperty("JScrollBar.fastWheelScrolling",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                   Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         * Messages super to set the value, and resets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         * <code>unitIncrementSet</code> instance variable to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
         * @param unitIncrement the new unit increment value, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        public void setUnitIncrement(int unitIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            unitIncrementSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            this.putClientProperty("JScrollBar.fastWheelScrolling", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            super.setUnitIncrement(unitIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         * Computes the unit increment for scrolling if the viewport's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
         * view is a <code>Scrollable</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * Otherwise return <code>super.getUnitIncrement</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         *      greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         * @return an integer, in pixels, containing the unit increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        public int getUnitIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            JViewport vp = getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            if (!unitIncrementSet && (vp != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                (vp.getView() instanceof Scrollable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                Scrollable view = (Scrollable)(vp.getView());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                Rectangle vr = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                return super.getUnitIncrement(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
         * Messages super to set the value, and resets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         * <code>blockIncrementSet</code> instance variable to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         * @param blockIncrement the new block increment value, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        public void setBlockIncrement(int blockIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            blockIncrementSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            this.putClientProperty("JScrollBar.fastWheelScrolling", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            super.setBlockIncrement(blockIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         * Computes the block increment for scrolling if the viewport's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * view is a <code>Scrollable</code> object.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * the <code>blockIncrement</code> equals the viewport's width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * or height.  If there's no viewport return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * <code>super.getBlockIncrement</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         *      greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * @return an integer, in pixels, containing the block increment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        public int getBlockIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            JViewport vp = getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (blockIncrementSet || vp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                return super.getBlockIncrement(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            else if (vp.getView() instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                Scrollable view = (Scrollable)(vp.getView());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                Rectangle vr = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            else if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                return vp.getExtentSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                return vp.getExtentSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Returns a <code>JScrollPane.ScrollBar</code> by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Subclasses may override this method to force <code>ScrollPaneUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * implementations to use a <code>JScrollBar</code> subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * Used by <code>ScrollPaneUI</code> implementations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * create the horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @return a <code>JScrollBar</code> with a horizontal orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public JScrollBar createHorizontalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return new ScrollBar(JScrollBar.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Returns the horizontal scroll bar that controls the viewport's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * horizontal view position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @return the <code>horizontalScrollBar</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @see #setHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   828
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public JScrollBar getHorizontalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        return horizontalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * Adds the scrollbar that controls the viewport's horizontal view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * position to the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * This is usually unnecessary, as <code>JScrollPane</code> creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * horizontal and vertical scrollbars by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @param horizontalScrollBar the horizontal scrollbar to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see #createHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @see #getHorizontalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *        expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *         bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *   description: The horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public void setHorizontalScrollBar(JScrollBar horizontalScrollBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        JScrollBar old = getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        this.horizontalScrollBar = horizontalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (horizontalScrollBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            add(horizontalScrollBar, HORIZONTAL_SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        else if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            remove(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        firePropertyChange("horizontalScrollBar", old, horizontalScrollBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * Returns a <code>JScrollPane.ScrollBar</code> by default.  Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * may override this method to force <code>ScrollPaneUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * implementations to use a <code>JScrollBar</code> subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Used by <code>ScrollPaneUI</code> implementations to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @return a <code>JScrollBar</code> with a vertical orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @see JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    public JScrollBar createVerticalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        return new ScrollBar(JScrollBar.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Returns the vertical scroll bar that controls the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * vertical view position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @return the <code>verticalScrollBar</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @see #setVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   887
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public JScrollBar getVerticalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return verticalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * Adds the scrollbar that controls the viewports vertical view position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * to the scrollpane.  This is usually unnecessary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * as <code>JScrollPane</code> creates vertical and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * horizontal scrollbars by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @param verticalScrollBar the new vertical scrollbar to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @see #createVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @see #getVerticalScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *        expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *         bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *   description: The vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public void setVerticalScrollBar(JScrollBar verticalScrollBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        JScrollBar old = getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        this.verticalScrollBar = verticalScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        add(verticalScrollBar, VERTICAL_SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        firePropertyChange("verticalScrollBar", old, verticalScrollBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Returns a new <code>JViewport</code> by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Used to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * viewport (as needed) in <code>setViewportView</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * <code>setRowHeaderView</code>, and <code>setColumnHeaderView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * Subclasses may override this method to return a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * <code>JViewport</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @return a new <code>JViewport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    protected JViewport createViewport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return new JViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Returns the current <code>JViewport</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @see #setViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @return the <code>viewport</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    public JViewport getViewport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        return viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Removes the old viewport (if there is one); forces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * viewPosition of the new viewport to be in the +x,+y quadrant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * syncs up the row and column headers (if there are any) with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * new viewport; and finally syncs the scrollbars and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * headers with the new viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * Most applications will find it more convenient to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * <code>setViewportView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * to add a viewport and a view to the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @param viewport the new viewport to be used; if viewport is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     *          <code>null</code>, the old viewport is still removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *          and the new viewport is set to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @see #createViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @see #getViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see #setViewportView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *  description: The viewport child for this scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public void setViewport(JViewport viewport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        JViewport old = getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        this.viewport = viewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            add(viewport, VIEWPORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        else if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            remove(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        firePropertyChange("viewport", old, viewport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            ((AccessibleJScrollPane)accessibleContext).resetViewPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
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
     * Creates a viewport if necessary and then sets its view.  Applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * that don't provide the view directly to the <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * should use this method to specify the scrollable child that's going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * to be displayed in the scrollpane. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * JScrollPane scrollpane = new JScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * scrollpane.setViewportView(myBigComponentToScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * Applications should not add children directly to the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @param view the component to add to the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @see #setViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @see JViewport#setView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public void setViewportView(Component view) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        if (getViewport() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            setViewport(createViewport());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        getViewport().setView(view);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * Returns the row header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @return the <code>rowHeader</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @see #setRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
  1020
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public JViewport getRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return rowHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * Removes the old rowHeader, if it exists; if the new rowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * isn't <code>null</code>, syncs the y coordinate of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * viewPosition with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * the viewport (if there is one) and then adds it to the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Most applications will find it more convenient to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * <code>setRowHeaderView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * to add a row header component and its viewport to the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @param rowHeader the new row header to be used; if <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *          the old row header is still removed and the new rowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *          is set to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @see #getRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @see #setRowHeaderView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *  description: The row header child for this scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    public void setRowHeader(JViewport rowHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        JViewport old = getRowHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        this.rowHeader = rowHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        if (rowHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            add(rowHeader, ROW_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        else if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            remove(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        firePropertyChange("rowHeader", old, rowHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * Creates a row-header viewport if necessary, sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * its view and then adds the row-header viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * to the scrollpane.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * JScrollPane scrollpane = new JScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * scrollpane.setViewportView(myBigComponentToScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * scrollpane.setRowHeaderView(myBigComponentsRowHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @see #setRowHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @see JViewport#setView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @param view the component to display as the row header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    public void setRowHeaderView(Component view) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        if (getRowHeader() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            setRowHeader(createViewport());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        getRowHeader().setView(view);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * Returns the column header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @return the <code>columnHeader</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @see #setColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
  1090
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    public JViewport getColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        return columnHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * Removes the old columnHeader, if it exists; if the new columnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * isn't <code>null</code>, syncs the x coordinate of its viewPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * with the viewport (if there is one) and then adds it to the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Most applications will find it more convenient to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * <code>setColumnHeaderView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * to add a column header component and its viewport to the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1105
     * @param columnHeader  a {@code JViewport} which is the new column header
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @see #getColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @see #setColumnHeaderView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *  description: The column header child for this scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    public void setColumnHeader(JViewport columnHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        JViewport old = getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        this.columnHeader = columnHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if (columnHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            add(columnHeader, COLUMN_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        else if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            remove(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        firePropertyChange("columnHeader", old, columnHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Creates a column-header viewport if necessary, sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * its view, and then adds the column-header viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * to the scrollpane.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * JScrollPane scrollpane = new JScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * scrollpane.setViewportView(myBigComponentToScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * scrollpane.setColumnHeaderView(myBigComponentsColumnHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @see #setColumnHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @see JViewport#setView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @param view the component to display as the column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    public void setColumnHeaderView(Component view) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (getColumnHeader() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            setColumnHeader(createViewport());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        getColumnHeader().setView(view);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * Returns the component at the specified corner. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * <code>key</code> value specifying the corner is one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * <li>ScrollPaneConstants.LOWER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * <li>ScrollPaneConstants.LOWER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * <li>ScrollPaneConstants.UPPER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * <li>ScrollPaneConstants.UPPER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * <li>ScrollPaneConstants.LOWER_LEADING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * <li>ScrollPaneConstants.LOWER_TRAILING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * <li>ScrollPaneConstants.UPPER_LEADING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * <li>ScrollPaneConstants.UPPER_TRAILING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * @param key one of the values as shown above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @return the corner component (which may be <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *         identified by the given key, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *         if the key is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @see #setCorner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    public Component getCorner(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        boolean isLeftToRight = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        if (key.equals(LOWER_LEADING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            key = isLeftToRight ? LOWER_LEFT_CORNER : LOWER_RIGHT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        } else if (key.equals(LOWER_TRAILING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            key = isLeftToRight ? LOWER_RIGHT_CORNER : LOWER_LEFT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        } else if (key.equals(UPPER_LEADING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            key = isLeftToRight ? UPPER_LEFT_CORNER : UPPER_RIGHT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        } else if (key.equals(UPPER_TRAILING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            key = isLeftToRight ? UPPER_RIGHT_CORNER : UPPER_LEFT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (key.equals(LOWER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            return lowerLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        else if (key.equals(LOWER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            return lowerRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        else if (key.equals(UPPER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            return upperLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        else if (key.equals(UPPER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            return upperRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * Adds a child that will appear in one of the scroll panes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * corners, if there's room.   For example with both scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * showing (on the right and bottom edges of the scrollpane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * the lower left corner component will be shown in the space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * between ends of the two scrollbars. Legal values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * the <b>key</b> are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * <li>ScrollPaneConstants.LOWER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * <li>ScrollPaneConstants.LOWER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * <li>ScrollPaneConstants.UPPER_LEFT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * <li>ScrollPaneConstants.UPPER_RIGHT_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * <li>ScrollPaneConstants.LOWER_LEADING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * <li>ScrollPaneConstants.LOWER_TRAILING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * <li>ScrollPaneConstants.UPPER_LEADING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * <li>ScrollPaneConstants.UPPER_TRAILING_CORNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * Although "corner" doesn't match any beans property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * signature, <code>PropertyChange</code> events are generated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * property name set to the corner key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * @param key identifies which corner the component will appear in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * @param corner one of the following components:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * <li>lowerLeft
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * <li>lowerRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * <li>upperLeft
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * <li>upperRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @exception IllegalArgumentException if corner key is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public void setCorner(String key, Component corner)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        Component old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        boolean isLeftToRight = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if (key.equals(LOWER_LEADING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            key = isLeftToRight ? LOWER_LEFT_CORNER : LOWER_RIGHT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        } else if (key.equals(LOWER_TRAILING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            key = isLeftToRight ? LOWER_RIGHT_CORNER : LOWER_LEFT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        } else if (key.equals(UPPER_LEADING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            key = isLeftToRight ? UPPER_LEFT_CORNER : UPPER_RIGHT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        } else if (key.equals(UPPER_TRAILING_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            key = isLeftToRight ? UPPER_RIGHT_CORNER : UPPER_LEFT_CORNER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        if (key.equals(LOWER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            old = lowerLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            lowerLeft = corner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        else if (key.equals(LOWER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            old = lowerRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            lowerRight = corner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        else if (key.equals(UPPER_LEFT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            old = upperLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            upperLeft = corner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        else if (key.equals(UPPER_RIGHT_CORNER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            old = upperRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            upperRight = corner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            throw new IllegalArgumentException("invalid corner key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            remove(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        if (corner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            add(corner, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        firePropertyChange(key, old, corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * Sets the orientation for the vertical and horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * scrollbars as determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * <code>ComponentOrientation</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * @param  co one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * <li>java.awt.ComponentOrientation.LEFT_TO_RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * <li>java.awt.ComponentOrientation.RIGHT_TO_LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * <li>java.awt.ComponentOrientation.UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * @see java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    public void setComponentOrientation( ComponentOrientation co ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        super.setComponentOrientation( co );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        if( verticalScrollBar != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            verticalScrollBar.setComponentOrientation( co );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        if( horizontalScrollBar != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            horizontalScrollBar.setComponentOrientation( co );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * Indicates whether or not scrolling will take place in response to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * mouse wheel.  Wheel scrolling is enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1303
     * @return true if mouse wheel scrolling is enabled, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @see #setWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * description: Flag for enabling/disabling mouse wheel scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    public boolean isWheelScrollingEnabled() {return wheelScrollState;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * Enables/disables scrolling in response to movement of the mouse wheel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * Wheel scrolling is enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * @param handleWheel   <code>true</code> if scrolling should be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *                      automatically for a MouseWheelEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *                      <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * @see #isWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * @see java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * @see java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * description: Flag for enabling/disabling mouse wheel scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    public void setWheelScrollingEnabled(boolean handleWheel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        boolean old = wheelScrollState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        wheelScrollState = handleWheel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        firePropertyChange("wheelScrollingEnabled", old, handleWheel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * Returns a string representation of this <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * @return  a string representation of this <code>JScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        String viewportBorderString = (viewportBorder != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                                       viewportBorder.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        String viewportString = (viewport != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                                 viewport.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        String verticalScrollBarPolicyString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_AS_NEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_AS_NEEDED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        } else if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_NEVER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        } else if (verticalScrollBarPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            verticalScrollBarPolicyString = "VERTICAL_SCROLLBAR_ALWAYS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        } else verticalScrollBarPolicyString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        String horizontalScrollBarPolicyString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_AS_NEEDED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        } else if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_NEVER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        } else if (horizontalScrollBarPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            horizontalScrollBarPolicyString = "HORIZONTAL_SCROLLBAR_ALWAYS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        } else horizontalScrollBarPolicyString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        String horizontalScrollBarString = (horizontalScrollBar != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                                            horizontalScrollBar.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                                            : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        String verticalScrollBarString = (verticalScrollBar != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                                          verticalScrollBar.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        String columnHeaderString = (columnHeader != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                                     columnHeader.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        String rowHeaderString = (rowHeader != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                                  rowHeader.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        String lowerLeftString = (lowerLeft != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                                  lowerLeft.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        String lowerRightString = (lowerRight != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                                  lowerRight.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        String upperLeftString = (upperLeft != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                                  upperLeft.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        String upperRightString = (upperRight != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                                  upperRight.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        ",columnHeader=" + columnHeaderString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        ",horizontalScrollBar=" + horizontalScrollBarString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        ",horizontalScrollBarPolicy=" + horizontalScrollBarPolicyString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        ",lowerLeft=" + lowerLeftString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        ",lowerRight=" + lowerRightString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        ",rowHeader=" + rowHeaderString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        ",upperLeft=" + upperLeftString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        ",upperRight=" + upperRightString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        ",verticalScrollBar=" + verticalScrollBarString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        ",verticalScrollBarPolicy=" + verticalScrollBarPolicyString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        ",viewport=" + viewportString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        ",viewportBorder=" + viewportBorderString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * Gets the AccessibleContext associated with this JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * For scroll panes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * AccessibleJScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * A new AccessibleJScrollPane instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @return an AccessibleJScrollPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     *         AccessibleContext of this JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            accessibleContext = new AccessibleJScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * <code>JScrollPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * Java Accessibility API appropriate to scroll pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  1445
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
  1449
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    protected class AccessibleJScrollPane extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        implements ChangeListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1453
        /**
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1454
         * this {@code JScrollPane}'s current {@code JViewport}
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1455
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        protected JViewport viewPort = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
  1458
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         * Resets the viewport ChangeListener and PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        public void resetViewPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            if (viewPort != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                viewPort.removeChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                viewPort.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            viewPort = JScrollPane.this.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            if (viewPort != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                viewPort.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                viewPort.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
         * AccessibleJScrollPane constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        public AccessibleJScrollPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            resetViewPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            // initialize the AccessibleRelationSets for the JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            // and JScrollBar(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            JScrollBar scrollBar = getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            if (scrollBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                setScrollBarRelations(scrollBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            scrollBar = getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            if (scrollBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                setScrollBarRelations(scrollBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            return AccessibleRole.SCROLL_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
         * Invoked when the target of the listener has changed its state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         * @param e  a <code>ChangeEvent</code> object. Must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
         * @throws NullPointerException if the parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            firePropertyChange(ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                               Boolean.valueOf(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                               Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * This method gets called when a bound property is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * @param e A <code>PropertyChangeEvent</code> object describing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * the event source and the property that has changed. Must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * @throws NullPointerException if the parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            if (propertyName == "horizontalScrollBar" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                propertyName == "verticalScrollBar") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                if (e.getNewValue() instanceof JScrollBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    setScrollBarRelations((JScrollBar)e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
         * Sets the CONTROLLER_FOR and CONTROLLED_BY AccessibleRelations for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
         * the JScrollPane and JScrollBar. JScrollBar must not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        void setScrollBarRelations(JScrollBar scrollBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
             * The JScrollBar is a CONTROLLER_FOR the JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
             * The JScrollPane is CONTROLLED_BY the JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            AccessibleRelation controlledBy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                new AccessibleRelation(AccessibleRelation.CONTROLLED_BY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                                       scrollBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            AccessibleRelation controllerFor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                new AccessibleRelation(AccessibleRelation.CONTROLLER_FOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                                       JScrollPane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            // set the relation set for the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            AccessibleContext ac = scrollBar.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            ac.getAccessibleRelationSet().add(controllerFor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            // set the relation set for the scroll pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            getAccessibleRelationSet().add(controlledBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
}