javax.swing

Class DefaultBoundedRangeModel

public class DefaultBoundedRangeModel extends Object implements BoundedRangeModel, Serializable

The default implementation of BoundedRangeModel.
Field Summary
protected ChangeEventchangeEvent
An event that is sent to all registered {@link ChangeListener}s when the state of this range model has changed.
protected EventListenerListlistenerList
The list of the currently registered EventListeners.
Constructor Summary
DefaultBoundedRangeModel()
Constructs a DefaultBoundedRangeModel with default values for the properties.
DefaultBoundedRangeModel(int value, int extent, int minimum, int maximum)
Constructs a DefaultBoundedRangeModel with the specified values for some properties.
Method Summary
voidaddChangeListener(ChangeListener listener)
Subscribes a ChangeListener to state changes.
protected voidfireStateChanged()
Sends a {@link ChangeEvent} to any registered {@link ChangeListener}s.
ChangeListener[]getChangeListeners()
Returns all ChangeListeners that are currently subscribed for changes to this DefaultBoundedRangeModel.
intgetExtent()
Returns the current extent of this bounded range model, which is a number greater than or equal to zero.
<T extends EventListener> T[]getListeners(Class<T> listenerType)
Retrieves the current listeners of the specified class.
intgetMaximum()
Returns the current maximal value of this bounded range model.
intgetMinimum()
Returns the current minimal value of this bounded range model.
intgetValue()
Returns the current value of this bounded range model.
booleangetValueIsAdjusting()
Returns whether or not the value of this bounded range model is going to change in the immediate future.
voidremoveChangeListener(ChangeListener listener)
Cancels the subscription of a ChangeListener.
voidsetExtent(int extent)
Changes the current extent of this bounded range model.
voidsetMaximum(int maximum)
Changes the current maximal value of this bounded range model.
voidsetMinimum(int minimum)
Changes the current minimal value of this bounded range model.
voidsetRangeProperties(int value, int extent, int minimum, int maximum, boolean isAdjusting)
Sets all properties.
voidsetValue(int value)
Changes the current value of this bounded range model.
voidsetValueIsAdjusting(boolean isAdjusting)
Specifies whether or not the value of this bounded range model is going to change in the immediate future.
StringtoString()
Returns a string with all relevant properties of this range model.

Field Detail

changeEvent

protected transient ChangeEvent changeEvent
An event that is sent to all registered {@link ChangeListener}s when the state of this range model has changed.

The event object is created on demand, the first time it is actually needed.

See Also: fireStateChanged

listenerList

protected EventListenerList listenerList
The list of the currently registered EventListeners.

Constructor Detail

DefaultBoundedRangeModel

public DefaultBoundedRangeModel()
Constructs a DefaultBoundedRangeModel with default values for the properties. The properties value, extent and minimum will be initialized to zero; maximum will be set to 100; the property valueIsAdjusting will be false.

DefaultBoundedRangeModel

public DefaultBoundedRangeModel(int value, int extent, int minimum, int maximum)
Constructs a DefaultBoundedRangeModel with the specified values for some properties.

Parameters: value the initial value of the range model, which must be a number between minimum and (maximum - extent). In a scroll bar visualization of a {@link BoundedRangeModel}, the value is displayed as the position of the thumb. extent the initial extent of the range model, which is a number greater than or equal to zero. In a scroll bar visualization of a {@link BoundedRangeModel}, the extent is displayed as the size of the thumb. minimum the initial minimal value of the range model. maximum the initial maximal value of the range model.

Throws: IllegalArgumentException if the following condition is not satisfied: minimum <= value <= value + extent <= maximum.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Subscribes a ChangeListener to state changes.

Parameters: listener the listener to be subscribed.

fireStateChanged

protected void fireStateChanged()
Sends a {@link ChangeEvent} to any registered {@link ChangeListener}s.

See Also: addChangeListener removeChangeListener

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns all ChangeListeners that are currently subscribed for changes to this DefaultBoundedRangeModel.

Returns: an array with the currently subscribed listeners, or an empty array if there are currently no listeners.

Since: 1.4

getExtent

public int getExtent()
Returns the current extent of this bounded range model, which is a number greater than or equal to zero. In a scroll bar visualization of a {@link BoundedRangeModel}, the extent is displayed as the size of the thumb.

Returns: the extent

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Retrieves the current listeners of the specified class.

Parameters: listenerType the class of listeners; usually {@link ChangeListener}.class.

Returns: an array with the currently subscribed listeners, or an empty array if there are currently no listeners.

Since: 1.3

getMaximum

public int getMaximum()
Returns the current maximal value of this bounded range model.

Returns: the maximum

getMinimum

public int getMinimum()
Returns the current minimal value of this bounded range model.

getValue

public int getValue()
Returns the current value of this bounded range model. In a scroll bar visualization of a {@link BoundedRangeModel}, the value is displayed as the position of the thumb.

Returns: the value

getValueIsAdjusting

public boolean getValueIsAdjusting()
Returns whether or not the value of this bounded range model is going to change in the immediate future. Scroll bars set this property to true while the thumb is being dragged around; when the mouse is relased, they set the property to false and post a final {@link ChangeEvent}.

Returns: true if the value will change soon again; false if the value will probably not change soon.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Cancels the subscription of a ChangeListener.

Parameters: listener the listener to be unsubscribed.

setExtent

public void setExtent(int extent)
Changes the current extent of this bounded range model. In a scroll bar visualization of a {@link BoundedRangeModel}, the extent is displayed as the size of the thumb.

Parameters: extent the new extent of the range model, which is a number greater than or equal to zero.

setMaximum

public void setMaximum(int maximum)
Changes the current maximal value of this bounded range model.

Parameters: maximum the new maximal value.

setMinimum

public void setMinimum(int minimum)
Changes the current minimal value of this bounded range model.

Parameters: minimum the new minimal value.

setRangeProperties

public void setRangeProperties(int value, int extent, int minimum, int maximum, boolean isAdjusting)
Sets all properties.

Parameters: value the new value of the range model. In a scroll bar visualization of a {@link BoundedRangeModel}, the value is displayed as the position of the thumb. extent the new extent of the range model, which is a number greater than or equal to zero. In a scroll bar visualization of a {@link BoundedRangeModel}, the extent is displayed as the size of the thumb. minimum the new minimal value of the range model. maximum the new maximal value of the range model. isAdjusting whether or not the value of this bounded range model is going to change in the immediate future. Scroll bars set this property to true while the thumb is being dragged around; when the mouse is relased, they set the property to false.

setValue

public void setValue(int value)
Changes the current value of this bounded range model. In a scroll bar visualization of a {@link BoundedRangeModel}, the value is displayed as the position of the thumb; changing the value of a scroll bar's model thus moves the thumb to a different position.

Parameters: value the value

setValueIsAdjusting

public void setValueIsAdjusting(boolean isAdjusting)
Specifies whether or not the value of this bounded range model is going to change in the immediate future. Scroll bars set this property to true while the thumb is being dragged around; when the mouse is relased, they set the property to false.

Parameters: isAdjusting true if the value will change soon again; false if the value will probably not change soon.

toString

public String toString()
Returns a string with all relevant properties of this range model.

Returns: a string representing the object