50
50
import javax.accessibility.Accessible;
51
51
import javax.accessibility.AccessibleContext;
52
52
import javax.accessibility.AccessibleRole;
53
import javax.accessibility.AccessibleState;
53
54
import javax.accessibility.AccessibleStateSet;
54
55
import javax.accessibility.AccessibleValue;
55
56
import javax.swing.event.ChangeEvent;
57
58
import javax.swing.plaf.SliderUI;
60
* The JSlider is a Swing component that allows selection of a value within a
61
* A visual component that allows selection of a value within a
61
62
* range by adjusting a thumb in a track. The values for the minimum,
62
63
* maximum, extent and value are stored in a {@link
63
64
* DefaultBoundedRangeModel}.
66
* JSliders have the following properties:
66
* A <code>JSlider</code> component has the following properties:
72
72
* <tr><td> inverted </td><td> slider </td><td> yes </td></tr>
73
73
* <tr><td> labelTable </td><td> slider </td><td> yes </td></tr>
74
74
* <tr><td> majorTickSpacing </td><td> slider </td><td> yes </td></tr>
75
* <tr><td> maximum </td><td> model </td><td> no </td></tr>
76
* <tr><td> minimum </td><td> model </td><td> no </td></tr>
75
* <tr><td> maximum </td><td> model </td><td> yes </td></tr>
76
* <tr><td> minimum </td><td> model </td><td> yes </td></tr>
77
77
* <tr><td> minorTickSpacing </td><td> slider </td><td> yes </td></tr>
78
78
* <tr><td> model </td><td> slider </td><td> yes </td></tr>
79
79
* <tr><td> orientation </td><td> slider </td><td> yes </td></tr>
80
80
* <tr><td> paintLabels </td><td> slider </td><td> yes </td></tr>
81
81
* <tr><td> paintTicks </td><td> slider </td><td> yes </td></tr>
82
* <tr><td> snapToTicks </td><td> slider </td><td> no </td></tr>
82
* <tr><td> snapToTicks </td><td> slider </td><td> yes </td></tr>
83
83
* <tr><td> value </td><td> model </td><td> no </td></tr>
84
84
* <tr><td> valueIsAdjusting </td><td> model </td><td> no </td></tr>
88
* The various behavioral aspects of these properties follows:
88
* The various behavioural aspects of these properties follows:
93
* When non-bound properties stored in the slider change, the slider fires
94
* ChangeEvents to its ChangeListeners.
97
* When bound properties stored in the slider change, the slider fires
98
* PropertyChangeEvents to its PropertyChangeListeners
101
* If any of the model's properties change, it fires a ChangeEvent to its
102
* ChangeListeners, which include the slider.
105
* If the slider receives a ChangeEvent from its model, it will propagate the
106
* ChangeEvent to its ChangeListeners, with the ChangeEvent's "source"
93
* When a non-bound property stored in the slider changes, the slider fires
94
* a {@link ChangeEvent} to its change listeners.
97
* When a bound property stored in the slider changes, the slider fires a
98
* {@link PropertyChangeEvent} to its property change listeners.
101
* If any of the model's properties change, it fires a {@link ChangeEvent} to
102
* its listeners, which include the slider.
105
* If the slider receives a {@link ChangeEvent} from its model, it will
106
* propagate the event to its own change listeners, with the event's "source"
107
107
* property set to refer to the slider, rather than the model.
113
113
MenuContainer, Serializable
116
115
private static final long serialVersionUID = -1441275936141218479L;
118
* Provides the accessibility features for the <code>JSlider</code>
121
// FIXME: This inner class is a complete stub and needs to be implemented
123
121
protected class AccessibleJSlider extends JComponent.AccessibleJComponent
124
122
implements AccessibleValue
126
124
private static final long serialVersionUID = -6301740148041106789L;
129
* Creates a new AccessibleJSlider object.
127
* Creates a new <code>AccessibleJSlider</code> instance.
131
129
protected AccessibleJSlider()
135
* Returns a set containing the current state of the {@link JSlider}
139
* @return DOCUMENT ME!
138
* @return The accessible state set.
141
140
public AccessibleStateSet getAccessibleStateSet()
142
AccessibleStateSet result = super.getAccessibleStateSet();
143
if (orientation == JSlider.HORIZONTAL)
144
result.add(AccessibleState.HORIZONTAL);
145
else if (orientation == JSlider.VERTICAL)
146
result.add(AccessibleState.VERTICAL);
151
* Returns the accessible role for the <code>JSlider</code> component.
149
* @return DOCUMENT ME!
153
* @return {@link AccessibleRole#SLIDER}.
151
155
public AccessibleRole getAccessibleRole()
157
return AccessibleRole.SLIDER;
161
* Returns an object that provides access to the current, minimum and
162
* maximum values for the {@link JSlider}. Since this class implements
163
* {@link AccessibleValue}, it returns itself.
159
* @return DOCUMENT ME!
165
* @return The accessible value.
161
167
public AccessibleValue getAccessibleValue()
173
* Returns the current value of the {@link JSlider} component, as an
169
* @return DOCUMENT ME!
176
* @return The current value of the {@link JSlider} component.
171
178
public Number getCurrentAccessibleValue()
180
return new Integer(getValue());
177
* setCurrentAccessibleValue
184
* Sets the current value of the {@link JSlider} component and sends a
185
* {@link PropertyChangeEvent} (with the property name
186
* {@link AccessibleContext#ACCESSIBLE_VALUE_PROPERTY}) to all registered
187
* listeners. If the supplied value is <code>null</code>, this method
188
* does nothing and returns <code>false</code>.
190
* @param value the new slider value (<code>null</code> permitted).
192
* @return <code>true</code> if the slider value is updated, and
193
* <code>false</code> otherwise.
183
public boolean setCurrentAccessibleValue(Number value0)
195
public boolean setCurrentAccessibleValue(Number value)
199
Number oldValue = getCurrentAccessibleValue();
200
setValue(value.intValue());
201
firePropertyChange(AccessibleContext.ACCESSIBLE_VALUE_PROPERTY, oldValue,
202
new Integer(getValue()));
189
* getMinimumAccessibleValue
207
* Returns the minimum value of the {@link JSlider} component, as an
210
* @return The minimum value of the {@link JSlider} component.
193
212
public Number getMinimumAccessibleValue()
214
return new Integer(getMinimum());
199
* getMaximumAccessibleValue
218
* Returns the maximum value of the {@link JSlider} component, as an
221
* @return The maximum value of the {@link JSlider} component.
203
223
public Number getMaximumAccessibleValue()
225
return new Integer(getMaximum());
222
242
private transient Dictionary labelTable;
224
/** The model used to describe the slider. */
244
/** The model used to store the slider's range and current value. */
225
245
protected BoundedRangeModel sliderModel;
227
/** The space between major ticks. */
247
/** The space/distance between major ticks. */
228
248
protected int majorTickSpacing;
230
/** The space between minor ticks. */
250
/** The space/distance between minor ticks. */
231
251
protected int minorTickSpacing;
233
253
/** Whether the slider snaps its values to ticks. */
234
254
protected boolean snapToTicks = false;
236
/** The orientation of the slider. */
256
/** The orientation (horizontal or vertical) of the slider. */
237
257
protected int orientation = HORIZONTAL;
239
259
/** Whether the slider is inverted. */
240
260
private transient boolean isInverted;
242
/** The ChangeListener that listens to the model. */
263
* The listener that monitors the slider's model and forwards events to the
264
* slider's listeners (see <code>createChangeListener()</code>).
243
266
protected ChangeListener changeListener;
245
/** The ChangeEvent that is passed to all listeners of this slider. */
268
/** The change event that is passed to all listeners of this slider. */
246
269
protected transient ChangeEvent changeEvent;
249
* Creates a new horizontal JSlider object with a minimum of 0, a maximum of
250
* 100, and a value of 50.
272
* Creates a new horizontal <code>JSlider</code> instance with a minimum of
273
* 0, a maximum of 100, and a value of 50.
258
* Creates a new JSlider object with the given orientation and a minimum of
259
* 0, a maximum of 100, and a value of 50.
281
* Creates a new <code>JSlider</code> instance with the given orientation
282
* and a minimum of 0, a maximum of 100, and a value of 50.
261
284
* @param orientation The orientation of the slider ({@link #HORIZONTAL} or
262
285
* {@link #VERTICAL}).
273
* Creates a new horizontal JSlider object with the given maximum and
274
* minimum and a value that is halfway between the minimum and the
296
* Creates a new horizontal <code>JSlider</code> instance with the given
297
* maximum and minimum and a value that is halfway between the minimum and the
277
* @param minimum The minimum value of the JSlider.
278
* @param maximum The maximum value of the JSlider.
300
* @param minimum The minimum value.
301
* @param maximum The maximum value.
303
* @throws IllegalArgumentException if <code>minimum</code> is greater than
304
* <code>maximum</code>.
280
306
public JSlider(int minimum, int maximum)
286
* Creates a new horizontal JSlider object with the given minimum, maximum,
312
* Creates a new horizontal <code>JSlider</code> instance with the given
313
* minimum, maximum, and value.
289
* @param minimum The minimum value of the JSlider.
290
* @param maximum The maximum value of the JSlider.
291
* @param value The initial value of the JSlider.
315
* @param minimum The minimum value.
316
* @param maximum The maximum value.
317
* @param value The initial value.
319
* @throws IllegalArgumentException if <code>value</code> is not in the
321
* @throws IllegalArgumentException if <code>minimum</code> is greater than
322
* <code>maximum</code>.
293
324
public JSlider(int minimum, int maximum, int value)
306
337
* @param value The initial value of the JSlider.
308
339
* @throws IllegalArgumentException if <code>orientation</code> is not one of
309
* the specified values.
340
* the specified values.
341
* @throws IllegalArgumentException if <code>value</code> is not in the
343
* @throws IllegalArgumentException if <code>minimum</code> is greater than
344
* <code>maximum</code>.
311
346
public JSlider(int orientation, int minimum, int maximum, int value)
313
348
sliderModel = new DefaultBoundedRangeModel(value, 0, minimum, maximum);
314
349
if (orientation != HORIZONTAL && orientation != VERTICAL)
315
throw new IllegalArgumentException(orientation + " is not a legal orientation");
350
throw new IllegalArgumentException(orientation
351
+ " is not a legal orientation");
316
352
this.orientation = orientation;
317
353
changeListener = createChangeListener();
318
354
sliderModel.addChangeListener(changeListener);
348
* This method sets the value of the slider.
387
* Sets the slider's value and sends a {@link ChangeEvent} to all
388
* registered listeners. Note that the model will fire a change event to all
389
* of its registered listeners first (with the model as the event source) and
390
* then the slider will fire another change event to all of its registered
391
* listeners (this time with the slider as the event source).
350
* @param value The slider's new value.
393
* @param value the new value.
352
397
public void setValue(int value)
378
* This method sets this slider's UI to the UIManager's default for the
379
* current look and feel.
423
* Sets this slider's UI delegate to the default (obtained from the
424
* {@link UIManager}) for the current look and feel.
381
426
public void updateUI()
383
428
setUI((SliderUI) UIManager.getUI(this));
389
* This method returns a name to identify which look and feel class will be
390
* the UI delegate for the slider.
432
* Returns the suffix (<code>"SliderUI"</code> in this case) used to
433
* determine the class name for a UI delegate that can provide the look and
434
* feel for a <code>JSlider</code>.
392
* @return The Look and Feel classID. "SliderUI"
436
* @return <code>"SliderUI"</code>.
394
438
public String getUIClassID()
400
* Creates a ChangeListener for this Slider.
444
* Creates a {@link ChangeListener} that is added to the slider's model and
445
* forwards change events generated by the model to the listeners that are
446
* registered with the <code>JSlider</code> (by calling the
447
* {@link #fireStateChanged} method).
402
* @return A new ChangeListener.
449
* @return A new listener.
404
451
protected ChangeListener createChangeListener()
406
453
return new ChangeListener()
408
public void stateChanged(ChangeEvent ce)
410
// No need to trigger a repaint since the UI listens to the model
411
// as well. All we need to do is pass on the stateChanged event
455
public void stateChanged(ChangeEvent ce)
457
// No need to trigger a repaint since the UI listens to the model
458
// as well. All we need to do is pass on the stateChanged event
419
* This method registers a listener to this slider. The listener will be
420
* informed of new ChangeEvents.
466
* Registers a listener with the slider so that it will receive
467
* {@link ChangeEvent} notifications. Note that change events generated
468
* by the slider's model will be forwarded automatically to the slider's
422
* @param listener The listener to register.
471
* @param listener the listener to register.
473
* @see #removeChangeListener(ChangeListener)
424
475
public void addChangeListener(ChangeListener listener)
448
501
changeEvent = new ChangeEvent(this);
449
502
for (int i = changeListeners.length - 2; i >= 0; i -= 2)
451
if (changeListeners[i] == ChangeListener.class)
452
((ChangeListener) changeListeners[i + 1]).stateChanged(changeEvent);
504
if (changeListeners[i] == ChangeListener.class)
505
((ChangeListener) changeListeners[i + 1]).stateChanged(changeEvent);
457
* This method returns an array of all ChangeListeners listening to this
510
* Returns an array containing all the {@link ChangeListener} instances
511
* registered with this slider. If no listeners are registered, this method
512
* returns an empty array.
460
* @return An array of ChangeListeners listening to this slider.
514
* @return An array array containing all the {@link ChangeListener} instances
515
* registered with this slider (possibly empty, but never
516
* <code>null</code>).
462
518
public ChangeListener[] getChangeListeners()
478
* This method changes the "model" property. It also needs to unregister
479
* any listeners to the old model and register any listeners to the new
537
* Sets the slider's model and sends a {@link PropertyChangeEvent} (with the
538
* property name "model") to all registered listeners. The change listener
539
* that the slider registered with the original model is removed and added
540
* to the new model (this ensures that {@link ChangeEvent} notifications
541
* generated by the model are automatically forwarded to listeners that are
542
* registered with the slider).
482
544
* @param model The model to use with the slider.
484
548
public void setModel(BoundedRangeModel model)
488
552
// and bork the next time it tries to access the model.
489
553
if (model != sliderModel)
491
BoundedRangeModel oldModel = sliderModel;
493
oldModel.removeChangeListener(changeListener);
494
sliderModel.addChangeListener(changeListener);
495
firePropertyChange("model", oldModel, sliderModel);
555
BoundedRangeModel oldModel = sliderModel;
557
oldModel.removeChangeListener(changeListener);
558
sliderModel.addChangeListener(changeListener);
559
firePropertyChange("model", oldModel, sliderModel);
500
* This method returns the minimum value of the slider.
564
* Returns the minimum value of the slider (from the slider's model).
502
566
* @return The minimum value of the slider.
568
* @see #setMinimum(int)
504
570
public int getMinimum()
510
* This method sets the minimum value of the slider.
576
* Sets the minimum value of the slider and fires a
577
* {@link PropertyChangeEvent} (with the property name "minimum") to all
578
* registered listeners. Note that:
581
* <li>the minimum value is stored in the slider's model (see
582
* {@link #getModel()});</li>
583
* <li>in addition to the property change event, the slider also fires a
584
* {@link ChangeEvent}.</li>
512
587
* @param minimum The minimum value of the slider.
514
591
public void setMinimum(int minimum)
533
* This method sets the maximum value of the slider.
612
* Sets the maximum value of the slider and fires a
613
* {@link PropertyChangeEvent} (with the property name "maximum") to all
614
* registered listeners. Note that:
617
* <li>the maximum value is stored in the slider's model (see
618
* {@link #getModel()});</li>
619
* <li>in addition to the property change event, the slider also fires a
620
* {@link ChangeEvent}.</li>
535
623
* @param maximum The maximum value of the slider.
537
627
public void setMaximum(int maximum)
546
* This method returns this slider's isAdjusting value which is true if the
547
* thumb is being dragged.
636
* Returns the <code>valueIsAdjusting</code> flag from the slider's model.
549
* @return The slider's isAdjusting value.
638
* @return The <code>valueIsAdjusting</code> flag from the slider's model.
640
* @see #setValueIsAdjusting(boolean)
551
642
public boolean getValueIsAdjusting()
557
* This method sets the isAdjusting value for the slider.
648
* Sets the <code>valueIsAdjusting</code> flag in the slider's model, and
649
* sends a {@link ChangeEvent} to all registered listeners.
559
* @param adjusting The slider's isAdjusting value.
651
* @param adjusting the new flag value.
653
* @see #getValueIsAdjusting()
561
655
public void setValueIsAdjusting(boolean adjusting)
577
* This method sets the extent value for this slider.
673
* Sets the slider's extent value and sends a {@link ChangeEvent} to all
674
* registered listeners. Note that the model will fire a change event to all
675
* of its registered listeners first (with the model as the event source) and
676
* then the slider will fire another change event to all of its registered
677
* listeners (this time with the slider as the event source).
579
679
* @param extent The extent value for this slider.
581
683
public void setExtent(int extent)
597
* This method changes the "orientation" property of this slider. If the
598
* orientation is not VERTICAL or HORIZONTAL, this method does nothing.
702
* Sets the orientation for the slider and sends a
703
* {@link PropertyChangeEvent} (with the property name "orientation") to all
704
* registered listeners.
600
* @param orientation The orientation of this slider.
706
* @param orientation the orientation (one of {@link JSlider#HORIZONTAL} or
707
* {@link JSlider#VERTICAL}).
709
* @throws IllegalArgumentException if <code>orientation</code> is not one of
710
* the permitted values.
712
* @see #getOrientation()
602
714
public void setOrientation(int orientation)
604
716
if (orientation != VERTICAL && orientation != HORIZONTAL)
605
throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
717
throw new IllegalArgumentException(
718
"orientation must be one of: VERTICAL, HORIZONTAL");
606
719
if (orientation != this.orientation)
608
int oldOrientation = this.orientation;
609
this.orientation = orientation;
610
firePropertyChange("orientation", oldOrientation,
721
int oldOrientation = this.orientation;
722
this.orientation = orientation;
723
firePropertyChange("orientation", oldOrientation, this.orientation);
616
* This method returns the label table for this slider.
728
* Returns the label table for the slider.
618
* @return The label table for this slider.
730
* @return The label table for the slider (possibly <code>null</code>).
732
* @see #setLabelTable(Dictionary)
620
734
public Dictionary getLabelTable()
626
* This method changes the "labelTable" property of this slider.
740
* Sets the table of labels for the slider and sends a
741
* {@link PropertyChangeEvent} (with the property name "labelTable") to all
742
* registered listeners.
628
* @param table The label table for this slider.
744
* @param table the table of labels (<code>null</code> permitted).
746
* @see #getLabelTable()
630
748
public void setLabelTable(Dictionary table)
632
750
if (table != labelTable)
634
Dictionary oldTable = labelTable;
636
firePropertyChange("labelTable", oldTable, labelTable);
752
Dictionary oldTable = labelTable;
754
firePropertyChange("labelTable", oldTable, labelTable);
641
* This method is called to reset UI delegates for the labels in the
642
* labelTable to a default for the current look and feel.
759
* Resets the UI delegates for the labels in the <code>labelTable</code> to
760
* the default for the current look and feel.
644
762
protected void updateLabelUIs()
648
766
for (Enumeration list = labelTable.elements(); list.hasMoreElements();)
650
JLabel label = (JLabel) list.nextElement();
768
JLabel label = (JLabel) list.nextElement();
656
* Creates a hashtable of (Integer, JLabel) pairs that can be used as a
657
* label table for this slider. The labels will start from the sliders
658
* minimum and increase by the increment. Each label will have a text
659
* string indicating their integer value.
774
* Creates a hashtable of <code>(Integer, JLabel)</code> pairs that can be
775
* used as a label table for this slider. The labels will start from the
776
* slider's minimum and increase by the increment. Each label will have a text
777
* string indicating its integer value.
661
779
* @param increment The increment between labels (must be > 0).
663
* @return A hashtable with the labels and their keys.
781
* @return A hashtable containing the labels.
665
783
* @throws IllegalArgumentException if <code>increment</code> is not greater
674
* Creates a hashtable of (Integer, JLabel) pairs that can be used as a
675
* label table for this slider. The labels will start from the given start
676
* value and increase by the increment. Each label will have a text string
677
* indicating its integer value.
792
* Creates a hashtable of <code>(Integer, JLabel)</code> pairs that can be
793
* used as a label table for this slider. The labels will start from the
794
* given start value and increase by the increment. Each label will have a
795
* text string indicating its integer value.
679
797
* @param increment The increment between labels (must be > 0).
680
798
* @param start The value to start from.
700
818
for (int i = start; i <= max; i += increment)
702
label = new JLabel(String.valueOf(i));
703
label.setVerticalAlignment(CENTER);
704
label.setHorizontalAlignment(CENTER);
706
// Make sure these labels have the width and height
708
dim = label.getPreferredSize();
709
label.setBounds(label.getX(), label.getY(),
710
(int) dim.getWidth(),
711
(int) dim.getHeight());
712
table.put(new Integer(i), label);
820
label = new JLabel(String.valueOf(i));
821
label.setVerticalAlignment(CENTER);
822
label.setHorizontalAlignment(CENTER);
824
// Make sure these labels have the width and height
826
dim = label.getPreferredSize();
827
label.setBounds(label.getX(), label.getY(),
828
(int) dim.getWidth(),
829
(int) dim.getHeight());
830
table.put(new Integer(i), label);
718
* This method returns whether the slider is inverted. Horizontal sliders
719
* that are not inverted will have the minimums on the left. If they are
720
* inverted, the minimums will be on the right. Vertical sliders that are
721
* not inverted will have the minimums at the bottom. If they are inverted,
722
* the minimums will be at the top.
836
* Returns the flag that controls whether or not the value scale for the
837
* slider is inverted (the default value is <code>false</code>).
724
* @return Whether this slider is inverted.
839
* @return The flag that controls whether or not the value scale for the
840
* slider is inverted.
842
* @see #setInverted(boolean)
726
844
public boolean getInverted()
732
* This method changes the "inverted" property for this slider.Horizontal
733
* sliders that are not inverted will have the minimums on the left. If
734
* they are inverted, the minimums will be on the right. Vertical sliders
735
* that are not inverted will have the minimums at the bottom. If they are
736
* inverted, the minimums will be at the top. However, if the slider's
737
* componentOrientation is set to RIGHT_TO_LEFT, then everything gets
850
* Sets the flag that controls whether or not the value scale for the
851
* slider is inverted and, if the new flag value is different to the old flag
852
* value, sends a {@link PropertyChangeEvent} to all registered listeners.
853
* Typically, a horizontal slider will display a scale that increases from
854
* left to right, but this is reversed if the 'inverted' flag is set to
855
* <code>true</code>. Similarly, a vertical slider will display a scale that
856
* increases from bottom to top, and this is reversed if the 'inverted' flag
857
* is set to <code>true</code>.
740
* @param inverted Whether the slider should be inverted.
859
* @param inverted the new flag value.
861
* @see #getInverted()
742
863
public void setInverted(boolean inverted)
744
865
if (isInverted != inverted)
746
boolean oldInverted = isInverted;
747
isInverted = inverted;
748
firePropertyChange("inverted", oldInverted, isInverted);
867
boolean oldInverted = isInverted;
868
isInverted = inverted;
869
firePropertyChange("inverted", oldInverted, isInverted);
753
* This method returns the amount of units between each major tick mark.
874
* Returns the distance between major tick marks along the slider's value
755
877
* @return The amount of units between each major tick mark.
879
* @see #setMajorTickSpacing(int)
757
881
public int getMajorTickSpacing()
763
* This method changes the "majorTickSpacing" property for this slider. The
764
* major tick spacing is the amount of units between each major tick mark.
887
* Sets the distance between major tick marks along the slider's value scale,
888
* and sends a {@link PropertyChangeEvent} (with the property name
889
* "majorTickSpacing") to all registered listeners.
766
* @param spacing The amount of units between each major tick mark.
891
* @param spacing the distance between major tick marks.
893
* @see #getMajorTickSpacing()
768
895
public void setMajorTickSpacing(int spacing)
770
897
if (majorTickSpacing != spacing)
772
int oldSpacing = majorTickSpacing;
773
majorTickSpacing = spacing;
774
firePropertyChange("majorTickSpacing", oldSpacing,
899
int oldSpacing = majorTickSpacing;
900
majorTickSpacing = spacing;
901
firePropertyChange("majorTickSpacing", oldSpacing, majorTickSpacing);
780
* This method returns the amount of units between each minor tick mark.
906
* Returns the distance between minor tick marks along the slider's value
782
* @return The amount of units between each minor tick mark.
909
* @return The distance between minor tick marks along the slider's value
912
* @see #setMinorTickSpacing(int)
784
914
public int getMinorTickSpacing()
790
* This method changes the "minorTickSpacing" property for this slider. The
791
* minor tick spacing is the amount of units between each minor tick mark.
920
* Sets the distance between minor tick marks along the slider's value scale,
921
* and sends a {@link PropertyChangeEvent} (with the property name
922
* "minorTickSpacing") to all registered listeners.
793
* @param spacing The amount of units between each minor tick mark.
924
* @param spacing the distance between minor tick marks.
926
* @see #getMinorTickSpacing()
795
928
public void setMinorTickSpacing(int spacing)
797
930
if (minorTickSpacing != spacing)
799
int oldSpacing = minorTickSpacing;
800
minorTickSpacing = spacing;
801
firePropertyChange("minorTickSpacing", oldSpacing,
932
int oldSpacing = minorTickSpacing;
933
minorTickSpacing = spacing;
934
firePropertyChange("minorTickSpacing", oldSpacing, minorTickSpacing);
807
* This method returns whether this slider is snapping to ticks. Sliders
808
* that snap to ticks will automatically move the thumb to the nearest tick
939
* Returns the flag that controls whether the slider thumb will snap to ticks.
940
* Sliders that snap to ticks will automatically move the thumb to the
811
* @return Whether this slider snaps to ticks.
943
* @return <code>true</code> if the slider thumb automatically.
945
* @see #setSnapToTicks(boolean)
813
947
public boolean getSnapToTicks()
819
* This method sets whether this slider will snap to ticks. Sliders that
820
* snap to ticks will automatically move the thumb to the nearest tick
953
* Sets the flag that controls whether the slider thumb will snap to ticks
954
* and sends a {@link PropertyChangeEvent} (with the property name
955
* 'snapToTicks') to all registered listeners. Sliders that snap to ticks
956
* will automatically move the thumb to the nearest tick mark.
823
* @param snap Whether this slider snaps to ticks.
958
* @param snap the new flag value.
960
* @see #getSnapToTicks()
825
962
public void setSnapToTicks(boolean snap)
827
964
if (snap != snapToTicks)
830
firePropertyChange("snapToTicks", !snap, snap);
967
firePropertyChange("snapToTicks", !snap, snap);
835
* This method returns whether the slider will paint its tick marks. In
836
* addition to setting this property to true, one of minor tick spacing or
837
* major tick spacing must be set to a value greater than 0 in order for
838
* ticks to be painted.
972
* Returns the flag that controls whether or not tick marks are painted along
973
* the slider's value scale.
840
* @return Whether ticks will be painted.
975
* @return <code>true</code> if tick marks should be painted, and
976
* <code>false</code> if tick marks should not be painted.
978
* @see #setPaintTicks(boolean)
842
980
public boolean getPaintTicks()
848
* This method changes the "paintTicks" property for this slider. In
849
* addition to setting this property to true, one of minor tick spacing or
850
* major tick spacing must be set to a value greater than 0 in order for
851
* ticks to be painted.
986
* Sets the flag that controls whether or not tick marks are painted along
987
* the slider's value scale, and sends a {@link PropertyChangeEvent} (with
988
* the property name "paintTicks") to all registered listeners. In
989
* addition to setting this property to <code>true</code>, one or both of the
990
* minor tick spacing and major tick spacing attributes must be set to a
991
* value greater than 0 in order for ticks to be painted.
853
993
* @param paint Whether ticks will be painted.
995
* @see #getPaintTicks()
855
997
public void setPaintTicks(boolean paint)
857
999
if (paint != paintTicks)
859
boolean oldPaintTicks = paintTicks;
861
firePropertyChange("paintTicks", oldPaintTicks, paintTicks);
1001
boolean oldPaintTicks = paintTicks;
1003
firePropertyChange("paintTicks", oldPaintTicks, paintTicks);
866
* This method returns whether the track will be painted.
1008
* Returns the flag that controls whether or not the track is painted.
868
1010
* @return Whether the track will be painted.
1012
* @see #setPaintTrack(boolean)
870
1014
public boolean getPaintTrack()
902
* This method changes the "paintLabels" property.
1051
* Sets the flag that controls whether or not labels are painted for the
1052
* tick marks along the slider and sends a {@link PropertyChangeEvent} (with
1053
* the property name "paintLabels") to all registered listeners.
904
1055
* @param paint Whether labels will be painted.
1057
* @see #getPaintLabels()
906
1059
public void setPaintLabels(boolean paint)
908
1061
if (paint != paintLabels)
911
if (paint && majorTickSpacing > 0)
1063
paintLabels = paint;
1064
if (paint && majorTickSpacing > 0 && labelTable == null)
912
1065
labelTable = createStandardLabels(majorTickSpacing);
913
firePropertyChange("paintLabels", !paint, paint);
1066
firePropertyChange("paintLabels", !paint, paint);
918
* This method is used primarily for debugging purposes and returns a string
919
* that can be used to represent this slider.
1071
* Returns an implementation-dependent string describing the attributes of
1072
* this <code>JSlider</code>.
921
* @return A string representing this slider.
1074
* @return A string describing the attributes of this <code>JSlider</code>
1075
* (never <code>null</code>).
923
1077
protected String paramString()
1079
String superParamStr = super.paramString();
1080
StringBuffer sb = new StringBuffer();
1081
sb.append(",isInverted=").append(getInverted());
1082
sb.append(",majorTickSpacing=").append(getMajorTickSpacing());
1083
sb.append(",minorTickSpacing=").append(getMinorTickSpacing());
1084
sb.append(",orientation=");
1085
if (orientation == HORIZONTAL)
1086
sb.append("HORIZONTAL");
1088
sb.append("VERTICAL");
1089
sb.append(",paintLabels=").append(getPaintLabels());
1090
sb.append(",paintTicks=").append(getPaintTicks());
1091
sb.append(",paintTrack=").append(getPaintTrack());
1092
sb.append(",snapToTicks=").append(getSnapToTicks());
1094
// the following is output by the reference implementation. We don't
1095
// strictly need to replicate this. Perhaps it has some meaning, but
1096
// I couldn't determine it yet...
1097
sb.append(",snapToValue=true");
1099
return superParamStr + sb.toString();
1103
* Returns the object that provides accessibility features for this
1104
* <code>JSlider</code> component.
931
* @return DOCUMENT ME!
1106
* @return The accessible context (an instance of {@link AccessibleJSlider}).
933
1108
public AccessibleContext getAccessibleContext()