com.jgoodies.binding.adapter

Class BoundedRangeAdapter

Implemented Interfaces:
BoundedRangeModel, Serializable

public final class BoundedRangeAdapter
extends java.lang.Object
implements BoundedRangeModel, Serializable

Converts a ValueModel to the BoundedRangeModel interface. Honors an upper and lower bound and returns the adapter's minimum in case the subject value is null.

Example:

 int minSaturation = 0;
 int maxSaturation = 255;
 PresentationModel pm = new PresentationModel(settings);
 ValueModel saturationModel = pm.getModel("saturation");
 JSlider saturationSlider = new JSlider(
     new BoundedRangeAdapter(saturationModel, 
                             0, 
                             minSaturation, 
                             maxSaturation));
 
Version:
$Revision: 1.3 $
Author:
Karsten Lentzsch
See Also:
javax.swing.JSlider

Constructor Summary

BoundedRangeAdapter(ValueModel subject, int extent, int min, int max)
Constructs a BoundedRangeAdapter on the given subject using the specified extend, minimum and maximum values.

Method Summary

void
addChangeListener(ChangeListener l)
Adds a ChangeListener.
protected void
fireStateChanged()
Runs each ChangeListeners stateChanged() method.
int
getExtent()
Returns this model's extent.
int
getMaximum()
Returns this model's upper bound, the maximum.
int
getMinimum()
Returns this model's lower bound, the minimum.
int
getValue()
Returns the current subject value, or the minimum if the subject value is null.
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.
void
setMaximum(int n)
Sets the maximum to n.
void
setMinimum(int n)
Sets the minimum to n.
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.

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.

Constructor Details

BoundedRangeAdapter

public BoundedRangeAdapter(ValueModel subject,
                           int extent,
                           int min,
                           int max)
Constructs a BoundedRangeAdapter on the given subject using the specified extend, minimum and maximum values.
Parameters:
subject - the underlying ValueModel that provides the value
extent - the extent to be set
min - the minimum to be set
max - the maximum to be set

Method Details

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.
Parameters:
l - the ChangeListener to add
See Also:
removeChangeListener(ChangeListener), BoundedRangeModel.addChangeListener(ChangeListener)

fireStateChanged

protected void fireStateChanged()
Runs each ChangeListeners stateChanged() method.

getExtent

public int getExtent()
Returns this model's extent.
Returns:
the model's extent
See Also:
setExtent(int), BoundedRangeModel.getExtent()

getMaximum

public int getMaximum()
Returns this model's upper bound, the maximum.
Returns:
the model's maximum
See Also:
setMaximum(int), BoundedRangeModel.getMaximum()

getMinimum

public int getMinimum()
Returns this model's lower bound, the minimum.
Returns:
the model's minimum
See Also:
setMinimum(int), BoundedRangeModel.getMinimum()

getValue

public int getValue()
Returns the current subject value, or the minimum if the subject value is null.
Returns:
the model's current value
See Also:
setValue(int), BoundedRangeModel.getValue()

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.
Returns:
the value of the valueIsAdjusting property
See Also:
setValue(int), BoundedRangeModel.getValueIsAdjusting()

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener.
Parameters:
l - the ChangeListener to remove
See Also:
addChangeListener(ChangeListener), BoundedRangeModel.removeChangeListener(ChangeListener)

setExtent

public void setExtent(int n)
Sets the extent to n. Ensures that n is greater than or equal to zero and falls within the adapter's constraints:
     minimum <= value <= value+extent <= maximum
 
Parameters:
n - the new extent before ensuring a non-negative number
See Also:
BoundedRangeModel.setExtent(int)

setMaximum

public void setMaximum(int n)
Sets the maximum to n. Ensures that n and the other three properties obey this adapter's constraints:
     minimum <= value <= value+extent <= maximum
 
Parameters:
n - the new maximum before ensuring this adapter's constraints
See Also:
BoundedRangeModel.setMaximum(int)

setMinimum

public void setMinimum(int n)
Sets the minimum to n. Ensures that n and the other three properties obey this adapter's constraints:
     minimum <= value <= value+extent <= maximum
 
Parameters:
n - the new minimum before ensuring constraints
See Also:
getMinimum(), BoundedRangeModel.setMinimum(int)

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.

Parameters:
newValue - the value to be set
newExtent - the extent to be set
newMin - the minimum to be set
newMax - the maximum to be set
adjusting - true if there are other pending changes

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
 
Parameters:
n - the new value before ensuring constraints
See Also:
BoundedRangeModel.setValue(int)

setValueIsAdjusting

public void setValueIsAdjusting(boolean b)
Sets the valueIsAdjusting property.
Parameters:
b - the new value
See Also:
getValueIsAdjusting(), setValue(int), BoundedRangeModel.setValueIsAdjusting(boolean)

toString

public String toString()
Returns a string that displays all of the BoundedRangeModel properties.
Returns:
a string representation of the properties

Copyright © 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.