public class MultiRangeSpinnerNumberModel
extends javax.swing.SpinnerNumberModel
Constructor and Description |
---|
MultiRangeSpinnerNumberModel()
Constructs a
MultiRangeSpinnerNumberModel with no
minimum or maximum value,
stepSize equal to one, and an initial value of zero. |
MultiRangeSpinnerNumberModel(java.lang.Comparable minimum,
java.lang.Comparable maximum,
java.lang.Number stepSize)
Constructs a
SpinnerModel that represents
a closed sequence of
numbers from minimum to maximum . |
MultiRangeSpinnerNumberModel(double minimum,
double maximum,
double stepSize)
Constructs a
MultiRangeSpinnerNumberModel with the specified
value , minimum /maximum bounds,
and stepSize . |
MultiRangeSpinnerNumberModel(int minimum,
int maximum,
int stepSize)
Constructs a
MultiRangeSpinnerNumberModel with the specified
value , minimum /maximum bounds,
and stepSize . |
Modifier and Type | Method and Description |
---|---|
void |
addRange(java.lang.Comparable minimum,
java.lang.Comparable maximum,
java.lang.Number stepSize)
Add another closed sequence of
numbers from
minimum to maximum . |
void |
addRange(double minimum,
double maximum,
double stepSize)
Add another closed sequence of
numbers from
minimum to maximum . |
void |
addRange(int minimum,
int maximum,
int stepSize)
Add another closed sequence of
numbers from
minimum to maximum . |
java.lang.Comparable |
getMaximum()
Returns the last number in the sequence.
|
java.lang.Comparable |
getMinimum()
Returns the first number in this sequence.
|
java.lang.Object |
getNextValue()
Returns the next number in the sequence.
|
java.lang.Number |
getNumber()
Returns the value of the current element of the sequence.
|
java.lang.Object |
getPreviousValue()
Returns the previous number in the sequence.
|
java.lang.Number |
getStepSize()
Returns the size of the value change computed by the
getNextValue
and getPreviousValue methods. |
java.lang.Object |
getValue()
Returns the value of the current element of the sequence.
|
void |
setMaximum(java.lang.Comparable maximum)
Changes the upper bound for numbers in this sequence.
|
void |
setMinimum(java.lang.Comparable minimum)
Changes the lower bound for numbers in this sequence.
|
void |
setValue(java.lang.Object value)
Sets the current value for this sequence.
|
java.lang.String |
toString()
Returns a string representation of the object.
|
public MultiRangeSpinnerNumberModel(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 minimum > maximum
then an
IllegalArgumentException
is thrown.
Similarly if (minimum <= value <= maximum
) is false,
an IllegalArgumentException
is thrown.
minimum
- the first number in the sequence or null
maximum
- the last number in the sequence or null
stepSize
- the difference between elements of the sequencejava.lang.IllegalArgumentException
- if stepSize is
null
or if the following expression is false:
minimum <= maximum
public MultiRangeSpinnerNumberModel(int minimum, int maximum, int stepSize)
MultiRangeSpinnerNumberModel
with the specified
value
, minimum
/maximum
bounds,
and stepSize
.minimum
- the first number in the sequencemaximum
- the last number in the sequencestepSize
- the difference between elements of the sequencejava.lang.IllegalArgumentException
- if the following expression is false:
minimum <= maximum
public MultiRangeSpinnerNumberModel(double minimum, double maximum, double stepSize)
MultiRangeSpinnerNumberModel
with the specified
value
, minimum
/maximum
bounds,
and stepSize
.minimum
- the first number in the sequencemaximum
- the last number in the sequencestepSize
- the difference between elements of the sequencejava.lang.IllegalArgumentException
- if the following expression is false:
minimum <= maximum
public MultiRangeSpinnerNumberModel()
MultiRangeSpinnerNumberModel
with no
minimum
or maximum
value,
stepSize
equal to one, and an initial value of zero.public void addRange(java.lang.Comparable minimum, java.lang.Comparable maximum, java.lang.Number stepSize)
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 stepSize
is null
,
or if both minimum
and maximum
are specified and minimum > maximum
then an
IllegalArgumentException
is thrown.
minimum
- the first number in the sequence or null
maximum
- the last number in the sequence or null
stepSize
- the difference between elements of the sequencejava.lang.IllegalArgumentException
- if stepSize or value is
null
or if the following expression is false:
minimum <= value <= maximum
public void addRange(int minimum, int maximum, int stepSize)
minimum
to maximum
.
Note that ranges should not overlap, but this class does not enforce that.minimum
- the first number in the sequencemaximum
- the last number in the sequencestepSize
- the difference between elements of this sequencejava.lang.IllegalArgumentException
- if the following expression is false:
minimum <= value <= maximum
public void addRange(double minimum, double maximum, double stepSize)
minimum
to maximum
.
Note that ranges should not overlap, but this class does not enforce that.minimum
- the first number in the sequencemaximum
- the last number in the sequencestepSize
- the difference between elements of this sequencejava.lang.IllegalArgumentException
- if the following expression is false:
minimum <= value <= maximum
public java.lang.Comparable getMinimum()
getMinimum
in class javax.swing.SpinnerNumberModel
minimum
propertypublic java.lang.Comparable getMaximum()
getMaximum
in class javax.swing.SpinnerNumberModel
maximum
propertypublic java.lang.Number getStepSize()
getNextValue
and getPreviousValue
methods.getStepSize
in class javax.swing.SpinnerNumberModel
stepSize
propertypublic java.lang.Object getNextValue()
getNextValue
in interface javax.swing.SpinnerModel
getNextValue
in class javax.swing.SpinnerNumberModel
value + stepSize
or null
if the sum
exceeds maximum
.SpinnerModel.getNextValue()
,
getPreviousValue()
public java.lang.Object getPreviousValue()
getPreviousValue
in interface javax.swing.SpinnerModel
getPreviousValue
in class javax.swing.SpinnerNumberModel
value - stepSize
, or
null
if the sum is less
than minimum
.SpinnerModel.getPreviousValue()
,
getNextValue()
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.
setMinimum
in class javax.swing.SpinnerNumberModel
minimum
- a Comparable
that has a
compareTo
method for Number
s with
the same type as value
getMinimum()
,
setMaximum(java.lang.Comparable)
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
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.
setMaximum
in class javax.swing.SpinnerNumberModel
maximum
- a Comparable
that has a
compareTo
method for Number
s with
the same type as value
getMaximum()
,
setMinimum(java.lang.Comparable)
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public java.lang.Number getNumber()
getNumber
in class javax.swing.SpinnerNumberModel
setValue(java.lang.Object)
public java.lang.Object getValue()
getValue
in interface javax.swing.SpinnerModel
getValue
in class javax.swing.SpinnerNumberModel
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 accommodate
spinners that don't want to restrict values that have been
directly entered by the user. 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.
setValue
in interface javax.swing.SpinnerModel
setValue
in class javax.swing.SpinnerNumberModel
value
- the current (non null
) Number
for this sequencejava.lang.IllegalArgumentException
- if value
is
null
or not a Number
getNumber()
,
getValue()
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public java.lang.String toString()
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.toString
in class java.lang.Object