Sky View Café - Java

org.shetline.gui
Class KPasswordField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by javax.swing.JPasswordField
                          extended by org.shetline.gui.KPasswordField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public class KPasswordField
extends JPasswordField

KPasswordField is a subclass of JPasswordField with extra features which include:

See Also:
Serialized Form

Nested Class Summary
protected static class KPasswordField.CharType
           
protected  class KPasswordField.StatusBorder
           
 
Nested classes/interfaces inherited from class javax.swing.JPasswordField
JPasswordField.AccessibleJPasswordField
 
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
protected  boolean altIsDown
           
protected  char[] baseText
           
protected  Color defaultBackground
           
protected  Border defaultBorder
           
protected  Color defaultForeground
           
protected  DocumentListener docListener
           
protected  Color editableBackground
           
protected static char[] EMPTY
           
protected  Color errorBackground
           
protected  Icon errorIcon
           
protected  KTextField.ErrorState errorState
           
protected  Border explicitBorder
           
protected  Color explicitDisabledBackground
           
protected  Color explicitStandardTextColor
           
protected  boolean hasBeenEdited
           
protected  int ignoreDocumentChange
           
protected  char[] lastText
           
protected  boolean leftToRight
           
protected  int maxLength
           
protected  Color modifiedTextColor
           
protected static char NUL_CHAR
           
protected  Container parent
           
protected  PropertyChangeListener propertyChangeListener
           
protected  char savedEchoChar
           
protected  boolean showModified
           
protected  boolean suggestionShowing
           
protected  String suggestionText
           
protected  Color suggestionTextColor
           
protected  int textCheckLength
           
protected  boolean textCheckPending
           
protected  int textCheckStart
           
protected  ListenerHandler textListenerHandler
           
protected  Pattern validCharacterPattern
           
 
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
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 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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
KPasswordField()
          Constructs a new KPasswordField, with a default document, an empty starting text string, and 0 column width.
KPasswordField(char[] password)
          Constructs a new KPasswordField initialized with the specified password.
KPasswordField(char[] password, int columns)
          Constructs a new KPasswordField initialized with the specified password and columns.
KPasswordField(Document doc, char[] password, int columns)
          Constructs a new KPasswordField that uses the given text storage model and the given number of columns.
KPasswordField(int columns)
          Constructs a new empty KPasswordField with the specified number of columns, using a default document model.
 
Method Summary
 void accept()
          Make the current content of the password field the base password for the field, and mark the password field as unedited.
 void addNotify()
           
 void addTextListener(TextListener listener)
          Adds the specified text event listener to receive text events from this password field.
protected  void beep()
           
protected  void broadcastTextChange()
           
protected  void checkTextChange(int start, int length)
           
protected  void checkTextChangeAux(int start, int length)
           
 void clearError()
          Clears the error state of the password field.
static char[] copy(char[] s)
          A convenience method to copy a char array.
protected  Border createOuterBorder()
           
protected  void finalize()
           
 Color getDisabledBackground()
          Returns the background color used to show that the password field is disabled.
 Color getEditableBackground()
          Returns the background color used to show that the password field is editable.
 Color getErrorBackground()
          Returns the background color used to show that the password field is in an error state.
 Icon getErrorIcon()
          Returns the Icon currently being used to show error conditions.
 KTextField.ErrorState getErrorState()
          Returns one of the following enumerated values: ErrorState.NO_ERROR, ErrorState.TRANSIENT_ERROR, or ErrorState.PERSISTENT_ERROR, representing the error state of the text field.
 boolean getHasBeenEdited()
          Returns true if the password field has been edited, that is, if the password field's current content differs from its current base password.
 int getLength()
          Returns the length in characters of the current content of the text field.
 int getMaximumLength()
          Returns the maximum length allowed for password input.
 Color getModifiedTextColor()
          Returns the color used to show that the password field has been edited by user input.
protected  char[] getPassword_JPasswordField()
          For subclasses of KPasswordField, access to JPasswordField.getPassword().
 char[] getPassword()
           
 int getPasswordStrength()
          Measures the strength of the password currently entered in the password field using getPasswordStrength(char[]).
static int getPasswordStrength(char[] pwd)
          Measures the strength of a password, based on criteria such length, mix of character types (lowercase, uppercase, numbers, symbols), lack of character repetition, lack of ordered character sequences (such as "abc" or "765"), etc.
 boolean getShowModified()
          Returns true if the password field shows edited text in a different color from unmodified text.
 Color getStandardTextColor()
          Returns the color used to show standard text.
protected  Insets getStatusBorderInsets()
           
 Color getStrengthColor()
           
static Color getStrengthColor(char[] pwd)
           
static Color getStrengthColor(int strength)
           
 String getStrengthDescription()
           
static String getStrengthDescription(char[] pwd)
           
static String getStrengthDescription(int strength)
           
 String getSuggestionText()
          Returns the text which will be shown as suggested or example input when the password field is empty and doesn't have focus, or null if there is no suggested text.
 Color getSuggestionTextColor()
          Returns the color used to show suggested text.
protected  String getText_JPasswordField()
          Deprecated. 
 String getText()
          Deprecated. 
 Border getUserBorder()
          Returns the border set by the user (or by the current look and feel) for this component, rather than the compound border created by combining the user border with this component's inner status border.
 char getUserEchoChar()
          The same as JPasswordField.getEchoChar(), except that character values deferred due to the display of suggestion text are returned, rather than the 0 which is returned by getEchoChar() when suggestion text is displayed.
 boolean hasError()
          Returns true if the password field is flagged as being in error.
 boolean isEmpty()
          Check if the password field is empty, disregarding any suggestion text that may currently be shown.
protected  boolean isReallyEmpty()
          Check if the text field is empty of both regular text and suggestion text.
protected  boolean isValidCharacter(char ch)
           
protected  void KPasswordFieldX()
           
 boolean matches(String s)
           
protected  void paintStatusBorder(Graphics g, int x, int y, int width, int height)
           
protected  void processKeyEvent_JPasswordField(KeyEvent event)
           
protected  void processKeyEvent(KeyEvent event)
           
protected  void refreshBorder()
           
 void removeNotify()
           
 void removeTextListener(TextListener listener)
          Removes the specified text event listener so that it no longer receives text events from this password field.
 void restore()
          Restore the password field to its base password, throwing away user changes, and mark the password field as unedited.
 void restore(boolean silently)
          Restore the password field to its base password, throwing away user changes, and mark the password field as unedited.
 void setBasePassword(char[] s)
          Sets the password that the password field will return to when restore() is called.
 void setBasePassword(char[] s, boolean silently)
          Sets the password that the password field will return to when restore() is called.
protected  void setBorder_JPasswordField(Border border)
          For subclasses of KPasswordField, access to JComponent.setBorder(Border).
 void setBorder(Border border)
          Sets the border for the password field to a new compound border with border as the outer border and an internal status border as the inside border.
 void setDisabledBackground(Color color)
          Sets the background color used to show that the text field is disabled.
 void setDocument(Document doc)
           
protected  void setEchoChar_JPasswordField(char c)
          For subclasses of KPasswordField, access to JPasswordField.setEchoChar(char).
 void setEchoChar(char c)
          The same as JPasswordField.setEchoChar(char), except that the change in echo character may be deferred while suggestion text is being shown.
 void setEditable(boolean editable)
           
 void setEditableBackground(Color color)
          Sets the background color used to show that the password field is editable.
 void setEnabled(boolean enabled)
           
 void setErrorBackground(Color color)
          Sets the background color used to show that the password field is in an error state.
 void setErrorIcon(Icon icon)
          Sets the Icon used to show error conditions.
 void setErrorState(KTextField.ErrorState state)
          Used to set or clear the error state of the password field.
 void setMaximumLength(int maxLength)
          Sets the maximum length allowed for password input.
 void setModifiedTextColor(Color color)
          Sets the color used to show that the password field has been edited by user input.
 void setPassword(char[] s)
          Sets the password to the contents of character array s.
 void setPassword(char[] s, boolean silently)
          Sets the password to the contents of character array s.
 void setPasswordAsIfTyped(char[] s)
          Sets the content of this password field without changing the base password which would be restored by the restore() method.
 void setPersistentError()
          Sets the error state of the password field.
 void setShowModified(boolean show)
          Set whether the text field shows edited text in a different color from unmodified text.
 void setStandardTextColor(Color color)
          Sets the color used to show standard text (text which is not a suggestion, not edited).
 void setSuggestionText(String s)
          Sets text to be displayed when the password field is both empty and out of focus.
 void setSuggestionTextColor(Color color)
          Sets the color used to show suggested text.
protected  void setText_JPasswordField(String s)
          For subclasses of KPasswordField, access to JTextComponent.setText(String).
 void setText(String s)
          Deprecated. 
 void setTransientError()
          Sets the error state of the password field.
 void setValidCharacterPattern(String pattern)
          Sets which characters are allowed for input.
 void setValidCharacterPattern(String pattern, boolean caseSensitive)
          Sets which characters are allowed for input.
protected  void updateAppearance()
           
protected  boolean updatePassword(char[] s, boolean filter)
           
protected  void updateTextListening()
           
 void updateUI()
           
 boolean userEchoCharIsSet()
          The same as JPasswordField.echoCharIsSet(), except that true is returned if a pending non-zero echo character has been set, regardless of the display of suggestion text which causes echoCharIsSet() to return false.
static void zap(char[] charArray)
          A convenience method to zero all characters in a char array.
 
Methods inherited from class javax.swing.JPasswordField
copy, cut, echoCharIsSet, getAccessibleContext, getEchoChar, getText, getUIClassID, paramString
 
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, isValidateRoot, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, 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, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, transferFocusBackward, 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, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

altIsDown

protected boolean altIsDown

baseText

protected char[] baseText

defaultBackground

protected Color defaultBackground

defaultBorder

protected Border defaultBorder

defaultForeground

protected Color defaultForeground

docListener

protected DocumentListener docListener

editableBackground

protected Color editableBackground

errorBackground

protected Color errorBackground

errorIcon

protected Icon errorIcon

errorState

protected KTextField.ErrorState errorState

explicitBorder

protected Border explicitBorder

explicitDisabledBackground

protected Color explicitDisabledBackground

explicitStandardTextColor

protected Color explicitStandardTextColor

hasBeenEdited

protected boolean hasBeenEdited

ignoreDocumentChange

protected int ignoreDocumentChange

lastText

protected char[] lastText

leftToRight

protected boolean leftToRight

maxLength

protected int maxLength

modifiedTextColor

protected Color modifiedTextColor

parent

protected Container parent

propertyChangeListener

protected PropertyChangeListener propertyChangeListener

savedEchoChar

protected char savedEchoChar

showModified

protected boolean showModified

suggestionShowing

protected boolean suggestionShowing

suggestionText

protected String suggestionText

suggestionTextColor

protected Color suggestionTextColor

textCheckLength

protected int textCheckLength

textCheckPending

protected boolean textCheckPending

textCheckStart

protected int textCheckStart

textListenerHandler

protected ListenerHandler textListenerHandler

validCharacterPattern

protected Pattern validCharacterPattern

EMPTY

protected static final char[] EMPTY

NUL_CHAR

protected static final char NUL_CHAR
See Also:
Constant Field Values
Constructor Detail

KPasswordField

public KPasswordField()
Constructs a new KPasswordField, with a default document, an empty starting text string, and 0 column width.


KPasswordField

public KPasswordField(char[] password)
Constructs a new KPasswordField initialized with the specified password. The document model is set to the default, and the number of columns to 0.

Parameters:
password - a pre-set password

KPasswordField

public KPasswordField(int columns)
Constructs a new empty KPasswordField with the specified number of columns, using a default document model.

Parameters:
columns - the number of columns >= 0

KPasswordField

public KPasswordField(char[] password,
                      int columns)
Constructs a new KPasswordField initialized with the specified password and columns. The document model is set to the default.

Parameters:
password - a pre-set password
columns - the number of columns >= 0

KPasswordField

public KPasswordField(Document doc,
                      char[] password,
                      int columns)
Constructs a new KPasswordField that uses the given text storage model and the given number of columns. The echo character is set to '*', but may be changed by the current Look and Feel. If the document model is null, a default model will be created.

Parameters:
doc - the text storage to use
password - a pre-set password, null if none
columns - the number of columns to use to calculate the preferred width >= 0; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
Method Detail

KPasswordFieldX

protected void KPasswordFieldX()

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

setBorder

public void setBorder(Border border)
Sets the border for the password field to a new compound border with border as the outer border and an internal status border as the inside border. If border is null, the password field's border will become the internal status border itself.

Overrides:
setBorder in class JComponent
Parameters:
border - the outermost border to be rendered for this component

setBorder_JPasswordField

protected final void setBorder_JPasswordField(Border border)
For subclasses of KPasswordField, access to JComponent.setBorder(Border).

Parameters:
border - the border to be rendered for this component

getUserBorder

public Border getUserBorder()
Returns the border set by the user (or by the current look and feel) for this component, rather than the compound border created by combining the user border with this component's inner status border.

Returns:
user border

addNotify

public void addNotify()
Overrides:
addNotify in class JComponent

removeNotify

public void removeNotify()
Overrides:
removeNotify in class JTextComponent

getText

@Deprecated
public String getText()
Deprecated. 

Overrides:
getText in class JPasswordField

getText_JPasswordField

@Deprecated
protected final String getText_JPasswordField()
Deprecated. 

For subclasses of KPasswordField, access to JPasswordField.getText().

Returns:
contents of password field

getPassword

public char[] getPassword()
Overrides:
getPassword in class JPasswordField

getPassword_JPasswordField

protected final char[] getPassword_JPasswordField()
For subclasses of KPasswordField, access to JPasswordField.getPassword().

Returns:
contents of password field

isEmpty

public boolean isEmpty()
Check if the password field is empty, disregarding any suggestion text that may currently be shown.

Returns:
true if the text field is empty

isReallyEmpty

protected boolean isReallyEmpty()
Check if the text field is empty of both regular text and suggestion text.

Returns:
true if the text field is empty

setText

@Deprecated
public void setText(String s)
Deprecated. 

This method is deprecated. setPassword(char[]) is the preferred method.

Overrides:
setText in class JTextComponent
Parameters:
s - new password to be set

setText_JPasswordField

protected final void setText_JPasswordField(String s)
For subclasses of KPasswordField, access to JTextComponent.setText(String).

Parameters:
s - new password to be set

setPasswordAsIfTyped

public void setPasswordAsIfTyped(char[] s)
Sets the content of this password field without changing the base password which would be restored by the restore() method. s will be filtered for invalid characters and checked against length limitations the same way typed text is checked. For improved security, it is recommended that s be cleared after calling this method. The static utility method zap(char[]) is available for this purpose.

Parameters:
s - new password to be set

setPassword

public void setPassword(char[] s)
Sets the password to the contents of character array s. For improved security, it is recommended that s be cleared after calling this method. The static utility method zap(char[]) is available for this purpose.

Parameters:
s - new password to be set

setPassword

public void setPassword(char[] s,
                        boolean silently)
Sets the password to the contents of character array s. For improved security, it is recommended that s be cleared after calling this method. The static utility method zap(char[]) is available for this purpose.

Parameters:
s - new password to be set
silently - true if TextListener[s] should not be notified of a text change.

updatePassword

protected boolean updatePassword(char[] s,
                                 boolean filter)

broadcastTextChange

protected void broadcastTextChange()

setEnabled

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

setEditable

public void setEditable(boolean editable)
Overrides:
setEditable in class JTextComponent

setEchoChar

public void setEchoChar(char c)
The same as JPasswordField.setEchoChar(char), except that the change in echo character may be deferred while suggestion text is being shown.

Overrides:
setEchoChar in class JPasswordField
Parameters:
c - the echo character to display

setEchoChar_JPasswordField

protected void setEchoChar_JPasswordField(char c)
For subclasses of KPasswordField, access to JPasswordField.setEchoChar(char).

Parameters:
c - the echo character to display

getUserEchoChar

public char getUserEchoChar()
The same as JPasswordField.getEchoChar(), except that character values deferred due to the display of suggestion text are returned, rather than the 0 which is returned by getEchoChar() when suggestion text is displayed.

Returns:
the echo character, 0 if unset

userEchoCharIsSet

public boolean userEchoCharIsSet()
The same as JPasswordField.echoCharIsSet(), except that true is returned if a pending non-zero echo character has been set, regardless of the display of suggestion text which causes echoCharIsSet() to return false.

Returns:
true if a character is set for echoing

getSuggestionText

public String getSuggestionText()
Returns the text which will be shown as suggested or example input when the password field is empty and doesn't have focus, or null if there is no suggested text.

Returns:
current suggested text, or null if not set

setSuggestionText

public void setSuggestionText(String s)
Sets text to be displayed when the password field is both empty and out of focus. The text will by default be displayed as light gray, but that color can be changed using setSuggestionTextColor(Color).

Parameters:
s - suggested or example text input

hasError

public boolean hasError()
Returns true if the password field is flagged as being in error.

Returns:
true if field is flagged as being in error

getErrorState

public KTextField.ErrorState getErrorState()
Returns one of the following enumerated values: ErrorState.NO_ERROR, ErrorState.TRANSIENT_ERROR, or ErrorState.PERSISTENT_ERROR, representing the error state of the text field.

Returns:
current error state
See Also:
KTextField.ErrorState

setErrorState

public void setErrorState(KTextField.ErrorState state)
Used to set or clear the error state of the password field. With default settings, an error state other than ErrorState.NO_ERROR will change the background color of the password field to pale red, and display a red stop sign icon at the trailing edge of the field (both the color and icon used can be customized). ErrorState.TRANSIENT_ERROR lasts until the user makes some change (any change) in the content of the text field. ErrorState.PERSISTENT_ERROR lasts until explicitly cleared.

Parameters:
state - ErrorState.NO_ERROR, ErrorState.TRANSIENT_ERROR, or ErrorState.PERSISTENT_ERROR
See Also:
KTextField.ErrorState

clearError

public void clearError()
Clears the error state of the password field. Equivalent to setErrorState(ErrorState.NO_ERROR).


setTransientError

public void setTransientError()
Sets the error state of the password field. Equivalent to setErrorState(ErrorState.TRANSIENT_ERROR).


setPersistentError

public void setPersistentError()
Sets the error state of the password field. Equivalent to setErrorState(ErrorState.PERSISTENT_ERROR).


getErrorIcon

public Icon getErrorIcon()
Returns the Icon currently being used to show error conditions.

Returns:
current error icon

setErrorIcon

public void setErrorIcon(Icon icon)
Sets the Icon used to show error conditions. This is preferably a 16x16 or smaller icon.

Parameters:
icon - error icon

getModifiedTextColor

public Color getModifiedTextColor()
Returns the color used to show that the password field has been edited by user input.

Returns:
color used to show modified text

setModifiedTextColor

public void setModifiedTextColor(Color color)
Sets the color used to show that the password field has been edited by user input.

Parameters:
color - color used to show modified text

getShowModified

public boolean getShowModified()
Returns true if the password field shows edited text in a different color from unmodified text.

Returns:
true if the password field shows edited text in a different color

setShowModified

public void setShowModified(boolean show)
Set whether the text field shows edited text in a different color from unmodified text.

Parameters:
show - true to show edited text in a different color

getEditableBackground

public Color getEditableBackground()
Returns the background color used to show that the password field is editable.

Returns:
background color used to show that the password field is editable

setEditableBackground

public void setEditableBackground(Color color)
Sets the background color used to show that the password field is editable.

Parameters:
color - background color used to show that the password field is editable

getErrorBackground

public Color getErrorBackground()
Returns the background color used to show that the password field is in an error state.

Returns:
background color used to show that the password field is in an error state

setErrorBackground

public void setErrorBackground(Color color)
Sets the background color used to show that the password field is in an error state.

Parameters:
color - background color used to show that the password field is in an error state

getSuggestionTextColor

public Color getSuggestionTextColor()
Returns the color used to show suggested text.

Returns:
color used to show suggested text

setSuggestionTextColor

public void setSuggestionTextColor(Color color)
Sets the color used to show suggested text.

Parameters:
color - color used to show suggested text

getDisabledBackground

public Color getDisabledBackground()
Returns the background color used to show that the password field is disabled.

Returns:
background color used to show that the text password is disabled

setDisabledBackground

public void setDisabledBackground(Color color)
Sets the background color used to show that the text field is disabled.

Parameters:
color - background color used to show that the text field is disabled

getStandardTextColor

public Color getStandardTextColor()
Returns the color used to show standard text.

Returns:
color used to show standard text

setStandardTextColor

public void setStandardTextColor(Color color)
Sets the color used to show standard text (text which is not a suggestion, not edited). (This text will normally be nothing more than a sequence of echo characters.)

Parameters:
color - color used to show standard text

getMaximumLength

public int getMaximumLength()
Returns the maximum length allowed for password input.

Returns:
maximum length allowed for password input

setMaximumLength

public void setMaximumLength(int maxLength)
Sets the maximum length allowed for password input.

Parameters:
maxLength - maximum length allowed for password input

setBasePassword

public void setBasePassword(char[] s)
Sets the password that the password field will return to when restore() is called. If the password field has not been edited by the user, the password content will immediately change to the new password.

Parameters:
s - base password for the password field

setBasePassword

public void setBasePassword(char[] s,
                            boolean silently)
Sets the password that the password field will return to when restore() is called. If the password field has not been edited by the user, the password content will immediately change to the new password. If the password changes TextListeners will not be notified of the change if silently is true.

Parameters:
s - base password for the password field
silently - true if TextListeners should not be notified of password changes.

getHasBeenEdited

public boolean getHasBeenEdited()
Returns true if the password field has been edited, that is, if the password field's current content differs from its current base password.

Returns:
true if the password field has been edited

accept

public void accept()
Make the current content of the password field the base password for the field, and mark the password field as unedited.


restore

public void restore()
Restore the password field to its base password, throwing away user changes, and mark the password field as unedited.


restore

public void restore(boolean silently)
Restore the password field to its base password, throwing away user changes, and mark the password field as unedited. If restoration changes the content of the password field, TextListeners will not be notified if silently is true.

Parameters:
silently - true if TextListeners should not be notified of password changes.

setValidCharacterPattern

public void setValidCharacterPattern(String pattern)
Sets which characters are allowed for input. Allowed characters are expressed in the form of a regular expression character class, with the outer square brackets assumed. For example, to allow hexadecimal input, use the pattern "0-9A-Za-z".

Parameters:
pattern - character class pattern for allowed characters

setValidCharacterPattern

public void setValidCharacterPattern(String pattern,
                                     boolean caseSensitive)
Sets which characters are allowed for input. Allowed characters are expressed in the form of a regular expression character class, with the outer square brackets assumed. For example, to allow hexadecimal input, use the pattern "0-9A-Za-z", or "0-9A-Z" with caseSensitive set to false.

Parameters:
pattern - character class pattern for allowed characters
caseSensitive - true if the pattern is case sensitive.

processKeyEvent

protected void processKeyEvent(KeyEvent event)
Overrides:
processKeyEvent in class JComponent

processKeyEvent_JPasswordField

protected final void processKeyEvent_JPasswordField(KeyEvent event)

updateTextListening

protected void updateTextListening()

checkTextChange

protected void checkTextChange(int start,
                               int length)

checkTextChangeAux

protected void checkTextChangeAux(int start,
                                  int length)

addTextListener

public void addTextListener(TextListener listener)
Adds the specified text event listener to receive text events from this password field.

Parameters:
listener - the text event listener
See Also:
removeTextListener(TextListener), TextListener

removeTextListener

public void removeTextListener(TextListener listener)
Removes the specified text event listener so that it no longer receives text events from this password field.

Parameters:
listener - the text listener
See Also:
addTextListener(TextListener)

setDocument

public void setDocument(Document doc)
Overrides:
setDocument in class JTextField

getLength

public int getLength()
Returns the length in characters of the current content of the text field.

Returns:
length of text content of text field, in characters

getPasswordStrength

public int getPasswordStrength()
Measures the strength of the password currently entered in the password field using getPasswordStrength(char[]).

Returns:
a strength score from 0 to 100
See Also:
getPasswordStrength(char[])

getStrengthDescription

public String getStrengthDescription()

getStrengthColor

public Color getStrengthColor()

matches

public boolean matches(String s)

getPasswordStrength

public static int getPasswordStrength(char[] pwd)
Measures the strength of a password, based on criteria such length, mix of character types (lowercase, uppercase, numbers, symbols), lack of character repetition, lack of ordered character sequences (such as "abc" or "765"), etc.

Parameters:
pwd - password to be checked
Returns:
a strength score from 0 to 100

getStrengthDescription

public static String getStrengthDescription(char[] pwd)

getStrengthDescription

public static String getStrengthDescription(int strength)

getStrengthColor

public static Color getStrengthColor(char[] pwd)

getStrengthColor

public static Color getStrengthColor(int strength)

beep

protected void beep()

isValidCharacter

protected boolean isValidCharacter(char ch)

updateAppearance

protected void updateAppearance()

updateUI

public void updateUI()
Overrides:
updateUI in class JPasswordField

createOuterBorder

protected Border createOuterBorder()

getStatusBorderInsets

protected Insets getStatusBorderInsets()

paintStatusBorder

protected void paintStatusBorder(Graphics g,
                                 int x,
                                 int y,
                                 int width,
                                 int height)

refreshBorder

protected void refreshBorder()

zap

public static void zap(char[] charArray)
A convenience method to zero all characters in a char array. This can be used for security, to avoid leaving traces of passwords in memory.

Parameters:
charArray - char array to be cleared to all-zero content

copy

public static char[] copy(char[] s)
A convenience method to copy a char array.

Parameters:
s - char array to be copied
Returns:
copy of s

Sky View Café - Java