ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui
Class JxTextNumberField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by javax.swing.JFormattedTextField
                          extended by com.ehsbe.commons.gui.JxTextNumberField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public class JxTextNumberField
extends JFormattedTextField

A textfield, which allows locale specific number characters only and restricts the number to certain size/precision.

Version:
$Revision: 432 $
Author:
Jens Elkner
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFormattedTextField
JFormattedTextField.AbstractFormatter, JFormattedTextField.AbstractFormatterFactory
 
Nested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFormattedTextField
COMMIT, COMMIT_OR_REVERT, PERSIST, REVERT
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JxTextNumberField()
          Default constructor, which uses a precision of 15 and a scale of 4 and the default locale.
JxTextNumberField(Class<?> entityClass, String methodName)
          Construct an text field for the given entity with the default locale.
JxTextNumberField(Class<?> entityClass, String methodName, Locale locale)
          Construct an text field for the given entity.
JxTextNumberField(int precision, int scale, Locale locale)
          Construct an text field for the given entity.
 
Method Summary
 String getDefaultTooltipText()
          Get the default tooltip for this component.
 NumberFormat getNumberFormat()
          Get the NumberFormatter used by this component.
 String getToolTipText()
          Get the tootltip for this component.
 Validator<Number> getValidator()
          Get the Validator used to check, whether the fields input is valid.
 Number getValue()
          
protected  void processFocusEvent(FocusEvent e)
          
 void setLocale(Locale l)
          
 void setMinimumDigits(int intDigits, int floatDigits)
          Set the minimum number of digits, which should be used by the formatter.
 void setTemplate(Class<?> entityClass, String methodName)
          Set the number formatter and validator wrt. the given entity class and method.
 void setToolTipText(String text)
          
 void setValidator(Validator<Number> validator)
          Set the Validator used to check, whether the fields input is valid.
 void setValue(Object value)
          
protected  void validate(Number num)
          If a validator is set, this method validates the input and decorates the component, which used this component in a setLabelFor method.
 
Methods inherited from class javax.swing.JFormattedTextField
commitEdit, getActions, getFocusLostBehavior, getFormatter, getFormatterFactory, getUIClassID, invalidEdit, isEditValid, processInputMethodEvent, setDocument, setFocusLostBehavior, setFormatter, setFormatterFactory
 
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JxTextNumberField

public JxTextNumberField()
Default constructor, which uses a precision of 15 and a scale of 4 and the default locale.


JxTextNumberField

public JxTextNumberField(Class<?> entityClass,
                         String methodName,
                         Locale locale)
Construct an text field for the given entity.

Parameters:
entityClass - entity class
methodName - name of the method, which should be used to obtain the Column.scale() and Column.precision() for the field
locale - locale to use for obtaining valid number characters. If null, default locale will be used to construct a formatter.
See Also:
setTemplate(Class, String)

JxTextNumberField

public JxTextNumberField(int precision,
                         int scale,
                         Locale locale)
Construct an text field for the given entity.

Parameters:
precision - number of digits excl. the floating point and possible leading sign character, i.e. number of digits on the left plus number of digits on the right side of the floating point.
scale - digits after (i.e. on the right side of) the floating point
locale - locale to use for obtaining valid number characters

JxTextNumberField

public JxTextNumberField(Class<?> entityClass,
                         String methodName)
Construct an text field for the given entity with the default locale.

Parameters:
entityClass - entity class
methodName - name of the method, which should be used to obtain the Column.scale() and Column.precision() for the field
Method Detail

setTemplate

public void setTemplate(Class<?> entityClass,
                        String methodName)
Set the number formatter and validator wrt. the given entity class and method.

If the given entity or method is null or the given method of the entity could not be found, a default precision of 15 and scale of 4 is used.

If the given entity and method has been found but extracted precision and scale are both 0 or no anotation was found at all, a default precision of 11 and scale of 0 is used.

Furthermore precision values of 0 are replaced with 15.

A scale of 0 forces Integer formatting style (i.e. fraction point and digits are stripped).

Parameters:
entityClass - entity class
methodName - name of the method, which should be used to obtain the Column.scale() and Column.precision() for the field

setLocale

public void setLocale(Locale l)

Overrides:
setLocale in class Component

setMinimumDigits

public void setMinimumDigits(int intDigits,
                             int floatDigits)
Set the minimum number of digits, which should be used by the formatter.

Parameters:
intDigits - number of integer digits before a possible floating point sign.
floatDigits - number of digits after the floating point sign.

getNumberFormat

public NumberFormat getNumberFormat()
Get the NumberFormatter used by this component.

Returns:
a reference to the currently used number formatter.

getValue

public Number getValue()

Overrides:
getValue in class JFormattedTextField

setValue

public void setValue(Object value)

Overrides:
setValue in class JFormattedTextField

validate

protected void validate(Number num)
If a validator is set, this method validates the input and decorates the component, which used this component in a setLabelFor method.

Parameters:
num - number to validate

getToolTipText

public String getToolTipText()
Get the tootltip for this component.

If tooltip is set to an empty String, this component tries to obtain the Tooltip from its corresponding label. If it is still null an empty string and there is a template set, which restricts the format, the number format message is returned.

Overrides:
getToolTipText in class JComponent
Returns:
See Also:
getDefaultTooltipText()

setToolTipText

public void setToolTipText(String text)

Overrides:
setToolTipText in class JComponent

getDefaultTooltipText

public String getDefaultTooltipText()
Get the default tooltip for this component.

Returns:
always a none-null value

processFocusEvent

protected void processFocusEvent(FocusEvent e)

Overrides:
processFocusEvent in class JFormattedTextField

getValidator

public Validator<Number> getValidator()
Get the Validator used to check, whether the fields input is valid.

Per default a validator gets automatically installed, if the @Column's nullable property is set to false. It accepts numbers, only.

Returns:
null if not set, the validator otherwise.

setValidator

public void setValidator(Validator<Number> validator)
Set the Validator used to check, whether the fields input is valid.

Parameters:
validator - null to disable validation, the validator otherwise.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.