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