|
Préférences
Moteurs de recherche
|
|||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.6.0
javax.swing
|
Field Summary |
---|
Fields inherited from class javax.swing.AbstractSpinnerModel |
---|
listenerList |
Constructor Summary | |
---|---|
SpinnerNumberModel()
Constructs 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)
Constructs a SpinnerNumberModel with the specified
value , minimum /maximum bounds,
and stepSize . |
|
SpinnerNumberModel(int value,
int minimum,
int maximum,
int stepSize)
Constructs a SpinnerNumberModel with the specified
value , minimum /maximum bounds,
and stepSize . |
|
SpinnerNumberModel(Number value,
Comparable minimum,
Comparable maximum,
Number stepSize)
Constructs a SpinnerModel that represents
a closed sequence of
numbers from minimum to maximum . |
Method Summary | |
---|---|
Comparable |
getMaximum()
Returns the last number in the sequence. |
Comparable |
getMinimum()
Returns the first number in this sequence. |
Object |
getNextValue()
Returns the next number in the sequence. |
Number |
getNumber()
Returns the value of the current element of the sequence. |
Object |
getPreviousValue()
Returns the previous number in the sequence. |
Number |
getStepSize()
Returns the size of the value change computed by the getNextValue
and getPreviousValue methods. |
Object |
getValue()
Returns the value of the current element of the sequence. |
void |
setMaximum(Comparable maximum)
Changes the upper bound for numbers in this sequence. |
void |
setMinimum(Comparable minimum)
Changes the lower bound for numbers in this sequence. |
void |
setStepSize(Number stepSize)
Changes the size of the value change computed by the getNextValue and getPreviousValue
methods. |
void |
setValue(Object value)
Sets the current value for this sequence. |
Methods inherited from class javax.swing.AbstractSpinnerModel |
---|
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, 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 null
maximum
- the last number in the sequence or null
stepSize
- the difference between elements of the sequence
IllegalArgumentException
- if stepSize or value is
null
or if the following expression is false:
minimum <= value <= maximum
public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
SpinnerNumberModel
with the specified
value
, 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 sequence
IllegalArgumentException
- if the following expression is false:
minimum <= value <= maximum
public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
SpinnerNumberModel
with the specified
value
, 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 sequence
IllegalArgumentException
- if the following expression is false:
minimum <= value <= maximum
public SpinnerNumberModel()
SpinnerNumberModel
with no
minimum
or maximum
value,
stepSize
equal to one, and an initial value of zero.
Method Detail |
---|
public void setMinimum(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 Number
s with
the same type as value
getMinimum()
,
setMaximum(java.lang.Comparable)
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public Comparable getMinimum()
minimum
propertysetMinimum(java.lang.Comparable)
public void setMaximum(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 Number
s with
the same type as value
getMaximum()
,
setMinimum(java.lang.Comparable)
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public Comparable getMaximum()
maximum
propertysetMaximum(java.lang.Comparable)
public void setStepSize(Number stepSize)
getNextValue
and getPreviousValue
methods. An IllegalArgumentException
is thrown if stepSize
is null
.
This method fires a ChangeEvent
if the
stepSize
has changed.
stepSize
- the size of the value change computed by the
getNextValue
and getPreviousValue
methodsgetNextValue()
,
getPreviousValue()
,
getStepSize()
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public Number getStepSize()
getNextValue
and getPreviousValue
methods.
stepSize
propertysetStepSize(java.lang.Number)
public Object getNextValue()
getNextValue
in interface SpinnerModel
value + stepSize
or null
if the sum
exceeds maximum
.SpinnerModel.getNextValue()
,
getPreviousValue()
,
setStepSize(java.lang.Number)
public Object getPreviousValue()
getPreviousValue
in interface SpinnerModel
value - stepSize
, or
null
if the sum is less
than minimum
.SpinnerModel.getPreviousValue()
,
getNextValue()
,
setStepSize(java.lang.Number)
public Number getNumber()
setValue(java.lang.Object)
public Object getValue()
getValue
in interface SpinnerModel
setValue(java.lang.Object)
,
getNumber()
public void setValue(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 SpinnerModel
value
- the current (non null
) Number
for this sequence
IllegalArgumentException
- if value
is
null
or not a Number
getNumber()
,
getValue()
,
SpinnerModel.addChangeListener(javax.swing.event.ChangeListener)