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.AccessibleJTextFieldNested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested 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.DecimalDocprotected booleanprotected booleanstatic final Localestatic final intprotected NumberFormatprotected intprotected intprotected booleanprotected PropertyChangeSupportprotected intFields inherited from class javax.swing.JTextField
notifyActionFields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields 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 doublechangeIt(int type, double value) protected doublechangeIt(int type, double value, double max) protected longchangeIt(int type, long value, long max) protected Documentprotected voidprotected longgetMaxValue(int len) protected NumberFormatintThis method retrieves the number of digits allowed in this textfield after the decimal separator.intintRetrieves 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 booleanThis method verifies that the specified string doesn't contain alphabetic characters.voidReplaces the currently selected content with the specified text, granted the specified text contains numeric data only.protected booleanvoidsetNumFractionalDigits(int num) This method will modify the number of digits allowed in this textfield after the decimal separator.voidsetNumIntegerDigits(int num) This method will modify the number of digits allowed in this textfield before the decimal separator.voidsetRounding(int r) Determines the rounding used when retrieving this value.voidSets the text of this textfield to the specified text, granted the specified text contains numeric data only.voidUsed to set the value of component as an Object (Number) instead of a String (using setText()).protected StringstripNonNumerics(String str) voidImplements the CyclerListener interface.Methods inherited from class com.portal.pfc.ui.ValidatedTextField
getSpecialChars, setSpecialCharsMethods 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, setScrollOffsetMethods 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, writeMethods 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, updateMethods 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, validateTreeMethods 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:
getValuein 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:
setTextin 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:
replaceSelectionin 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:
valueChangein interfaceCyclerListener- Specified by:
valueChangein 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:ValidatedTextFieldThis method verifies that the specified string doesn't contain alphabetic characters.- Overrides:
isValidInputin classValidatedTextField- Returns:
- true if the input contains numeric data only; false otherwise
-
representsNegative
-
formatText
protected void formatText() -
createDefaultModel
- Overrides:
createDefaultModelin classJTextField
-