Class ValidatedTextField

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, javax.swing.SwingConstants

    public class ValidatedTextField
    extends javax.swing.JTextField
    Extends JTextField to provide a data validation function and a colorization function.

    Supports two types of validated field: a generic text fields with length and/or character set limited by a Java regular expression or an integral numeric field with minimum and maximum allowed values.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JTextField

        javax.swing.JTextField.AccessibleJTextField
      • Nested classes/interfaces inherited from class javax.swing.text.JTextComponent

        javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.awt.Color COLOR_BG_EDITED  
      static java.awt.Color COLOR_BG_ERROR  
      static java.awt.Color COLOR_BG_OK  
      static java.awt.Color COLOR_BG_UNEDITED  
      static java.awt.Color COLOR_ERROR_VAL  
      static java.awt.Color COLOR_OK  
      (package private) ValidatedTextField thisone  
      static java.lang.String VTF_PC_STAT_LN_UPDATE  
      • 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

      Constructors 
      Constructor Description
      ValidatedTextField​(java.lang.Integer len, boolean allow0LengthValue, boolean forceUppercase, java.lang.Integer minValue, java.lang.Integer maxValue, java.lang.String validationRegExpr, java.lang.String validationErrorMessage)
      Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr, and where the string begins with a number which must be within a specified integral range.
      ValidatedTextField​(java.lang.Integer len, boolean allow0LengthValue, java.lang.Integer minValue, java.lang.Integer maxValue, java.lang.String validationErrorMessage)
      Provides a validated text field for integral values, where the validation mechanism requires a numeric value between a minimum and maximum value.
      ValidatedTextField​(java.lang.Integer len, boolean forceUppercase, java.lang.String validationRegExpr, java.lang.String validationErrorMessage)
      Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr .
      ValidatedTextField​(java.lang.Integer len, int minAcceptableVal, int maxAcceptableVal, java.lang.String validationErrorMessage)
      Provide a validated text field, where the validation mechanism requires a Numeric value which is a hexadecimal value which is valid and within a given numeric range.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getLastQueriedValue()
      Retrieve the current value of the "Last Queried Value".
      java.lang.String getValidateRegExp()
      Retrieve the current "validationRegExp".
      boolean isValid()
      Validate the field information.
      void setInvalidBackgroundColor​(java.awt.Color c)
      Set the color used for the field background when the field value is invalid.
      void setLastQueriedValue​(java.lang.String lastQueriedValue)
      Set the "Last Queried Value".
      void setValidateRegExp​(java.lang.String validationRegExpr)
      Set the "validationRegExp".
      • Methods inherited from class javax.swing.JTextField

        actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, 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, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, 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, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ValidatedTextField

        public ValidatedTextField​(java.lang.Integer len,
                                  boolean forceUppercase,
                                  java.lang.String validationRegExpr,
                                  java.lang.String validationErrorMessage)
        Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr .

        Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.

        When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue(String) method to set the value for this comparison.

        Parameters:
        len - defines the width of the text field entry box, in characters
        forceUppercase - determines if all alphabetic characters are forced to uppercase
        validationRegExpr - defines a java regular expression which is used when validating the text input. A string such as "^[0-9]{2}[a-zA-Z]{3,4}$" would require the text field to be a 5 or 6 character string which starts with exactly two digits and followed by either 3 or 4 upper-case or lower-case letters
        validationErrorMessage - is passed as an argument to the property change listener for the instantiating class
      • ValidatedTextField

        public ValidatedTextField​(java.lang.Integer len,
                                  boolean allow0LengthValue,
                                  boolean forceUppercase,
                                  java.lang.Integer minValue,
                                  java.lang.Integer maxValue,
                                  java.lang.String validationRegExpr,
                                  java.lang.String validationErrorMessage)
        Provides a validated text field, where the validation mechanism requires a String value which passes the matching defined in validationRegExpr, and where the string begins with a number which must be within a specified integral range.

        Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.

        When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colorized using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue() method to set the value for this comparison.

        Parameters:
        len - defines the width of the text field entry box, in characters.
        allow0LengthValue - determines if a value of 0 characters is allowed as a valid value.
        forceUppercase - determines if all alphabetic characters are forced to uppercase.
        minValue - is the smallest allowed value.
        maxValue - is the largest allowed value.
        validationRegExpr - defines a java regular expression which is used when validating the text input. A string such as "^[0-9]{2}[a-zA-Z]{3,4}$" would require the text field to be a 5 or 6 character string which starts with exactly two digits and followed by either 3 or 4 upper-case or lower-case letters.
        validationErrorMessage - is passed as an argument to the property change listener for the instantiating class.
      • ValidatedTextField

        public ValidatedTextField​(java.lang.Integer len,
                                  boolean allow0LengthValue,
                                  java.lang.Integer minValue,
                                  java.lang.Integer maxValue,
                                  java.lang.String validationErrorMessage)
        Provides a validated text field for integral values, where the validation mechanism requires a numeric value between a minimum and maximum value.

        Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.

        When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue() method to set the value for this comparison.

        Parameters:
        len - defines the width of the text field entry box, in characters
        allow0LengthValue - determines if a value of 0 characters is allowed as a valid value
        minValue - is the smallest allowed value
        maxValue - is the largest allowed value
        validationErrorMessage - is passed as an argument to the property change listener for the instantiating class.
      • ValidatedTextField

        public ValidatedTextField​(java.lang.Integer len,
                                  int minAcceptableVal,
                                  int maxAcceptableVal,
                                  java.lang.String validationErrorMessage)
        Provide a validated text field, where the validation mechanism requires a Numeric value which is a hexadecimal value which is valid and within a given numeric range.

        Validation occurs as part of the process of focus leaving the field. When validation fails, the focus remains within the field, and the field foreground and background colors are changed.

        When focus leaves the field and the field value is valid, the value will be checked against the "Last Queried Value". If the current field value matches the "Last Queried Value", the field is colored using the default field foreground and background colors. If instead the current field value does not match the "Last Queried Value", the field background color is changed to reflect that the value is not yet saved. Use the setLastQueriedValue(String) method to set the value for this comparison.

        Parameters:
        len - the length of the field
        minAcceptableVal - defines the lowest acceptable value
        maxAcceptableVal - defines the lowest acceptable value
        validationErrorMessage - is passed as an argument to the property change listener for the instantiating class
    • Method Detail

      • isValid

        public boolean isValid()
        Validate the field information. Does not make any GUI changes. A field value that is zero-length is considered invalid.
        Overrides:
        isValid in class java.awt.Component
        Returns:
        true if current field information is valid; otherwise false
      • setLastQueriedValue

        public void setLastQueriedValue​(java.lang.String lastQueriedValue)
        Set the "Last Queried Value". This value is used by the colorization process when focus is exiting the field.
        Parameters:
        lastQueriedValue - the last value verified
        See Also:
        getLastQueriedValue()
      • setValidateRegExp

        public void setValidateRegExp​(java.lang.String validationRegExpr)
        Set the "validationRegExp".
        Parameters:
        validationRegExpr - new validation pattern
        See Also:
        getValidateRegExp()
      • getValidateRegExp

        public java.lang.String getValidateRegExp()
        Retrieve the current "validationRegExp". Used in eg. Add Turnout to attach a manager-specific pattern without redrawing the pane
        Returns:
        the current validation pattern
        See Also:
        setValidateRegExp(String)
      • setInvalidBackgroundColor

        public void setInvalidBackgroundColor​(java.awt.Color c)
        Set the color used for the field background when the field value is invalid.
        Parameters:
        c - background Color to be used when the value is invalid