diff options
Diffstat (limited to 'libjava/classpath/javax/swing/JSlider.java')
-rw-r--r-- | libjava/classpath/javax/swing/JSlider.java | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/libjava/classpath/javax/swing/JSlider.java b/libjava/classpath/javax/swing/JSlider.java index 7f995115d8f..2caf509a1bb 100644 --- a/libjava/classpath/javax/swing/JSlider.java +++ b/libjava/classpath/javax/swing/JSlider.java @@ -41,6 +41,7 @@ package javax.swing; import java.awt.Dimension; import java.awt.MenuContainer; import java.awt.image.ImageObserver; +import java.beans.PropertyChangeEvent; import java.io.Serializable; import java.util.Dictionary; import java.util.Enumeration; @@ -124,8 +125,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, /** * Creates a new AccessibleJSlider object. - * - * @param value0 DOCUMENT ME! */ protected AccessibleJSlider() { @@ -229,7 +228,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, protected int minorTickSpacing; /** Whether the slider snaps its values to ticks. */ - protected boolean snapToTicks = true; + protected boolean snapToTicks = false; /** The orientation of the slider. */ protected int orientation = HORIZONTAL; @@ -256,7 +255,11 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, * Creates a new JSlider object with the given orientation and a minimum of * 0, a maximum of 100, and a value of 50. * - * @param orientation The orientation of the slider. + * @param orientation The orientation of the slider ({@link #HORIZONTAL} or + * {@link #VERTICAL}). + * + * @throws IllegalArgumentException if <code>orientation</code> is not one of + * the specified values. */ public JSlider(int orientation) { @@ -293,10 +296,14 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, * Creates a new JSlider object with the given orientation, minimum, * maximum, and value. * - * @param orientation The orientation of the JSlider. + * @param orientation The orientation of the slider ({@link #HORIZONTAL} or + * {@link #VERTICAL}). * @param minimum The minimum value of the JSlider. * @param maximum The maximum value of the JSlider. * @param value The initial value of the JSlider. + * + * @throws IllegalArgumentException if <code>orientation</code> is not one of + * the specified values. */ public JSlider(int orientation, int minimum, int maximum, int value) { @@ -312,14 +319,13 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, /** * Creates a new horizontal JSlider object with the given model. * - * @param model The model the slider will be created with. + * @param model The model (<code>null</code> not permitted). + * + * @throws NullPointerException if <code>model</code> is <code>null</code>. */ public JSlider(BoundedRangeModel model) { - if (model == null) - sliderModel = new DefaultBoundedRangeModel(50, 0, 0, 100); - else - sliderModel = model; + sliderModel = model; changeListener = createChangeListener(); sliderModel.addChangeListener(changeListener); updateUI(); @@ -504,7 +510,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, */ public void setMinimum(int minimum) { + int old = sliderModel.getMinimum(); sliderModel.setMinimum(minimum); + if (minimum != old) + firePropertyChange("minimum", old, minimum); } /** @@ -524,7 +533,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, */ public void setMaximum(int maximum) { + int old = sliderModel.getMaximum(); sliderModel.setMaximum(maximum); + if (maximum != old) + firePropertyChange("maximum", old, maximum); } /** @@ -643,9 +655,12 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, * minimum and increase by the increment. Each label will have a text * string indicating their integer value. * - * @param increment The increment to between labels. + * @param increment The increment between labels (must be > 0). * * @return A hashtable with the labels and their keys. + * + * @throws IllegalArgumentException if <code>increment</code> is not greater + * than zero. */ public Hashtable createStandardLabels(int increment) { @@ -656,15 +671,23 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, * Creates a hashtable of (Integer, JLabel) pairs that can be used as a * label table for this slider. The labels will start from the given start * value and increase by the increment. Each label will have a text string - * indicating their integer value. + * indicating its integer value. * - * @param increment The increment to between labels. + * @param increment The increment between labels (must be > 0). * @param start The value to start from. * * @return A hashtable with the labels and their keys. + * + * @throws IllegalArgumentException if <code>increment</code> is not greater + * than zero, or <code>start</code> is not within the range of the + * model. */ public Hashtable createStandardLabels(int increment, int start) { + if (increment <= 0) + throw new IllegalArgumentException("Requires 'increment' > 0."); + if (start < getMinimum() || start > getMaximum()) + throw new IllegalArgumentException("The 'start' value is out of range."); Hashtable table = new Hashtable(); JLabel label; Dimension dim; @@ -801,7 +824,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, if (snap != snapToTicks) { snapToTicks = snap; - fireStateChanged(); + firePropertyChange("snapToTicks", !snap, snap); } } @@ -847,13 +870,19 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, } /** - * This method sets whether the track will be painted. + * Sets the flag that controls whether or not the track is painted, and + * sends a {@link PropertyChangeEvent} (for the "paintTrack" property) to all + * registered listeners. * * @param paint Whether the track will be painted. */ public void setPaintTrack(boolean paint) { - paintTrack = paint; + if (paintTrack != paint) + { + paintTrack = paint; + firePropertyChange("paintTrack", !paint, paint); + } } /** @@ -875,9 +904,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, { if (paint != paintLabels) { - boolean oldPaintLabels = paintLabels; paintLabels = paint; - firePropertyChange("paintLabels", oldPaintLabels, paintLabels); + if (paint && majorTickSpacing > 0) + labelTable = createStandardLabels(majorTickSpacing); + firePropertyChange("paintLabels", !paint, paint); } } |