Package com.portal.pfc.ui
Class DecimalTextField
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
com.portal.pfc.ui.ValidatedTextField
com.portal.pfc.ui.DecimalTextField
- All Implemented Interfaces:
CyclerListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,Scrollable
,SwingConstants
- Direct Known Subclasses:
CurrencyTextField
,PIANumberField
A textfield that understands a percentage-type number (i.e. a number
consisting of an integer, a decimal separator, and a fractional portion i.e.
23.00). This component will format the numeric data appropriately for a
given Locale, as well as perform manipulations on the data as it is input by
the user.
- See Also:
-
Nested Class Summary
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
FieldsModifier and TypeFieldDescriptionprotected com.portal.pfc.ui.DecimalDoc
protected boolean
protected boolean
static final Locale
static final int
protected NumberFormat
protected int
protected int
protected boolean
protected PropertyChangeSupport
protected int
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
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
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
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
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new DecimalTextField.DecimalTextField
(int columns) Constructs a new DecimalTextField containing the specified number of columns. -
Method Summary
Modifier and TypeMethodDescriptionprotected double
changeIt
(int type, double value) protected double
changeIt
(int type, double value, double max) protected long
changeIt
(int type, long value, long max) protected Document
protected void
protected long
getMaxValue
(int len) protected NumberFormat
int
This method retrieves the number of digits allowed in this textfield after the decimal separator.int
int
Retrieves the rounding used when retrieving this value.getValue()
Used to retrieve the value of component as an Object (BigDecimal) instead of a String (using getText()).protected boolean
This method verifies that the specified string doesn't contain alphabetic characters.void
Replaces the currently selected content with the specified text, granted the specified text contains numeric data only.protected boolean
void
setNumFractionalDigits
(int num) This method will modify the number of digits allowed in this textfield after the decimal separator.void
setNumIntegerDigits
(int num) This method will modify the number of digits allowed in this textfield before the decimal separator.void
setRounding
(int r) Determines the rounding used when retrieving this value.void
Sets the text of this textfield to the specified text, granted the specified text contains numeric data only.void
Used to set the value of component as an Object (Number) instead of a String (using setText()).protected String
stripNonNumerics
(String str) void
Implements the CyclerListener interface.Methods inherited from class com.portal.pfc.ui.ValidatedTextField
getSpecialChars, setSpecialChars
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, 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, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, viewToModel2D, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setToolTipText, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
LOCALE
-
MAX_INTS
public static final int MAX_INTS- See Also:
-
doc
protected com.portal.pfc.ui.DecimalDoc doc -
numformat
-
processWithoutParsing
protected boolean processWithoutParsing -
formatNumberAsNegative
protected boolean formatNumberAsNegative -
isSpinning
protected boolean isSpinning -
numFractionalDigits
protected int numFractionalDigits -
numIntegerDigits
protected int numIntegerDigits -
propHandler
-
rounding
protected int rounding
-
-
Constructor Details
-
DecimalTextField
public DecimalTextField()Constructs a new DecimalTextField. The number of columns is set to zero and the initial text is set to 0.00 -
DecimalTextField
public DecimalTextField(int columns) Constructs a new DecimalTextField containing the specified number of columns. The initial text is set to 0.00- Parameters:
columns
- The number of columns to use in calculating the preferred width.
-
-
Method Details
-
getValue
Used to retrieve the value of component as an Object (BigDecimal) instead of a String (using getText()).- Specified by:
getValue
in classValidatedTextField
- Returns:
- the numeric value of the component
-
setValue
Used to set the value of component as an Object (Number) instead of a String (using setText()). -
setRounding
public void setRounding(int r) Determines the rounding used when retrieving this value.- Parameters:
r
- the rounding option. Should be one of the BigDecimal.ROUND* types.
-
getRounding
public int getRounding()Retrieves the rounding used when retrieving this value.- Returns:
- the rounding option.
-
setNumIntegerDigits
public void setNumIntegerDigits(int num) This method will modify the number of digits allowed in this textfield before the decimal separator.- Parameters:
the
- number of digits allowed after the decimal separator
-
getNumIntegerDigits
public int getNumIntegerDigits() -
setNumFractionalDigits
public void setNumFractionalDigits(int num) This method will modify the number of digits allowed in this textfield after the decimal separator. Once the number of digits is entered, any additional data is ignored.
The default is 2.- Parameters:
the
- number of digits allowed after the decimal separator
-
getNumFractionalDigits
public int getNumFractionalDigits()This method retrieves the number of digits allowed in this textfield after the decimal separator.- Returns:
- the number of digits allowed after the decimal separator
-
setText
Sets the text of this textfield to the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters (including the currency symbol and/or the grouping separator) the text is rejected.- Overrides:
setText
in classJTextComponent
- Parameters:
str
- the new text to display
-
replaceSelection
Replaces the currently selected content with the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters (including the currency symbol and/or the grouping separator) the text is rejected. If there is no selection this amounts to an insert of the specified text.- Overrides:
replaceSelection
in classJTextComponent
- Parameters:
str
- the new text to use when replacing the selected text
-
valueChange
Implements the CyclerListener interface. This method retrieves the currently selected text (or the entire text if there is no selection), turns it into a number, and increments/decrements it appropriately.- Specified by:
valueChange
in interfaceCyclerListener
- Specified by:
valueChange
in classValidatedTextField
- Parameters:
e
- the event generated from the Cycler action
-
getNumberFormat
-
stripNonNumerics
-
changeIt
protected double changeIt(int type, double value) -
changeIt
protected long changeIt(int type, long value, long max) -
changeIt
protected double changeIt(int type, double value, double max) -
getMaxValue
protected long getMaxValue(int len) -
isValidInput
Description copied from class:ValidatedTextField
This method verifies that the specified string doesn't contain alphabetic characters.- Overrides:
isValidInput
in classValidatedTextField
- Returns:
- true if the input contains numeric data only; false otherwise
-
representsNegative
-
formatText
protected void formatText() -
createDefaultModel
- Overrides:
createDefaultModel
in classJTextField
-