java.lang.Object
javax.swing.DefaultBoundedRangeModel
- All Implemented Interfaces:
Serializable,BoundedRangeModel
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChangeEventOnly oneChangeEventis needed per model instance since the event's only (read-only) state is the source property.protected EventListenerListThe listeners waiting for model changes. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes 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 TypeMethodDescriptionvoidAdds aChangeListener.protected voidRuns eachChangeListener'sstateChangedmethod.Returns an array of all the change listeners registered on thisDefaultBoundedRangeModel.intReturns the model's extent.<T extends EventListener>
T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon this model.intReturns the model's maximum.intReturns the model's minimum.intgetValue()Returns the model's current value.booleanReturns true if the value is in the process of changing as a result of actions being taken by the user.voidRemoves aChangeListener.voidsetExtent(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:voidsetMaximum(int n) Sets the maximum to n after ensuring that n that the other three properties obey the model's constraints:voidsetMinimum(int n) Sets the minimum to n after ensuring that n that the other three properties obey the model's constraints:voidsetRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) Sets all of theBoundedRangeModelproperties after forcing the arguments to obey the usual constraints:voidsetValue(int n) Sets the current value of the model.voidsetValueIsAdjusting(boolean b) Sets thevalueIsAdjustingproperty.toString()Returns a string that displays all of theBoundedRangeModelproperties.
-
Field Details
-
changeEvent
Only oneChangeEventis 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 anIllegalArgumentExceptionif 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:
getValuein interfaceBoundedRangeModel- Returns:
- the model's current value
- See Also:
-
getExtent
public int getExtent()Returns the model's extent.- Specified by:
getExtentin interfaceBoundedRangeModel- Returns:
- the model's extent
- See Also:
-
getMinimum
public int getMinimum()Returns the model's minimum.- Specified by:
getMinimumin interfaceBoundedRangeModel- Returns:
- the model's minimum
- See Also:
-
getMaximum
public int getMaximum()Returns the model's maximum.- Specified by:
getMaximumin interfaceBoundedRangeModel- Returns:
- the model's maximum
- See Also:
-
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:
setValuein interfaceBoundedRangeModel- Parameters:
n- the model's new value- See Also:
-
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:
setExtentin interfaceBoundedRangeModel- Parameters:
n- the model's new extent- See Also:
-
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:
setMinimumin interfaceBoundedRangeModel- Parameters:
n- the model's new minimum- See Also:
-
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:
setMaximumin interfaceBoundedRangeModel- Parameters:
n- the model's new maximum- See Also:
-
setValueIsAdjusting
public void setValueIsAdjusting(boolean b) Sets thevalueIsAdjustingproperty.- Specified by:
setValueIsAdjustingin interfaceBoundedRangeModel- Parameters:
b- true if the upcoming changes to the value property are part of a series- See Also:
-
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:
getValueIsAdjustingin interfaceBoundedRangeModel- Returns:
- the value of the
valueIsAdjustingproperty - See Also:
-
setRangeProperties
public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) Sets all of theBoundedRangeModelproperties after forcing the arguments to obey the usual constraints:minimum <= value <= value+extent <= maximumAt most, one
ChangeEventis generated.- Specified by:
setRangePropertiesin 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:
-
addChangeListener
Adds aChangeListener. The change listeners are run each time any one of the Bounded Range model properties changes.- Specified by:
addChangeListenerin interfaceBoundedRangeModel- Parameters:
l- the ChangeListener to add- See Also:
-
removeChangeListener
Removes aChangeListener.- Specified by:
removeChangeListenerin interfaceBoundedRangeModel- Parameters:
l- theChangeListenerto remove- See Also:
-
getChangeListeners
Returns an array of all the change listeners registered on thisDefaultBoundedRangeModel.- Returns:
- all of this model's
ChangeListeners or an empty array if no change listeners are currently registered - Since:
- 1.4
- See Also:
-
fireStateChanged
protected void fireStateChanged()Runs eachChangeListener'sstateChangedmethod.- See Also:
-
toString
Returns a string that displays all of theBoundedRangeModelproperties. -
getListeners
Returns an array of all the objects currently registered asFooListeners upon this model.FooListeners are registered using theaddFooListenermethod.You can specify the
listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aDefaultBoundedRangeModelinstancemfor 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 ofEventListenerclass 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
FooListeners on this model, or an empty array if no such listeners have been added - Throws:
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener- Since:
- 1.3
- See Also:
-