org.springframework.richclient.form.binding.swing
Class NumberBinder

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.application.support.ApplicationServicesAccessor
      extended by org.springframework.richclient.form.binding.support.AbstractBinder
          extended by org.springframework.richclient.form.binding.swing.NumberBinder
All Implemented Interfaces:
Binder

public class NumberBinder
extends AbstractBinder

Binder for numeric fields. Constructs a NumberBinding which holds a special inputfield org.springframework.richclient.swing.BigDecimalTextField.

This binder comes with a set of configuration properties which makes this easy reusable.

Examples:

 <bean id="euroBinder" class="org.springframework.richclient.form.binding.swing.NumberBinder" lazy-init="true">
    <property name="format">
     <value>###,###,###,##0.00</value>
   </property>
   <property name="nrOfDecimals">
     <value type="int">2</value>
   </property>
   <property name="leftDecoration">
     <value>€</value>
   </property>
 </bean>
 
 <bean id="percentageBinder" class="org.springframework.richclient.form.binding.swing.NumberBinder" lazy-init="true">
   <property name="nrOfNonDecimals">
     <value type="int">3</value>
   </property>
   <property name="nrOfDecimals">
     <value type="int">4</value>
   </property>
   <property name="rightDecoration">
     <value>%</value>
   </property>
   <property name="shiftFactor">
     <value type="java.math.BigDecimal">100</value>
   </property>
 </bean>
 

TODO it might be better to get the number of decimals/nonDecimals from the format

Author:
jh

Field Summary
protected  int alignment
           
protected  String format
           
protected  String leftDecoration
           
protected  boolean negativeSign
           
protected  int nrOfDecimals
           
protected  int nrOfNonDecimals
           
protected  boolean readOnly
           
protected  String rightDecoration
           
protected  Integer scale
           
protected  BigDecimal shiftFactor
           
protected  String unformat
           
 
Fields inherited from class org.springframework.richclient.form.binding.support.AbstractBinder
BINDING_CLIENT_PROPERTY_KEY, log
 
Fields inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
logger
 
Constructor Summary
NumberBinder()
          Default constructor.
NumberBinder(Class requiredSourceClass)
          Constructor taking the requiredSourceClass for this binder.
 
Method Summary
protected  JComponent createControl(Map context)
           
protected  Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context)
           
 void setAlignment(int alignment)
          Sets the horizontal aligment of the BigDecimalTextField.
 void setFormat(String format)
          Format that will be used to show this number.
 void setLeftDecoration(String leftDecoration)
          Set a decoration to the left of the inputField.
 void setNegativeSign(boolean negativeSign)
          Allow negative numbers.
 void setNrOfDecimals(int nrOfDecimals)
          Maximum number of decimals.
 void setNrOfNonDecimals(int nrOfNonDecimals)
          Maximum number of non-decimals.
 void setReadOnly(boolean readOnly)
          Force this inputField to be readOnly.
 void setRightDecoration(String rightDecoration)
          Set a decoration to the right of the inputField.
 void setScale(Integer scale)
          Enforce a given scale for the result.
 void setShiftFactor(BigDecimal shiftFactor)
           BigDecimals can be shifted right/left when storing.
 void setUnformat(String unformat)
           Format that will be used when user is editing the field.
 
Methods inherited from class org.springframework.richclient.form.binding.support.AbstractBinder
bind, bind, getPropertyType, getRequiredSourceClass, validateContextKeys
 
Methods inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
getActiveWindow, getApplication, getApplicationContext, getApplicationName, getApplicationServices, getCommandConfigurer, getComponentFactory, getConversionService, getIconSource, getImageSource, getMessage, getMessage, getMessage, getMessage, getMessages, getMessageSource, getObjectConfigurer, getService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

readOnly

protected boolean readOnly

format

protected String format

unformat

protected String unformat

nrOfDecimals

protected int nrOfDecimals

nrOfNonDecimals

protected int nrOfNonDecimals

negativeSign

protected boolean negativeSign

leftDecoration

protected String leftDecoration

rightDecoration

protected String rightDecoration

shiftFactor

protected BigDecimal shiftFactor

scale

protected Integer scale

alignment

protected int alignment
Constructor Detail

NumberBinder

public NumberBinder()

Default constructor.

Sets BigDecimal as requiredSourceClass.


NumberBinder

public NumberBinder(Class requiredSourceClass)
Constructor taking the requiredSourceClass for this binder.

Parameters:
requiredSourceClass - Required source class.
Method Detail

setReadOnly

public void setReadOnly(boolean readOnly)
Force this inputField to be readOnly.

Parameters:
readOnly -

setLeftDecoration

public void setLeftDecoration(String leftDecoration)
Set a decoration to the left of the inputField.

Parameters:
leftDecoration - Decoration to be placed.

setRightDecoration

public void setRightDecoration(String rightDecoration)
Set a decoration to the right of the inputField.

Parameters:
rightDecoration - Decoration to be placed.

setFormat

public void setFormat(String format)
Format that will be used to show this number.

Parameters:
format - NumberFormat.

setUnformat

public void setUnformat(String unformat)

Format that will be used when user is editing the field.

eg. when inputField gets focus, all formatting can be disabled. If focus is shifted, number will be formatted.

Parameters:
unformat - NumberFormat

setNrOfDecimals

public void setNrOfDecimals(int nrOfDecimals)
Maximum number of decimals.

Parameters:
nrOfDecimals -

setNrOfNonDecimals

public void setNrOfNonDecimals(int nrOfNonDecimals)
Maximum number of non-decimals.

Parameters:
nrOfNonDecimals -

setNegativeSign

public void setNegativeSign(boolean negativeSign)
Allow negative numbers. Default is true.

Parameters:
negativeSign - True if negative numbers are used.

setShiftFactor

public void setShiftFactor(BigDecimal shiftFactor)

BigDecimals can be shifted right/left when storing.

Eg. percentages may be shown as ###.## and saved as #.####.

Parameters:
shiftFactor - Factor to shift number when saved.

setScale

public void setScale(Integer scale)
Enforce a given scale for the result.

Parameters:
scale - The scale to set.
See Also:
BigDecimal.setScale(int)

setAlignment

public void setAlignment(int alignment)
Sets the horizontal aligment of the BigDecimalTextField. Default is SwingConstants.RIGHT.

Parameters:
alignment - Horizontal alignment to set.

createControl

protected JComponent createControl(Map context)
Specified by:
createControl in class AbstractBinder

doBind

protected Binding doBind(JComponent control,
                         FormModel formModel,
                         String formPropertyPath,
                         Map context)
Specified by:
doBind in class AbstractBinder


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.