jdk/src/share/classes/javax/swing/JSlider.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 438 2ae294e4518c
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
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 javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A component that lets the user graphically select a value by sliding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a knob within a bounded interval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The slider can show both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * major tick marks, and minor tick marks between the major ones.  The number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * values between the tick marks is controlled with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>setMajorTickSpacing</code> and <code>setMinorTickSpacing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Painting of tick marks is controlled by {@code setPaintTicks}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Sliders can also print text labels at regular intervals (or at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * arbitrary locations) along the slider track.  Painting of labels is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * controlled by {@code setLabelTable} and {@code setPaintLabels}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * For further information and examples see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 href="http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html">How to Use Sliders</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *    description: A component that supports selecting a integer value from a range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
public class JSlider extends JComponent implements SwingConstants, Accessible {
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 = "SliderUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private boolean paintTicks = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private boolean paintTrack = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean paintLabels = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private boolean isInverted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * The data model that handles the numeric maximum value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * minimum value, and current-position value for the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected BoundedRangeModel sliderModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * The number of values between the major tick marks -- the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * larger marks that break up the minor tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    protected int majorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * The number of values between the minor tick marks -- the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * smaller marks that occur between the major tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #setMinorTickSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected int minorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * If true, the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * resolve to the closest tick mark next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * positioned the knob.  The default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #setSnapToTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected boolean snapToTicks = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * If true, the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * resolve to the closest slider value next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * positioned the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    boolean snapToValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Whether the slider is horizontal or vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The default is horizontal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * {@code Dictionary} of what labels to draw at which values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private Dictionary labelTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * The changeListener (no suffix) is the listener we add to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * slider's model.  This listener is initialized to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * {@code ChangeListener} returned from {@code createChangeListener},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * which by default just forwards events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * to {@code ChangeListener}s (if any) added directly to the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #createChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected ChangeListener changeListener = createChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Only one <code>ChangeEvent</code> is needed per slider instance since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * event's only (read-only) state is the source property.  The source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * of events generated here is always "this". The event is lazily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * created the first time that an event notification is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected transient ChangeEvent changeEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private void checkOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
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
     * Creates a horizontal slider with the range 0 to 100 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * an initial value of 50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public JSlider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this(HORIZONTAL, 0, 100, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Creates a slider using the specified orientation with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * range {@code 0} to {@code 100} and an initial value of {@code 50}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * The orientation can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * either <code>SwingConstants.VERTICAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <code>SwingConstants.HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param  orientation  the orientation of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public JSlider(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this(orientation, 0, 100, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Creates a horizontal slider using the specified min and max
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * with an initial value equal to the average of the min plus max.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * The <code>BoundedRangeModel</code> that holds the slider's data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * handles any issues that may arise from improperly setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * minimum and maximum values on the slider.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param min  the minimum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param max  the maximum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public JSlider(int min, int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        this(HORIZONTAL, min, max, (min + max) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Creates a horizontal slider using the specified min, max and value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * The <code>BoundedRangeModel</code> that holds the slider's data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * handles any issues that may arise from improperly setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * minimum, initial, and maximum values on the slider.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param min  the minimum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param max  the maximum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param value  the initial value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public JSlider(int min, int max, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        this(HORIZONTAL, min, max, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Creates a slider with the specified orientation and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * specified minimum, maximum, and initial values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * The orientation can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * either <code>SwingConstants.VERTICAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <code>SwingConstants.HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * The <code>BoundedRangeModel</code> that holds the slider's data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * handles any issues that may arise from improperly setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * minimum, initial, and maximum values on the slider.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param orientation  the orientation of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param min  the minimum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param max  the maximum value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param value  the initial value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public JSlider(int orientation, int min, int max, int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        sliderModel = new DefaultBoundedRangeModel(value, 0, min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        sliderModel.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Creates a horizontal slider using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * BoundedRangeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public JSlider(BoundedRangeModel brm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        this.orientation = JSlider.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        setModel(brm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        sliderModel.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Gets the UI object which implements the L&F for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return the SliderUI object that implements the Slider L&F
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public SliderUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return(SliderUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Sets the UI object which implements the L&F for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param ui the SliderUI L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *  description: The UI object that implements the slider's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public void setUI(SliderUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        setUI((SliderUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // The labels preferred size may be derived from the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // of the slider, so we must update the UI of the slider first, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        // that of labels.  This way when setSize is called the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // font is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        updateLabelUIs();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Returns the name of the L&F class that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return "SliderUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * We pass Change events along to the listeners with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * the slider (instead of the model itself) as the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
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
     * Subclasses that want to handle {@code ChangeEvent}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * from the model differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * can override this to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * an instance of a custom <code>ChangeListener</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * The default {@code ChangeListener} simply calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * {@code fireStateChanged} method to forward {@code ChangeEvent}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * to the {@code ChangeListener}s that have been added directly to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see #changeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see javax.swing.event.ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see javax.swing.BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    protected ChangeListener createChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return new ModelListener();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Adds a ChangeListener to the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param l the ChangeListener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see #removeChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public void addChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        listenerList.add(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Removes a ChangeListener from the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param l the ChangeListener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void removeChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        listenerList.remove(ChangeListener.class, l);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns an array of all the <code>ChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * to this JSlider with addChangeListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @return all of the <code>ChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public ChangeListener[] getChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return (ChangeListener[])listenerList.getListeners(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                ChangeListener.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Send a {@code ChangeEvent}, whose source is this {@code JSlider}, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * all {@code ChangeListener}s that have registered interest in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * {@code ChangeEvent}s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * This method is called each time a {@code ChangeEvent} is received from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * The event instance is created if necessary, and stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * {@code changeEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    protected void fireStateChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (listeners[i]==ChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                if (changeEvent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Returns the {@code BoundedRangeModel} that handles the slider's three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * fundamental properties: minimum, maximum, value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return the data model for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see    BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public BoundedRangeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return sliderModel;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Sets the {@code BoundedRangeModel} that handles the slider's three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * fundamental properties: minimum, maximum, value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * Attempts to pass a {@code null} model to this method result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * undefined behavior, and, most likely, exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @param  newModel the new, {@code non-null} <code>BoundedRangeModel</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see    BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * description: The sliders BoundedRangeModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public void setModel(BoundedRangeModel newModel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        BoundedRangeModel oldModel = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            oldModel.removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        sliderModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (newModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            newModel.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                    (oldModel == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                     ? null : new Integer(oldModel.getValue())),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                    (newModel == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                     ? null : new Integer(newModel.getValue())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        firePropertyChange("model", oldModel, sliderModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Returns the slider's current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * from the {@code BoundedRangeModel}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @return  the current value of the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see     #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see     BoundedRangeModel#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return getModel().getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Sets the slider's current value to {@code n}.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * forwards the new value to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * The data model (an instance of {@code BoundedRangeModel})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * issues arising from assigning faulty values.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * If the new value is different from the previous value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @param   n       the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see     #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see     #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see     BoundedRangeModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * description: The sliders current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public void setValue(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        int oldValue = m.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (oldValue == n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        m.setValue(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                new Integer(oldValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                                new Integer(m.getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Returns the minimum value supported by the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @return the value of the model's minimum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @see #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @see     BoundedRangeModel#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    public int getMinimum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        return getModel().getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Sets the slider's minimum value to {@code minimum}.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * forwards the new minimum value to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * The data model (an instance of {@code BoundedRangeModel})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * issues arising from assigning faulty values.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * If the new minimum value is different from the previous minimum value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @param minimum  the new minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @see    #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @see BoundedRangeModel#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * description: The sliders minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public void setMinimum(int minimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        int oldMin = getModel().getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        getModel().setMinimum(minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        firePropertyChange( "minimum", new Integer( oldMin ), new Integer( minimum ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Returns the maximum value supported by the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return the value of the model's maximum property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @see #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @see BoundedRangeModel#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public int getMaximum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return getModel().getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Sets the slider's maximum value to {@code maximum}.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * forwards the new maximum value to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * The data model (an instance of {@code BoundedRangeModel})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * issues arising from assigning faulty values.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * If the new maximum value is different from the previous maximum value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param maximum  the new maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @see #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see BoundedRangeModel#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * description: The sliders maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public void setMaximum(int maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        int oldMax = getModel().getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        getModel().setMaximum(maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        firePropertyChange( "maximum", new Integer( oldMax ), new Integer( maximum ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Returns the {@code valueIsAdjusting} property from the model.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * details on how this is used, see the {@code setValueIsAdjusting}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @return the value of the model's {@code valueIsAdjusting} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @see #setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public boolean getValueIsAdjusting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return getModel().getValueIsAdjusting();
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
     * Sets the model's {@code valueIsAdjusting} property.  Slider look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * feel implementations should set this property to {@code true} when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * a knob drag begins, and to {@code false} when the drag ends.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * slider model will not generate {@code ChangeEvent}s while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * {@code valueIsAdjusting} is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @param b the new value for the {@code valueIsAdjusting} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @see   #getValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @see   BoundedRangeModel#setValueIsAdjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * description: True if the slider knob is being dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    public void setValueIsAdjusting(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        BoundedRangeModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        boolean oldValue = m.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        m.setValueIsAdjusting(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if ((oldValue != b) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                                                AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                                ((oldValue) ? AccessibleState.BUSY : null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                                                ((b) ? AccessibleState.BUSY : null));
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Returns the "extent" from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * This respresents the range of values "covered" by the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @return an int representing the extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @see #setExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @see BoundedRangeModel#getExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public int getExtent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return getModel().getExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Sets the size of the range "covered" by the knob.  Most look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * and feel implementations will change the value by this amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * if the user clicks on either side of the knob.  This method just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * forwards the new extent value to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * The data model (an instance of {@code BoundedRangeModel})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * issues arising from assigning faulty values.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * If the new extent value is different from the previous extent value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @param extent the new extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see   #getExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see   BoundedRangeModel#setExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * description: Size of the range covered by the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public void setExtent(int extent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        getModel().setExtent(extent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * Return this slider's vertical or horizontal orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @return {@code SwingConstants.VERTICAL} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *  {@code SwingConstants.HORIZONTAL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Set the slider's orientation to either {@code SwingConstants.VERTICAL} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * {@code SwingConstants.HORIZONTAL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @param orientation {@code HORIZONTAL} or {@code VERTICAL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *  description: Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *         enum: VERTICAL JSlider.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *               HORIZONTAL JSlider.HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public void setOrientation(int orientation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        checkOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        int oldValue = this.orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        firePropertyChange("orientation", oldValue, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if ((oldValue != orientation) && (accessibleContext != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                                                AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                                                ((oldValue == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                                 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                                                ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                                 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (orientation != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    public void setFont(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        super.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        updateLabelSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * Returns the dictionary of what labels to draw at which values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @return the <code>Dictionary</code> containing labels and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *    where to draw them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public Dictionary getLabelTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if ( labelTable == null && getMajorTickSpacing() > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return labelTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * Used to specify what label will be drawn at any given value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * The key-value pairs are of this format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * <code>{ Integer value, java.swing.JComponent label }</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * An easy way to generate a standard table of value labels is by using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * {@code createStandardLabels} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Once the labels have been set, this method calls {@link #updateLabelUIs}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Note that the labels are only painted if the {@code paintLabels}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * property is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @param labels new {@code Dictionary} of labels, or {@code null} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *        remove all labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see #createStandardLabels(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @see #getLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see #setPaintLabels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *  description: Specifies what labels will be drawn for any given value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    public void setLabelTable( Dictionary labels ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        Dictionary oldTable = labelTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        labelTable = labels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        updateLabelUIs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        firePropertyChange("labelTable", oldTable, labelTable );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (labels != oldTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Updates the UIs for the labels in the label table by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * {@code updateUI} on each label.  The UIs are updated from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * the current look and feel.  The labels are also set to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @see #setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    protected void updateLabelUIs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        if ( getLabelTable() == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        Enumeration labels = getLabelTable().keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        while ( labels.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            Object value = getLabelTable().get( labels.nextElement() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            if ( value instanceof JComponent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                JComponent component = (JComponent)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                component.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                component.setSize( component.getPreferredSize()  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    private void updateLabelSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        Dictionary labelTable = getLabelTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (labelTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            Enumeration labels = labelTable.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            while (labels.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                Object value = labels.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                if (value instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    JComponent component = (JComponent)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    component.setSize(component.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Creates a {@code Hashtable} of numerical text labels, starting at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * slider minimum, and using the increment specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * For example, if you call <code>createStandardLabels( 10 )</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * and the slider minimum is zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * then labels will be created for the values 0, 10, 20, 30, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * For the labels to be drawn on the slider, the returned {@code Hashtable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * must be passed into {@code setLabelTable}, and {@code setPaintLabels}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * must be set to {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * For further details on the makeup of the returned {@code Hashtable}, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * the {@code setLabelTable} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @param  increment  distance between labels in the generated hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @return a new {@code Hashtable} of labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see #setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @see #setPaintLabels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @throws IllegalArgumentException if {@code increment} is less than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *          equal to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public Hashtable createStandardLabels( int increment ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        return createStandardLabels( increment, getMinimum() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * Creates a {@code Hashtable} of numerical text labels, starting at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * starting point specified, and using the increment specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * For example, if you call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <code>createStandardLabels( 10, 2 )</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * then labels will be created for the values 2, 12, 22, 32, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * For the labels to be drawn on the slider, the returned {@code Hashtable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * must be passed into {@code setLabelTable}, and {@code setPaintLabels}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * must be set to {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * For further details on the makeup of the returned {@code Hashtable}, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * the {@code setLabelTable} documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @param  increment  distance between labels in the generated hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @param  start      value at which the labels will begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @return a new {@code Hashtable} of labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @see #setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @see #setPaintLabels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @exception IllegalArgumentException if {@code start} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *          out of range, or if {@code increment} is less than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *          to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    public Hashtable createStandardLabels( int increment, int start ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        if ( start > getMaximum() || start < getMinimum() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            throw new IllegalArgumentException( "Slider label start point out of range." );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        if ( increment <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            throw new IllegalArgumentException( "Label incremement must be > 0" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        class SmartHashtable extends Hashtable implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            int increment = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            boolean startAtMin = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            class LabelUIResource extends JLabel implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                public LabelUIResource( String text, int alignment ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    super( text, alignment );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    setName("Slider.label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    Font font = super.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    if (font != null && !(font instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    return JSlider.this.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    Color fg = super.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    if (fg != null && !(fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                        return fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    if (!(JSlider.this.getForeground() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                        return JSlider.this.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    return fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            public SmartHashtable( int increment, int start ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                this.increment = increment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                startAtMin = start == getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                createLabels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            public void propertyChange( PropertyChangeEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                if ( e.getPropertyName().equals( "minimum" ) && startAtMin ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    start = getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                if ( e.getPropertyName().equals( "minimum" ) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                     e.getPropertyName().equals( "maximum" ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    Enumeration keys = getLabelTable().keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    Object key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    Hashtable hashtable = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    // Save the labels that were added by the developer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    while ( keys.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                        key = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        Object value = getLabelTable().get( key );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                        if ( !(value instanceof LabelUIResource) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                            hashtable.put( key, value );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    createLabels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    // Add the saved labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                    keys = hashtable.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    while ( keys.hasMoreElements() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                        key = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                        put( key, hashtable.get( key ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    ((JSlider)e.getSource()).setLabelTable( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            void createLabels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                for ( int labelIndex = start; labelIndex <= getMaximum(); labelIndex += increment ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    put( new Integer( labelIndex ), new LabelUIResource( ""+labelIndex, JLabel.CENTER ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        SmartHashtable table = new SmartHashtable( increment, start );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        if ( getLabelTable() != null && (getLabelTable() instanceof PropertyChangeListener) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            removePropertyChangeListener( (PropertyChangeListener)getLabelTable() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        addPropertyChangeListener( table );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * Returns true if the value-range shown for the slider is reversed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @return true if the slider values are reversed from their normal order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * @see #setInverted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public boolean getInverted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        return isInverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * Specify true to reverse the value-range shown for the slider and false to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * put the value range in the normal order.  The order depends on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * slider's <code>ComponentOrientation</code> property.  Normal (non-inverted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * horizontal sliders with a <code>ComponentOrientation</code> value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <code>LEFT_TO_RIGHT</code> have their maximum on the right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Normal horizontal sliders with a <code>ComponentOrientation</code> value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <code>RIGHT_TO_LEFT</code> have their maximum on the left.  Normal vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * sliders have their maximum on the top.  These labels are reversed when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * slider is inverted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * By default, the value of this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @param b  true to reverse the slider values from their normal order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *  description: If true reverses the slider values from their normal order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    public void setInverted( boolean b ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        boolean oldValue = isInverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        isInverted = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        firePropertyChange("inverted", oldValue, isInverted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        if (b != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * This method returns the major tick spacing.  The number that is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * represents the distance, measured in values, between each major tick mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * If you have a slider with a range from 0 to 50 and the major tick spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * is set to 10, you will get major ticks next to the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * 0, 10, 20, 30, 40, 50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * @return the number of values between major ticks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * @see #setMajorTickSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    public int getMajorTickSpacing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        return majorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * This method sets the major tick spacing.  The number that is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * represents the distance, measured in values, between each major tick mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * If you have a slider with a range from 0 to 50 and the major tick spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * is set to 10, you will get major ticks next to the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * 0, 10, 20, 30, 40, 50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * In order for major ticks to be painted, {@code setPaintTicks} must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * set to {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * This method will also set up a label table for you.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * If there is not already a label table, and the major tick spacing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * {@code > 0}, and {@code getPaintLabels} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * {@code true}, a standard label table will be generated (by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * {@code createStandardLabels}) with labels at the major tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * For the example above, you would get text labels: "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * "10", "20", "30", "40", "50".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * The label table is then set on the slider by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * {@code setLabelTable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @param  n  new value for the {@code majorTickSpacing} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @see #getMajorTickSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @see #setPaintTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @see #setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * @see #createStandardLabels(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *  description: Sets the number of values between major tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    public void setMajorTickSpacing(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        int oldValue = majorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        majorTickSpacing = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        if ( labelTable == null && getMajorTickSpacing() > 0 && getPaintLabels() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        firePropertyChange("majorTickSpacing", oldValue, majorTickSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        if (majorTickSpacing != oldValue && getPaintTicks()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * This method returns the minor tick spacing.  The number that is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * represents the distance, measured in values, between each minor tick mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * If you have a slider with a range from 0 to 50 and the minor tick spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * is set to 10, you will get minor ticks next to the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * 0, 10, 20, 30, 40, 50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @return the number of values between minor ticks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @see #getMinorTickSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    public int getMinorTickSpacing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        return minorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * This method sets the minor tick spacing.  The number that is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * represents the distance, measured in values, between each minor tick mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * If you have a slider with a range from 0 to 50 and the minor tick spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * is set to 10, you will get minor ticks next to the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * 0, 10, 20, 30, 40, 50.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * In order for minor ticks to be painted, {@code setPaintTicks} must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * set to {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @param  n  new value for the {@code minorTickSpacing} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @see #getMinorTickSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @see #setPaintTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *  description: Sets the number of values between minor tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    public void setMinorTickSpacing(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        int oldValue = minorTickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        minorTickSpacing = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        firePropertyChange("minorTickSpacing", oldValue, minorTickSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (minorTickSpacing != oldValue && getPaintTicks()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * Returns true if the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * resolve to the closest tick mark next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * positioned the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @return true if the value snaps to the nearest tick mark, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * @see #setSnapToTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public boolean getSnapToTicks() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        return snapToTicks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * Returns true if the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * resolve to the closest slider value next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * positioned the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @return true if the value snaps to the nearest slider value, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @see #setSnapToValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    boolean getSnapToValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        return snapToValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * Specifying true makes the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * resolve to the closest tick mark next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * positioned the knob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * By default, this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @param b  true to snap the knob to the nearest tick mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @see #getSnapToTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * description: If true snap the knob to the nearest tick mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    public void setSnapToTicks(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        boolean oldValue = snapToTicks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        snapToTicks = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        firePropertyChange("snapToTicks", oldValue, snapToTicks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * Specifying true makes the knob (and the data value it represents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * resolve to the closest slider value next to where the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * positioned the knob. If the {@code snapToTicks} property has also been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * set to {@code true}, the snap-to-ticks behavior will prevail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * By default, the snapToValue property is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @param b  true to snap the knob to the nearest slider value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * @see #getSnapToValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @see #setSnapToTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * description: If true snap the knob to the nearest slider value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    void setSnapToValue(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        boolean oldValue = snapToValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        snapToValue = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        firePropertyChange("snapToValue", oldValue, snapToValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * Tells if tick marks are to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * @return true if tick marks are painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * @see #setPaintTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    public boolean getPaintTicks() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        return paintTicks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Determines whether tick marks are painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * By default, this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @param  b  whether or not tick marks should be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * @see #getPaintTicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *  description: If true tick marks are painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    public void setPaintTicks(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        boolean oldValue = paintTicks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        paintTicks = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        firePropertyChange("paintTicks", oldValue, paintTicks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        if (paintTicks != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * Tells if the track (area the slider slides in) is to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * @return true if track is painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * @see #setPaintTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    public boolean getPaintTrack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        return paintTrack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * Determines whether the track is painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * By default, this property is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * @param  b  whether or not to paint the slider track
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * @see #getPaintTrack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     *  description: If true, the track is painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    public void setPaintTrack(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        boolean oldValue = paintTrack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        paintTrack = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        firePropertyChange("paintTrack", oldValue, paintTrack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        if (paintTrack != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * Tells if labels are to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * @return true if labels are painted, else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @see #setPaintLabels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    public boolean getPaintLabels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        return paintLabels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * Determines whether labels are painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * This method will also set up a label table for you.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * If there is not already a label table, and the major tick spacing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * {@code > 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * a standard label table will be generated (by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * {@code createStandardLabels}) with labels at the major tick marks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * The label table is then set on the slider by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * {@code setLabelTable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * By default, this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @param  b  whether or not to paint labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @see #getPaintLabels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @see #getLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * @see #createStandardLabels(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     *  description: If true labels are painted on the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    public void setPaintLabels(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        boolean oldValue = paintLabels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        paintLabels = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        if ( labelTable == null && getMajorTickSpacing() > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        firePropertyChange("paintLabels", oldValue, paintLabels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        if (paintLabels != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * Returns a string representation of this JSlider. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * @return  a string representation of this JSlider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        String paintTicksString = (paintTicks ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        String paintTrackString = (paintTrack ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        String paintLabelsString = (paintLabels ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        String isInvertedString = (isInverted ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        String snapToTicksString = (snapToTicks ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        String snapToValueString = (snapToValue ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        ",isInverted=" + isInvertedString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        ",majorTickSpacing=" + majorTickSpacing +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        ",minorTickSpacing=" + minorTickSpacing +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        ",paintLabels=" + paintLabelsString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        ",paintTicks=" + paintTicksString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        ",paintTrack=" + paintTrackString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        ",snapToTicks=" + snapToTicksString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        ",snapToValue=" + snapToValueString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Gets the AccessibleContext associated with this JSlider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * For sliders, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * AccessibleJSlider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * A new AccessibleJSlider instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * @return an AccessibleJSlider that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     *         AccessibleContext of this JSlider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            accessibleContext = new AccessibleJSlider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * <code>JSlider</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * Java Accessibility API appropriate to slider user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    protected class AccessibleJSlider extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    implements AccessibleValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
         * Get the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            if (getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            return AccessibleRole.SLIDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
         * Get the AccessibleValue associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
         * AccessibleValue interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
         * Get the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
         * @return The current value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        public Number getCurrentAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            return new Integer(getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
         * Set the value of this object as a Number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
         * @return True if the value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            // TIGER - 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
         * Get the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
         * @return The minimum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        public Number getMinimumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            return new Integer(getMinimum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
         * Get the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
         * @return The maximum value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            // TIGER - 4422362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            BoundedRangeModel model = JSlider.this.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            return new Integer(model.getMaximum() - model.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    } // AccessibleJSlider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
}