facets.util
Class NumberPolicy

java.lang.Object
  extended by facets.util.Tracer
      extended by facets.util.NumberPolicy
Direct Known Subclasses:
NumberPolicy.Ticked

public class NumberPolicy
extends Tracer

Validation and display of numbers.

NumberPolicy supplies the policy information required when validating a number or displaying it in the application surface.


Nested Class Summary
static class NumberPolicy.Ticked
          Validation and tick-based display of numbers.
static class NumberPolicy.ValueVariable
          NumberPolicy.Ticked that adjusts to changes in the value managed.
 
Field Summary
static int COLUMNS_DEFAULT
           
static boolean debug
           
static int FORMAT_DECIMALS_0
           
static int FORMAT_DECIMALS_1
           
static int FORMAT_DECIMALS_2
           
static int FORMAT_DECIMALS_3
           
static int FORMAT_DECIMALS_4
           
static int FORMAT_HEX
           
static double MAX_VALUE
           
static double MIN_VALUE
           
static double UNIT_JUMP_DEFAULT
           
 
Constructor Summary
NumberPolicy(double min, double max)
          Construct a policy that constrains valid values within the immutable range min to max.
 
Method Summary
 boolean canCycle()
          If true, values outside the range will be normalised to within it.
 int columns()
          The column width for text boxes in which values are to be displayed.
protected  boolean debug()
           
 int format()
          Hint on formatting the number.
 java.lang.String[] incrementTitles()
          Human-readable description of increment directions.
 double max()
          The highest possible value under the policy.
 double min()
          The lowest possible value under the policy.
protected  boolean reverseIncrements()
          Reverses the normal increment direction.
 java.lang.String toString()
           
 double unit()
          The smallest possible increment under the policy.
protected  double unitJump()
          Returns the multiple of unit defining the current minimum valid value change.
 double validIncrement(double existing, boolean positive)
          Returns a valid increment to existing in the direction given by positive, or zero if the incremented value is outside the range.
 double validValue(double existing, double proposed)
          Returns the nearest valid value to proposed.
 
Methods inherited from class facets.util.Tracer
trace, trace, trace, trace, trace, traceDebug, traceDebug, traceObjectText, traceOutput, traceOutputWithClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final double MIN_VALUE
See Also:
Constant Field Values

MAX_VALUE

public static final double MAX_VALUE
See Also:
Constant Field Values

debug

public static final boolean debug
See Also:
Constant Field Values

UNIT_JUMP_DEFAULT

public static double UNIT_JUMP_DEFAULT

COLUMNS_DEFAULT

public static int COLUMNS_DEFAULT

FORMAT_DECIMALS_0

public static final int FORMAT_DECIMALS_0
See Also:
Constant Field Values

FORMAT_DECIMALS_1

public static final int FORMAT_DECIMALS_1
See Also:
Constant Field Values

FORMAT_DECIMALS_2

public static final int FORMAT_DECIMALS_2
See Also:
Constant Field Values

FORMAT_DECIMALS_3

public static final int FORMAT_DECIMALS_3
See Also:
Constant Field Values

FORMAT_DECIMALS_4

public static final int FORMAT_DECIMALS_4
See Also:
Constant Field Values

FORMAT_HEX

public static final int FORMAT_HEX
See Also:
Constant Field Values
Constructor Detail

NumberPolicy

public NumberPolicy(double min,
                    double max)
Construct a policy that constrains valid values within the immutable range min to max.

Method Detail

max

public double max()
The highest possible value under the policy.

Set immutably during construction but only accessed via this method, enabling subclasses to define it dynamically by overriding.


min

public double min()
The lowest possible value under the policy.

Set immutably during construction but only accessed via this method, enabling subclasses to define it dynamically by overriding.


validIncrement

public final double validIncrement(double existing,
                                   boolean positive)
Returns a valid increment to existing in the direction given by positive, or zero if the incremented value is outside the range.

Calculation of the increment takes into account unit, unitJump, and reverseIncrements and its sum with existing is validated using valueValue.


validValue

public double validValue(double existing,
                         double proposed)
Returns the nearest valid value to proposed.

Though not used in the basic implementation, specifying existing as a parameter allows for non-linear validation in subclasses.


debug

protected boolean debug()

unit

public double unit()
The smallest possible increment under the policy.

The default implementation deduces this value from format().


canCycle

public boolean canCycle()
If true, values outside the range will be normalised to within it.

Default is false.


format

public int format()
Hint on formatting the number.

These are defined by the class FORMAT_x constants, which are mutually exclusive.

For FORMAT_PLACES_x constants the format should normally be consistent with unit.


columns

public int columns()
The column width for text boxes in which values are to be displayed.

Follows AWT convention.


incrementTitles

public java.lang.String[] incrementTitles()
Human-readable description of increment directions.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

reverseIncrements

protected boolean reverseIncrements()
Reverses the normal increment direction.

Used by validIncrement, default is false.


unitJump

protected double unitJump()
Returns the multiple of unit defining the current minimum valid value change.