jdk/src/share/classes/javax/swing/JScrollBar.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 1301 15e81207e1f2
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @return the value of the unitIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see #setUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public int getUnitIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Sets the unitIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * the most look and feels will not provide the scrolling to the right/down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see #getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * description: The scrollbar's unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public void setUnitIncrement(int unitIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int oldValue = this.unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        this.unitIncrement = unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        firePropertyChange("unitIncrement", oldValue, unitIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Returns the amount to change the scrollbar's value by,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * given a block (usually "page") up/down request.  A ScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * implementation typically calls this method when the user clicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * above or below the scrollbar "knob" to change the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * up or down by large amount.  Subclasses my override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * method to compute a value, e.g. the change required to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * up or down one paragraph in a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * The JScrollPane component creates scrollbars (by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * that override this method and delegate to the viewports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Scrollable view, if it has one.  The Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * provides a more specialized version of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param direction is -1 or 1 for up/down respectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return the value of the blockIncrement property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see #setBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public int getBlockIncrement(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Sets the blockIncrement property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Note, that if the argument is equal to the value of Integer.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * the most look and feels will not provide the scrolling to the right/down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see #getBlockIncrement()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * description: The scrollbar's block increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void setBlockIncrement(int blockIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        int oldValue = this.blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        this.blockIncrement = blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        firePropertyChange("blockIncrement", oldValue, blockIncrement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see Adjustable#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see #getUnitIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public int getUnitIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * For backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @see Adjustable#getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see #getBlockIncrement(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public int getBlockIncrement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return blockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Returns the scrollbar's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @return the model's value property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return getModel().getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Sets the scrollbar's value.  This method just forwards the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @see BoundedRangeModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * description: The scrollbar's current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public void setValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        m.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   468
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   469
                    Integer.valueOf(m.getValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Returns the scrollbar's extent, aka its "visibleAmount".  In many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * scrollbar look and feel implementations the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * scrollbar "knob" or "thumb" is proportional to the extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @return the value of the model's extent property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public int getVisibleAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return getModel().getExtent();
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
     * Set the model's extent property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @see #getVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see BoundedRangeModel#setExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * description: The amount of the view that is currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public void setVisibleAmount(int extent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        getModel().setExtent(extent);
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
     * Returns the minimum value supported by the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * (usually zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @return the value of the model's minimum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return getModel().getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Sets the model's minimum property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @see BoundedRangeModel#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * description: The scrollbar's minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public void setMinimum(int minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        getModel().setMinimum(minimum);
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
     * The maximum value of the scrollbar is maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @return the value of the model's maximum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return getModel().getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Sets the model's maximum property.  Note that the scrollbar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * can only be set to maximum - extent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @see BoundedRangeModel#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * description: The scrollbar's maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public void setMaximum(int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        getModel().setMaximum(maximum);
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
     * True if the scrollbar knob is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @return the value of the model's valueIsAdjusting property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return getModel().getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Sets the model's valueIsAdjusting property.  Scrollbar look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * feel implementations should set this property to true when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * a knob drag begins, and to false when the drag ends.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * scrollbar model will not generate ChangeEvents while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * valueIsAdjusting is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see BoundedRangeModel#setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * description: True if the scrollbar thumb is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        boolean oldValue = m.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        m.setValueIsAdjusting(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    ((b) ? AccessibleState.BUSY : null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Sets the four BoundedRangeModel properties after forcing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * the arguments to obey the usual constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * minimum <= value <= value+extent <= maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see BoundedRangeModel#setRangeProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see #setVisibleAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public void setValues(int newValue, int newExtent, int newMin, int newMax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   614
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   615
                    Integer.valueOf(m.getValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * Adds an AdjustmentListener.  Adjustment listeners are notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * each time the scrollbar's model changes.  Adjustment events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * provided for backwards compatibility with java.awt.Scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Note that the AdjustmentEvents type property will always have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * placeholder value of AdjustmentEvent.TRACK because all changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * to a BoundedRangeModels value are considered equivalent.  To change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * the value of a BoundedRangeModel one just sets its value property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * i.e. model.setValue(123).  No information about the origin of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * change, e.g. it's a block decrement, is provided.  We don't try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * fabricate the origin of the change here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @param l the AdjustmentLister to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @see #removeAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @see BoundedRangeModel#addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public void addAdjustmentListener(AdjustmentListener l)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        listenerList.add(AdjustmentListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Removes an AdjustmentEvent listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param l the AdjustmentLister to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void removeAdjustmentListener(AdjustmentListener l)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        listenerList.remove(AdjustmentListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Returns an array of all the <code>AdjustmentListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * to this JScrollBar with addAdjustmentListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return all of the <code>AdjustmentListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public AdjustmentListener[] getAdjustmentListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return (AdjustmentListener[])listenerList.getListeners(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                AdjustmentListener.class);
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
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    protected void fireAdjustmentValueChanged(int id, int type, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        fireAdjustmentValueChanged(id, type, value, getValueIsAdjusting());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Notify listeners that the scrollbar's model has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @see #addAdjustmentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    private void fireAdjustmentValueChanged(int id, int type, int value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                            boolean isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        AdjustmentEvent e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            if (listeners[i]==AdjustmentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    e = new AdjustmentEvent(this, id, type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * This class listens to ChangeEvents on the model and forwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * AdjustmentEvents for the sake of backwards compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Unfortunately there's no way to determine the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * type of the AdjustmentEvent as all updates to the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * value are considered equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    private class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        public void stateChanged(ChangeEvent e)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            Object obj = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (obj instanceof BoundedRangeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                int type = AdjustmentEvent.TRACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                BoundedRangeModel model = (BoundedRangeModel)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                int value = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                boolean isAdjusting = model.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                fireAdjustmentValueChanged(id, type, value, isAdjusting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    // PENDING(hmuller) - the next three methods should be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * The scrollbar is flexible along it's scrolling axis and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * rigid along the other axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (orientation == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            return new Dimension(pref.width, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            return new Dimension(5, pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
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 getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        Dimension pref = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            return new Dimension(pref.width, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            return new Dimension(Short.MAX_VALUE, 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
     * Enables the component so that the knob position can be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * When the disabled, the knob position cannot be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @param x a boolean value, where true enables the component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *          false disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    public void setEnabled(boolean x)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        super.setEnabled(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        Component[] children = getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        for(int i = 0; i < children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            children[i].setEnabled(x);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                ui.installUI(this);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Returns a string representation of this JScrollBar. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return  a string representation of this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        ",blockIncrement=" + blockIncrement +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        ",unitIncrement=" + unitIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Gets the AccessibleContext associated with this JScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * For JScrollBar, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * AccessibleJScrollBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * A new AccessibleJScrollBar instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @return an AccessibleJScrollBar that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *         AccessibleContext of this JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            accessibleContext = new AccessibleJScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * <code>JScrollBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Java Accessibility API appropriate to scroll bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    protected class AccessibleJScrollBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        implements AccessibleValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            return AccessibleRole.SCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        public Number getCurrentAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   883
            return Integer.valueOf(getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            // TIGER - 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        public Number getMinimumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   906
            return Integer.valueOf(getMinimum());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            // TIGER - 4422362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            return new Integer(model.getMaximum() - model.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    } // AccessibleJScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
}