jdk/src/share/classes/java/awt/Scrollbar.java
author henryjen
Tue, 10 Jun 2014 16:18:54 -0700
changeset 24865 09b1d992ca72
parent 23010 6dadb192ad81
child 25162 c388078278d4
permissions -rw-r--r--
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo Reviewed-by: mduigou, lancea, alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21957
diff changeset
     2
 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
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."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20120
diff changeset
    45
 * style="float:center; margin: 7px 10px;">
2
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:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
    49
 *
2
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."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20120
diff changeset
    63
 * style="float:center; margin: 7px 10px;">
2
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:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
    68
 *
2
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:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
   106
 *
2
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.
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
   139
 *
2
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
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   164
 * @since       1.0
2
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.
7000
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   216
     * Depending on platform, this may be visually indicated
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   217
     * by the size of the bubble.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    int visibleAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The <code>Scrollbar</code>'s orientation--being either horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * or vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * This value should be specified when the scrollbar is created.<BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * orientation can be either : <code>VERTICAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <code>HORIZONTAL</code> only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * up or down by a line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * This value must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see #getLineIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see #setLineIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    int lineIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * The amount by which the scrollbar value will change when going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * up or down by a page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * This value must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #getPageIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #setPageIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    int pageIncrement = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * The adjusting status of the <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * True if the value is in the process of changing as a result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    transient boolean isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    transient AdjustmentListener adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private static final String base = "scrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private static final long serialVersionUID = 8451667562882310543L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Initialize JNI field and method IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            initIDs();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Constructs a new vertical scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * The default properties of the scroll bar are listed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * the following table:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
   298
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <table border=1 summary="Scrollbar default properties">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *   <th>Property</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *   <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *   <th>Default Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *   <td>orientation</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *   <td>indicates whether the scroll bar is vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *   <br>or horizontal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *   <td><code>Scrollbar.VERTICAL</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *   <td>value</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *   <td>value which controls the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *   <br>of the scroll bar's bubble</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *   <td>0</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *   <td>visible amount</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *   <td>visible amount of the scroll bar's range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *   <br>typically represented by the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *   <br>scroll bar's bubble</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *   <td>10</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *   <td>minimum</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *   <td>minimum value of the scroll bar</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *   <td>0</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *   <td>maximum</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *   <td>maximum value of the scroll bar</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *   <td>100</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *   <td>unit increment</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *   <td>amount the value changes when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *   <br>Line Up or Line Down key is pressed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *   <br>or when the end arrows of the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *   <br>are clicked </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *   <td>1</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *   <td>block increment</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *   <td>amount the value changes when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *   <br>Page Up or Page Down key is pressed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *   <br>or when the scrollbar track is clicked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *   <br>on either side of the bubble </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *   <td>10</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public Scrollbar() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        this(VERTICAL, 0, 10, 0, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Constructs a new scroll bar with the specified orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * The <code>orientation</code> argument must take one of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * values <code>Scrollbar.HORIZONTAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * or <code>Scrollbar.VERTICAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * indicating a horizontal or vertical scroll bar, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param       orientation   indicates the orientation of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @exception   IllegalArgumentException    when an illegal value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *                    the <code>orientation</code> argument is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public Scrollbar(int orientation) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        this(orientation, 0, 10, 0, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Constructs a new scroll bar with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * initial value, visible amount, and minimum and maximum values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * The <code>orientation</code> argument must take one of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * values <code>Scrollbar.HORIZONTAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * or <code>Scrollbar.VERTICAL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * indicating a horizontal or vertical scroll bar, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * The parameters supplied to this constructor are subject to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * constraints described in {@link #setValues(int, int, int, int)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param     orientation   indicates the orientation of the scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param     value     the initial value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param     visible   the visible amount of the scroll bar, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *                      represented by the size of the bubble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param     minimum   the minimum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param     maximum   the maximum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @exception IllegalArgumentException    when an illegal value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *                    the <code>orientation</code> argument is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see #setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public Scrollbar(int orientation, int value, int visible, int minimum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        int maximum) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
          case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
          case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            throw new IllegalArgumentException("illegal scrollbar orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        setValues(value, visible, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Constructs a name for this component.  Called by <code>getName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * when the name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        synchronized (Scrollbar.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return base + nameCounter++;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Creates the <code>Scrollbar</code>'s peer.  The peer allows you to modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * the appearance of the <code>Scrollbar</code> without changing any of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                peer = getToolkit().createScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            super.addNotify();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Returns the orientation of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @return    the orientation of this scroll bar, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *               <code>Scrollbar.HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *               <code>Scrollbar.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see       java.awt.Scrollbar#setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Sets the orientation for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param orientation  the orientation of this scroll bar, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *               <code>Scrollbar.HORIZONTAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *               <code>Scrollbar.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @see       java.awt.Scrollbar#getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @exception   IllegalArgumentException  if the value supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *                   for <code>orientation</code> is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *                   legal value
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   463
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public void setOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (orientation == this.orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    throw new IllegalArgumentException("illegal scrollbar orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            /* Create a new peer with the specified orientation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                     ? AccessibleState.HORIZONTAL : AccessibleState.VERTICAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Gets the current value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return      the current value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Sets the value of this scroll bar to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * If the value supplied is less than the current <code>minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * or greater than the current <code>maximum - visibleAmount</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * then either <code>minimum</code> or <code>maximum - visibleAmount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * is substituted, as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Normally, a program should change a scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Calling this method does not fire an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <code>AdjustmentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @param       newValue   the new value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public void setValue(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        setValues(newValue, visibleAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Gets the minimum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @return      the minimum value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @see         java.awt.Scrollbar#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Sets the minimum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * When <code>setMinimum</code> is called, the minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * is changed, and other values (including the maximum, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * visible amount, and the current scroll bar value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * are changed to be consistent with the new minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Normally, a program should change a scroll bar's minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Note that setting the minimum value to <code>Integer.MAX_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * will result in the new minimum value being set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <code>Integer.MAX_VALUE - 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @param       newMinimum   the new minimum value for this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @see         java.awt.Scrollbar#setMaximum
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   569
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    public void setMinimum(int newMinimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // No checks are necessary in this method since minimum is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // the first variable checked in the setValues function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        setValues(value, visibleAmount, newMinimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Gets the maximum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @return      the maximum value of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see         java.awt.Scrollbar#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see         java.awt.Scrollbar#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        return maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Sets the maximum value of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * When <code>setMaximum</code> is called, the maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * is changed, and other values (including the minimum, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * visible amount, and the current scroll bar value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * are changed to be consistent with the new maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Normally, a program should change a scroll bar's maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Note that setting the maximum value to <code>Integer.MIN_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * will result in the new maximum value being set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <code>Integer.MIN_VALUE + 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param       newMaximum   the new maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *                     for this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see         java.awt.Scrollbar#setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @see         java.awt.Scrollbar#setMinimum
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   614
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public void setMaximum(int newMaximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        // minimum is checked first in setValues, so we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // enforce minimum and maximum checks here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (newMaximum == Integer.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            newMaximum = Integer.MIN_VALUE + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        if (minimum >= newMaximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            minimum = newMaximum - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        setValues(value, visibleAmount, minimum, newMaximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * Gets the visible amount of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * When a scroll bar is used to select a range of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * the visible amount is used to represent the range of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * that are currently visible.  The size of the scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * bubble (also called a thumb or scroll box), usually gives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * visual representation of the relationship of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * amount to the range of the scroll bar.
7000
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   641
     * Note that depending on platform, the value of the visible amount property
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   642
     * may not be visually indicated by the size of the bubble.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * The scroll bar's bubble may not be displayed when it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * moveable (e.g. when it takes up the entire length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * scroll bar's track, or when the scroll bar is disabled).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Whether the bubble is displayed or not will not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * the value returned by <code>getVisibleAmount</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @return      the visible amount of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @see         java.awt.Scrollbar#setVisibleAmount
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   652
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return getVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * replaced by <code>getVisibleAmount()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public int getVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return visibleAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Sets the visible amount of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * When a scroll bar is used to select a range of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * the visible amount is used to represent the range of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * that are currently visible.  The size of the scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * bubble (also called a thumb or scroll box), usually gives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * visual representation of the relationship of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * amount to the range of the scroll bar.
7000
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   676
     * Note that depending on platform, the value of the visible amount property
5ddef688a02d 6659228: GridBagConstraints API typo - 'ComponentOrienation' (missing t)
dav
parents: 5506
diff changeset
   677
     * may not be visually indicated by the size of the bubble.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * The scroll bar's bubble may not be displayed when it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * moveable (e.g. when it takes up the entire length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * scroll bar's track, or when the scroll bar is disabled).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Whether the bubble is displayed or not will not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * the value returned by <code>getVisibleAmount</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * If the visible amount supplied is less than <code>one</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * or greater than the current <code>maximum - minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * then either <code>one</code> or <code>maximum - minimum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * is substituted, as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Normally, a program should change a scroll bar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * value only by calling <code>setValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * The <code>setValues</code> method simultaneously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * and synchronously sets the minimum, maximum, visible amount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * and value properties of a scroll bar, so that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * mutually consistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @param       newAmount the new visible amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see         java.awt.Scrollbar#getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see         java.awt.Scrollbar#setValues
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   700
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public void setVisibleAmount(int newAmount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // Use setValues so that a consistent policy relating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // minimum, maximum, visible amount, and value is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        setValues(value, newAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Sets the unit increment for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * The unit increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * when the user activates the unit increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * The unit increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Attepts to set the unit increment to a value lower than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * will result in a value of 1 being set.
20120
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   718
     * <p>
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   719
     * In some operating systems, this property
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   720
     * can be ignored by the underlying controls.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @param        v  the amount by which to increment or decrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *                         the scroll bar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @see          java.awt.Scrollbar#getUnitIncrement
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   725
     * @since        1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public void setUnitIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        setLineIncrement(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * replaced by <code>setUnitIncrement(int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public synchronized void setLineIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        int tmp = (v < 1) ? 1 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (lineIncrement == tmp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        lineIncrement = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            peer.setLineIncrement(lineIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * Gets the unit increment for this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * The unit increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * when the user activates the unit increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * The unit increment must be greater than zero.
20120
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   758
     * <p>
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   759
     * In some operating systems, this property
e89bfc3f8d0e 7057770: (spec)Scrollbar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 15318
diff changeset
   760
     * can be ignored by the underlying controls.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @return      the unit increment of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @see         java.awt.Scrollbar#setUnitIncrement
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   764
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return getLineIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * replaced by <code>getUnitIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public int getLineIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        return lineIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * Sets the block increment for this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * The block increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * when the user activates the block increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * The block increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Attepts to set the block increment to a value lower than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * will result in a value of 1 being set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param        v  the amount by which to increment or decrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *                         the scroll bar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @see          java.awt.Scrollbar#getBlockIncrement
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   793
     * @since        1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public void setBlockIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        setPageIncrement(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * replaced by <code>setBlockIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public synchronized void setPageIncrement(int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        int tmp = (v < 1) ? 1 : v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if (pageIncrement == tmp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        pageIncrement = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            peer.setPageIncrement(pageIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * Gets the block increment of this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * The block increment is the value that is added or subtracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * when the user activates the block increment area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * scroll bar, generally through a mouse or keyboard gesture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * that the scroll bar receives as an adjustment event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * The block increment must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @return      the block increment of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @see         java.awt.Scrollbar#setBlockIncrement
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   829
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        return getPageIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * replaced by <code>getBlockIncrement()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    public int getPageIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        return pageIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Sets the values of four properties for this scroll bar:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <code>value</code>, <code>visibleAmount</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <code>minimum</code>, and <code>maximum</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * If the values supplied for these properties are inconsistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * or incorrect, they will be changed to ensure consistency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * This method simultaneously and synchronously sets the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * of four scroll bar properties, assuring that the values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * these properties are mutually consistent. It enforces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * following constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * <code>maximum</code> must be greater than <code>minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * <code>maximum - minimum</code> must not be greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *     than <code>Integer.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * <code>visibleAmount</code> must be greater than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * <code>visibleAmount</code> must not be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *     <code>maximum - minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * <code>value</code> must not be less than <code>minimum</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * and <code>value</code> must not be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *     <code>maximum - visibleAmount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * Calling this method does not fire an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * <code>AdjustmentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @param      value is the position in the current window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @param      visible is the visible amount of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * @param      minimum is the minimum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @param      maximum is the maximum value of the scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @see        #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @see        #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see        #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @see        #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    public void setValues(int value, int visible, int minimum, int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        int oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if (minimum == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                minimum = Integer.MAX_VALUE - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            if (maximum <= minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                maximum = minimum + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            long maxMinusMin = (long) maximum - (long) minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            if (maxMinusMin > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                maxMinusMin = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                maximum = minimum + (int) maxMinusMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if (visible > (int) maxMinusMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                visible = (int) maxMinusMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (visible < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                visible = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (value < minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                value = minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            if (value > maximum - visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                value = maximum - visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            oldValue = this.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            this.visibleAmount = visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            this.minimum = minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            this.maximum = maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            ScrollbarPeer peer = (ScrollbarPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                peer.setValues(value, visibleAmount, minimum, maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if ((oldValue != value) && (accessibleContext != null))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    Integer.valueOf(oldValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    Integer.valueOf(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Returns true if the value is in the process of changing as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * result of actions being taken by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @return the value of the <code>valueIsAdjusting</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @see #setValueIsAdjusting
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 boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        return isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * Sets the <code>valueIsAdjusting</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * @param b new adjustment-in-progress status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        boolean oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            oldValue = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            isAdjusting = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                    ((b) ? AccessibleState.BUSY : null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * Adds the specified adjustment listener to receive instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * <code>AdjustmentEvent</code> from this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * If l is <code>null</code>, no exception is thrown and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * @param        l the adjustment listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * @see          #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @see          #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * @see          java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * @see          java.awt.event.AdjustmentListener
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   975
     * @since        1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    public synchronized void addAdjustmentListener(AdjustmentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * Removes the specified adjustment listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * If l is <code>null</code>, no exception is thrown and no action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @param           l    the adjustment listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @see             #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @see             #getAdjustmentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @see             java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * @see             java.awt.event.AdjustmentListener
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   998
     * @since           1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    public synchronized void removeAdjustmentListener(AdjustmentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * Returns an array of all the adjustment listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * registered on this scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @return all of this scrollbar's <code>AdjustmentListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *         or an empty array if no adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @see             #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @see             #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @see             java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @see             java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    public synchronized AdjustmentListener[] getAdjustmentListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 7668
diff changeset
  1021
        return getListeners(AdjustmentListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * upon this <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * with a class literal,  such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * <code>Scrollbar</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * for its mouse listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     *          or an empty array if no such listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        if  (listenerType == AdjustmentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            l = adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        if (e.id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                adjustmentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Processes events on this scroll bar. If the event is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * instance of <code>AdjustmentEvent</code>, it invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * <code>processAdjustmentEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * Otherwise, it invokes its superclass's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * <code>processEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @param        e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @see          java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @see          java.awt.Scrollbar#processAdjustmentEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
  1089
     * @since        1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        if (e instanceof AdjustmentEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            processAdjustmentEvent((AdjustmentEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * Processes adjustment events occurring on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * scrollbar by dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * <code>AdjustmentListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * This method is not called unless adjustment events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * enabled for this component. Adjustment events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
  1107
     * <ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * <li>An <code>AdjustmentListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * via <code>addAdjustmentListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * <li>Adjustment events are enabled via <code>enableEvents</code>.
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 20451
diff changeset
  1111
     * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @param       e the adjustment event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @see         java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @see         java.awt.event.AdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @see         java.awt.Scrollbar#addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @see         java.awt.Component#enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
  1121
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    protected void processAdjustmentEvent(AdjustmentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        AdjustmentListener listener = adjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            listener.adjustmentValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * Returns a string representing the state of this <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @return      the parameter string of this scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            ",val=" + value +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            ",vis=" + visibleAmount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            ",min=" + minimum +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            ",max=" + maximum +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            ((orientation == VERTICAL) ? ",vert" : ",horz") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            ",isAdjusting=" + isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    /* Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * The scroll bar's serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    private int scrollbarSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * a list of serializable <code>AdjustmentListeners</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * as optional data. The non-serializable listeners are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * detected and no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * @serialData <code>null</code> terminated sequence of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *   or more pairs; the pair consists of a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *   and an <code>Object</code>; the <code>String</code> indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *   the type of object and is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *   <code>adjustmentListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *     <code>AdjustmentListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @see java.awt.Component#adjustmentListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
      s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
      AWTEventMulticaster.save(s, adjustmentListenerK, adjustmentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
      s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * Reads the <code>ObjectInputStream</code> and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * it isn't <code>null</code> adds a listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * receive adjustment events fired by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * <code>Scrollbar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
      GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
      Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
      while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        if (adjustmentListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
          addAdjustmentListener((AdjustmentListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
          s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * <code>Scrollbar</code>. For scrollbars, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * <code>AccessibleAWTScrollBar</code>. A new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * <code>AccessibleAWTScrollBar</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @return an <code>AccessibleAWTScrollBar</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *         <code>AccessibleContext</code> of this <code>ScrollBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            accessibleContext = new AccessibleAWTScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * <code>Scrollbar</code> class.  It provides an implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * the Java Accessibility API appropriate to scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    protected class AccessibleAWTScrollBar extends AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        implements AccessibleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        private static final long serialVersionUID = -344337268523697807L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
         * @return an instance of <code>AccessibleState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
         *     containing the current state of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
         * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
         *     describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            return AccessibleRole.SCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
         * Get the <code>AccessibleValue</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
         * object.  In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
         * API for this class, return this object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
         * responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * <code>AccessibleValue</code> interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return Integer.valueOf(getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            if (n instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        public Number getMinimumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            return Integer.valueOf(getMinimum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            return Integer.valueOf(getMaximum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    } // AccessibleAWTScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
}