org.vostok.vaadin.addon.button.spin
Class NumberModel

java.lang.Object
  extended by org.vostok.vaadin.addon.button.spin.NumberModel
All Implemented Interfaces:
com.vaadin.data.Property<java.lang.Double>, java.io.Serializable, SpinButton.Editable<java.lang.Double>, SpinButton.Model<java.lang.Double>

public class NumberModel
extends java.lang.Object
implements SpinButton.Model<java.lang.Double>, SpinButton.Editable<java.lang.Double>

SpinButton's model for numbers such as integer, long, double, percent, even date.
Internal representation is double.
Output depends on format, you can pass your own or use ones of several presets.
Note : to be used with regular usage. If you need real precision you must implement your own model / converter with appropiate type.

Since:
1.1 : implement SpinButton.Editable
Author:
levreau.jerome@vostoksystem.eu
See Also:
SpinButton, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyException, com.vaadin.data.Property.ReadOnlyStatusChangeEvent, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.Transactional<T>, com.vaadin.data.Property.ValueChangeEvent, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer
 
Field Summary
 double EPSILON
           
static java.lang.String FORMAT_CURRENCY_DOLLAR
          format for dollars currency. display 2 diggit.
static java.lang.String FORMAT_CURRENCY_EURO
          format for euros currency. display 2 diggit.
static java.lang.String FORMAT_DECIMAL
          simple decimal
static java.lang.String FORMAT_DECIMAL2
          decimal ouput, 2 digit
static java.lang.String FORMAT_DECIMAL3
          decimal ouput, 3 digit
static java.lang.String FORMAT_FULLDATE
          full localized plain date , localized (ie : Monday, January).
static java.lang.String FORMAT_FULLDATETIME
          full localized plain date and time, localized (ie : Monday, January).
static java.lang.String FORMAT_FULLTIME
          full time formating (with second).
static java.lang.String FORMAT_INTEGER
          simple integer formating.
static java.lang.String FORMAT_SHORTDATE
          short localized plain date , localized (ie : Mon, Jan).
static java.lang.String FORMAT_SHORTDATETIME
          short localized plain date and time, localized (ie : Mon, Jan).
static java.lang.String FORMAT_SIMPLEDATE
          simple date formating.
static java.lang.String FORMAT_SIMPLEDATETIME
          simple date and time formating (all numeric).
static java.lang.String FORMAT_SIMPLETIME
          simple time formating (without second).
 
Constructor Summary
NumberModel(double start)
          Model with no limit, step = 1, format = FORMAT_INTEGER
NumberModel(double start, double step, double lower, double max, boolean loop, java.lang.String format)
           
NumberModel(double start, java.lang.String format)
          Model with no limit, step = 1,
 
Method Summary
protected  java.lang.String format(double value)
           
 com.vaadin.data.util.converter.Converter<java.lang.String,java.lang.Double> getConverter()
          NumberModel provide converter support but not logic. return null, must be overrided
 java.lang.String getHint()
          return hint to dispay while in edition mode.
 java.lang.Object getRawValue()
          return value for GetValue return internal data, for exemple index x while getRawValue return the actual value y for index x
 java.lang.Class<? extends java.lang.Double> getType()
           
 java.lang.Double getValue()
           
 java.lang.Double init()
          Called from contructor
 boolean isReadOnly()
          not used, always return false
 java.lang.Double next()
          return next value but do not set current one.
 java.lang.Double prev()
          return previous value but do not set current one.
 void setLocale(java.util.Locale locale)
          Locale for output formating. default to user's locale
 void setReadOnly(boolean newStatus)
          not used
 void setValue(java.lang.Double newValue)
           
 java.lang.Object toObject()
          return a human formated representation of the current value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EPSILON

public final double EPSILON
See Also:
Constant Field Values

FORMAT_INTEGER

public static final java.lang.String FORMAT_INTEGER
simple integer formating. This is the default

See Also:
Constant Field Values

FORMAT_DECIMAL

public static final java.lang.String FORMAT_DECIMAL
simple decimal

See Also:
Constant Field Values

FORMAT_DECIMAL2

public static final java.lang.String FORMAT_DECIMAL2
decimal ouput, 2 digit

See Also:
Constant Field Values

FORMAT_DECIMAL3

public static final java.lang.String FORMAT_DECIMAL3
decimal ouput, 3 digit

See Also:
Constant Field Values

FORMAT_FULLDATETIME

public static final java.lang.String FORMAT_FULLDATETIME
full localized plain date and time, localized (ie : Monday, January).
Data format/step in milisecond. for a finer control on step, use CalendarModel

See Also:
Constant Field Values

FORMAT_SHORTDATETIME

public static final java.lang.String FORMAT_SHORTDATETIME
short localized plain date and time, localized (ie : Mon, Jan).
Data format/step in milisecond. for a finer control on step, use CalendarModel

See Also:
Constant Field Values

FORMAT_SIMPLEDATETIME

public static final java.lang.String FORMAT_SIMPLEDATETIME
simple date and time formating (all numeric).
Data format/step in milisecond. for a finer control on step, use CalendarModel

See Also:
Constant Field Values

FORMAT_FULLDATE

public static final java.lang.String FORMAT_FULLDATE
full localized plain date , localized (ie : Monday, January).
Data format/step in milisecond. for a finer control on step, use CalendarModel

See Also:
Constant Field Values

FORMAT_SHORTDATE

public static final java.lang.String FORMAT_SHORTDATE
short localized plain date , localized (ie : Mon, Jan).
Data format/step in milisecond. for a finer control on step, use CalendarModel

See Also:
Constant Field Values

FORMAT_SIMPLEDATE

public static final java.lang.String FORMAT_SIMPLEDATE
simple date formating.
Data format in milisecond

See Also:
Constant Field Values

FORMAT_SIMPLETIME

public static final java.lang.String FORMAT_SIMPLETIME
simple time formating (without second).
Data format in milisecond

See Also:
Constant Field Values

FORMAT_FULLTIME

public static final java.lang.String FORMAT_FULLTIME
full time formating (with second).
Data format in milisecond

See Also:
Constant Field Values

FORMAT_CURRENCY_EURO

public static final java.lang.String FORMAT_CURRENCY_EURO
format for euros currency. display 2 diggit.

See Also:
Constant Field Values

FORMAT_CURRENCY_DOLLAR

public static final java.lang.String FORMAT_CURRENCY_DOLLAR
format for dollars currency. display 2 diggit.

See Also:
Constant Field Values
Constructor Detail

NumberModel

public NumberModel(double start)
            throws java.lang.Exception
Model with no limit, step = 1, format = FORMAT_INTEGER

Parameters:
start - initial value for spin
Throws:
java.lang.Exception, - never throw, backward compatibility
java.lang.Exception

NumberModel

public NumberModel(double start,
                   java.lang.String format)
            throws java.lang.Exception
Model with no limit, step = 1,

Parameters:
start - initial value for spin
format - Formater value or preset. if null, will use FORMAT_INTEGER
Throws:
java.lang.Exception, - never throw, backward compatibility
java.lang.Exception
Since:
1.1

NumberModel

public NumberModel(double start,
                   double step,
                   double lower,
                   double max,
                   boolean loop,
                   java.lang.String format)
            throws java.lang.Exception
Parameters:
start - start value ; must be between min and max (inclusive)
step - increment ; must be >0
lower - lower valid value (inclusive) ; must be lower than max
max - maximum valid value (inclusive) ; must be > lower
loop - if true, will loop through value. (at max+step return min)
format - Formater value or preset. if null, will use FORMAT_INTEGER
Throws:
java.lang.Exception - on wrong argument value
Method Detail

setLocale

public void setLocale(java.util.Locale locale)
Locale for output formating. default to user's locale

Parameters:
locale -

init

public java.lang.Double init()
Description copied from interface: SpinButton.Model
Called from contructor

Specified by:
init in interface SpinButton.Model<java.lang.Double>
Returns:
initial value .

next

public java.lang.Double next()
Description copied from interface: SpinButton.Model
return next value but do not set current one.

Specified by:
next in interface SpinButton.Model<java.lang.Double>
Returns:
next valid value or null if none

prev

public java.lang.Double prev()
Description copied from interface: SpinButton.Model
return previous value but do not set current one.

Specified by:
prev in interface SpinButton.Model<java.lang.Double>
Returns:
previous value or null if none

format

protected final java.lang.String format(double value)
Parameters:
value -
Returns:
String date formated according to locale

getValue

public java.lang.Double getValue()
Specified by:
getValue in interface com.vaadin.data.Property<java.lang.Double>

setValue

public void setValue(java.lang.Double newValue)
              throws com.vaadin.data.Property.ReadOnlyException
Specified by:
setValue in interface com.vaadin.data.Property<java.lang.Double>
Throws:
com.vaadin.data.Property.ReadOnlyException

getType

public java.lang.Class<? extends java.lang.Double> getType()
Specified by:
getType in interface com.vaadin.data.Property<java.lang.Double>

isReadOnly

public boolean isReadOnly()
not used, always return false

Specified by:
isReadOnly in interface com.vaadin.data.Property<java.lang.Double>
Returns:
false

setReadOnly

public void setReadOnly(boolean newStatus)
not used

Specified by:
setReadOnly in interface com.vaadin.data.Property<java.lang.Double>
Parameters:
newStatus -

toObject

public java.lang.Object toObject()
Description copied from interface: SpinButton.Model
return a human formated representation of the current value.

Specified by:
toObject in interface SpinButton.Model<java.lang.Double>
Returns:
Component to direclty pack or String which will be display as a TextField through toString() method

getRawValue

public java.lang.Object getRawValue()
Description copied from interface: SpinButton.Model
return value for GetValue return internal data, for exemple index x while getRawValue return the actual value y for index x

Specified by:
getRawValue in interface SpinButton.Model<java.lang.Double>
Returns:
raw value from model

getConverter

public com.vaadin.data.util.converter.Converter<java.lang.String,java.lang.Double> getConverter()
NumberModel provide converter support but not logic. return null, must be overrided

Specified by:
getConverter in interface SpinButton.Editable<java.lang.Double>
Returns:
nullalways null. Must be overrided
Since:
1.1

getHint

public java.lang.String getHint()
Description copied from interface: SpinButton.Editable
return hint to dispay while in edition mode.

Specified by:
getHint in interface SpinButton.Editable<java.lang.Double>
Returns:
Since:
1.1