jdk/src/share/classes/javax/swing/JScrollBar.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 22574 7f8ce0c8c20a
child 24983 f5a6e2ed8c7d
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
    81
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public class JScrollBar extends JComponent implements Adjustable, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final String uiClassID = "ScrollBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * All changes from the model are treated as though the user moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * the scrollbar knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private ChangeListener fwdAdjustmentEvents = new ModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The model that represents the scrollbar's minimum, maximum, extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * (aka "visibleAmount") and current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    protected BoundedRangeModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected int unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected int blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private void checkOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Creates a scrollbar with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * value, extent, minimum, and maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The "extent" is the size of the viewable area. It is also known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * as the "visible amount".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Note: Use <code>setBlockIncrement</code> to set the block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * increment to a size slightly smaller than the view's extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * That way, when the user jumps the knob to an adjacent position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * one or two lines of the original contents remain in view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public JScrollBar(int orientation, int value, int extent, int min, int max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.unitIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.blockIncrement = (extent == 0) ? 1 : extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.model = new DefaultBoundedRangeModel(value, extent, min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this.model.addChangeListener(fwdAdjustmentEvents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        updateUI();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Creates a scrollbar with the specified orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * and the following initial values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * minimum = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * maximum = 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * value = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * extent = 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public JScrollBar(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this(orientation, 0, 10, 0, 100);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Creates a vertical scrollbar with the following initial values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * minimum = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * maximum = 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * value = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * extent = 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public JScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this(VERTICAL);
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
    /**
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   196
     * Sets the {@literal L&F} object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   198
     * @param ui  the <code>ScrollBarUI</code> {@literal L&F} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *  description: The UI object that implements the Component's LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public void setUI(ScrollBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        super.setUI(ui);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Returns the delegate that implements the look and feel for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see JComponent#setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public ScrollBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return (ScrollBarUI)ui;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Overrides <code>JComponent.updateUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        setUI((ScrollBarUI)UIManager.getUI(this));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns the name of the LookAndFeel class for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return "ScrollBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return uiClassID;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns the component's orientation (horizontal or vertical).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return VERTICAL or HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see java.awt.Adjustable#getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return orientation;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Set the scrollbar's orientation to either VERTICAL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * HORIZONTAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *  description: The scrollbar's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *         enum: VERTICAL JScrollBar.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *               HORIZONTAL JScrollBar.HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void setOrientation(int orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int oldValue = this.orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        firePropertyChange("orientation", oldValue, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if ((oldValue != orientation) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    ((oldValue == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                     ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (orientation != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            revalidate();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Returns data model that handles the scrollbar's four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * fundamental properties: minimum, maximum, value, extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public BoundedRangeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return model;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Sets the model that handles the scrollbar's four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * fundamental properties: minimum, maximum, value, extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * description: The scrollbar's BoundedRangeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void setModel(BoundedRangeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Integer oldValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        BoundedRangeModel oldModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            model.removeChangeListener(fwdAdjustmentEvents);
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   318
            oldValue = Integer.valueOf(model.getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        model = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            model.addChangeListener(fwdAdjustmentEvents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        firePropertyChange("model", oldModel, model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    oldValue, new Integer(model.getValue()));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Returns the amount to change the scrollbar's value by,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * given a unit up/down request.  A ScrollBarUI implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * typically calls this method when the user clicks on a scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * up/down arrow and uses the result to update the scrollbar's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * value.   Subclasses my override this method to compute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * a value, e.g. the change required to scroll up or down one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * (variable height) line text or one row in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * The JScrollPane component creates scrollbars (by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * that override this method and delegate to the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Scrollable view, if it has one.  The Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * 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
   348
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   349
     * 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
   350
     * and ignore this property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return the value of the unitIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public int getUnitIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return unitIncrement;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Sets the unitIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * 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
   368
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   369
     * 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
   370
     * and ignore this property.
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   371
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see #getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * description: The scrollbar's unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public void setUnitIncrement(int unitIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int oldValue = this.unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        this.unitIncrement = unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        firePropertyChange("unitIncrement", oldValue, unitIncrement);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns the amount to change the scrollbar's value by,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * given a block (usually "page") up/down request.  A ScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * implementation typically calls this method when the user clicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * above or below the scrollbar "knob" to change the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * up or down by large amount.  Subclasses my override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * method to compute a value, e.g. the change required to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * up or down one paragraph in a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * The JScrollPane component creates scrollbars (by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * that override this method and delegate to the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Scrollable view, if it has one.  The Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * 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
   398
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   399
     * 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
   400
     * and ignore this property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return the value of the blockIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public int getBlockIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return blockIncrement;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Sets the blockIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * 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
   418
     * <p>
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   419
     * 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
   420
     * and ignore this property.
619a080ff304 7057769: JScrollBar spec should specify that unit increment & decrement functionality may not be present
malenkov
parents: 5506
diff changeset
   421
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see #getBlockIncrement()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * description: The scrollbar's block increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public void setBlockIncrement(int blockIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        int oldValue = this.blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        this.blockIncrement = blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        firePropertyChange("blockIncrement", oldValue, blockIncrement);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see Adjustable#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see #getUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return unitIncrement;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see Adjustable#getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #getBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return blockIncrement;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Returns the scrollbar's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @return the model's value property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return getModel().getValue();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Sets the scrollbar's value.  This method just forwards the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see BoundedRangeModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * description: The scrollbar's current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public void setValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        m.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   483
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   484
                    Integer.valueOf(m.getValue()));
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Returns the scrollbar's extent, aka its "visibleAmount".  In many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * scrollbar look and feel implementations the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * scrollbar "knob" or "thumb" is proportional to the extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @return the value of the model's extent property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return getModel().getExtent();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Set the model's extent property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see BoundedRangeModel#setExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * description: The amount of the view that is currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public void setVisibleAmount(int extent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        getModel().setExtent(extent);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Returns the minimum value supported by the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * (usually zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @return the value of the model's minimum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return getModel().getMinimum();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Sets the model's minimum property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @see BoundedRangeModel#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * description: The scrollbar's minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public void setMinimum(int minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        getModel().setMinimum(minimum);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * The maximum value of the scrollbar is maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return the value of the model's maximum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return getModel().getMaximum();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Sets the model's maximum property.  Note that the scrollbar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * can only be set to maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see BoundedRangeModel#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * description: The scrollbar's maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public void setMaximum(int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        getModel().setMaximum(maximum);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * True if the scrollbar knob is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @return the value of the model's valueIsAdjusting property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return getModel().getValueIsAdjusting();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Sets the model's valueIsAdjusting property.  Scrollbar look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * feel implementations should set this property to true when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * a knob drag begins, and to false when the drag ends.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * scrollbar model will not generate ChangeEvents while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * valueIsAdjusting is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @see BoundedRangeModel#setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * description: True if the scrollbar thumb is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        boolean oldValue = m.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        m.setValueIsAdjusting(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    ((b) ? AccessibleState.BUSY : null));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Sets the four BoundedRangeModel properties after forcing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * the arguments to obey the usual constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <pre>
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   610
     * minimum &le; value &le; value+extent &le; maximum
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * </pre>
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   612
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @see BoundedRangeModel#setRangeProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public void setValues(int newValue, int newExtent, int newMin, int newMax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   629
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   630
                    Integer.valueOf(m.getValue()));
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Adds an AdjustmentListener.  Adjustment listeners are notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * each time the scrollbar's model changes.  Adjustment events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * provided for backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Note that the AdjustmentEvents type property will always have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * placeholder value of AdjustmentEvent.TRACK because all changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * to a BoundedRangeModels value are considered equivalent.  To change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * the value of a BoundedRangeModel one just sets its value property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * i.e. model.setValue(123).  No information about the origin of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * change, e.g. it's a block decrement, is provided.  We don't try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * fabricate the origin of the change here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @param l the AdjustmentLister to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @see BoundedRangeModel#addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public void addAdjustmentListener(AdjustmentListener l)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        listenerList.add(AdjustmentListener.class, l);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Removes an AdjustmentEvent listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @param l the AdjustmentLister to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public void removeAdjustmentListener(AdjustmentListener l)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        listenerList.remove(AdjustmentListener.class, l);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Returns an array of all the <code>AdjustmentListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * to this JScrollBar with addAdjustmentListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @return all of the <code>AdjustmentListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    public AdjustmentListener[] getAdjustmentListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   677
        return listenerList.getListeners(AdjustmentListener.class);
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    protected void fireAdjustmentValueChanged(int id, int type, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        fireAdjustmentValueChanged(id, type, value, getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    private void fireAdjustmentValueChanged(int id, int type, int value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                                            boolean isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        AdjustmentEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (listeners[i]==AdjustmentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    e = new AdjustmentEvent(this, id, type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * This class listens to ChangeEvents on the model and forwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * AdjustmentEvents for the sake of backwards compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Unfortunately there's no way to determine the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * type of the AdjustmentEvent as all updates to the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * value are considered equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    private class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        public void stateChanged(ChangeEvent e)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            Object obj = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            if (obj instanceof BoundedRangeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                int type = AdjustmentEvent.TRACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                BoundedRangeModel model = (BoundedRangeModel)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                int value = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                boolean isAdjusting = model.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                fireAdjustmentValueChanged(id, type, value, isAdjusting);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    // PENDING(hmuller) - the next three methods should be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * The scrollbar is flexible along it's scrolling axis and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * rigid along the other axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (orientation == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            return new Dimension(pref.width, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            return new Dimension(5, pref.height);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * The scrollbar is flexible along it's scrolling axis and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * rigid along the other axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            return new Dimension(pref.width, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            return new Dimension(Short.MAX_VALUE, pref.height);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Enables the component so that the knob position can be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * When the disabled, the knob position cannot be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @param x a boolean value, where true enables the component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *          false disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public void setEnabled(boolean x)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        super.setEnabled(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        Component[] children = getComponents();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   771
        for (Component child : children) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   772
            child.setEnabled(x);
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                ui.installUI(this);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Returns a string representation of this JScrollBar. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @return  a string representation of this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        ",blockIncrement=" + blockIncrement +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        ",unitIncrement=" + unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Gets the AccessibleContext associated with this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * For JScrollBar, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * AccessibleJScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * A new AccessibleJScrollBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @return an AccessibleJScrollBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *         AccessibleContext of this JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            accessibleContext = new AccessibleJScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * <code>JScrollBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Java Accessibility API appropriate to scroll bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * 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
   842
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
   846
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    protected class AccessibleJScrollBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        implements AccessibleValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            return AccessibleRole.SCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        public Number getCurrentAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   898
            return Integer.valueOf(getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            // TIGER - 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        public Number getMinimumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   921
            return Integer.valueOf(getMinimum());
2
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
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            // TIGER - 4422362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            return new Integer(model.getMaximum() - model.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    } // AccessibleJScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
}