jdk/src/share/classes/java/awt/Scrollbar.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
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 1995-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.peer.ScrollbarPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The <code>Scrollbar</code> class embodies a scroll bar, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * familiar user-interface object. A scroll bar provides a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * convenient means for allowing a user to select from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * range of values. The following three vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * scroll bars could be used as slider controls to pick
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * the red, green, and blue components of a color:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <img src="doc-files/Scrollbar-1.gif" alt="Image shows 3 vertical sliders, side-by-side."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Each scroll bar in this example could be created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * code similar to the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * add(redSlider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Alternatively, a scroll bar can represent a range of values. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * example, if a scroll bar is used for scrolling through text, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * width of the "bubble" (also called the "thumb" or "scroll box")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * can be used to represent the amount of text that is visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Here is an example of a scroll bar that represents a range:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <img src="doc-files/Scrollbar-2.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * alt="Image shows horizontal slider with starting range of 0 and ending range of 300. The slider thumb is labeled 60."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The value range represented by the bubble in this example
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * is the <em>visible amount</em>. The horizontal scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * in this example could be created with code like the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * add(ranger);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Note that the actual maximum value of the scroll bar is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <code>maximum</code> minus the <code>visible amount</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * In the previous example, because the <code>maximum</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * 300 and the <code>visible amount</code> is 60, the actual maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * value is 240.  The range of the scrollbar track is 0 - 300.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The left side of the bubble indicates the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Normally, the user changes the value of the scroll bar by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * making a gesture with the mouse. For example, the user can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * drag the scroll bar's bubble up and down, or click in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * scroll bar's unit increment or block increment areas. Keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * gestures can also be mapped to the scroll bar. By convention,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * the <b>Page&nbsp;Up</b> and <b>Page&nbsp;Down</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * keys are equivalent to clicking in the scroll bar's block
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * increment and block decrement areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * When the user changes the value of the scroll bar, the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * receives an instance of <code>AdjustmentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * The scroll bar processes this event, passing it along to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * any registered listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Any object that wishes to be notified of changes to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * scroll bar's value should implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <code>AdjustmentListener</code>, an interface defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * the package <code>java.awt.event</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Listeners can be added and removed dynamically by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * the methods <code>addAdjustmentListener</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <code>removeAdjustmentListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * The <code>AdjustmentEvent</code> class defines five types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * of adjustment event, listed here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <li><code>AdjustmentEvent.TRACK</code> is sent out when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * user drags the scroll bar's bubble.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> is sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * when the user clicks in the left arrow of a horizontal scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * bar, or the top arrow of a vertical scroll bar, or makes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * equivalent gesture from the keyboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> is sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * when the user clicks in the right arrow of a horizontal scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * bar, or the bottom arrow of a vertical scroll bar, or makes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * equivalent gesture from the keyboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> is sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * when the user clicks in the track, to the left of the bubble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * on a horizontal scroll bar, or above the bubble on a vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * scroll bar. By convention, the <b>Page&nbsp;Up</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * key is equivalent, if the user is using a keyboard that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * defines a <b>Page&nbsp;Up</b> key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> is sent out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * when the user clicks in the track, to the right of the bubble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * on a horizontal scroll bar, or below the bubble on a vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * scroll bar. By convention, the <b>Page&nbsp;Down</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * key is equivalent, if the user is using a keyboard that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * defines a <b>Page&nbsp;Down</b> key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * The JDK&nbsp;1.0 event system is supported for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * compatibility, but its use with newer versions of the platform is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * discouraged. The five types of adjustment events introduced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * with JDK&nbsp;1.1 correspond to the five event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * that are associated with scroll bars in previous platform versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * The following list gives the adjustment event type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * and the corresponding JDK&nbsp;1.0 event type it replaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <li><code>AdjustmentEvent.TRACK</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <code>Event.SCROLL_ABSOLUTE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <code>Event.SCROLL_LINE_UP</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <code>Event.SCROLL_LINE_DOWN</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>Event.SCROLL_PAGE_UP</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <code>Event.SCROLL_PAGE_DOWN</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <b>Note</b>: We recommend using a <code>Scrollbar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * for value selection only.  If you want to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * a scrollable component inside a container, we recommend you use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * a {@link ScrollPane ScrollPane}. If you use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <code>Scrollbar</code> for this purpose, you are likely to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * encounter issues with painting, key handling, sizing and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * positioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @see         java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @see         java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
public class Scrollbar extends Component implements Adjustable, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * A constant that indicates a horizontal scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public static final int     HORIZONTAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * A constant that indicates a vertical scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public static final int     VERTICAL   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * The value of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * This property must be greater than or equal to <code>minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * and less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <code>maximum - visibleAmount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * The maximum value of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * This value must be greater than the <code>minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * value.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    int maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * The minimum value of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This value must be less than the <code>maximum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * value.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    int minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The size of the <code>Scrollbar</code>'s bubble.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * When a scroll bar is used to select a range of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the visibleAmount represents the size of this range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * This is visually indicated by the size of the bubble.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    int visibleAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * The <code>Scrollbar</code>'s orientation--being either horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * or vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This value should be specified when the scrollbar is created.<BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * orientation can be either : <code>VERTICAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <code>HORIZONTAL</code> only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * up or down by a line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * This value must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see #getLineIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see #setLineIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    int lineIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * up or down by a page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * This value must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #getPageIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #setPageIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    int pageIncrement = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * The adjusting status of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * True if the value is in the process of changing as a result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    transient boolean isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    transient AdjustmentListener adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static final String base = "scrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static final long serialVersionUID = 8451667562882310543L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Initialize JNI field and method IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Constructs a new vertical scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * The default properties of the scroll bar are listed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * the following table:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <p> </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <table border=1 summary="Scrollbar default properties">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *   <th>Property</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *   <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *   <th>Default Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *   <td>orientation</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *   <td>indicates whether the scroll bar is vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *   <br>or horizontal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *   <td><code>Scrollbar.VERTICAL</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *   <td>value</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *   <td>value which controls the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *   <br>of the scroll bar's bubble</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *   <td>0</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *   <td>visible amount</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *   <td>visible amount of the scroll bar's range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *   <br>typically represented by the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *   <br>scroll bar's bubble</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *   <td>10</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *   <td>minimum</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *   <td>minimum value of the scroll bar</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *   <td>0</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *   <td>maximum</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *   <td>maximum value of the scroll bar</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *   <td>100</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *   <td>unit increment</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *   <td>amount the value changes when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *   <br>Line Up or Line Down key is pressed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *   <br>or when the end arrows of the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *   <br>are clicked </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *   <td>1</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *   <td>block increment</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *   <td>amount the value changes when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *   <br>Page Up or Page Down key is pressed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *   <br>or when the scrollbar track is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *   <br>on either side of the bubble </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *   <td>10</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public Scrollbar() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        this(VERTICAL, 0, 10, 0, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Constructs a new scroll bar with the specified orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * The <code>orientation</code> argument must take one of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * values <code>Scrollbar.HORIZONTAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * or <code>Scrollbar.VERTICAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * indicating a horizontal or vertical scroll bar, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param       orientation   indicates the orientation of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @exception   IllegalArgumentException    when an illegal value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *                    the <code>orientation</code> argument is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public Scrollbar(int orientation) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        this(orientation, 0, 10, 0, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Constructs a new scroll bar with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * initial value, visible amount, and minimum and maximum values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * The <code>orientation</code> argument must take one of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * values <code>Scrollbar.HORIZONTAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * or <code>Scrollbar.VERTICAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * indicating a horizontal or vertical scroll bar, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * The parameters supplied to this constructor are subject to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * constraints described in {@link #setValues(int, int, int, int)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param     orientation   indicates the orientation of the scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param     value     the initial value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param     visible   the visible amount of the scroll bar, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *                      represented by the size of the bubble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param     minimum   the minimum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param     maximum   the maximum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @exception IllegalArgumentException    when an illegal value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *                    the <code>orientation</code> argument is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see #setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public Scrollbar(int orientation, int value, int visible, int minimum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        int maximum) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
          case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
          case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            throw new IllegalArgumentException("illegal scrollbar orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        setValues(value, visible, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Constructs a name for this component.  Called by <code>getName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * when the name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        synchronized (Scrollbar.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Creates the <code>Scrollbar</code>'s peer.  The peer allows you to modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * the appearance of the <code>Scrollbar</code> without changing any of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                peer = getToolkit().createScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Returns the orientation of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @return    the orientation of this scroll bar, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *               <code>Scrollbar.HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *               <code>Scrollbar.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see       java.awt.Scrollbar#setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Sets the orientation for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @param orientation  the orientation of this scroll bar, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *               <code>Scrollbar.HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *               <code>Scrollbar.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @see       java.awt.Scrollbar#getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception   IllegalArgumentException  if the value supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *                   for <code>orientation</code> is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *                   legal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public void setOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            if (orientation == this.orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    throw new IllegalArgumentException("illegal scrollbar orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            /* Create a new peer with the specified orientation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                     ? AccessibleState.HORIZONTAL : AccessibleState.VERTICAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Gets the current value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return      the current value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Sets the value of this scroll bar to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * If the value supplied is less than the current <code>minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * or greater than the current <code>maximum - visibleAmount</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * then either <code>minimum</code> or <code>maximum - visibleAmount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * is substituted, as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Normally, a program should change a scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Calling this method does not fire an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * <code>AdjustmentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param       newValue   the new value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public void setValue(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        setValues(newValue, visibleAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Gets the minimum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return      the minimum value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Sets the minimum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * When <code>setMinimum</code> is called, the minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * is changed, and other values (including the maximum, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * visible amount, and the current scroll bar value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * are changed to be consistent with the new minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Normally, a program should change a scroll bar's minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Note that setting the minimum value to <code>Integer.MAX_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * will result in the new minimum value being set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <code>Integer.MAX_VALUE - 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @param       newMinimum   the new minimum value for this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @see         java.awt.Scrollbar#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public void setMinimum(int newMinimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // No checks are necessary in this method since minimum is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // the first variable checked in the setValues function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        setValues(value, visibleAmount, newMinimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Gets the maximum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @return      the maximum value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Sets the maximum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * When <code>setMaximum</code> is called, the maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * is changed, and other values (including the minimum, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * visible amount, and the current scroll bar value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * are changed to be consistent with the new maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Normally, a program should change a scroll bar's maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Note that setting the maximum value to <code>Integer.MIN_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * will result in the new maximum value being set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <code>Integer.MIN_VALUE + 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param       newMaximum   the new maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *                     for this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see         java.awt.Scrollbar#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public void setMaximum(int newMaximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        // minimum is checked first in setValues, so we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        // enforce minimum and maximum checks here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (newMaximum == Integer.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            newMaximum = Integer.MIN_VALUE + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (minimum >= newMaximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            minimum = newMaximum - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        setValues(value, visibleAmount, minimum, newMaximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Gets the visible amount of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * When a scroll bar is used to select a range of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * the visible amount is used to represent the range of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * that are currently visible.  The size of the scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * bubble (also called a thumb or scroll box), usually gives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * visual representation of the relationship of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * amount to the range of the scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * The scroll bar's bubble may not be displayed when it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * moveable (e.g. when it takes up the entire length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * scroll bar's track, or when the scroll bar is disabled).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Whether the bubble is displayed or not will not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * the value returned by <code>getVisibleAmount</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @return      the visible amount of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see         java.awt.Scrollbar#setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return getVisible();
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
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * replaced by <code>getVisibleAmount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public int getVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return visibleAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Sets the visible amount of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * When a scroll bar is used to select a range of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * the visible amount is used to represent the range of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * that are currently visible.  The size of the scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * bubble (also called a thumb or scroll box), usually gives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * visual representation of the relationship of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * amount to the range of the scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * The scroll bar's bubble may not be displayed when it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * moveable (e.g. when it takes up the entire length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * scroll bar's track, or when the scroll bar is disabled).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Whether the bubble is displayed or not will not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * the value returned by <code>getVisibleAmount</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * If the visible amount supplied is less than <code>one</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * or greater than the current <code>maximum - minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * then either <code>one</code> or <code>maximum - minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * is substituted, as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * Normally, a program should change a scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @param       newAmount the new visible amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @see         java.awt.Scrollbar#getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public void setVisibleAmount(int newAmount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        setValues(value, newAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Sets the unit increment for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * The unit increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * when the user activates the unit increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * The unit increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * Attepts to set the unit increment to a value lower than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * will result in a value of 1 being set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @param        v  the amount by which to increment or decrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *                         the scroll bar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @see          java.awt.Scrollbar#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public void setUnitIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        setLineIncrement(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * replaced by <code>setUnitIncrement(int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    public synchronized void setLineIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        int tmp = (v < 1) ? 1 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (lineIncrement == tmp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        lineIncrement = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            peer.setLineIncrement(lineIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * Gets the unit increment for this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * The unit increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * when the user activates the unit increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * The unit increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @return      the unit increment of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see         java.awt.Scrollbar#setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        return getLineIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * replaced by <code>getUnitIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public int getLineIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return lineIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * Sets the block increment for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * The block increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * when the user activates the block increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * The block increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Attepts to set the block increment to a value lower than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * will result in a value of 1 being set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param        v  the amount by which to increment or decrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *                         the scroll bar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @see          java.awt.Scrollbar#getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    public void setBlockIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        setPageIncrement(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * replaced by <code>setBlockIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public synchronized void setPageIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        int tmp = (v < 1) ? 1 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        if (pageIncrement == tmp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        pageIncrement = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            peer.setPageIncrement(pageIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Gets the block increment of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * The block increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * when the user activates the block increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * The block increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @return      the block increment of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @see         java.awt.Scrollbar#setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return getPageIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * replaced by <code>getBlockIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public int getPageIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        return pageIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Sets the values of four properties for this scroll bar:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <code>value</code>, <code>visibleAmount</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <code>minimum</code>, and <code>maximum</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * If the values supplied for these properties are inconsistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * or incorrect, they will be changed to ensure consistency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * This method simultaneously and synchronously sets the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * of four scroll bar properties, assuring that the values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * these properties are mutually consistent. It enforces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * following constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <code>maximum</code> must be greater than <code>minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * <code>maximum - minimum</code> must not be greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *     than <code>Integer.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <code>visibleAmount</code> must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * <code>visibleAmount</code> must not be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *     <code>maximum - minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <code>value</code> must not be less than <code>minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * and <code>value</code> must not be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *     <code>maximum - visibleAmount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Calling this method does not fire an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * <code>AdjustmentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @param      value is the position in the current window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @param      visible is the visible amount of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @param      minimum is the minimum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @param      maximum is the maximum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @see        #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @see        #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @see        #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @see        #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    public void setValues(int value, int visible, int minimum, int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        int oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (minimum == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                minimum = Integer.MAX_VALUE - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (maximum <= minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                maximum = minimum + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            long maxMinusMin = (long) maximum - (long) minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            if (maxMinusMin > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                maxMinusMin = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                maximum = minimum + (int) maxMinusMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (visible > (int) maxMinusMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                visible = (int) maxMinusMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            if (visible < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                visible = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            if (value < minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                value = minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            if (value > maximum - visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                value = maximum - visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            oldValue = this.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            this.visibleAmount = visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            this.minimum = minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            this.maximum = maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                peer.setValues(value, visibleAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        if ((oldValue != value) && (accessibleContext != null))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                    Integer.valueOf(oldValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                    Integer.valueOf(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Returns true if the value is in the process of changing as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * result of actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @return the value of the <code>valueIsAdjusting</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        return isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * Sets the <code>valueIsAdjusting</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param b new adjustment-in-progress status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        boolean oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            oldValue = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            isAdjusting = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    ((b) ? AccessibleState.BUSY : null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * Adds the specified adjustment listener to receive instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * <code>AdjustmentEvent</code> from this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * If l is <code>null</code>, no exception is thrown and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @param        l the adjustment listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @see          #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see          #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @see          java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @see          java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    public synchronized void addAdjustmentListener(AdjustmentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * Removes the specified adjustment listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * If l is <code>null</code>, no exception is thrown and no action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @param           l    the adjustment listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @see             #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @see             #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @see             java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see             java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @since           JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public synchronized void removeAdjustmentListener(AdjustmentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Returns an array of all the adjustment listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * registered on this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @return all of this scrollbar's <code>AdjustmentListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *         or an empty array if no adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @see             #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @see             #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @see             java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @see             java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    public synchronized AdjustmentListener[] getAdjustmentListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        return (AdjustmentListener[])(getListeners(AdjustmentListener.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * upon this <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * with a class literal,  such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * <code>Scrollbar</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * for its mouse listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *          or an empty array if no such listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if  (listenerType == AdjustmentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            l = adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        if (e.id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                adjustmentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * Processes events on this scroll bar. If the event is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * instance of <code>AdjustmentEvent</code>, it invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * <code>processAdjustmentEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * Otherwise, it invokes its superclass's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * <code>processEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @param        e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @see          java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @see          java.awt.Scrollbar#processAdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (e instanceof AdjustmentEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            processAdjustmentEvent((AdjustmentEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * Processes adjustment events occurring on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * scrollbar by dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * <code>AdjustmentListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * This method is not called unless adjustment events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * enabled for this component. Adjustment events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * <li>An <code>AdjustmentListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * via <code>addAdjustmentListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * <li>Adjustment events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * </ul><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @param       e the adjustment event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @see         java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @see         java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @see         java.awt.Scrollbar#addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @see         java.awt.Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    protected void processAdjustmentEvent(AdjustmentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        AdjustmentListener listener = adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            listener.adjustmentValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * Returns a string representing the state of this <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * @return      the parameter string of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            ",val=" + value +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            ",vis=" + visibleAmount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            ",min=" + minimum +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            ",max=" + maximum +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            ((orientation == VERTICAL) ? ",vert" : ",horz") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            ",isAdjusting=" + isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /* Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * The scroll bar's serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    private int scrollbarSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * a list of serializable <code>AdjustmentListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * as optional data. The non-serializable listeners are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * detected and no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @serialData <code>null</code> terminated sequence of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *   or more pairs; the pair consists of a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     *   and an <code>Object</code>; the <code>String</code> indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *   the type of object and is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *   <code>adjustmentListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     *     <code>AdjustmentListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @see java.awt.Component#adjustmentListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
      AWTEventMulticaster.save(s, adjustmentListenerK, adjustmentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
      s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * Reads the <code>ObjectInputStream</code> and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * it isn't <code>null</code> adds a listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * receive adjustment events fired by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
      GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
      Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
      while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if (adjustmentListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
          addAdjustmentListener((AdjustmentListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
          s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * <code>Scrollbar</code>. For scrollbars, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * <code>AccessibleAWTScrollBar</code>. A new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * <code>AccessibleAWTScrollBar</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * @return an <code>AccessibleAWTScrollBar</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     *         <code>AccessibleContext</code> of this <code>ScrollBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            accessibleContext = new AccessibleAWTScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * <code>Scrollbar</code> class.  It provides an implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * the Java Accessibility API appropriate to scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    protected class AccessibleAWTScrollBar extends AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        implements AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        private static final long serialVersionUID = -344337268523697807L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
         * @return an instance of <code>AccessibleState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
         *     containing the current state of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
         *     describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            return AccessibleRole.SCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         * Get the <code>AccessibleValue</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
         * object.  In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
         * API for this class, return this object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
         * responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
         * <code>AccessibleValue</code> interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            return Integer.valueOf(getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            if (n instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        public Number getMinimumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            return Integer.valueOf(getMinimum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            return Integer.valueOf(getMaximum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    } // AccessibleAWTScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
}