|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--AbstractSpinnerModel | +--SpinnerNumberModel
A SpinnerModel for sequences of numbers.
The upper and lower
bounds of the sequence are defined by properties called
minimum and maximum and the size of the
increase or decrease computed by the nextValue and
previousValue methods is defined by a property called
stepSize. The minimum and
maximum properties can be
null to indicate that the sequence has no lower or upper limit.
All of the properties in this class are defined in terms of two
generic types: Number and
Comparable, so that it can accomodate all
of the Java numeric types. Internally, there's only support for
values that whose type is one of the primitive Number types -
Double, Float, Long, Integer, Short, or Byte.
To create a SpinnerNumberModel for the integer
range zero to one hundred, with
fifty as the initial value, one could write:
Integer value = new Integer(50); Integer min = new Integer(0); Integer max = new Integer(100); Integer step = new Integer(1); SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step); int fifty = model.getNumber().intValue();
Spinners for integers and doubles are common, so special constructors for these cases are provided. For example to create the model in the previous example, one could also write:
SpinnerNumberModel model = new SpinnerNumberModel(50, 0, 100, 1);
This model inherits a ChangeListener. The ChangeListeners are notified
whenever the models value, stepSize,
minimum, or maximum properties changes.
JSpinner,
SpinnerModel,
AbstractSpinnerModel,
SpinnerListModel,
SpinnerDateModel| Fields inherited from class AbstractSpinnerModel |
listenerList |
| Constructor Summary | |
SpinnerNumberModel()
Construct a SpinnerNumberModel with no minimum or maximum value,
stepSize equal to one, and an initial value of zero. |
|
SpinnerNumberModel(double value,
double minimum,
double maximum,
double stepSize)
Construct a SpinnerNumberModel with the specified value, minimum/maximum bounds,
and stepSize. |
|
SpinnerNumberModel(int value,
int minimum,
int maximum,
int stepSize)
Construct a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize. |
|
SpinnerNumberModel(java.lang.Number value,
java.lang.Comparable minimum,
java.lang.Comparable maximum,
java.lang.Number stepSize)
Construct a SpinnerModel that represents a closed sequence of
numbers from minimum to maximum. |
|
| Method Summary | |
java.lang.Comparable |
getMaximum()
Return the last number in the sequence. |
java.lang.Comparable |
getMinimum()
Return the first number in this sequence. |
java.lang.Object |
getNextValue()
Return the next number in the sequence. |
java.lang.Number |
getNumber()
Return the value of the current element of the sequence. |
java.lang.Object |
getPreviousValue()
Return the previous number in the sequence. |
java.lang.Number |
getStepSize()
Return the size of the value change computed by the getNextValue
and getPreviousValue methods. |
java.lang.Object |
getValue()
Return the value of the current element of the sequence. |
void |
setMaximum(java.lang.Comparable maximum)
Change the upper bound for numbers in this sequence. |
void |
setMinimum(java.lang.Comparable minimum)
Change the lower bound for numbers in this sequence. |
void |
setStepSize(java.lang.Number stepSize)
Change the size of the value change computed by the getNextValue
and getPreviousValue methods. |
void |
setValue(java.lang.Object value)
Set the current value for this sequence. |
| Methods inherited from class AbstractSpinnerModel |
addChangeListener, fireStateChanged, getListeners, removeChangeListener |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public SpinnerNumberModel(java.lang.Number value, java.lang.Comparable minimum, java.lang.Comparable maximum, java.lang.Number stepSize)
SpinnerModel that represents a closed sequence of
numbers from minimum to maximum. The
nextValue and previousValue methods
compute elements of the sequence by adding or subtracting
stepSize respectively. All of the parameters
must be mutually Comparable, value
and stepSize must be instances of Integer
Long, Float, or Double.
The minimum and maximum parameters can be null
to indicate that the range doesn't have an upper or lower bound.
If value or stepSize is null, or if both
minimum and maximum are specified and
mininum > maximum then an IllegalArgumentException is thrown.
Similarly if (minimum <= value <= maximum) is false,
an IllegalArgumentException is thrown.
value - the current (non null) value of the modelminimum - the first number in the sequence or nullmaximum - the last number in the sequence or nullstepSize - the difference between elements of the sequencejava.lang.IllegalArgumentException - if stepSize or value is null or if
the following expression is false: minimum <= value <= maximumpublic SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
minimum/maximum bounds, and stepSize.value - the current value of the modelminimum - the first number in the sequencemaximum - the last number in the sequencestepSize - the difference between elements of the sequencejava.lang.IllegalArgumentException - if stepSize or value is null or if
the following expression is false: minimum <= value <= maximumpublic SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
minimum/maximum bounds,
and stepSize.value - the current value of the modelminimum - the first number in the sequencemaximum - the last number in the sequencestepSize - the difference between elements of the sequencejava.lang.IllegalArgumentException - if stepSize or value is null or if
the following expression is false: minimum <= value <= maximumpublic SpinnerNumberModel()
minimum or maximum value,
stepSize equal to one, and an initial value of zero.| Method Detail |
public void setMinimum(java.lang.Comparable minimum)
minimum is null,
then there is no lower bound. No bounds checking is done here: the new
minimum value may invalidate the (minimum <= value <= maximum)
invariant enforced by the constructors. This is to simplify updating
the model, naturally one should ensure that the invariant is true
before calling the getNextValue, getPreviousValue,
or setValue methods.
Typically this property is a Number of the same type as the value
however it's possible to use any Comparable with a compareTo
method for a Number with the same type as the value. For example if value
was a Long, minimum might be a Date subclass defined like this:
MyDate extends Date { // Date already implements Comparable
public int compareTo(Long o) {
long t = getTime();
return (t < o.longValue() ? -1 : (t == o.longValue() ? 0 : 1));
}
}
This method fires a ChangeEvent if the minimum has changed.
minimum - a Comparable that has a compareTo method for Numbers with
the same type as valuegetMinimum(),
setMaximum(java.lang.Comparable),
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)public java.lang.Comparable getMinimum()
minimum propertysetMinimum(java.lang.Comparable)public void setMaximum(java.lang.Comparable maximum)
maximum
is null, then there is no upper bound. No bounds checking is done here: the new
maximum value may invalidate the (minimum <= value < maximum)
invariant enforced by the constructors. This is to simplify updating
the model, naturally one should ensure that the invariant is true
before calling the next, previous, or setValue methods.
Typically this property is a Number of the same type as the value
however it's possible to use any Comparable with a compareTo
method for a Number with the same type as the value. See setMinimum
for an example.
This method fires a ChangeEvent if the maximum has changed.
maximum - a Comparable that has a compareTo method for Numbers with
the same type as valuegetMaximum(),
setMinimum(java.lang.Comparable),
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)public java.lang.Comparable getMaximum()
maximum propertysetMaximum(java.lang.Comparable)public void setStepSize(java.lang.Number stepSize)
getNextValue
and getPreviousValue methods. An IllegalArgumenException
is thrown if stepSize is null.
This method fires a ChangeEvent if the minimum has changed. *
stepSize - the size of the value change computed by the
getNextValue and getPreviousValue methodsgetNextValue(),
getPreviousValue(),
getStepSize(),
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)public java.lang.Number getStepSize()
getNextValue
and getPreviousValue methods.setStepSize(java.lang.Number)public java.lang.Object getNextValue()
value + stepSize or null if the sum
exceeds maximum.SpinnerModel.getNextValue(),
getPreviousValue(),
setStepSize(java.lang.Number)public java.lang.Object getPreviousValue()
value - stepSize or null if the sum is less
than minimum.SpinnerModel.getPreviousValue(),
getNextValue(),
setStepSize(java.lang.Number)public java.lang.Number getNumber()
setValue(java.lang.Object)public java.lang.Object getValue()
setValue(java.lang.Object),
getNumber()public void setValue(java.lang.Object value)
value is null,
or not a Number, an IllegalArgumentException is thrown. No
bounds checking is done here: the new value may invalidate the
(minimum <= value <= maximum)
invariant enforced by the constructors. It's also possible to set
the value to be something that wouldn't naturally occur in the sequence,
i.e. a value that's not modulo the stepSize. This is to simplify
updating the model, and to accomodate spinners that don't want
to restrict values that have been directly entered by the user.
Naturally naturally one should ensure that the
(minimum <= value <= maximum) invariant is true
before calling the next, previous, or setValue methods.
This method fires a ChangeEvent if the value has changed.
value - the current (non null) Number for this sequencejava.lang.IllegalArgumentException - if value is null or not a NumbergetNumber(),
getValue(),
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||