0N/A/*
3909N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.IOException;
0N/A
343N/Aimport java.awt.*;
0N/Aimport java.util.*;
0N/Aimport java.beans.*;
0N/A
0N/A
0N/A/**
0N/A * A component that lets the user graphically select a value by sliding
3305N/A * a knob within a bounded interval. The knob is always positioned
3305N/A * at the points that match integer values within the specified interval.
0N/A * <p>
0N/A * The slider can show both
0N/A * major tick marks, and minor tick marks between the major ones. The number of
0N/A * values between the tick marks is controlled with
0N/A * <code>setMajorTickSpacing</code> and <code>setMinorTickSpacing</code>.
0N/A * Painting of tick marks is controlled by {@code setPaintTicks}.
0N/A * <p>
0N/A * Sliders can also print text labels at regular intervals (or at
0N/A * arbitrary locations) along the slider track. Painting of labels is
0N/A * controlled by {@code setLabelTable} and {@code setPaintLabels}.
0N/A * <p>
0N/A * For further information and examples see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html">How to Use Sliders</a>,
0N/A * a section in <em>The Java Tutorial.</em>
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer false
0N/A * description: A component that supports selecting a integer value from a range.
0N/A *
0N/A * @author David Kloba
0N/A */
0N/Apublic class JSlider extends JComponent implements SwingConstants, Accessible {
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "SliderUI";
0N/A
0N/A private boolean paintTicks = false;
0N/A private boolean paintTrack = true;
0N/A private boolean paintLabels = false;
0N/A private boolean isInverted = false;
0N/A
0N/A /**
0N/A * The data model that handles the numeric maximum value,
0N/A * minimum value, and current-position value for the slider.
0N/A */
0N/A protected BoundedRangeModel sliderModel;
0N/A
0N/A /**
0N/A * The number of values between the major tick marks -- the
0N/A * larger marks that break up the minor tick marks.
0N/A */
0N/A protected int majorTickSpacing;
0N/A
0N/A /**
0N/A * The number of values between the minor tick marks -- the
0N/A * smaller marks that occur between the major tick marks.
0N/A * @see #setMinorTickSpacing
0N/A */
0N/A protected int minorTickSpacing;
0N/A
0N/A /**
0N/A * If true, the knob (and the data value it represents)
0N/A * resolve to the closest tick mark next to where the user
0N/A * positioned the knob. The default is false.
0N/A * @see #setSnapToTicks
0N/A */
0N/A protected boolean snapToTicks = false;
0N/A
0N/A /**
0N/A * If true, the knob (and the data value it represents)
0N/A * resolve to the closest slider value next to where the user
0N/A * positioned the knob.
0N/A */
0N/A boolean snapToValue = true;
0N/A
0N/A /**
0N/A * Whether the slider is horizontal or vertical
0N/A * The default is horizontal.
0N/A *
0N/A * @see #setOrientation
0N/A */
0N/A protected int orientation;
0N/A
0N/A
0N/A /**
0N/A * {@code Dictionary} of what labels to draw at which values
0N/A */
0N/A private Dictionary labelTable;
0N/A
0N/A
0N/A /**
0N/A * The changeListener (no suffix) is the listener we add to the
0N/A * slider's model. This listener is initialized to the
0N/A * {@code ChangeListener} returned from {@code createChangeListener},
0N/A * which by default just forwards events
0N/A * to {@code ChangeListener}s (if any) added directly to the slider.
0N/A *
0N/A * @see #addChangeListener
0N/A * @see #createChangeListener
0N/A */
0N/A protected ChangeListener changeListener = createChangeListener();
0N/A
0N/A
0N/A /**
0N/A * Only one <code>ChangeEvent</code> is needed per slider instance since the
0N/A * event's only (read-only) state is the source property. The source
0N/A * of events generated here is always "this". The event is lazily
0N/A * created the first time that an event notification is fired.
0N/A *
0N/A * @see #fireStateChanged
0N/A */
0N/A protected transient ChangeEvent changeEvent = null;
0N/A
0N/A
0N/A private void checkOrientation(int orientation) {
0N/A switch (orientation) {
0N/A case VERTICAL:
0N/A case HORIZONTAL:
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a horizontal slider with the range 0 to 100 and
0N/A * an initial value of 50.
0N/A */
0N/A public JSlider() {
0N/A this(HORIZONTAL, 0, 100, 50);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a slider using the specified orientation with the
0N/A * range {@code 0} to {@code 100} and an initial value of {@code 50}.
0N/A * The orientation can be
0N/A * either <code>SwingConstants.VERTICAL</code> or
0N/A * <code>SwingConstants.HORIZONTAL</code>.
0N/A *
0N/A * @param orientation the orientation of the slider
0N/A * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
0N/A * @see #setOrientation
0N/A */
0N/A public JSlider(int orientation) {
0N/A this(orientation, 0, 100, 50);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a horizontal slider using the specified min and max
0N/A * with an initial value equal to the average of the min plus max.
0N/A * <p>
0N/A * The <code>BoundedRangeModel</code> that holds the slider's data
0N/A * handles any issues that may arise from improperly setting the
0N/A * minimum and maximum values on the slider. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A *
0N/A * @param min the minimum value of the slider
0N/A * @param max the maximum value of the slider
0N/A *
0N/A * @see BoundedRangeModel
0N/A * @see #setMinimum
0N/A * @see #setMaximum
0N/A */
0N/A public JSlider(int min, int max) {
0N/A this(HORIZONTAL, min, max, (min + max) / 2);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a horizontal slider using the specified min, max and value.
0N/A * <p>
0N/A * The <code>BoundedRangeModel</code> that holds the slider's data
0N/A * handles any issues that may arise from improperly setting the
0N/A * minimum, initial, and maximum values on the slider. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A *
0N/A * @param min the minimum value of the slider
0N/A * @param max the maximum value of the slider
0N/A * @param value the initial value of the slider
0N/A *
0N/A * @see BoundedRangeModel
0N/A * @see #setMinimum
0N/A * @see #setMaximum
0N/A * @see #setValue
0N/A */
0N/A public JSlider(int min, int max, int value) {
0N/A this(HORIZONTAL, min, max, value);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a slider with the specified orientation and the
0N/A * specified minimum, maximum, and initial values.
0N/A * The orientation can be
0N/A * either <code>SwingConstants.VERTICAL</code> or
0N/A * <code>SwingConstants.HORIZONTAL</code>.
0N/A * <p>
0N/A * The <code>BoundedRangeModel</code> that holds the slider's data
0N/A * handles any issues that may arise from improperly setting the
0N/A * minimum, initial, and maximum values on the slider. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A *
0N/A * @param orientation the orientation of the slider
0N/A * @param min the minimum value of the slider
0N/A * @param max the maximum value of the slider
0N/A * @param value the initial value of the slider
0N/A *
0N/A * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
0N/A *
0N/A * @see BoundedRangeModel
0N/A * @see #setOrientation
0N/A * @see #setMinimum
0N/A * @see #setMaximum
0N/A * @see #setValue
0N/A */
0N/A public JSlider(int orientation, int min, int max, int value)
0N/A {
0N/A checkOrientation(orientation);
0N/A this.orientation = orientation;
633N/A setModel(new DefaultBoundedRangeModel(value, 0, min, max));
0N/A updateUI();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a horizontal slider using the specified
0N/A * BoundedRangeModel.
0N/A */
0N/A public JSlider(BoundedRangeModel brm)
0N/A {
0N/A this.orientation = JSlider.HORIZONTAL;
0N/A setModel(brm);
0N/A updateUI();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the UI object which implements the L&F for this component.
0N/A *
0N/A * @return the SliderUI object that implements the Slider L&F
0N/A */
0N/A public SliderUI getUI() {
0N/A return(SliderUI)ui;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the UI object which implements the L&F for this component.
0N/A *
0N/A * @param ui the SliderUI L&F object
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * attribute: visualUpdate true
0N/A * description: The UI object that implements the slider's LookAndFeel.
0N/A */
0N/A public void setUI(SliderUI ui) {
0N/A super.setUI(ui);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((SliderUI)UIManager.getUI(this));
0N/A // The labels preferred size may be derived from the font
0N/A // of the slider, so we must update the UI of the slider first, then
0N/A // that of labels. This way when setSize is called the right
0N/A // font is used.
0N/A updateLabelUIs();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return "SliderUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * We pass Change events along to the listeners with the
0N/A * the slider (instead of the model itself) as the event source.
0N/A */
0N/A private class ModelListener implements ChangeListener, Serializable {
0N/A public void stateChanged(ChangeEvent e) {
0N/A fireStateChanged();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Subclasses that want to handle {@code ChangeEvent}s
0N/A * from the model differently
0N/A * can override this to return
0N/A * an instance of a custom <code>ChangeListener</code> implementation.
0N/A * The default {@code ChangeListener} simply calls the
0N/A * {@code fireStateChanged} method to forward {@code ChangeEvent}s
0N/A * to the {@code ChangeListener}s that have been added directly to the
0N/A * slider.
0N/A * @see #changeListener
0N/A * @see #fireStateChanged
0N/A * @see javax.swing.event.ChangeListener
0N/A * @see javax.swing.BoundedRangeModel
0N/A */
0N/A protected ChangeListener createChangeListener() {
0N/A return new ModelListener();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds a ChangeListener to the slider.
0N/A *
0N/A * @param l the ChangeListener to add
0N/A * @see #fireStateChanged
0N/A * @see #removeChangeListener
0N/A */
0N/A public void addChangeListener(ChangeListener l) {
0N/A listenerList.add(ChangeListener.class, l);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes a ChangeListener from the slider.
0N/A *
0N/A * @param l the ChangeListener to remove
0N/A * @see #fireStateChanged
0N/A * @see #addChangeListener
0N/A
0N/A */
0N/A public void removeChangeListener(ChangeListener l) {
0N/A listenerList.remove(ChangeListener.class, l);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an array of all the <code>ChangeListener</code>s added
0N/A * to this JSlider with addChangeListener().
0N/A *
0N/A * @return all of the <code>ChangeListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public ChangeListener[] getChangeListeners() {
342N/A return listenerList.getListeners(ChangeListener.class);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Send a {@code ChangeEvent}, whose source is this {@code JSlider}, to
0N/A * all {@code ChangeListener}s that have registered interest in
0N/A * {@code ChangeEvent}s.
0N/A * This method is called each time a {@code ChangeEvent} is received from
0N/A * the model.
0N/A * <p>
0N/A * The event instance is created if necessary, and stored in
0N/A * {@code changeEvent}.
0N/A *
0N/A * @see #addChangeListener
0N/A * @see EventListenerList
0N/A */
0N/A protected void fireStateChanged() {
0N/A Object[] listeners = listenerList.getListenerList();
0N/A for (int i = listeners.length - 2; i >= 0; i -= 2) {
0N/A if (listeners[i]==ChangeListener.class) {
0N/A if (changeEvent == null) {
0N/A changeEvent = new ChangeEvent(this);
0N/A }
0N/A ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the {@code BoundedRangeModel} that handles the slider's three
0N/A * fundamental properties: minimum, maximum, value.
0N/A *
0N/A * @return the data model for this component
0N/A * @see #setModel
0N/A * @see BoundedRangeModel
0N/A */
0N/A public BoundedRangeModel getModel() {
0N/A return sliderModel;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the {@code BoundedRangeModel} that handles the slider's three
0N/A * fundamental properties: minimum, maximum, value.
0N/A *<p>
0N/A * Attempts to pass a {@code null} model to this method result in
0N/A * undefined behavior, and, most likely, exceptions.
0N/A *
0N/A * @param newModel the new, {@code non-null} <code>BoundedRangeModel</code> to use
0N/A *
0N/A * @see #getModel
0N/A * @see BoundedRangeModel
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The sliders BoundedRangeModel.
0N/A */
0N/A public void setModel(BoundedRangeModel newModel)
0N/A {
0N/A BoundedRangeModel oldModel = getModel();
0N/A
0N/A if (oldModel != null) {
0N/A oldModel.removeChangeListener(changeListener);
0N/A }
0N/A
0N/A sliderModel = newModel;
0N/A
0N/A if (newModel != null) {
0N/A newModel.addChangeListener(changeListener);
633N/A }
0N/A
633N/A if (accessibleContext != null) {
633N/A accessibleContext.firePropertyChange(
633N/A AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
633N/A (oldModel == null
633N/A ? null : Integer.valueOf(oldModel.getValue())),
633N/A (newModel == null
633N/A ? null : Integer.valueOf(newModel.getValue())));
0N/A }
0N/A
0N/A firePropertyChange("model", oldModel, sliderModel);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the slider's current value
0N/A * from the {@code BoundedRangeModel}.
0N/A *
0N/A * @return the current value of the slider
0N/A * @see #setValue
0N/A * @see BoundedRangeModel#getValue
0N/A */
0N/A public int getValue() {
0N/A return getModel().getValue();
0N/A }
0N/A
0N/A /**
0N/A * Sets the slider's current value to {@code n}. This method
0N/A * forwards the new value to the model.
0N/A * <p>
0N/A * The data model (an instance of {@code BoundedRangeModel})
0N/A * handles any mathematical
0N/A * issues arising from assigning faulty values. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A * <p>
0N/A * If the new value is different from the previous value,
0N/A * all change listeners are notified.
0N/A *
0N/A * @param n the new value
0N/A * @see #getValue
0N/A * @see #addChangeListener
0N/A * @see BoundedRangeModel#setValue
0N/A * @beaninfo
0N/A * preferred: true
0N/A * description: The sliders current value.
0N/A */
0N/A public void setValue(int n) {
0N/A BoundedRangeModel m = getModel();
0N/A int oldValue = m.getValue();
0N/A if (oldValue == n) {
0N/A return;
0N/A }
0N/A m.setValue(n);
0N/A
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
215N/A Integer.valueOf(oldValue),
215N/A Integer.valueOf(m.getValue()));
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the minimum value supported by the slider
0N/A * from the <code>BoundedRangeModel</code>.
0N/A *
0N/A * @return the value of the model's minimum property
0N/A * @see #setMinimum
0N/A * @see BoundedRangeModel#getMinimum
0N/A */
0N/A public int getMinimum() {
0N/A return getModel().getMinimum();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the slider's minimum value to {@code minimum}. This method
0N/A * forwards the new minimum value to the model.
0N/A * <p>
0N/A * The data model (an instance of {@code BoundedRangeModel})
0N/A * handles any mathematical
0N/A * issues arising from assigning faulty values. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A * <p>
0N/A * If the new minimum value is different from the previous minimum value,
0N/A * all change listeners are notified.
0N/A *
0N/A * @param minimum the new minimum
0N/A * @see #getMinimum
0N/A * @see #addChangeListener
0N/A * @see BoundedRangeModel#setMinimum
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * description: The sliders minimum value.
0N/A */
0N/A public void setMinimum(int minimum) {
0N/A int oldMin = getModel().getMinimum();
0N/A getModel().setMinimum(minimum);
215N/A firePropertyChange( "minimum", Integer.valueOf( oldMin ), Integer.valueOf( minimum ) );
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the maximum value supported by the slider
0N/A * from the <code>BoundedRangeModel</code>.
0N/A *
0N/A * @return the value of the model's maximum property
0N/A * @see #setMaximum
0N/A * @see BoundedRangeModel#getMaximum
0N/A */
0N/A public int getMaximum() {
0N/A return getModel().getMaximum();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the slider's maximum value to {@code maximum}. This method
0N/A * forwards the new maximum value to the model.
0N/A * <p>
0N/A * The data model (an instance of {@code BoundedRangeModel})
0N/A * handles any mathematical
0N/A * issues arising from assigning faulty values. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A * <p>
0N/A * If the new maximum value is different from the previous maximum value,
0N/A * all change listeners are notified.
0N/A *
0N/A * @param maximum the new maximum
0N/A * @see #getMaximum
0N/A * @see #addChangeListener
0N/A * @see BoundedRangeModel#setMaximum
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * description: The sliders maximum value.
0N/A */
0N/A public void setMaximum(int maximum) {
0N/A int oldMax = getModel().getMaximum();
0N/A getModel().setMaximum(maximum);
215N/A firePropertyChange( "maximum", Integer.valueOf( oldMax ), Integer.valueOf( maximum ) );
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the {@code valueIsAdjusting} property from the model. For
0N/A * details on how this is used, see the {@code setValueIsAdjusting}
0N/A * documentation.
0N/A *
0N/A * @return the value of the model's {@code valueIsAdjusting} property
0N/A * @see #setValueIsAdjusting
0N/A */
0N/A public boolean getValueIsAdjusting() {
0N/A return getModel().getValueIsAdjusting();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the model's {@code valueIsAdjusting} property. Slider look and
0N/A * feel implementations should set this property to {@code true} when
345N/A * a knob drag begins, and to {@code false} when the drag ends.
0N/A *
0N/A * @param b the new value for the {@code valueIsAdjusting} property
0N/A * @see #getValueIsAdjusting
0N/A * @see BoundedRangeModel#setValueIsAdjusting
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: True if the slider knob is being dragged.
0N/A */
0N/A public void setValueIsAdjusting(boolean b) {
0N/A BoundedRangeModel m = getModel();
0N/A boolean oldValue = m.getValueIsAdjusting();
0N/A m.setValueIsAdjusting(b);
0N/A
0N/A if ((oldValue != b) && (accessibleContext != null)) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A ((oldValue) ? AccessibleState.BUSY : null),
0N/A ((b) ? AccessibleState.BUSY : null));
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the "extent" from the <code>BoundedRangeModel</code>.
0N/A * This respresents the range of values "covered" by the knob.
0N/A *
0N/A * @return an int representing the extent
0N/A * @see #setExtent
0N/A * @see BoundedRangeModel#getExtent
0N/A */
0N/A public int getExtent() {
0N/A return getModel().getExtent();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the size of the range "covered" by the knob. Most look
0N/A * and feel implementations will change the value by this amount
0N/A * if the user clicks on either side of the knob. This method just
0N/A * forwards the new extent value to the model.
0N/A * <p>
0N/A * The data model (an instance of {@code BoundedRangeModel})
0N/A * handles any mathematical
0N/A * issues arising from assigning faulty values. See the
0N/A * {@code BoundedRangeModel} documentation for details.
0N/A * <p>
0N/A * If the new extent value is different from the previous extent value,
0N/A * all change listeners are notified.
0N/A *
0N/A * @param extent the new extent
0N/A * @see #getExtent
0N/A * @see BoundedRangeModel#setExtent
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: Size of the range covered by the knob.
0N/A */
0N/A public void setExtent(int extent) {
0N/A getModel().setExtent(extent);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Return this slider's vertical or horizontal orientation.
0N/A * @return {@code SwingConstants.VERTICAL} or
0N/A * {@code SwingConstants.HORIZONTAL}
0N/A * @see #setOrientation
0N/A */
0N/A public int getOrientation() {
0N/A return orientation;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Set the slider's orientation to either {@code SwingConstants.VERTICAL} or
0N/A * {@code SwingConstants.HORIZONTAL}.
0N/A *
0N/A * @param orientation {@code HORIZONTAL} or {@code VERTICAL}
0N/A * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL}
0N/A * @see #getOrientation
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
0N/A * enum: VERTICAL JSlider.VERTICAL
0N/A * HORIZONTAL JSlider.HORIZONTAL
0N/A *
0N/A */
0N/A public void setOrientation(int orientation)
0N/A {
0N/A checkOrientation(orientation);
0N/A int oldValue = this.orientation;
0N/A this.orientation = orientation;
0N/A firePropertyChange("orientation", oldValue, orientation);
0N/A
0N/A if ((oldValue != orientation) && (accessibleContext != null)) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A ((oldValue == VERTICAL)
0N/A ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
0N/A ((orientation == VERTICAL)
0N/A ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
0N/A }
0N/A if (orientation != oldValue) {
0N/A revalidate();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public void setFont(Font font) {
0N/A super.setFont(font);
0N/A updateLabelSizes();
0N/A }
0N/A
343N/A /**
343N/A * {@inheritDoc}
343N/A * @since 1.7
343N/A */
343N/A public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
343N/A if (!isShowing()) {
343N/A return false;
343N/A }
343N/A
343N/A // Check that there is a label with such image
343N/A Enumeration elements = labelTable.elements();
343N/A
343N/A while (elements.hasMoreElements()) {
343N/A Component component = (Component) elements.nextElement();
343N/A
343N/A if (component instanceof JLabel) {
343N/A JLabel label = (JLabel) component;
343N/A
343N/A if (SwingUtilities.doesIconReferenceImage(label.getIcon(), img) ||
343N/A SwingUtilities.doesIconReferenceImage(label.getDisabledIcon(), img)) {
343N/A return super.imageUpdate(img, infoflags, x, y, w, h);
343N/A }
343N/A }
343N/A }
343N/A
343N/A return false;
343N/A }
0N/A
0N/A /**
0N/A * Returns the dictionary of what labels to draw at which values.
0N/A *
0N/A * @return the <code>Dictionary</code> containing labels and
0N/A * where to draw them
0N/A */
0N/A public Dictionary getLabelTable() {
0N/A/*
0N/A if ( labelTable == null && getMajorTickSpacing() > 0 ) {
0N/A setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
0N/A }
0N/A*/
0N/A return labelTable;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Used to specify what label will be drawn at any given value.
0N/A * The key-value pairs are of this format:
0N/A * <code>{ Integer value, java.swing.JComponent label }</code>.
0N/A * <p>
0N/A * An easy way to generate a standard table of value labels is by using the
0N/A * {@code createStandardLabels} method.
0N/A * <p>
0N/A * Once the labels have been set, this method calls {@link #updateLabelUIs}.
0N/A * Note that the labels are only painted if the {@code paintLabels}
0N/A * property is {@code true}.
0N/A *
0N/A * @param labels new {@code Dictionary} of labels, or {@code null} to
0N/A * remove all labels
0N/A * @see #createStandardLabels(int)
0N/A * @see #getLabelTable
0N/A * @see #setPaintLabels
0N/A * @beaninfo
0N/A * hidden: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Specifies what labels will be drawn for any given value.
0N/A */
0N/A public void setLabelTable( Dictionary labels ) {
0N/A Dictionary oldTable = labelTable;
0N/A labelTable = labels;
0N/A updateLabelUIs();
0N/A firePropertyChange("labelTable", oldTable, labelTable );
0N/A if (labels != oldTable) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Updates the UIs for the labels in the label table by calling
0N/A * {@code updateUI} on each label. The UIs are updated from
0N/A * the current look and feel. The labels are also set to their
0N/A * preferred size.
0N/A *
0N/A * @see #setLabelTable
0N/A * @see JComponent#updateUI
0N/A */
0N/A protected void updateLabelUIs() {
342N/A Dictionary labelTable = getLabelTable();
342N/A
342N/A if (labelTable == null) {
0N/A return;
0N/A }
342N/A Enumeration labels = labelTable.keys();
0N/A while ( labels.hasMoreElements() ) {
342N/A JComponent component = (JComponent) labelTable.get(labels.nextElement());
342N/A component.updateUI();
342N/A component.setSize(component.getPreferredSize());
0N/A }
0N/A }
0N/A
0N/A private void updateLabelSizes() {
0N/A Dictionary labelTable = getLabelTable();
0N/A if (labelTable != null) {
0N/A Enumeration labels = labelTable.elements();
0N/A while (labels.hasMoreElements()) {
342N/A JComponent component = (JComponent) labels.nextElement();
342N/A component.setSize(component.getPreferredSize());
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a {@code Hashtable} of numerical text labels, starting at the
0N/A * slider minimum, and using the increment specified.
0N/A * For example, if you call <code>createStandardLabels( 10 )</code>
0N/A * and the slider minimum is zero,
0N/A * then labels will be created for the values 0, 10, 20, 30, and so on.
0N/A * <p>
0N/A * For the labels to be drawn on the slider, the returned {@code Hashtable}
0N/A * must be passed into {@code setLabelTable}, and {@code setPaintLabels}
0N/A * must be set to {@code true}.
0N/A * <p>
0N/A * For further details on the makeup of the returned {@code Hashtable}, see
0N/A * the {@code setLabelTable} documentation.
0N/A *
0N/A * @param increment distance between labels in the generated hashtable
0N/A * @return a new {@code Hashtable} of labels
0N/A * @see #setLabelTable
0N/A * @see #setPaintLabels
0N/A * @throws IllegalArgumentException if {@code increment} is less than or
0N/A * equal to zero
0N/A */
0N/A public Hashtable createStandardLabels( int increment ) {
0N/A return createStandardLabels( increment, getMinimum() );
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Creates a {@code Hashtable} of numerical text labels, starting at the
0N/A * starting point specified, and using the increment specified.
0N/A * For example, if you call
0N/A * <code>createStandardLabels( 10, 2 )</code>,
0N/A * then labels will be created for the values 2, 12, 22, 32, and so on.
0N/A * <p>
0N/A * For the labels to be drawn on the slider, the returned {@code Hashtable}
0N/A * must be passed into {@code setLabelTable}, and {@code setPaintLabels}
0N/A * must be set to {@code true}.
0N/A * <p>
0N/A * For further details on the makeup of the returned {@code Hashtable}, see
0N/A * the {@code setLabelTable} documentation.
0N/A *
0N/A * @param increment distance between labels in the generated hashtable
0N/A * @param start value at which the labels will begin
0N/A * @return a new {@code Hashtable} of labels
0N/A * @see #setLabelTable
0N/A * @see #setPaintLabels
0N/A * @exception IllegalArgumentException if {@code start} is
0N/A * out of range, or if {@code increment} is less than or equal
0N/A * to zero
0N/A */
0N/A public Hashtable createStandardLabels( int increment, int start ) {
0N/A if ( start > getMaximum() || start < getMinimum() ) {
0N/A throw new IllegalArgumentException( "Slider label start point out of range." );
0N/A }
0N/A
0N/A if ( increment <= 0 ) {
0N/A throw new IllegalArgumentException( "Label incremement must be > 0" );
0N/A }
0N/A
625N/A class SmartHashtable extends Hashtable<Object, Object> implements PropertyChangeListener {
0N/A int increment = 0;
0N/A int start = 0;
0N/A boolean startAtMin = false;
0N/A
0N/A class LabelUIResource extends JLabel implements UIResource {
0N/A public LabelUIResource( String text, int alignment ) {
0N/A super( text, alignment );
0N/A setName("Slider.label");
0N/A }
0N/A
0N/A public Font getFont() {
0N/A Font font = super.getFont();
0N/A if (font != null && !(font instanceof UIResource)) {
0N/A return font;
0N/A }
0N/A return JSlider.this.getFont();
0N/A }
0N/A
0N/A public Color getForeground() {
0N/A Color fg = super.getForeground();
0N/A if (fg != null && !(fg instanceof UIResource)) {
0N/A return fg;
0N/A }
0N/A if (!(JSlider.this.getForeground() instanceof UIResource)) {
0N/A return JSlider.this.getForeground();
0N/A }
0N/A return fg;
0N/A }
0N/A }
0N/A
0N/A public SmartHashtable( int increment, int start ) {
0N/A super();
0N/A this.increment = increment;
0N/A this.start = start;
0N/A startAtMin = start == getMinimum();
0N/A createLabels();
0N/A }
0N/A
0N/A public void propertyChange( PropertyChangeEvent e ) {
0N/A if ( e.getPropertyName().equals( "minimum" ) && startAtMin ) {
0N/A start = getMinimum();
0N/A }
0N/A
0N/A if ( e.getPropertyName().equals( "minimum" ) ||
0N/A e.getPropertyName().equals( "maximum" ) ) {
0N/A
625N/A Enumeration keys = getLabelTable().keys();
625N/A Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>();
0N/A
0N/A // Save the labels that were added by the developer
0N/A while ( keys.hasMoreElements() ) {
342N/A Object key = keys.nextElement();
342N/A Object value = labelTable.get(key);
0N/A if ( !(value instanceof LabelUIResource) ) {
0N/A hashtable.put( key, value );
0N/A }
0N/A }
0N/A
0N/A clear();
0N/A createLabels();
0N/A
0N/A // Add the saved labels
0N/A keys = hashtable.keys();
0N/A while ( keys.hasMoreElements() ) {
342N/A Object key = keys.nextElement();
0N/A put( key, hashtable.get( key ) );
0N/A }
0N/A
0N/A ((JSlider)e.getSource()).setLabelTable( this );
0N/A }
0N/A }
0N/A
0N/A void createLabels() {
0N/A for ( int labelIndex = start; labelIndex <= getMaximum(); labelIndex += increment ) {
215N/A put( Integer.valueOf( labelIndex ), new LabelUIResource( ""+labelIndex, JLabel.CENTER ) );
0N/A }
0N/A }
0N/A }
0N/A
0N/A SmartHashtable table = new SmartHashtable( increment, start );
0N/A
342N/A Dictionary labelTable = getLabelTable();
342N/A
342N/A if (labelTable != null && (labelTable instanceof PropertyChangeListener)) {
342N/A removePropertyChangeListener((PropertyChangeListener) labelTable);
0N/A }
0N/A
0N/A addPropertyChangeListener( table );
0N/A
0N/A return table;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if the value-range shown for the slider is reversed,
0N/A *
0N/A * @return true if the slider values are reversed from their normal order
0N/A * @see #setInverted
0N/A */
0N/A public boolean getInverted() {
0N/A return isInverted;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specify true to reverse the value-range shown for the slider and false to
0N/A * put the value range in the normal order. The order depends on the
0N/A * slider's <code>ComponentOrientation</code> property. Normal (non-inverted)
0N/A * horizontal sliders with a <code>ComponentOrientation</code> value of
0N/A * <code>LEFT_TO_RIGHT</code> have their maximum on the right.
0N/A * Normal horizontal sliders with a <code>ComponentOrientation</code> value of
0N/A * <code>RIGHT_TO_LEFT</code> have their maximum on the left. Normal vertical
0N/A * sliders have their maximum on the top. These labels are reversed when the
0N/A * slider is inverted.
0N/A * <p>
0N/A * By default, the value of this property is {@code false}.
0N/A *
0N/A * @param b true to reverse the slider values from their normal order
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: If true reverses the slider values from their normal order
0N/A *
0N/A */
0N/A public void setInverted( boolean b ) {
0N/A boolean oldValue = isInverted;
0N/A isInverted = b;
0N/A firePropertyChange("inverted", oldValue, isInverted);
0N/A if (b != oldValue) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method returns the major tick spacing. The number that is returned
0N/A * represents the distance, measured in values, between each major tick mark.
0N/A * If you have a slider with a range from 0 to 50 and the major tick spacing
0N/A * is set to 10, you will get major ticks next to the following values:
0N/A * 0, 10, 20, 30, 40, 50.
0N/A *
0N/A * @return the number of values between major ticks
0N/A * @see #setMajorTickSpacing
0N/A */
0N/A public int getMajorTickSpacing() {
0N/A return majorTickSpacing;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method sets the major tick spacing. The number that is passed in
0N/A * represents the distance, measured in values, between each major tick mark.
0N/A * If you have a slider with a range from 0 to 50 and the major tick spacing
0N/A * is set to 10, you will get major ticks next to the following values:
0N/A * 0, 10, 20, 30, 40, 50.
0N/A * <p>
0N/A * In order for major ticks to be painted, {@code setPaintTicks} must be
0N/A * set to {@code true}.
0N/A * <p>
0N/A * This method will also set up a label table for you.
0N/A * If there is not already a label table, and the major tick spacing is
0N/A * {@code > 0}, and {@code getPaintLabels} returns
0N/A * {@code true}, a standard label table will be generated (by calling
0N/A * {@code createStandardLabels}) with labels at the major tick marks.
0N/A * For the example above, you would get text labels: "0",
0N/A * "10", "20", "30", "40", "50".
0N/A * The label table is then set on the slider by calling
0N/A * {@code setLabelTable}.
0N/A *
0N/A * @param n new value for the {@code majorTickSpacing} property
0N/A * @see #getMajorTickSpacing
0N/A * @see #setPaintTicks
0N/A * @see #setLabelTable
0N/A * @see #createStandardLabels(int)
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Sets the number of values between major tick marks.
0N/A *
0N/A */
0N/A public void setMajorTickSpacing(int n) {
0N/A int oldValue = majorTickSpacing;
0N/A majorTickSpacing = n;
0N/A if ( labelTable == null && getMajorTickSpacing() > 0 && getPaintLabels() ) {
0N/A setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
0N/A }
0N/A firePropertyChange("majorTickSpacing", oldValue, majorTickSpacing);
0N/A if (majorTickSpacing != oldValue && getPaintTicks()) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * This method returns the minor tick spacing. The number that is returned
0N/A * represents the distance, measured in values, between each minor tick mark.
0N/A * If you have a slider with a range from 0 to 50 and the minor tick spacing
0N/A * is set to 10, you will get minor ticks next to the following values:
0N/A * 0, 10, 20, 30, 40, 50.
0N/A *
0N/A * @return the number of values between minor ticks
0N/A * @see #getMinorTickSpacing
0N/A */
0N/A public int getMinorTickSpacing() {
0N/A return minorTickSpacing;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This method sets the minor tick spacing. The number that is passed in
0N/A * represents the distance, measured in values, between each minor tick mark.
0N/A * If you have a slider with a range from 0 to 50 and the minor tick spacing
0N/A * is set to 10, you will get minor ticks next to the following values:
0N/A * 0, 10, 20, 30, 40, 50.
0N/A * <p>
0N/A * In order for minor ticks to be painted, {@code setPaintTicks} must be
0N/A * set to {@code true}.
0N/A *
0N/A * @param n new value for the {@code minorTickSpacing} property
0N/A * @see #getMinorTickSpacing
0N/A * @see #setPaintTicks
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Sets the number of values between minor tick marks.
0N/A */
0N/A public void setMinorTickSpacing(int n) {
0N/A int oldValue = minorTickSpacing;
0N/A minorTickSpacing = n;
0N/A firePropertyChange("minorTickSpacing", oldValue, minorTickSpacing);
0N/A if (minorTickSpacing != oldValue && getPaintTicks()) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if the knob (and the data value it represents)
0N/A * resolve to the closest tick mark next to where the user
0N/A * positioned the knob.
0N/A *
0N/A * @return true if the value snaps to the nearest tick mark, else false
0N/A * @see #setSnapToTicks
0N/A */
0N/A public boolean getSnapToTicks() {
0N/A return snapToTicks;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if the knob (and the data value it represents)
0N/A * resolve to the closest slider value next to where the user
0N/A * positioned the knob.
0N/A *
0N/A * @return true if the value snaps to the nearest slider value, else false
0N/A * @see #setSnapToValue
0N/A */
0N/A boolean getSnapToValue() {
0N/A return snapToValue;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifying true makes the knob (and the data value it represents)
0N/A * resolve to the closest tick mark next to where the user
0N/A * positioned the knob.
0N/A * By default, this property is {@code false}.
0N/A *
0N/A * @param b true to snap the knob to the nearest tick mark
0N/A * @see #getSnapToTicks
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: If true snap the knob to the nearest tick mark.
0N/A */
0N/A public void setSnapToTicks(boolean b) {
0N/A boolean oldValue = snapToTicks;
0N/A snapToTicks = b;
0N/A firePropertyChange("snapToTicks", oldValue, snapToTicks);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Specifying true makes the knob (and the data value it represents)
0N/A * resolve to the closest slider value next to where the user
0N/A * positioned the knob. If the {@code snapToTicks} property has also been
0N/A * set to {@code true}, the snap-to-ticks behavior will prevail.
0N/A * By default, the snapToValue property is {@code true}.
0N/A *
0N/A * @param b true to snap the knob to the nearest slider value
0N/A * @see #getSnapToValue
0N/A * @see #setSnapToTicks
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: If true snap the knob to the nearest slider value.
0N/A */
0N/A void setSnapToValue(boolean b) {
0N/A boolean oldValue = snapToValue;
0N/A snapToValue = b;
0N/A firePropertyChange("snapToValue", oldValue, snapToValue);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Tells if tick marks are to be painted.
0N/A * @return true if tick marks are painted, else false
0N/A * @see #setPaintTicks
0N/A */
0N/A public boolean getPaintTicks() {
0N/A return paintTicks;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines whether tick marks are painted on the slider.
0N/A * By default, this property is {@code false}.
0N/A *
0N/A * @param b whether or not tick marks should be painted
0N/A * @see #getPaintTicks
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: If true tick marks are painted on the slider.
0N/A */
0N/A public void setPaintTicks(boolean b) {
0N/A boolean oldValue = paintTicks;
0N/A paintTicks = b;
0N/A firePropertyChange("paintTicks", oldValue, paintTicks);
0N/A if (paintTicks != oldValue) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Tells if the track (area the slider slides in) is to be painted.
0N/A * @return true if track is painted, else false
0N/A * @see #setPaintTrack
0N/A */
0N/A public boolean getPaintTrack() {
0N/A return paintTrack;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines whether the track is painted on the slider.
0N/A * By default, this property is {@code true}.
0N/A *
0N/A * @param b whether or not to paint the slider track
0N/A * @see #getPaintTrack
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: If true, the track is painted on the slider.
0N/A */
0N/A public void setPaintTrack(boolean b) {
0N/A boolean oldValue = paintTrack;
0N/A paintTrack = b;
0N/A firePropertyChange("paintTrack", oldValue, paintTrack);
0N/A if (paintTrack != oldValue) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Tells if labels are to be painted.
0N/A * @return true if labels are painted, else false
0N/A * @see #setPaintLabels
0N/A */
0N/A public boolean getPaintLabels() {
0N/A return paintLabels;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines whether labels are painted on the slider.
0N/A * <p>
0N/A * This method will also set up a label table for you.
0N/A * If there is not already a label table, and the major tick spacing is
0N/A * {@code > 0},
0N/A * a standard label table will be generated (by calling
0N/A * {@code createStandardLabels}) with labels at the major tick marks.
0N/A * The label table is then set on the slider by calling
0N/A * {@code setLabelTable}.
0N/A * <p>
0N/A * By default, this property is {@code false}.
0N/A *
0N/A * @param b whether or not to paint labels
0N/A * @see #getPaintLabels
0N/A * @see #getLabelTable
0N/A * @see #createStandardLabels(int)
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: If true labels are painted on the slider.
0N/A */
0N/A public void setPaintLabels(boolean b) {
0N/A boolean oldValue = paintLabels;
0N/A paintLabels = b;
0N/A if ( labelTable == null && getMajorTickSpacing() > 0 ) {
0N/A setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
0N/A }
0N/A firePropertyChange("paintLabels", oldValue, paintLabels);
0N/A if (paintLabels != oldValue) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * See readObject() and writeObject() in JComponent for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this JSlider. This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this JSlider.
0N/A */
0N/A protected String paramString() {
0N/A String paintTicksString = (paintTicks ?
0N/A "true" : "false");
0N/A String paintTrackString = (paintTrack ?
0N/A "true" : "false");
0N/A String paintLabelsString = (paintLabels ?
0N/A "true" : "false");
0N/A String isInvertedString = (isInverted ?
0N/A "true" : "false");
0N/A String snapToTicksString = (snapToTicks ?
0N/A "true" : "false");
0N/A String snapToValueString = (snapToValue ?
0N/A "true" : "false");
0N/A String orientationString = (orientation == HORIZONTAL ?
0N/A "HORIZONTAL" : "VERTICAL");
0N/A
0N/A return super.paramString() +
0N/A ",isInverted=" + isInvertedString +
0N/A ",majorTickSpacing=" + majorTickSpacing +
0N/A ",minorTickSpacing=" + minorTickSpacing +
0N/A ",orientation=" + orientationString +
0N/A ",paintLabels=" + paintLabelsString +
0N/A ",paintTicks=" + paintTicksString +
0N/A ",paintTrack=" + paintTrackString +
0N/A ",snapToTicks=" + snapToTicksString +
0N/A ",snapToValue=" + snapToValueString;
0N/A }
0N/A
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JSlider.
0N/A * For sliders, the AccessibleContext takes the form of an
0N/A * AccessibleJSlider.
0N/A * A new AccessibleJSlider instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJSlider that serves as the
0N/A * AccessibleContext of this JSlider
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJSlider();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JSlider</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to slider user-interface elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJSlider extends AccessibleJComponent
0N/A implements AccessibleValue {
0N/A
0N/A /**
0N/A * Get the state set of this object.
0N/A *
0N/A * @return an instance of AccessibleState containing the current state
0N/A * of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (getValueIsAdjusting()) {
0N/A states.add(AccessibleState.BUSY);
0N/A }
0N/A if (getOrientation() == VERTICAL) {
0N/A states.add(AccessibleState.VERTICAL);
0N/A }
0N/A else {
0N/A states.add(AccessibleState.HORIZONTAL);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the object
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.SLIDER;
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleValue associated with this object. In the
0N/A * implementation of the Java Accessibility API for this class,
0N/A * return this object, which is responsible for implementing the
0N/A * AccessibleValue interface on behalf of itself.
0N/A *
0N/A * @return this object
0N/A */
0N/A public AccessibleValue getAccessibleValue() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Get the accessible value of this object.
0N/A *
0N/A * @return The current value of this object.
0N/A */
0N/A public Number getCurrentAccessibleValue() {
215N/A return Integer.valueOf(getValue());
0N/A }
0N/A
0N/A /**
0N/A * Set the value of this object as a Number.
0N/A *
0N/A * @return True if the value was set.
0N/A */
0N/A public boolean setCurrentAccessibleValue(Number n) {
0N/A // TIGER - 4422535
0N/A if (n == null) {
0N/A return false;
0N/A }
0N/A setValue(n.intValue());
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Get the minimum accessible value of this object.
0N/A *
0N/A * @return The minimum value of this object.
0N/A */
0N/A public Number getMinimumAccessibleValue() {
215N/A return Integer.valueOf(getMinimum());
0N/A }
0N/A
0N/A /**
0N/A * Get the maximum accessible value of this object.
0N/A *
0N/A * @return The maximum value of this object.
0N/A */
0N/A public Number getMaximumAccessibleValue() {
0N/A // TIGER - 4422362
0N/A BoundedRangeModel model = JSlider.this.getModel();
215N/A return Integer.valueOf(model.getMaximum() - model.getExtent());
0N/A }
0N/A } // AccessibleJSlider
0N/A}