jdk/src/share/classes/javax/swing/JScrollBar.java
author cl
Mon, 07 Oct 2013 11:34:44 -0700
changeset 20458 f2423fb3fd19
parent 20095 619a080ff304
child 21982 fd6e5fe509df
permissions -rw-r--r--
8025840: Fix all the doclint warnings about trademark Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
     2
 * Copyright (c) 1997, 2008, 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: 1301
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: 1301
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: 1301
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Adjustable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.AdjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.AdjustmentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * An implementation of a scrollbar. The user positions the knob in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * scrollbar to determine the contents of the viewing area. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * program typically adjusts the display so that the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * scrollbar represents the end of the displayable contents, or 100%
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * of the contents. The start of the scrollbar is the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * displayable contents, or 0%. The position of the knob within
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * those bounds then translates to the corresponding percentage of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * the displayable contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Typically, as the position of the knob in the scrollbar changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * a corresponding change is made to the position of the JViewport on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the underlying view, changing the contents of the JViewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20095
diff changeset
    70
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *      attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *    description: A component that helps determine the visible content range of an area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
public class JScrollBar extends JComponent implements Adjustable, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final String uiClassID = "ScrollBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * All changes from the model are treated as though the user moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * the scrollbar knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private ChangeListener fwdAdjustmentEvents = new ModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * The model that represents the scrollbar's minimum, maximum, extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * (aka "visibleAmount") and current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected BoundedRangeModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected int unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected int blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private void checkOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Creates a scrollbar with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * value, extent, minimum, and maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * The "extent" is the size of the viewable area. It is also known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * as the "visible amount".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Note: Use <code>setBlockIncrement</code> to set the block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * increment to a size slightly smaller than the view's extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * That way, when the user jumps the knob to an adjacent position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * one or two lines of the original contents remain in view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public JScrollBar(int orientation, int value, int extent, int min, int max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this.unitIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.blockIncrement = (extent == 0) ? 1 : extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.model = new DefaultBoundedRangeModel(value, extent, min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.model.addChangeListener(fwdAdjustmentEvents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Creates a scrollbar with the specified orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * and the following initial values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * minimum = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * maximum = 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * value = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * extent = 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public JScrollBar(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this(orientation, 0, 10, 0, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Creates a vertical scrollbar with the following initial values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * minimum = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * maximum = 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * value = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * extent = 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public JScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this(VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Sets the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param ui  the <code>ScrollBarUI</code> L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *  description: The UI object that implements the Component's LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public void setUI(ScrollBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Returns the delegate that implements the look and feel for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see JComponent#setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public ScrollBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return (ScrollBarUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Overrides <code>JComponent.updateUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        setUI((ScrollBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns the name of the LookAndFeel class for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return "ScrollBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns the component's orientation (horizontal or vertical).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return VERTICAL or HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see java.awt.Adjustable#getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Set the scrollbar's orientation to either VERTICAL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * HORIZONTAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *  description: The scrollbar's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *         enum: VERTICAL JScrollBar.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *               HORIZONTAL JScrollBar.HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public void setOrientation(int orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int oldValue = this.orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        firePropertyChange("orientation", oldValue, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if ((oldValue != orientation) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    ((oldValue == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (orientation != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Returns data model that handles the scrollbar's four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * fundamental properties: minimum, maximum, value, extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public BoundedRangeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Sets the model that handles the scrollbar's four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * fundamental properties: minimum, maximum, value, extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * description: The scrollbar's BoundedRangeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void setModel(BoundedRangeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Integer oldValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        BoundedRangeModel oldModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            model.removeChangeListener(fwdAdjustmentEvents);
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   317
            oldValue = Integer.valueOf(model.getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        model = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            model.addChangeListener(fwdAdjustmentEvents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        firePropertyChange("model", oldModel, model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    oldValue, new Integer(model.getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Returns the amount to change the scrollbar's value by,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * given a unit up/down request.  A ScrollBarUI implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * typically calls this method when the user clicks on a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * up/down arrow and uses the result to update the scrollbar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * value.   Subclasses my override this method to compute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * a value, e.g. the change required to scroll up or down one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * (variable height) line text or one row in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * The JScrollPane component creates scrollbars (by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * that override this method and delegate to the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Scrollable view, if it has one.  The Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * provides a more specialized version of this method.
20095
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   347
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   348
     * Some look and feels implement custom scrolling behavior
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   349
     * and ignore this property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return the value of the unitIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public int getUnitIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Sets the unitIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * the most look and feels will not provide the scrolling to the right/down.
20095
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   367
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   368
     * Some look and feels implement custom scrolling behavior
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   369
     * and ignore this property.
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   370
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see #getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * description: The scrollbar's unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public void setUnitIncrement(int unitIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int oldValue = this.unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        this.unitIncrement = unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        firePropertyChange("unitIncrement", oldValue, unitIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Returns the amount to change the scrollbar's value by,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * given a block (usually "page") up/down request.  A ScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * implementation typically calls this method when the user clicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * above or below the scrollbar "knob" to change the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * up or down by large amount.  Subclasses my override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * method to compute a value, e.g. the change required to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * up or down one paragraph in a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * The JScrollPane component creates scrollbars (by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * that override this method and delegate to the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Scrollable view, if it has one.  The Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * provides a more specialized version of this method.
20095
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   397
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   398
     * Some look and feels implement custom scrolling behavior
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   399
     * and ignore this property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return the value of the blockIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public int getBlockIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Sets the blockIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * the most look and feels will not provide the scrolling to the right/down.
20095
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   417
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   418
     * Some look and feels implement custom scrolling behavior
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   419
     * and ignore this property.
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   420
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see #getBlockIncrement()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * description: The scrollbar's block increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public void setBlockIncrement(int blockIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        int oldValue = this.blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        this.blockIncrement = blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        firePropertyChange("blockIncrement", oldValue, blockIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see Adjustable#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #getUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see Adjustable#getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see #getBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return blockIncrement;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns the scrollbar's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @return the model's value property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return getModel().getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Sets the scrollbar's value.  This method just forwards the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see BoundedRangeModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * description: The scrollbar's current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public void setValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        m.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   482
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   483
                    Integer.valueOf(m.getValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Returns the scrollbar's extent, aka its "visibleAmount".  In many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * scrollbar look and feel implementations the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * scrollbar "knob" or "thumb" is proportional to the extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return the value of the model's extent property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return getModel().getExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Set the model's extent property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see BoundedRangeModel#setExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * description: The amount of the view that is currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public void setVisibleAmount(int extent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        getModel().setExtent(extent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Returns the minimum value supported by the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * (usually zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @return the value of the model's minimum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return getModel().getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Sets the model's minimum property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see BoundedRangeModel#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * description: The scrollbar's minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public void setMinimum(int minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        getModel().setMinimum(minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * The maximum value of the scrollbar is maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @return the value of the model's maximum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return getModel().getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Sets the model's maximum property.  Note that the scrollbar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * can only be set to maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see BoundedRangeModel#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * description: The scrollbar's maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public void setMaximum(int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        getModel().setMaximum(maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * True if the scrollbar knob is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @return the value of the model's valueIsAdjusting property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return getModel().getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Sets the model's valueIsAdjusting property.  Scrollbar look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * feel implementations should set this property to true when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * a knob drag begins, and to false when the drag ends.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * scrollbar model will not generate ChangeEvents while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * valueIsAdjusting is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see BoundedRangeModel#setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * description: True if the scrollbar thumb is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        boolean oldValue = m.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        m.setValueIsAdjusting(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    ((b) ? AccessibleState.BUSY : null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Sets the four BoundedRangeModel properties after forcing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * the arguments to obey the usual constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * minimum <= value <= value+extent <= maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @see BoundedRangeModel#setRangeProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public void setValues(int newValue, int newExtent, int newMin, int newMax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   628
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   629
                    Integer.valueOf(m.getValue()));
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Adds an AdjustmentListener.  Adjustment listeners are notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * each time the scrollbar's model changes.  Adjustment events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * provided for backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Note that the AdjustmentEvents type property will always have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * placeholder value of AdjustmentEvent.TRACK because all changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * to a BoundedRangeModels value are considered equivalent.  To change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * the value of a BoundedRangeModel one just sets its value property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * i.e. model.setValue(123).  No information about the origin of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * change, e.g. it's a block decrement, is provided.  We don't try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * fabricate the origin of the change here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param l the AdjustmentLister to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see BoundedRangeModel#addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public void addAdjustmentListener(AdjustmentListener l)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        listenerList.add(AdjustmentListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * Removes an AdjustmentEvent listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @param l the AdjustmentLister to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    public void removeAdjustmentListener(AdjustmentListener l)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        listenerList.remove(AdjustmentListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Returns an array of all the <code>AdjustmentListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * to this JScrollBar with addAdjustmentListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return all of the <code>AdjustmentListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public AdjustmentListener[] getAdjustmentListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   676
        return listenerList.getListeners(AdjustmentListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    protected void fireAdjustmentValueChanged(int id, int type, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        fireAdjustmentValueChanged(id, type, value, getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    private void fireAdjustmentValueChanged(int id, int type, int value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                            boolean isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        AdjustmentEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (listeners[i]==AdjustmentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    e = new AdjustmentEvent(this, id, type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * This class listens to ChangeEvents on the model and forwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * AdjustmentEvents for the sake of backwards compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Unfortunately there's no way to determine the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * type of the AdjustmentEvent as all updates to the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * value are considered equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    private class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        public void stateChanged(ChangeEvent e)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            Object obj = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            if (obj instanceof BoundedRangeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                int type = AdjustmentEvent.TRACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                BoundedRangeModel model = (BoundedRangeModel)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                int value = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                boolean isAdjusting = model.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                fireAdjustmentValueChanged(id, type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            }
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
    // PENDING(hmuller) - the next three methods should be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * The scrollbar is flexible along it's scrolling axis and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * rigid along the other axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (orientation == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            return new Dimension(pref.width, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            return new Dimension(5, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * The scrollbar is flexible along it's scrolling axis and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * rigid along the other axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            return new Dimension(pref.width, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            return new Dimension(Short.MAX_VALUE, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * Enables the component so that the knob position can be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * When the disabled, the knob position cannot be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @param x a boolean value, where true enables the component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *          false disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public void setEnabled(boolean x)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        super.setEnabled(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        Component[] children = getComponents();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   770
        for (Component child : children) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   771
            child.setEnabled(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Returns a string representation of this JScrollBar. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @return  a string representation of this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        ",blockIncrement=" + blockIncrement +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        ",unitIncrement=" + unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Gets the AccessibleContext associated with this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * For JScrollBar, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * AccessibleJScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * A new AccessibleJScrollBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @return an AccessibleJScrollBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *         AccessibleContext of this JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            accessibleContext = new AccessibleJScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * <code>JScrollBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Java Accessibility API appropriate to scroll bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20095
diff changeset
   841
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    protected class AccessibleJScrollBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        implements AccessibleValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            return AccessibleRole.SCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        public Number getCurrentAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   896
            return Integer.valueOf(getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            // TIGER - 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        public Number getMinimumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   919
            return Integer.valueOf(getMinimum());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            // TIGER - 4422362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            return new Integer(model.getMaximum() - model.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    } // AccessibleJScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
}