|
Sky View Café - Java | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
javax.swing.JPasswordField
org.shetline.gui.KPasswordField
public class KPasswordField
KPasswordField
is a subclass of JPasswordField
with extra features which include:
char
arrays,
complementing the functionality of JPasswordField.getPassword()
.
getPasswordStrength()
method to rate the strength of passwords.
TextListener
s.
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 |
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 java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean altIsDown
protected char[] baseText
protected Color defaultBackground
protected Border defaultBorder
protected Color defaultForeground
protected DocumentListener docListener
protected Color editableBackground
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 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
protected static final char[] EMPTY
protected static final char NUL_CHAR
Constructor Detail |
---|
public KPasswordField()
KPasswordField
, with a default document, an empty starting text string, and 0
column width.
public KPasswordField(char[] password)
KPasswordField
initialized with the specified password. The document model is set
to the default, and the number of columns to 0.
password
- a pre-set passwordpublic KPasswordField(int columns)
KPasswordField
with the specified number of columns, using a default
document model.
columns
- the number of columns >= 0public KPasswordField(char[] password, int columns)
KPasswordField
initialized with the specified password and columns. The document
model is set to the default.
password
- a pre-set passwordcolumns
- the number of columns >= 0public KPasswordField(Document doc, char[] password, int columns)
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.
doc
- the text storage to usepassword
- a pre-set password, null
if nonecolumns
- 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 implementationMethod Detail |
---|
protected void KPasswordFieldX()
protected void finalize() throws Throwable
finalize
in class Object
Throwable
public void setBorder(Border border)
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.
setBorder
in class JComponent
border
- the outermost border to be rendered for this componentprotected final void setBorder_JPasswordField(Border border)
KPasswordField
, access to JComponent.setBorder(Border)
.
border
- the border to be rendered for this componentpublic Border getUserBorder()
public void addNotify()
addNotify
in class JComponent
public void removeNotify()
removeNotify
in class JTextComponent
@Deprecated public String getText()
getText
in class JPasswordField
@Deprecated protected final String getText_JPasswordField()
KPasswordField
, access to JPasswordField.getText()
.
public char[] getPassword()
getPassword
in class JPasswordField
protected final char[] getPassword_JPasswordField()
KPasswordField
, access to JPasswordField.getPassword()
.
public boolean isEmpty()
true
if the text field is emptyprotected boolean isReallyEmpty()
true
if the text field is empty@Deprecated public void setText(String s)
setPassword(char[])
is the preferred method.
setText
in class JTextComponent
s
- new password to be setprotected final void setText_JPasswordField(String s)
KPasswordField
, access to JTextComponent.setText(String)
.
s
- new password to be setpublic void setPasswordAsIfTyped(char[] s)
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.
s
- new password to be setpublic void setPassword(char[] s)
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.
s
- new password to be setpublic void setPassword(char[] s, boolean silently)
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.
s
- new password to be setsilently
- true
if TextListener[s] should not be notified of a text change.protected boolean updatePassword(char[] s, boolean filter)
protected void broadcastTextChange()
public void setEnabled(boolean enabled)
setEnabled
in class JComponent
public void setEditable(boolean editable)
setEditable
in class JTextComponent
public void setEchoChar(char c)
JPasswordField.setEchoChar(char)
, except that the change in echo
character may be deferred while suggestion text is being shown.
setEchoChar
in class JPasswordField
c
- the echo character to displayprotected void setEchoChar_JPasswordField(char c)
KPasswordField
, access to JPasswordField.setEchoChar(char)
.
c
- the echo character to displaypublic char getUserEchoChar()
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.
public boolean userEchoCharIsSet()
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
.
true
if a character is set for echoingpublic String getSuggestionText()
public void setSuggestionText(String s)
setSuggestionTextColor(Color)
.
s
- suggested or example text inputpublic boolean hasError()
true
if the password field is flagged as being in error.
true
if field is flagged as being in errorpublic KTextField.ErrorState getErrorState()
ErrorState.NO_ERROR
,
ErrorState.TRANSIENT_ERROR
, or ErrorState.PERSISTENT_ERROR
, representing the
error state of the text field.
KTextField.ErrorState
public void setErrorState(KTextField.ErrorState state)
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.
state
- ErrorState.NO_ERROR
, ErrorState.TRANSIENT_ERROR
, or
ErrorState.PERSISTENT_ERROR
KTextField.ErrorState
public void clearError()
setErrorState(ErrorState.NO_ERROR)
.
public void setTransientError()
setErrorState(ErrorState.TRANSIENT_ERROR)
.
public void setPersistentError()
setErrorState(ErrorState.PERSISTENT_ERROR)
.
public Icon getErrorIcon()
Icon
currently being used to show error conditions.
public void setErrorIcon(Icon icon)
Icon
used to show error conditions. This is preferably a 16x16 or smaller icon.
icon
- error iconpublic Color getModifiedTextColor()
public void setModifiedTextColor(Color color)
color
- color used to show modified textpublic boolean getShowModified()
true
if the password field shows edited text in a different color from unmodified text.
true
if the password field shows edited text in a different colorpublic void setShowModified(boolean show)
show
- true
to show edited text in a different colorpublic Color getEditableBackground()
public void setEditableBackground(Color color)
color
- background color used to show that the password field is editablepublic Color getErrorBackground()
public void setErrorBackground(Color color)
color
- background color used to show that the password field is in an error statepublic Color getSuggestionTextColor()
public void setSuggestionTextColor(Color color)
color
- color used to show suggested textpublic Color getDisabledBackground()
public void setDisabledBackground(Color color)
color
- background color used to show that the text field is disabledpublic Color getStandardTextColor()
public void setStandardTextColor(Color color)
color
- color used to show standard textpublic int getMaximumLength()
public void setMaximumLength(int maxLength)
maxLength
- maximum length allowed for password inputpublic void setBasePassword(char[] s)
restore()
is called. If the password
field has not been edited by the user, the password content will immediately change to the new password.
s
- base password for the password fieldpublic void setBasePassword(char[] s, boolean silently)
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 TextListener
s will not be notified of the change if silently
is true
.
s
- base password for the password fieldsilently
- true
if TextListener
s should not be notified of password changes.public boolean getHasBeenEdited()
true
if the password field has been edited, that is, if the password field's current content differs
from its current base password.
true
if the password field has been editedpublic void accept()
public void restore()
public void restore(boolean silently)
TextListener
s will not
be notified if silently
is true
.
silently
- true
if TextListener
s should not be notified of password changes.public void setValidCharacterPattern(String pattern)
pattern
- character class pattern for allowed characterspublic void setValidCharacterPattern(String pattern, boolean caseSensitive)
caseSensitive
set to false
.
pattern
- character class pattern for allowed characterscaseSensitive
- true
if the pattern is case sensitive.protected void processKeyEvent(KeyEvent event)
processKeyEvent
in class JComponent
protected final void processKeyEvent_JPasswordField(KeyEvent event)
protected void updateTextListening()
protected void checkTextChange(int start, int length)
protected void checkTextChangeAux(int start, int length)
public void addTextListener(TextListener listener)
listener
- the text event listenerremoveTextListener(TextListener)
,
TextListener
public void removeTextListener(TextListener listener)
listener
- the text listeneraddTextListener(TextListener)
public void setDocument(Document doc)
setDocument
in class JTextField
public int getLength()
public int getPasswordStrength()
getPasswordStrength(char[])
.
getPasswordStrength(char[])
public String getStrengthDescription()
public Color getStrengthColor()
public boolean matches(String s)
public static int getPasswordStrength(char[] pwd)
pwd
- password to be checked
public static String getStrengthDescription(char[] pwd)
public static String getStrengthDescription(int strength)
public static Color getStrengthColor(char[] pwd)
public static Color getStrengthColor(int strength)
protected void beep()
protected boolean isValidCharacter(char ch)
protected void updateAppearance()
public void updateUI()
updateUI
in class JPasswordField
protected Border createOuterBorder()
protected Insets getStatusBorderInsets()
protected void paintStatusBorder(Graphics g, int x, int y, int width, int height)
protected void refreshBorder()
public static void zap(char[] charArray)
char
array. This can be used for security,
to avoid leaving traces of passwords in memory.
charArray
- char
array to be cleared to all-zero contentpublic static char[] copy(char[] s)
char
array.
s
- char
array to be copied
s
|
Sky View Café - Java | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |