DefaultBoundedRangeModel (Java 2 Platform SE 5.0) (original) (raw)


javax.swing

Class DefaultBoundedRangeModel

java.lang.Object extended by 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 JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

See Also:

BoundedRangeModel


Field Summary
protected ChangeEvent changeEvent Only one ChangeEvent 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
DefaultBoundedRangeModel() Initializes all of the properties with default values.
[DefaultBoundedRangeModel](../../javax/swing/DefaultBoundedRangeModel.html#DefaultBoundedRangeModel%28int, int, int, int%29)(int value, int extent, int min, int max) Initializes value, extent, minimum and maximum.
Method Summary
void addChangeListener(ChangeListener l) Adds a ChangeListener.
protected void fireStateChanged() Runs each ChangeListener's stateChanged method.
ChangeListener[] getChangeListeners() Returns an array of all the change listeners registered on this DefaultBoundedRangeModel.
int getExtent() Returns the model's extent.
<T extends EventListener> T[] getListeners(Class listenerType) Returns an array of all the objects currently registered as_Foo_Listeners 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 a ChangeListener.
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](../../javax/swing/DefaultBoundedRangeModel.html#setRangeProperties%28int, int, int, int, boolean%29)(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) Sets all of the BoundedRangeModel 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 the valueIsAdjusting property.
String toString() Returns a string that displays all of the BoundedRangeModel properties.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29)
Field Detail

changeEvent

protected transient ChangeEvent changeEvent

Only one ChangeEvent 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

protected EventListenerList listenerList

The listeners waiting for model changes.

Constructor Detail

DefaultBoundedRangeModel

public DefaultBoundedRangeModel()

Initializes all of the properties with default values. Those values are:


DefaultBoundedRangeModel

public DefaultBoundedRangeModel(int value, int extent, int min, int max)

Initializes value, extent, minimum and maximum. Adjusting is false. Throws an IllegalArgumentException if the following constraints aren't satisfied:

min <= value <= value+extent <= max

Method Detail

getValue

public int getValue()

Returns the model's current value.

Specified by:

[getValue](../../javax/swing/BoundedRangeModel.html#getValue%28%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Returns:

the model's current value

See Also:

setValue(int), BoundedRangeModel.getValue()


getExtent

public int getExtent()

Returns the model's extent.

Specified by:

[getExtent](../../javax/swing/BoundedRangeModel.html#getExtent%28%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Returns:

the model's extent

See Also:

setExtent(int), BoundedRangeModel.getExtent()


getMinimum

public int getMinimum()

Returns the model's minimum.

Specified by:

[getMinimum](../../javax/swing/BoundedRangeModel.html#getMinimum%28%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Returns:

the model's minimum

See Also:

setMinimum(int), BoundedRangeModel.getMinimum()


getMaximum

public int getMaximum()

Returns the model's maximum.

Specified by:

[getMaximum](../../javax/swing/BoundedRangeModel.html#getMaximum%28%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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](../../javax/swing/BoundedRangeModel.html#setValue%28int%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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](../../javax/swing/BoundedRangeModel.html#setExtent%28int%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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](../../javax/swing/BoundedRangeModel.html#setMinimum%28int%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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](../../javax/swing/BoundedRangeModel.html#setMaximum%28int%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Parameters:

n - the model's new maximum

See Also:

BoundedRangeModel.setMaximum(int)


setValueIsAdjusting

public void setValueIsAdjusting(boolean b)

Sets the valueIsAdjusting property.

Specified by:

[setValueIsAdjusting](../../javax/swing/BoundedRangeModel.html#setValueIsAdjusting%28boolean%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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](../../javax/swing/BoundedRangeModel.html#getValueIsAdjusting%28%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

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 the BoundedRangeModel properties after forcing the arguments to obey the usual constraints:

 minimum <= value <= value+extent <= maximum

At most, one ChangeEvent is generated.

Specified by:

[setRangeProperties](../../javax/swing/BoundedRangeModel.html#setRangeProperties%28int, int, int, int, boolean%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Parameters:

newValue - an int giving the current value

newExtent - an int giving the amount by which the value can "jump"

newMin - an int giving the minimum value

newMax - an int giving the maximum value

adjusting - a boolean, true if a series of changes are in progress

See Also:

[BoundedRangeModel.setRangeProperties(int, int, int, int, boolean)](../../javax/swing/BoundedRangeModel.html#setRangeProperties%28int, int, int, int, boolean%29), setValue(int), setExtent(int), setMinimum(int), setMaximum(int), setValueIsAdjusting(boolean)


addChangeListener

public void addChangeListener(ChangeListener l)

Adds a ChangeListener. The change listeners are run each time any one of the Bounded Range model properties changes.

Specified by:

[addChangeListener](../../javax/swing/BoundedRangeModel.html#addChangeListener%28javax.swing.event.ChangeListener%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Parameters:

l - the ChangeListener to add

See Also:

removeChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel.addChangeListener(javax.swing.event.ChangeListener)


removeChangeListener

public void removeChangeListener(ChangeListener l)

Removes a ChangeListener.

Specified by:

[removeChangeListener](../../javax/swing/BoundedRangeModel.html#removeChangeListener%28javax.swing.event.ChangeListener%29) in interface [BoundedRangeModel](../../javax/swing/BoundedRangeModel.html "interface in javax.swing")

Parameters:

l - the ChangeListener to remove

See Also:

addChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel.removeChangeListener(javax.swing.event.ChangeListener)


getChangeListeners

public ChangeListener[] getChangeListeners()

Returns an array of all the change listeners registered on this DefaultBoundedRangeModel.

Returns:

all of this model's ChangeListeners 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 each ChangeListener's stateChanged method.

See Also:

[setRangeProperties(int, int, int, int, boolean)](../../javax/swing/DefaultBoundedRangeModel.html#setRangeProperties%28int, int, int, int, boolean%29), EventListenerList


toString

public String toString()

Returns a string that displays all of the BoundedRangeModel properties.

Overrides:

[toString](../../java/lang/Object.html#toString%28%29) in class [Object](../../java/lang/Object.html "class in java.lang")

Returns:

a string representation of the object.


getListeners

public <T extends EventListener> T[] getListeners(Class listenerType)

Returns an array of all the objects currently registered as_Foo_Listeners upon this model._Foo_Listeners are registered using the add_Foo_Listener method.

You can specify the listenerType argument with a class literal, such as _Foo_Listener.class. For example, you can query a DefaultBoundedRangeModel instance m 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.

Parameters:

listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener

Returns:

an array of all objects registered as_Foo_Listeners on this model, or an empty array if no such listeners have been added

Throws:

[ClassCastException](../../java/lang/ClassCastException.html "class in java.lang") - if listenerType doesn't specify a class or interface that implementsjava.util.EventListener

Since:

1.3

See Also:

getChangeListeners()



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.