jdk/src/java.desktop/share/classes/java/awt/ScrollPaneAdjustable.java
author serb
Wed, 17 Sep 2014 16:14:12 +0400
changeset 26749 b6598aa90114
parent 25859 3317bb8137f4
child 35667 ed476aba94de
permissions -rw-r--r--
8055326: Fix typos in client-related packages Reviewed-by: prr, azvegint, alexsch Contributed-by: pavel.rappo@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2000, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
10097
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
    27
import sun.awt.AWTAccessor;
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.AdjustmentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.AdjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.ScrollPanePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class represents the state of a horizontal or vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * scrollbar of a <code>ScrollPane</code>.  Objects of this class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * returned by <code>ScrollPane</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class ScrollPaneAdjustable implements Adjustable, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * The <code>ScrollPane</code> this object is a scrollbar of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private ScrollPane sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Orientation of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @see java.awt.Adjustable#HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @see java.awt.Adjustable#VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The value of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <code>value</code> should be greater than <code>minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * and less than <code>maximum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The minimum value of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * This value can only be set by the <code>ScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <strong>ATTN:</strong> In current implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <code>minimum</code> is always <code>0</code>.  This field can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * only be altered via <code>setSpan</code> method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <code>ScrollPane</code> always calls that method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <code>0</code> for the minimum.  <code>getMinimum</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * always returns <code>0</code> without checking this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #setSpan(int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private int minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * The maximum value of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * This value can only be set by the <code>ScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see #setSpan(int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * The size of the visible portion of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This value can only be set by the <code>ScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see #setSpan(int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private int visibleAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * The adjusting status of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * True if the value is in the process of changing as a result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private transient boolean isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * up or down by a line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * This value should be a non negative integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see #getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private int unitIncrement  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * up or down by a page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * This value should be a non negative integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private int blockIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private AdjustmentListener adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Error message for <code>AWTError</code> reported when one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the public but unsupported methods is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static final String SCROLLPANE_ONLY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        "Can be set by scrollpane only";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Initialize JNI field and method ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
10097
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   161
        AWTAccessor.setScrollPaneAdjustableAccessor(new AWTAccessor.ScrollPaneAdjustableAccessor() {
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   162
            public void setTypedValue(final ScrollPaneAdjustable adj,
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   163
                                      final int v, final int type) {
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   164
                adj.setTypedValue(v, type);
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   165
            }
67449ffe5991 6642728: Use reflection to access ScrollPane's private method from within sun.awt package
serb
parents: 5506
diff changeset
   166
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * JDK 1.1 serialVersionUID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static final long serialVersionUID = -3359745691033257079L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Constructs a new object to represent specified scrollabar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * of the specified <code>ScrollPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Only ScrollPane creates instances of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param sp           <code>ScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param l            <code>AdjustmentListener</code> to add upon creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param orientation  specifies which scrollbar this object represents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                     can be either  <code>Adjustable.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *                     or <code>Adjustable.VERTICAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    ScrollPaneAdjustable(ScrollPane sp, AdjustmentListener l, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this.sp = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        addAdjustmentListener(l);
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
     * This is called by the scrollpane itself to update the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <code>minimum</code>, <code>maximum</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <code>visible</code> values.  The scrollpane is the only one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * that should be changing these since it is the source of these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    void setSpan(int min, int max, int visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // adjust the values to be reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        minimum = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        maximum = Math.max(max, minimum + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        visibleAmount = Math.min(visible, maximum - minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        visibleAmount = Math.max(visibleAmount, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        blockIncrement = Math.max((int)(visible * .90), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returns the orientation of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return    the orientation of this scrollbar, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *            <code>Adjustable.HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *            <code>Adjustable.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * This method should <strong>NOT</strong> be called by user code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * This method is public for this class to properly implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <code>Adjustable</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 10097
diff changeset
   223
     * @throws AWTError Always throws an error when called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void setMinimum(int min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        throw new AWTError(SCROLLPANE_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // XXX: This relies on setSpan always being called with 0 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // the minimum (which is currently true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This method should <strong>NOT</strong> be called by user code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * This method is public for this class to properly implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <code>Adjustable</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 10097
diff changeset
   240
     * @throws AWTError Always throws an error when called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public void setMaximum(int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        throw new AWTError(SCROLLPANE_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public synchronized void setUnitIncrement(int u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (u != unitIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            unitIncrement = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (sp.peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                ScrollPanePeer peer = (ScrollPanePeer) sp.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                peer.setUnitIncrement(this, u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public synchronized void setBlockIncrement(int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        blockIncrement = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * This method should <strong>NOT</strong> be called by user code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * This method is public for this class to properly implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <code>Adjustable</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 10097
diff changeset
   277
     * @throws AWTError Always throws an error when called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public void setVisibleAmount(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throw new AWTError(SCROLLPANE_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return visibleAmount;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Sets the <code>valueIsAdjusting</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param b new adjustment-in-progress status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (isAdjusting != b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            isAdjusting = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            AdjustmentEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                new AdjustmentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        AdjustmentEvent.TRACK, value, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            adjustmentListener.adjustmentValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Returns true if the value is in the process of changing as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * result of actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the value of the <code>valueIsAdjusting</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Sets the value of this scrollbar to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * If the value supplied is less than the current minimum or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * greater than the current maximum, then one of those values is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * substituted, as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param v the new value of the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void setValue(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        setTypedValue(v, AdjustmentEvent.TRACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Sets the value of this scrollbar to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * If the value supplied is less than the current minimum or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * greater than the current maximum, then one of those values is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * substituted, as appropriate. Also, creates and dispatches
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   336
     * the AdjustmentEvent with specified type and value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param v the new value of the scrollbar
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20172
diff changeset
   339
     * @param type the type of the scrolling operation occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    private void setTypedValue(int v, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        v = Math.max(v, minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        v = Math.min(v, maximum - visibleAmount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (v != value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            value = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            // Synchronously notify the listeners so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            // guaranteed to be up-to-date with the Adjustable before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            // it is mutated again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            AdjustmentEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                new AdjustmentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            adjustmentListener.adjustmentValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Adds the specified adjustment listener to receive adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * events from this <code>ScrollPaneAdjustable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * If <code>l</code> is <code>null</code>, no exception is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param    l   the adjustment listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see      #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see      #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see      java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see      java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public synchronized void addAdjustmentListener(AdjustmentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Removes the specified adjustment listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * receives adjustment events from this <code>ScrollPaneAdjustable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * If <code>l</code> is <code>null</code>, no exception is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param         l     the adjustment listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see           #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see           #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see           java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see           java.awt.event.AdjustmentEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22584
diff changeset
   396
     * @since         1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public synchronized void removeAdjustmentListener(AdjustmentListener l){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Returns an array of all the adjustment listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * registered on this <code>ScrollPaneAdjustable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @return all of this <code>ScrollPaneAdjustable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *         <code>AdjustmentListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *         or an empty array if no adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see           #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see           #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see           java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see           java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public synchronized AdjustmentListener[] getAdjustmentListeners() {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   421
        return AWTEventMulticaster.getListeners(adjustmentListener,
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   422
                                                AdjustmentListener.class);
2
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
     * Returns a string representation of this scrollbar and its values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @return    a string representation of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return getClass().getName() + "[" + paramString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Returns a string representing the state of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * and the content and format of the returned string may vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * between implementations.  The returned string may be empty but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * may not be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @return      the parameter string of this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return ((orientation == Adjustable.VERTICAL ? "vertical,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                                    :"horizontal,")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                + "[0.."+maximum+"]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                + ",val=" + value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                + ",vis=" + visibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                + ",unit=" + unitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                + ",block=" + blockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                + ",isAdjusting=" + isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
}