com.linxpda.dbaware.swing
Class DBNumericField

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JTextField
                                |
                                +--com.linxpda.dbaware.swing.DBNumericField
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, DBAware, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, javax.swing.SwingConstants

public class DBNumericField
extends javax.swing.JTextField
implements java.awt.event.ActionListener, DBAware

A data-aware component that only allows input of number values. A subclass of javax.swing.JTextField that only allows input of digits and decimal placeholders. A JNumericField can be specified to allow only integers (no decimals), currency (two decimal places only) or a preset number of decimals.

JNumericField uses special document classes, not event handlers, to control it's input so even text that is pasted into it is subject to the input constraints defined.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JTextField
javax.swing.JTextField.AccessibleJTextField
 
Inner classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int CURRENCY
          Variable denoting the acceptance of up to two decimal places only.
static int DECIMAL
          Variable denoting the allowance of decimal values.
static int INTEGER
          Variable denoting to allow integer input only.
 
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, NORTH, NORTH_EAST, NORTH_WEST, 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
DBNumericField()
          Creates an initially empty JNumericField.
DBNumericField(int cols)
          Creates an initially empty JNumericField that is 'cols' columns wide.
DBNumericField(int cols, int type)
          Creates an empty JNumeric that is 'cols' columns wide and allows 'type' input.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
protected  javax.swing.text.Document createDefaultModel()
           
 java.lang.String getColumnLabel()
          Returns the data column label associated with this component.
 float getFloat()
          Returns the current value of the JNumericField as a float.
 int getInteger()
          Returns the current value of the JNumericField as an int.
 java.lang.Object getValue()
          Returns a dbaware component's value as an Object formatted in a manner in which the component can display.
 void reset()
          Resets the component upon a request to clear screen from a DBRootPane.
 void setColumnLabel(java.lang.String column)
          Sets the data column into which this component's value will be stored.
 void setDecimalsAllowed(int d)
          Sets the maximum number of decimals allowed.
 void setType(int type)
          Sets the type of input allowed.
 void setValue(Entry value)
          Passes an Entry object, from which the dbaware component retrieves it's value and displays it.
 void setValue(float f)
          Sets the value to the given float.
 void setValue(int i)
          Sets the value to the given int.
 void setValue(java.lang.String value)
          Sets the value of the JNumericField, using a string as the initializer.
 
Methods inherited from class javax.swing.JTextField
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, 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, getCaretPosition, getDisabledTextColor, getDocument, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getUI, isEditable, isFocusTraversable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDocument, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, 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, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTEGER

public static final int INTEGER
Variable denoting to allow integer input only.

DECIMAL

public static final int DECIMAL
Variable denoting the allowance of decimal values.

CURRENCY

public static final int CURRENCY
Variable denoting the acceptance of up to two decimal places only.
Constructor Detail

DBNumericField

public DBNumericField()
Creates an initially empty JNumericField. Default type is DECIMAL.

DBNumericField

public DBNumericField(int cols)
Creates an initially empty JNumericField that is 'cols' columns wide. Default type is DECIMAL.
Parameters:
cols - The number of columns wide to make the JNumericField

DBNumericField

public DBNumericField(int cols,
                      int type)
Creates an empty JNumeric that is 'cols' columns wide and allows 'type' input.
Parameters:
cols - The number of columns wide to make the component.
type - Input type to allow. Should correlate to the static variables INTEGER, DECIMAL or CURRENCY.
Method Detail

setType

public void setType(int type)
Sets the type of input allowed.
Parameters:
type - The type of input to allow. Should equal the static variabled INTEGER, DECIMAL or CURRENCY.

setDecimalsAllowed

public void setDecimalsAllowed(int d)
Sets the maximum number of decimals allowed. This method only works the type DECIMAL has been set. If this method is not called then an infinite number of decimal places will be allowed.
Parameters:
d - The maximum number of decimal places to allow.

getFloat

public float getFloat()
Returns the current value of the JNumericField as a float.
Returns:
The current value as a float.

getInteger

public int getInteger()
Returns the current value of the JNumericField as an int.
Returns:
The current value as an int.

setValue

public void setValue(java.lang.String value)
Sets the value of the JNumericField, using a string as the initializer. All input rules apply.
Parameters:
value - A String that represents the value to display.

setValue

public void setValue(float f)
Sets the value to the given float. If the type is set to INTEGER and decimals are truncated.
Parameters:
f - The value to set.

setValue

public void setValue(int i)
Sets the value to the given int. If type is not INTEGER no decimals are added automatically.
Parameters:
i - The int value to set.

getColumnLabel

public java.lang.String getColumnLabel()
Description copied from interface: DBAware
Returns the data column label associated with this component.
Specified by:
getColumnLabel in interface DBAware

setColumnLabel

public void setColumnLabel(java.lang.String column)
Description copied from interface: DBAware
Sets the data column into which this component's value will be stored.
Specified by:
setColumnLabel in interface DBAware
Following copied from interface: com.linxpda.dbaware.DBAware
Parameters:
label - The name of the column in which to store this component's value.

getValue

public java.lang.Object getValue()
Description copied from interface: DBAware
Returns a dbaware component's value as an Object formatted in a manner in which the component can display.
Specified by:
getValue in interface DBAware

setValue

public void setValue(Entry value)
Description copied from interface: DBAware
Passes an Entry object, from which the dbaware component retrieves it's value and displays it.
Specified by:
setValue in interface DBAware

reset

public void reset()
Description copied from interface: DBAware
Resets the component upon a request to clear screen from a DBRootPane.
Specified by:
reset in interface DBAware

createDefaultModel

protected javax.swing.text.Document createDefaultModel()
Overrides:
createDefaultModel in class javax.swing.JTextField

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener