java.lang.Object
javax.swing.DefaultBoundedRangeModel
- All Implemented Interfaces:
Serializable
,BoundedRangeModel
public class DefaultBoundedRangeModel extends Object implements BoundedRangeModel, Serializable
A generic implementation of BoundedRangeModel.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans™
has been added to the java.beans
package.
Please see XMLEncoder
.
- Since:
- 1.2
- See Also:
BoundedRangeModel
-
Field Summary
Fields Modifier and Type Field Description protected ChangeEvent
changeEvent
Only oneChangeEvent
is needed per model instance since the event's only (read-only) state is the source property.protected EventListenerList
listenerList
The listeners waiting for model changes. -
Constructor Summary
Constructors Constructor Description DefaultBoundedRangeModel()
Initializes all of the properties with default values.DefaultBoundedRangeModel(int value, int extent, int min, int max)
Initializes value, extent, minimum and maximum. -
Method Summary
Modifier and Type Method Description void
addChangeListener(ChangeListener l)
Adds aChangeListener
.protected void
fireStateChanged()
Runs eachChangeListener
'sstateChanged
method.ChangeListener[]
getChangeListeners()
Returns an array of all the change listeners registered on thisDefaultBoundedRangeModel
.int
getExtent()
Returns the model's extent.<T extends EventListener>
T[]getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered asFooListener
s upon this model.int
getMaximum()
Returns the model's maximum.int
getMinimum()
Returns the model's minimum.int
getValue()
Returns the model's current value.boolean
getValueIsAdjusting()
Returns true if the value is in the process of changing as a result of actions being taken by the user.void
removeChangeListener(ChangeListener l)
Removes aChangeListener
.void
setExtent(int n)
Sets the extent to n after ensuring that n is greater than or equal to zero and falls within the model's constraints:void
setMaximum(int n)
Sets the maximum to n after ensuring that n that the other three properties obey the model's constraints:void
setMinimum(int n)
Sets the minimum to n after ensuring that n that the other three properties obey the model's constraints:void
setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting)
Sets all of theBoundedRangeModel
properties after forcing the arguments to obey the usual constraints:void
setValue(int n)
Sets the current value of the model.void
setValueIsAdjusting(boolean b)
Sets thevalueIsAdjusting
property.String
toString()
Returns a string that displays all of theBoundedRangeModel
properties.
-
Field Details
-
changeEvent
Only oneChangeEvent
is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this". -
listenerList
The listeners waiting for model changes.
-
-
Constructor Details
-
DefaultBoundedRangeModel
public DefaultBoundedRangeModel()Initializes all of the properties with default values. Those values are:value
= 0extent
= 0minimum
= 0maximum
= 100adjusting
= false
-
DefaultBoundedRangeModel
public DefaultBoundedRangeModel(int value, int extent, int min, int max)Initializes value, extent, minimum and maximum. Adjusting is false. Throws anIllegalArgumentException
if the following constraints aren't satisfied:min <= value <= value+extent <= max
- Parameters:
value
- an int giving the current valueextent
- the length of the inner range that begins at the model's valuemin
- an int giving the minimum valuemax
- an int giving the maximum value
-
-
Method Details
-
getValue
public int getValue()Returns the model's current value.- Specified by:
getValue
in interfaceBoundedRangeModel
- Returns:
- the model's current value
- See Also:
setValue(int)
,BoundedRangeModel.getValue()
-
getExtent
public int getExtent()Returns the model's extent.- Specified by:
getExtent
in interfaceBoundedRangeModel
- Returns:
- the model's extent
- See Also:
setExtent(int)
,BoundedRangeModel.getExtent()
-
getMinimum
public int getMinimum()Returns the model's minimum.- Specified by:
getMinimum
in interfaceBoundedRangeModel
- Returns:
- the model's minimum
- See Also:
setMinimum(int)
,BoundedRangeModel.getMinimum()
-
getMaximum
public int getMaximum()Returns the model's maximum.- Specified by:
getMaximum
in interfaceBoundedRangeModel
- Returns:
- the model's maximum
- See Also:
setMaximum(int)
,BoundedRangeModel.getMaximum()
-
setValue
public void setValue(int n)Sets the current value of the model. For a slider, that determines where the knob appears. Ensures that the new value, n falls within the model's constraints:minimum <= value <= value+extent <= maximum
- Specified by:
setValue
in interfaceBoundedRangeModel
- Parameters:
n
- the model's new value- See Also:
BoundedRangeModel.setValue(int)
-
setExtent
public void setExtent(int n)Sets the extent to n after ensuring that n is greater than or equal to zero and falls within the model's constraints:minimum <= value <= value+extent <= maximum
- Specified by:
setExtent
in interfaceBoundedRangeModel
- Parameters:
n
- the model's new extent- See Also:
BoundedRangeModel.setExtent(int)
-
setMinimum
public void setMinimum(int n)Sets the minimum to n after ensuring that n that the other three properties obey the model's constraints:minimum <= value <= value+extent <= maximum
- Specified by:
setMinimum
in interfaceBoundedRangeModel
- Parameters:
n
- the model's new minimum- See Also:
getMinimum()
,BoundedRangeModel.setMinimum(int)
-
setMaximum
public void setMaximum(int n)Sets the maximum to n after ensuring that n that the other three properties obey the model's constraints:minimum <= value <= value+extent <= maximum
- Specified by:
setMaximum
in interfaceBoundedRangeModel
- Parameters:
n
- the model's new maximum- See Also:
BoundedRangeModel.setMaximum(int)
-
setValueIsAdjusting
public void setValueIsAdjusting(boolean b)Sets thevalueIsAdjusting
property.- Specified by:
setValueIsAdjusting
in interfaceBoundedRangeModel
- Parameters:
b
- true if the upcoming changes to the value property are part of a series- See Also:
getValueIsAdjusting()
,setValue(int)
,BoundedRangeModel.setValueIsAdjusting(boolean)
-
getValueIsAdjusting
public boolean getValueIsAdjusting()Returns true if the value is in the process of changing as a result of actions being taken by the user.- Specified by:
getValueIsAdjusting
in interfaceBoundedRangeModel
- Returns:
- the value of the
valueIsAdjusting
property - See Also:
setValue(int)
,BoundedRangeModel.getValueIsAdjusting()
-
setRangeProperties
public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting)Sets all of theBoundedRangeModel
properties after forcing the arguments to obey the usual constraints:minimum <= value <= value+extent <= maximum
At most, one
ChangeEvent
is generated.- Specified by:
setRangeProperties
in interfaceBoundedRangeModel
- Parameters:
newValue
- an int giving the current valuenewExtent
- an int giving the amount by which the value can "jump"newMin
- an int giving the minimum valuenewMax
- an int giving the maximum valueadjusting
- a boolean, true if a series of changes are in progress- See Also:
BoundedRangeModel.setRangeProperties(int, int, int, int, boolean)
,setValue(int)
,setExtent(int)
,setMinimum(int)
,setMaximum(int)
,setValueIsAdjusting(boolean)
-
addChangeListener
Adds aChangeListener
. The change listeners are run each time any one of the Bounded Range model properties changes.- Specified by:
addChangeListener
in interfaceBoundedRangeModel
- Parameters:
l
- the ChangeListener to add- See Also:
removeChangeListener(javax.swing.event.ChangeListener)
,BoundedRangeModel.addChangeListener(javax.swing.event.ChangeListener)
-
removeChangeListener
Removes aChangeListener
.- Specified by:
removeChangeListener
in interfaceBoundedRangeModel
- Parameters:
l
- theChangeListener
to remove- See Also:
addChangeListener(javax.swing.event.ChangeListener)
,BoundedRangeModel.removeChangeListener(javax.swing.event.ChangeListener)
-
getChangeListeners
Returns an array of all the change listeners registered on thisDefaultBoundedRangeModel
.- Returns:
- all of this model's
ChangeListener
s or an empty array if no change listeners are currently registered - Since:
- 1.4
- See Also:
addChangeListener(javax.swing.event.ChangeListener)
,removeChangeListener(javax.swing.event.ChangeListener)
-
fireStateChanged
protected void fireStateChanged()Runs eachChangeListener
'sstateChanged
method. -
toString
Returns a string that displays all of theBoundedRangeModel
properties. -
getListeners
Returns an array of all the objects currently registered asFooListener
s upon this model.FooListener
s are registered using theaddFooListener
method.You can specify the
listenerType
argument with a class literal, such asFooListener.class
. For example, you can query aDefaultBoundedRangeModel
instancem
for its change listeners with the following code:ChangeListener[] cls = (ChangeListener[])(m.getListeners(ChangeListener.class));
If no such listeners exist, this method returns an empty array.- Type Parameters:
T
- the type ofEventListener
class being requested- Parameters:
listenerType
- the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener
- Returns:
- an array of all objects registered as
FooListener
s on this model, or an empty array if no such listeners have been added - Throws:
ClassCastException
- iflistenerType
doesn't specify a class or interface that implementsjava.util.EventListener
- Since:
- 1.3
- See Also:
getChangeListeners()
-