Java Reference
In-Depth Information
The settings for the four properties must abide by the following ordering:
minimum <= value <= value+extent <= maximum
When one of the settings changes, the change may trigger changes to other settings to keep
the ordering valid. For instance, changing the
minimum
to a setting between the current
value
plus
extent
setting and the
maximum
will decrease the
extent
and increase the
value
to keep the
ordering valid. In addition, the original property change may result in a change to a new setting
other than the requested setting. For instance, attempting to set the
value
below the
minimum
or
maximum
will set the
value
to the nearest limit of the range.
The
BoundedRangeModel
interface definition follows:
public interface BoundedRangeModel {
// Properties
public int getExtent();
public void setExtent(int newValue);
public int getMaximum();
public void setMaximum(int newValue);
public int getMinimum();
public void setMinimum(int newValue);
public int getValue();
public void setValue(int newValue);
public boolean getValueIsAdjusting();
public void setValueIsAdjusting(boolean newValue);
// Listeners
public void addChangeListener(ChangeListener listener);
public void removeChangeListener(ChangeListener listener);
// Other Methods
public void setRangeProperties(int value, int extent, int minimum,
int maximum, boolean adjusting);
}
Although the different settings available for the model are JavaBean properties, when a
property setting changes, the interface uses Swing's
ChangeListener
approach instead of a
java.beans.PropertyChangeListener
.
The model's
valueIsAdjusting
property comes into play when the user is performing a
series of rapid changes to the model, probably as a result of dragging the slider on the screen.
For someone interested in knowing only when the final value is set for a model, a listener
would ignore any changes until
getValueIsAdjusting()
returns
false
.
DefaultBoundedRangeModel Class
The Swing class actually implementing the
BoundedRangeModel
interface is
DefaultBounded
➥
RangeModel
. This class takes care of the adjustments necessary to ensure the appropriate
ordering of the different property values. It also manages a
ChangeListener
list to notify
listeners when a model change happens.