com.izforge.izpack.panels.userinput.gui.rule
Class RuleInputField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.izforge.izpack.panels.userinput.gui.rule.RuleInputField
All Implemented Interfaces:
FocusListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, CaretListener

public class RuleInputField
extends JComponent
implements KeyListener, FocusListener, CaretListener

This class assists the user in entering serial numbers.

Serial numbers, license number, CD keys and the like are often lenghty alpha-numerical numbers. In many cases they are devided into multiple parts by dash or point separators. Entering these in a single text field can be a frustrating experience for the user. This class provides a way of presenting the user with an assembly of input fields that are arranged in the same way as the key, with the separators already in place. Immideate testing for format compliance if performed ans soon as each field is completed. In addition, the cursor is automatically advanced to make entering numbers as painless as possible.

Formatting:

Example:

"N:4:4 - H:6:6 - AN:3:3 x A:5:5"

This formatting string will produce a serial number field consisting of four separate input fields. The fisrt input field will accept four numeric digits, the second six hexa-decimal digits, the third three alpha-numeric digits and the fourth five letters. The first three input fields will be separated by '-' and the third and fourth by 'x'. The following snapshot was obtained with this setting:

Version:
0.0.1 / 10/19/02
Author:
Elmar Grom
See Also:
Serialized Form

Nested Class Summary
 
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.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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RuleInputField(RuleField field)
          Constructs a RuleInputField.
 
Method Summary
 void caretUpdate(CaretEvent event)
          Called when the caret position is updated.
 void focusGained(FocusEvent event)
          Invoked when a component gains the keyboard focus.
 void focusLost(FocusEvent event)
          Invoked when a component loses the keyboard focus.
 List<JTextField> getInputFields()
           
 String getText()
          Returns the field contents, formatted according to its RuleFormat.
 String[] getValues()
          Returns the field values.
 void keyPressed(KeyEvent event)
          This method is invoked when a key has been pressed.
 void keyReleased(KeyEvent event)
          This method is invoked when a key has been released.
 void keyTyped(KeyEvent event)
          This method is invoked when a key has been typed.
 void setEnabled(boolean enabled)
           
 void setValues(String[] values)
          Sets the field values.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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, addInputMethodListener, 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, getInputMethodRequests, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, 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

RuleInputField

public RuleInputField(RuleField field)
Constructs a RuleInputField.

Parameters:
field - the field
Method Detail

getInputFields

public List<JTextField> getInputFields()

getText

public String getText()
Returns the field contents, formatted according to its RuleFormat.

Returns:
the field contents

getValues

public String[] getValues()
Returns the field values.

Returns:
the field values

setValues

public void setValues(String[] values)
Sets the field values.

Parameters:
values - the values to set

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class JComponent

keyTyped

public void keyTyped(KeyEvent event)
This method is invoked when a key has been typed. The event occurs when a key press is followed by a key release.

Specified by:
keyTyped in interface KeyListener
Parameters:
event - the key event forwarded by the system.

keyPressed

public void keyPressed(KeyEvent event)
This method is invoked when a key has been pressed. This method verifies the condition of the input field in focus. Once the column count in the field has reached the specified maximum, the rule specified for the field in question is invoked. In case the test result is positive, focus is set to the next field. If hte test result is negative, the field content is marked and the caret set to the start of the field.

Specified by:
keyPressed in interface KeyListener
Parameters:
event - the key event forwarded by the system.

keyReleased

public void keyReleased(KeyEvent event)
This method is invoked when a key has been released.

Specified by:
keyReleased in interface KeyListener
Parameters:
event - the key event forwarded by the system.

focusGained

public void focusGained(FocusEvent event)
Invoked when a component gains the keyboard focus.

Specified by:
focusGained in interface FocusListener
Parameters:
event - the focus event forwardes by the sytem.

focusLost

public void focusLost(FocusEvent event)
Invoked when a component loses the keyboard focus. This method does nothing, we are only interested in 'focus gained' events.

Specified by:
focusLost in interface FocusListener
Parameters:
event - the focus event forwardes by the sytem.

caretUpdate

public void caretUpdate(CaretEvent event)
Called when the caret position is updated.

Specified by:
caretUpdate in interface CaretListener
Parameters:
event - the caret event received from the text field


Copyright © 2018. All rights reserved.