DESY ACOP Beans Home

com.cosylab.gui.components.range2
Class RangedValueController

java.lang.Object
  extended by com.cosylab.gui.components.range2.RangedValueController

public class RangedValueController
extends java.lang.Object

RangedValue is used as pasive data representation, where each change to the RangedValue is reported via RangedValueListener. This ensures centralized handling of all changes and modifications.
This is also the central class to be used when working with ranged value. Typical use can be shown as:
class Example implements RangedValueListener {
...
RangedValue value = new RangedValue();
value.addRangeValueListener(this);
value.addChangePolicy(new RescalingValuePolicy()); value.setRange(new LogarithmicRange()); ... void valueChanged(RangedValueEvent event) { if (event.minOrMaxChanged()) { // repaint scale } if (event.valueChanged()) { // repaint value }}

RangedValue will ensure that value vill always be consistant within min, max in range and policies.

Version:
$id$
Author:
Ales Pucelj

Constructor Summary
RangedValueController()
           
 
Method Summary
 void addPolicy(RangedValuePolicy p)
          Adds a policy to this controller.
 void addRangedValueListener(RangedValueListener listener)
          Adds a RangedValueListener to the the controller.
 Tick[] calculateTicks(int width)
          Calculates ticks using default the given width and default measurer.
 Tick[] calculateTicks(int w, TickParameters measurer)
          Calculates ticks using the given measurer and width.
protected  Range createDefaultRange()
          Creates default range implementation.
protected  void firePolicyAdded()
           
protected  void firePolicyRemoved()
           
protected  void fireValueChange(boolean min, boolean max, boolean val, boolean raw)
           
protected  void fireValueChange(RangedValueEvent event)
          Notify listeners of the change.
 double getMaximum()
          Returns current maximum the value can take.
 double getMinimum()
          Returns current minimum the value can take.
 RangedValuePolicy getPolicy()
          Returns the currently employed policy.
 Range getRange()
          Returns current range definition.
 RangedValue getRangedValue()
          Returns the RangedValue employed by this controller.
 double getRawValue()
          Returns the actual value.
 double getRelativeValue()
          Returns the relative value between min and max.
 double getScalingFactor()
          Returns the scalingFactor.
 TickCalculator getTickCalculator()
          Returns the ManualTickProvider which is used to calculated ticks for this controller.
 double getValue()
          Returns current value.
 boolean isSnapToTicks()
          Returns true if snap to ticks is turned on.
 void removePolicy(RangedValuePolicy p)
          Removes the policy from the controller.
 void removePolicyByType(java.lang.Class<? extends RangedValuePolicy> c)
          Removes all policies of the given type.
 void removeRangedValueListener(RangedValueListener listener)
          Removes RangedValueListener from this controller.
 void setMaximum(double value)
          Sets new maximum.
 void setMinimum(double value)
          Sets new minimum.
 void setPolicy(RangedValuePolicy policy)
          Adds new RangedValuePolicy.
 void setRange(Range newRange)
          Sets the new definition of Range.
 void setRangedValue(RangedValue v)
          Sets the RangedValue to this controller.
 void setRelativeValue(double value)
          Sets relative value according to min and max.
 void setScalingFactor(double scalingFactor)
          Sets new scalingFactor.
 void setSnapToTicks(boolean snapToTicks)
          Sets the snap to ticks property.
 void setTickCalculator(TickCalculator calculator)
          Sets the TickCalculator which overrides any default settings for this controller.
 void setValue(double value)
          Sets new value.
 void setValue(double minimum, double maximum, double value)
          Initializes all values to new values.
 double toAbsolute(double proportional)
          Converts proportional value to the absolute.
 double toRelative(double d)
          Converts the given value to the relative value according to the bounds.
 double validate(double value)
          Validates the value according to the bounds and policies.
 RangedValue validatePolicies(RangedValue values)
          Checks all policies to give them oportunity to modify the values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangedValueController

public RangedValueController()
Method Detail

createDefaultRange

protected Range createDefaultRange()
Creates default range implementation. Override this method to provide different default implementation. By default, LinearRange class is created.

Returns:
Range range Range interface implementation.

getRange

public Range getRange()
Returns current range definition.

See Also:
getRange()

setRange

public void setRange(Range newRange)
Sets the new definition of Range.

See Also:
setRange(Range)

setRangedValue

public void setRangedValue(RangedValue v)
Sets the RangedValue to this controller.

Parameters:
v - new ranged value

getRangedValue

public RangedValue getRangedValue()
Returns the RangedValue employed by this controller.

Returns:

getMinimum

public double getMinimum()
Returns current minimum the value can take. Depending on effective policies, value could still be set below minimum.

Returns:
double current minimum.
See Also:
getMinimum()

getMaximum

public double getMaximum()
Returns current maximum the value can take. Depending on effective policies, value could still be set above maximum.

Returns:
double current maximum.
See Also:
getMaximum()

getValue

public double getValue()
Returns current value.

Returns:
double current value.
See Also:
getValue()

setValue

public void setValue(double value)
Sets new value. This will attempt to set new value. If new value is outside of range or policies are set, new value might not be the same as the one set. Notification about this change will be reported via RangedValueListener, where event can be queried about the actual changes.
setValue(double, double, double) should be called before using this method for the first time to ensure the values. This is not neccessary if no policies are in effect or values are known to conform to with them.

See Also:
com.cosylab.gui.components.range2.RangedValueController#setValue()

setMinimum

public void setMinimum(double value)
Sets new minimum. Setting the minimum may have side effects based on range definition, policies and current value or maximum. Actual change will be reported via RangedValueListener.
setValue(double, double, double) should be called before using this method for the first time to ensure the values. This is not neccessary if no policies are in effect or values are known to conform to with them.

Parameters:
value - double

setMaximum

public void setMaximum(double value)
Sets new maximum. Setting the maximum may have side effects based on range definition, policies and current value or minimum. Actual change will be reported via RangedValueListener.
setValue(double, double, double) should be called before using this method for the first time to ensure the values. This is not neccessary if no policies are in effect or values are known to conform to with them.

Parameters:
value - double

validatePolicies

public RangedValue validatePolicies(RangedValue values)
Checks all policies to give them oportunity to modify the values.

Parameters:
values - holder of values.

setValue

public void setValue(double minimum,
                     double maximum,
                     double value)
Initializes all values to new values. Minimum, value and maximum should be in this order when compared to each other.

Parameters:
minimum - double
maximum - double
value - double
Throws:
InvalidBoundException - In case the parameters do not conform with policies defined by this range.

fireValueChange

protected void fireValueChange(RangedValueEvent event)
Notify listeners of the change.

Parameters:
event -

fireValueChange

protected void fireValueChange(boolean min,
                               boolean max,
                               boolean val,
                               boolean raw)

firePolicyAdded

protected void firePolicyAdded()

firePolicyRemoved

protected void firePolicyRemoved()

setPolicy

public void setPolicy(RangedValuePolicy policy)
Adds new RangedValuePolicy. Polices will be checked in the same order they are added.

See Also:
com.cosylab.gui.components.range2.RangedValueController#addChangePolicy(RangedValuePolicy)

addRangedValueListener

public void addRangedValueListener(RangedValueListener listener)
Adds a RangedValueListener to the the controller. Listener is notified of changes in the ranged value.

Parameters:
listener -

removeRangedValueListener

public void removeRangedValueListener(RangedValueListener listener)
Removes RangedValueListener from this controller.

Parameters:
listener -

getRelativeValue

public double getRelativeValue()
Returns the relative value between min and max.

Returns:

setRelativeValue

public void setRelativeValue(double value)
Sets relative value according to min and max.

Parameters:
value - new value

getRawValue

public double getRawValue()
Returns the actual value.

Returns:

validate

public double validate(double value)
Validates the value according to the bounds and policies.

Parameters:
value - value to be validated
Returns:
validated value

getScalingFactor

public double getScalingFactor()
Returns the scalingFactor.

Returns:
Returns the scalingFactor.

setScalingFactor

public void setScalingFactor(double scalingFactor)
Sets new scalingFactor. Scaling factor scales relative value from 0 to 1.0 or whatever scaling factor is.

Parameters:
scalingFactor - The scalingFactor to set.

getPolicy

public RangedValuePolicy getPolicy()
Returns the currently employed policy.

Returns:

addPolicy

public void addPolicy(RangedValuePolicy p)
Adds a policy to this controller.

Parameters:
p -

removePolicy

public void removePolicy(RangedValuePolicy p)
Removes the policy from the controller.

Parameters:
p -

removePolicyByType

public void removePolicyByType(java.lang.Class<? extends RangedValuePolicy> c)
Removes all policies of the given type.

Parameters:
c -

toRelative

public double toRelative(double d)
Converts the given value to the relative value according to the bounds.

Parameters:
d - value to be converted
Returns:
converted value

calculateTicks

public Tick[] calculateTicks(int w,
                             TickParameters measurer)
Calculates ticks using the given measurer and width.

Parameters:
w -
measurer -
Returns:

toAbsolute

public double toAbsolute(double proportional)
Converts proportional value to the absolute.

Parameters:
proportional - value to be converted
Returns:
converted value

calculateTicks

public Tick[] calculateTicks(int width)
Calculates ticks using default the given width and default measurer.

Parameters:
width -
Returns:

setTickCalculator

public void setTickCalculator(TickCalculator calculator)
Sets the TickCalculator which overrides any default settings for this controller. If this provider is non-null the controller should always take this controller to calculate ticks.

Parameters:
provider -

getTickCalculator

public TickCalculator getTickCalculator()
Returns the ManualTickProvider which is used to calculated ticks for this controller. If the provider is null the default settings are used, which means that ticks calculation is delegated further to the Range.

Returns:

setSnapToTicks

public void setSnapToTicks(boolean snapToTicks)
Sets the snap to ticks property. If true the slider thumb can be moved on discrete values defined by the slider ticks.

Parameters:
snapToTicks - true if thumb should snap to ticks

isSnapToTicks

public boolean isSnapToTicks()
Returns true if snap to ticks is turned on.

Returns:
true if snap is turned on
See Also:
setSnapToTicks(boolean)


Copyright © 2010. All Rights Reserved.