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