com.gridsystems.config.tools.swing
Class PasswordField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.gridsystems.config.tools.swing.PasswordField
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class PasswordField
extends javax.swing.JPanel
implements java.awt.event.FocusListener

Component that asks the passwords twice to avoid errors. This component presents two password fields. The user must fill both fields with the same value in order to change the value managed by the component. The component automatically compares the two values and launches an error popup when they are not the same. The comparison is done every time one of the fields loses the focus and it is not gained by the other field of the component.

Author:
SJM
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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 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
PasswordField(java.util.ResourceBundle resourceBundle, java.lang.String originalValue)
          Constructor.
 
Method Summary
 void discard()
          Sets the previous value as the current one.
 void focusGained(java.awt.event.FocusEvent event)
          Reacts to a Component gaining the focus.
 void focusLost(java.awt.event.FocusEvent event)
          Reacts to a Component losing the focus.
 javax.swing.InputVerifier getInputVerifier()
          Gets the input verifier that affects each of both password fields.
 java.lang.String getValue()
          Returns the password managed by the component.
 void postCheckChanges()
          Checks for changes in the value and, in that case, fires an event.
 void preCheckChanges()
          Stores the value of the component value to check for future changes.
 void setInputVerifier(javax.swing.InputVerifier inputVerifier)
          Sets an input verifier that affects each of both password fields.
 void setValue(java.lang.String value)
          Sets the password managed by the component.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, 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, 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

PasswordField

public PasswordField(java.util.ResourceBundle resourceBundle,
                     java.lang.String originalValue)
Constructor.

Parameters:
resourceBundle - the ResourceBundle from where the component gets the texts to display for labels and messages. If it is null, default messages (in english) are used.
originalValue - a String with the original value of the password. It can be null.
Method Detail

setInputVerifier

public void setInputVerifier(javax.swing.InputVerifier inputVerifier)
Sets an input verifier that affects each of both password fields. Sets an input verifier that affects each of both password fields. It should only check that the field values are correct (length, allowed characters) but must not check that both fields match, that comparison is done automatically by the control when needed.

Overrides:
setInputVerifier in class javax.swing.JComponent
Parameters:
inputVerifier - the InputVerifier to check each of the password fields.

getInputVerifier

public javax.swing.InputVerifier getInputVerifier()
Gets the input verifier that affects each of both password fields.

Overrides:
getInputVerifier in class javax.swing.JComponent
Returns:
the InputVerifier that checks each of the password fields.

getValue

public java.lang.String getValue()
Returns the password managed by the component.

Returns:
an String with the password.

setValue

public void setValue(java.lang.String value)
Sets the password managed by the component. Sets the password managed by the component. Sets the value to both fields of the component to the value passed.

Parameters:
value - a String with the password.

preCheckChanges

public final void preCheckChanges()
Stores the value of the component value to check for future changes. Stores the current value of the component value to check for changes. This method should be called before every possible ocassion in which the value managed by the component could be modified. In the default implementation, it is before opening the popup or when the text field gets the focus. The checks are made in the postCheckChanges method.

See Also:
postCheckChanges()

postCheckChanges

public final void postCheckChanges()
Checks for changes in the value and, in that case, fires an event. Checks for changes in the value managed by the component. The check is made calling the hasChanged() method. If a change is detected, a PropertyChanged event reporting this is fired. This method should be called after every possible ocassion in which the value managed by the component could have been modified. In the default implementation, it is after calling openPopup() or when the text field loses the focus.


discard

public final void discard()
Sets the previous value as the current one.


focusLost

public void focusLost(java.awt.event.FocusEvent event)
Reacts to a Component losing the focus. Reacts to a Component losing the focus. Objects of this class should not be used as FocusListener of any object (even themselves); its implementation of FocusListener is for internal use only. It allows them to know if a field loses focus to the other field of the componenent (in that case there is no need for checks) or to an external component (in that case the fields are checked to make sure that both values match).

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
event - the FocusEvent with the information of the event that happened.

focusGained

public void focusGained(java.awt.event.FocusEvent event)
Reacts to a Component gaining the focus. Reacts to a Component gaining the focus. Objects of this class should not be used as FocusListener of any object (even themselves); its implementation of FocusListener is for internal use only. It allows them to know if a field gains focus from the other field of the componenent (in that case there is no need for checks) or from an external component (in that case the component current value is stored to compare the values for changes and/or to discard the changes).

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
event - the FocusEvent with the information of the event that happened.


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.