| Method from javax.swing.DefaultBoundedRangeModel Detail: |
public void addChangeListener(ChangeListener l) {
listenerList.add(ChangeListener.class, l);
}
Adds a ChangeListener. The change listeners are run each
time any one of the Bounded Range model properties changes. |
protected void fireStateChanged() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -=2 ) {
if (listeners[i] == ChangeListener.class) {
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
}
}
}
Runs each ChangeListener's stateChanged method. |
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
}
Returns an array of all the change listeners
registered on this DefaultBoundedRangeModel. |
public int getExtent() {
return extent;
}
Returns the model's extent. |
public T[] getListeners(Class listenerType) {
return listenerList.getListeners(listenerType);
}
Returns an array of all the objects currently registered as
FooListeners
upon this model.
FooListeners
are registered using the addFooListener method.
You can specify the listenerType argument
with a class literal, such as FooListener.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. |
public int getMaximum() {
return max;
}
Returns the model's maximum. |
public int getMinimum() {
return min;
}
Returns the model's minimum. |
public int getValue() {
return value;
}
Returns the model's current value. |
public boolean getValueIsAdjusting() {
return isAdjusting;
}
Returns true if the value is in the process of changing
as a result of actions being taken by the user. |
public void removeChangeListener(ChangeListener l) {
listenerList.remove(ChangeListener.class, l);
}
Removes a ChangeListener. |
public void setExtent(int n) {
int newExtent = Math.max(0, n);
if(value + newExtent > max) {
newExtent = max - value;
}
setRangeProperties(value, newExtent, min, max, isAdjusting);
}
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
|
public void setMaximum(int n) {
int newMin = Math.min(n, min);
int newExtent = Math.min(n - newMin, extent);
int newValue = Math.min(n - newExtent, value);
setRangeProperties(newValue, newExtent, newMin, n, isAdjusting);
}
Sets the maximum to n after ensuring that n
that the other three properties obey the model's constraints:
minimum <= value <= value+extent <= maximum
|
public void setMinimum(int n) {
int newMax = Math.max(n, max);
int newValue = Math.max(n, value);
int newExtent = Math.min(newMax - newValue, extent);
setRangeProperties(newValue, newExtent, n, newMax, isAdjusting);
}
Sets the minimum to n after ensuring that n
that the other three properties obey the model's constraints:
minimum <= value <= value+extent <= maximum
|
public void setRangeProperties(int newValue,
int newExtent,
int newMin,
int newMax,
boolean adjusting) {
if (newMin > newMax) {
newMin = newMax;
}
if (newValue > newMax) {
newMax = newValue;
}
if (newValue < newMin) {
newMin = newValue;
}
/* Convert the addends to long so that extent can be
* Integer.MAX_VALUE without rolling over the sum.
* A JCK test covers this, see bug 4097718.
*/
if (((long)newExtent + (long)newValue) > newMax) {
newExtent = newMax - newValue;
}
if (newExtent < 0) {
newExtent = 0;
}
boolean isChange =
(newValue != value) ||
(newExtent != extent) ||
(newMin != min) ||
(newMax != max) ||
(adjusting != isAdjusting);
if (isChange) {
value = newValue;
extent = newExtent;
min = newMin;
max = newMax;
isAdjusting = adjusting;
fireStateChanged();
}
}
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. |
public void setValue(int n) {
n = Math.min(n, Integer.MAX_VALUE - extent);
int newValue = Math.max(n, min);
if (newValue + extent > max) {
newValue = max - extent;
}
setRangeProperties(newValue, extent, min, max, isAdjusting);
}
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
|
public void setValueIsAdjusting(boolean b) {
setRangeProperties(value, extent, min, max, b);
}
Sets the valueIsAdjusting property. |
public String toString() {
String modelString =
"value=" + getValue() + ", " +
"extent=" + getExtent() + ", " +
"min=" + getMinimum() + ", " +
"max=" + getMaximum() + ", " +
"adj=" + getValueIsAdjusting();
return getClass().getName() + "[" + modelString + "]";
}
Returns a string that displays all of the
BoundedRangeModel properties. |