jdk/src/share/classes/java/awt/ScrollPane.java
author tbell
Wed, 07 Oct 2009 14:15:01 -0700
changeset 3965 63aae8ce7f47
parent 1172 a1d23c450f84
child 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.ScrollPanePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.ScrollPaneWheelScroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.ConstructorProperties;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    35
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A container class which implements automatic horizontal and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * vertical scrolling for a single child component.  The display
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * policy for the scrollbars can be set to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <LI>as needed: scrollbars created and shown only when needed by scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <LI>always: scrollbars created and always shown by the scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <LI>never: scrollbars never created or shown by the scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The state of the horizontal and vertical scrollbars is represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * by two <code>ScrollPaneAdjustable</code> objects (one for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * dimension) which implement the <code>Adjustable</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The API provides methods to access those objects such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * attributes on the Adjustable object (such as unitIncrement, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * etc.) can be manipulated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Certain adjustable properties (minimum, maximum, blockIncrement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * and visibleAmount) are set internally by the scrollpane in accordance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * with the geometry of the scrollpane and its child and these should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * not be set by programs using the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * If the scrollbar display policy is defined as "never", then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * scrollpane can still be programmatically scrolled using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * setScrollPosition() method and the scrollpane will move and clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the child's contents appropriately.  This policy is useful if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * program needs to create and manage its own adjustable controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The placement of the scrollbars is controlled by platform-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * properties set by the user outside of the program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The initial size of this container is set to 100x100, but can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * be reset using setSize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Scrolling with the wheel on a wheel-equipped mouse is enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * This can be disabled using <code>setWheelScrollingEnabled</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Wheel scrolling can be customized by setting the block and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * unit increment of the horizontal and vertical Adjustables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * For information on how mouse wheel events are dispatched, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the class description for {@link MouseWheelEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Insets are used to define any space used by scrollbars and any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * borders created by the scroll pane. getInsets() can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * to get the current value for the insets.  If the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * scrollbarsAlwaysVisible is false, then the value of the insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * will change dynamically depending on whether the scrollbars are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * currently visible or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author      Tom Ball
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author      Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @author      Tim Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class ScrollPane extends Container implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Specifies that horizontal/vertical scrollbar should be shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * only when the size of the child exceeds the size of the scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * in the horizontal/vertical dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static final int SCROLLBARS_AS_NEEDED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Specifies that horizontal/vertical scrollbars should always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * shown regardless of the respective sizes of the scrollpane and child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final int SCROLLBARS_ALWAYS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Specifies that horizontal/vertical scrollbars should never be shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * regardless of the respective sizes of the scrollpane and child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final int SCROLLBARS_NEVER = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * There are 3 ways in which a scroll bar can be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * This integer will represent one of these 3 displays -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * (SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #getScrollbarDisplayPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private int scrollbarDisplayPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * An adjustable vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * It is important to note that you must <em>NOT</em> call 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <code>Adjustable</code> methods, namely:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>setMinimum()</code>, <code>setMaximum()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>setVisibleAmount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #getVAdjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private ScrollPaneAdjustable vAdjustable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * An adjustable horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * It is important to note that you must <em>NOT</em> call 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <code>Adjustable</code> methods, namely:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <code>setMinimum()</code>, <code>setMaximum()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>setVisibleAmount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #getHAdjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private ScrollPaneAdjustable hAdjustable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static final String base = "scrollpane";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private static final boolean defaultWheelScroll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Indicates whether or not scrolling should take place when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * MouseWheelEvent is received.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private boolean wheelScrollingEnabled = defaultWheelScroll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final long serialVersionUID = 7956609840827222915L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Create a new scrollpane container with a scrollbar display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * policy of "as needed".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *     returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public ScrollPane() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this(SCROLLBARS_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Create a new scrollpane container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param scrollbarDisplayPolicy policy for when scrollbars should be shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @throws IllegalArgumentException if the specified scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *     display policy is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *     returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    @ConstructorProperties({"scrollbarDisplayPolicy"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public ScrollPane(int scrollbarDisplayPolicy) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this.layoutMgr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.width = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.height = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        switch (scrollbarDisplayPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            case SCROLLBARS_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            case SCROLLBARS_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            case SCROLLBARS_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                this.scrollbarDisplayPolicy = scrollbarDisplayPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                throw new IllegalArgumentException("illegal scrollbar display policy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        vAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                               Adjustable.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        hAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                               Adjustable.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        setWheelScrollingEnabled(defaultWheelScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Construct a name for this component.  Called by getName() when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        synchronized (ScrollPane.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return base + nameCounter++;
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 scrollpane won't work with a windowless child... it assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    // it is moving a child window around so the windowless child is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // wrapped with a window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private void addToPanel(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        Panel child = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        child.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        child.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        super.addImpl(child, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Adds the specified component to this scroll pane container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * If the scroll pane has an existing child component, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * component is removed and the new one is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param constraints  not applicable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param index position of child component (must be <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected final void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (index > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                throw new IllegalArgumentException("position greater than 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (!SunToolkit.isLightweightOrUnknown(comp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                addToPanel(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the display policy for the scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return the display policy for the scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public int getScrollbarDisplayPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return scrollbarDisplayPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Returns the current size of the scroll pane's view port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return the size of the view port in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Dimension getViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return new Dimension(width - i.right - i.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                             height - i.top - i.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns the height that would be occupied by a horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * scrollbar, which is independent of whether it is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * displayed by the scroll pane or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return the height of a horizontal scrollbar in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public int getHScrollbarHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        int h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            ScrollPanePeer peer = (ScrollPanePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                h = peer.getHScrollbarHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Returns the width that would be occupied by a vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * scrollbar, which is independent of whether it is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * displayed by the scroll pane or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return the width of a vertical scrollbar in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public int getVScrollbarWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        int w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            ScrollPanePeer peer = (ScrollPanePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                w = peer.getVScrollbarWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Returns the <code>ScrollPaneAdjustable</code> object which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * represents the state of the vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * The declared return type of this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <code>Adjustable</code> to maintain backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see java.awt.ScrollPaneAdjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public Adjustable getVAdjustable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return vAdjustable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Returns the <code>ScrollPaneAdjustable</code> object which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * represents the state of the horizontal scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * The declared return type of this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <code>Adjustable</code> to maintain backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @see java.awt.ScrollPaneAdjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public Adjustable getHAdjustable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return hAdjustable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Scrolls to the specified position within the child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * A call to this method is only valid if the scroll pane contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * a child.  Specifying a position outside of the legal scrolling bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * of the child will scroll to the closest legal position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Legal bounds are defined to be the rectangle:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * x = 0, y = 0, width = (child width - view port width),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * height = (child height - view port height).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * This is a convenience method which interfaces with the Adjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * objects which represent the state of the scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param x the x position to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param y the y position to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @throws NullPointerException if the scrollpane does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *     a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public void setScrollPosition(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        synchronized (getTreeLock()) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   360
            if (getComponentCount()==0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                throw new NullPointerException("child is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            hAdjustable.setValue(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            vAdjustable.setValue(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Scrolls to the specified position within the child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * A call to this method is only valid if the scroll pane contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * a child and the specified position is within legal scrolling bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * of the child.  Specifying a position outside of the legal scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * bounds of the child will scroll to the closest legal position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Legal bounds are defined to be the rectangle:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * x = 0, y = 0, width = (child width - view port width),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * height = (child height - view port height).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * This is a convenience method which interfaces with the Adjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * objects which represent the state of the scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @param p the Point representing the position to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public void setScrollPosition(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        setScrollPosition(p.x, p.y);
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
     * Returns the current x,y position within the child which is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * at the 0,0 location of the scrolled panel's view port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * This is a convenience method which interfaces with the adjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * objects which represent the state of the scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @return the coordinate position for the current scroll position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @throws NullPointerException if the scrollpane does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *     a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   394
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public Point getScrollPosition() {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   396
        synchronized (getTreeLock()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   397
            if (getComponentCount()==0) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   398
                throw new NullPointerException("child is null");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   399
            }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   400
            return new Point(hAdjustable.getValue(), vAdjustable.getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Sets the layout manager for this container.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * overridden to prevent the layout mgr from being set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param mgr the specified layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public final void setLayout(LayoutManager mgr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        throw new AWTError("ScrollPane controls layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Lays out this container by resizing its child to its preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * If the new preferred size of the child causes the current scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * position to be invalid, the scroll position is set to the closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * valid position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see Component#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Determine the size to allocate the child component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * If the viewport area is bigger than the childs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * preferred size then the child is allocated enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * to fill the viewport, otherwise the child is given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * it's preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    Dimension calculateChildSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // calculate the view size, accounting for border but not scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // - don't use right/bottom insets since they vary depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        //   on whether or not scrollbars were displayed on last resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        Dimension       size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        Insets          insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int             viewWidth = size.width - insets.left*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int             viewHeight = size.height - insets.top*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // determine whether or not horz or vert scrollbars will be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        boolean vbarOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        boolean hbarOn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        Component child = getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        Dimension childSize = new Dimension(child.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (scrollbarDisplayPolicy == SCROLLBARS_AS_NEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            vbarOn = childSize.height > viewHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            hbarOn = childSize.width  > viewWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        } else if (scrollbarDisplayPolicy == SCROLLBARS_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            vbarOn = hbarOn = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } else { // SCROLLBARS_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            vbarOn = hbarOn = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // adjust predicted view size to account for scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int vbarWidth = getVScrollbarWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        int hbarHeight = getHScrollbarHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (vbarOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            viewWidth -= vbarWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if(hbarOn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            viewHeight -= hbarHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // if child is smaller than view, size it up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (childSize.width < viewWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            childSize.width = viewWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (childSize.height < viewHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            childSize.height = viewHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return childSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * replaced by <code>doLayout()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void layout() {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   491
        if (getComponentCount()==0) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   492
            return;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   493
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   494
        Component c = getComponent(0);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   495
        Point p = getScrollPosition();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   496
        Dimension cs = calculateChildSize();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   497
        Dimension vs = getViewportSize();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   498
        Insets i = getInsets();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   500
        c.reshape(i.left - p.x, i.top - p.y, cs.width, cs.height);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   501
        ScrollPanePeer peer = (ScrollPanePeer)this.peer;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   502
        if (peer != null) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   503
            peer.childResized(cs.width, cs.height);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   504
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   506
        // update adjustables... the viewport size may have changed
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   507
        // with the scrollbars coming or going so the viewport size
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   508
        // is updated before the adjustables.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   509
        vs = getViewportSize();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   510
        hAdjustable.setSpan(0, cs.width, vs.width);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   511
        vAdjustable.setSpan(0, cs.height, vs.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Prints the component in this scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @param g the specified Graphics window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @see Component#print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @see Component#printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    public void printComponents(Graphics g) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   521
        if (getComponentCount()==0) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   522
            return;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   523
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   524
        Component c = getComponent(0);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   525
        Point p = c.getLocation();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   526
        Dimension vs = getViewportSize();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   527
        Insets i = getInsets();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   529
        Graphics cg = g.create();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   530
        try {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   531
            cg.clipRect(i.left, i.top, vs.width, vs.height);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   532
            cg.translate(p.x, p.y);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   533
            c.printAll(cg);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   534
        } finally {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   535
            cg.dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Creates the scroll pane's peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            int vAdjustableValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            int hAdjustableValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            // Bug 4124460. Save the current adjustable values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            // so they can be restored after addnotify. Set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            // adjustables to 0, to prevent crashes for possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            // negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                vAdjustableValue = vAdjustable.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                hAdjustableValue = hAdjustable.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                vAdjustable.setValue(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                hAdjustable.setValue(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                peer = getToolkit().createScrollPane(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            // Bug 4124460. Restore the adjustable values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                vAdjustable.setValue(vAdjustableValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                hAdjustable.setValue(hAdjustableValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns a string representing the state of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <code>ScrollPane</code>. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @return the parameter string of this scroll pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        String sdpStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        switch (scrollbarDisplayPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            case SCROLLBARS_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                sdpStr = "as-needed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            case SCROLLBARS_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                sdpStr = "always";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            case SCROLLBARS_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                sdpStr = "never";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                sdpStr = "invalid display policy";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 466
diff changeset
   596
        Point p = (getComponentCount()>0)? getScrollPosition() : new Point(0,0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return super.paramString()+",ScrollPosition=("+p.x+","+p.y+")"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            ",Insets=("+i.top+","+i.left+","+i.bottom+","+i.right+")"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            ",ScrollbarDisplayPolicy="+sdpStr+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        ",wheelScrollingEnabled="+isWheelScrollingEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    void autoProcessMouseWheel(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        processMouseWheelEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Process mouse wheel events that are delivered to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <code>ScrollPane</code> by scrolling an appropriate amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @param e  the mouse wheel event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    protected void processMouseWheelEvent(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (isWheelScrollingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            ScrollPaneWheelScroller.handleWheelScrolling(this, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        super.processMouseWheelEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * If wheel scrolling is enabled, we return true for MouseWheelEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    protected boolean eventTypeEnabled(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (type == MouseEvent.MOUSE_WHEEL && isWheelScrollingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            return super.eventTypeEnabled(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Enables/disables scrolling in response to movement of the mouse wheel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * Wheel scrolling is enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @param handleWheel   <code>true</code> if scrolling should be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *                      automatically for a MouseWheelEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *                      <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @see #isWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public void setWheelScrollingEnabled(boolean handleWheel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        wheelScrollingEnabled = handleWheel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Indicates whether or not scrolling will take place in response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * the mouse wheel.  Wheel scrolling is enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see #setWheelScrollingEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    public boolean isWheelScrollingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return wheelScrollingEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
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
     * Writes default serializable fields to stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // 4352819: We only need this degenerate writeObject to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        // it safe for future versions of this class to write optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        // data to the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Reads default serializable fields to stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <code>GraphicsEnvironment.isHeadless()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // then continue with reading optional data.  Use GetField instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        ObjectInputStream.GetField f = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        // Old fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                                       SCROLLBARS_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        // Since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        wheelScrollingEnabled = f.get("wheelScrollingEnabled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                                      defaultWheelScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
//      // Note to future maintainers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
//      if (f.defaulted("wheelScrollingEnabled")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
//          // We are reading pre-1.4 stream that doesn't have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
//          // optional data, not even the TC_ENDBLOCKDATA marker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
//          // Reading anything after this point is unsafe as we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
//          // read unrelated objects further down the stream (4352819).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
//      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
//      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
//          // Reading data from 1.4 or later, it's ok to try to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
//          // optional data as OptionalDataException with eof == true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
//          // will be correctly reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
//      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    class PeerFixer implements AdjustmentListener, java.io.Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        private static final long serialVersionUID = 1043664721353696630L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        PeerFixer(ScrollPane scroller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            this.scroller = scroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
         * Invoked when the value of the adjustable has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        public void adjustmentValueChanged(AdjustmentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            Adjustable adj = e.getAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            int value = e.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                peer.setValue(adj, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            Component c = scroller.getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            switch(adj.getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            case Adjustable.VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                c.move(c.getLocation().x, -(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            case Adjustable.HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                c.move(-(value), c.getLocation().y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                throw new IllegalArgumentException("Illegal adjustable orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        private ScrollPane scroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Gets the AccessibleContext associated with this ScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * For scroll panes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * AccessibleAWTScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * A new AccessibleAWTScrollPane instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @return an AccessibleAWTScrollPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *         AccessibleContext of this ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            accessibleContext = new AccessibleAWTScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        return accessibleContext;
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
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <code>ScrollPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Java Accessibility API appropriate to scroll pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    protected class AccessibleAWTScrollPane extends AccessibleAWTContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        private static final long serialVersionUID = 6100703663886637L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return AccessibleRole.SCROLL_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    } // class AccessibleAWTScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
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
 * In JDK 1.1.1, the pkg private class java.awt.PeerFixer was moved to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
 * become an inner class of ScrollPane, which broke serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
 * for ScrollPane objects using JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
 * Instead of moving it back out here, which would break all JDK 1.1.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
 * releases, we keep PeerFixer in both places. Because of the scoping rules,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 * the PeerFixer that is used in ScrollPane will be the one that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
 * inner class. This pkg private PeerFixer class below will only be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
 * if the Java 2 platform is used to deserialize ScrollPane objects that were serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
 * using JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
class PeerFixer implements AdjustmentListener, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    private static final long serialVersionUID = 7051237413532574756L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    PeerFixer(ScrollPane scroller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        this.scroller = scroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Invoked when the value of the adjustable has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public void adjustmentValueChanged(AdjustmentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        Adjustable adj = e.getAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        int value = e.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        ScrollPanePeer peer = (ScrollPanePeer) scroller.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            peer.setValue(adj, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        Component c = scroller.getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        switch(adj.getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        case Adjustable.VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            c.move(c.getLocation().x, -(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        case Adjustable.HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            c.move(-(value), c.getLocation().y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            throw new IllegalArgumentException("Illegal adjustable orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    private ScrollPane scroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
}