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