|
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
org.shetline.gui.KTextField
public class KTextField
KTextField
is a subclass of JTextField
with extra features which include:
TextListener
s.
ActionEvent
s after a programmable delay following typed input, a delay
which is restarted with each keystroke until keystrokes stop for the duration of the specified
delay. Event notification can optionally occur outside of the AWT event dispatch thread.
Nested Class Summary | |
---|---|
static class |
KTextField.CaseMode
|
static class |
KTextField.ErrorState
|
protected class |
KTextField.StatusBorder
|
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 | |
---|---|
KTextField()
Constructs a new empty KTextField . |
|
KTextField(Document doc,
String text,
int columns)
Constructs a new KTextField which uses the specified text
storage model, text content, and number of columns. |
|
KTextField(int columns)
Constructs a new empty KTextField with the specified number of
columns. |
|
KTextField(String text)
Constructs a new KTextField initialized with the specified text. |
|
KTextField(String text,
int columns)
Constructs a new KTextField initialized with the specified text
and column width. |
Method Summary | |
---|---|
void |
accept()
Make the current content of the text field the base text for the field, and mark the text field as unedited. |
void |
addNotify()
|
void |
addTextListener(TextListener listener)
Adds the specified text event listener to receive text events from this text field. |
void |
addTypingListener(ActionListener listener)
Add an ActionListener which will be called in response to typing changes, once changes have stopped
occurring for a specified typing update delay (which defaults to 250 msec. |
void |
addTypingListener(ActionListener listener,
boolean awtNotify)
Add an ActionListener which will be called in response to typing changes, once changes have stopped
occurring for a specified typing update delay (which defaults to 250 msec. |
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 text field. |
protected Border |
createOuterBorder()
|
String |
getByteEncoding()
Returns the byte encoding (such as "UTF-8") used to measure the length of the text field in bytes. |
KTextField.CaseMode |
getCaseMode()
Returns the current case conversion mode of the text field, one of CaseMode.NO_CHANGE ,
CaseMode.TO_UPPER , or CaseMode.TO_LOWER . |
Color |
getDisabledBackground()
Returns the background color used to show that the text field is disabled. |
Color |
getEditableBackground()
Returns the background color used to show that the text field is editable. |
Color |
getErrorBackground()
Returns the background color used to show that the text 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 text field has been edited, that is, if the text field's current content differs from its
current base text. |
int |
getLength()
Returns the length in characters of the current content of the text field. |
int |
getMaximumLength()
Returns the maximum length allowed for text input. |
int |
getMeasuredLength()
Returns the current length of the text field, measured in characters or bytes, depending on which length is currently being enforced for maximum length. |
protected int |
getMeasuredLength(String s)
|
Color |
getModifiedTextColor()
Returns the color used to show that the text field has been edited by user input. |
boolean |
getShowModified()
Returns true if the text field shows edited text in a different color from unmodified text. |
Color |
getStandardTextColor()
Returns the color used to show standard text. |
protected Insets |
getStatusBorderInsets()
|
String |
getSuggestionText()
Returns the text which will be shown as suggested or example input when the text 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_JTextField()
For subclasses of KTextField , access to JTextComponent.getText() . |
String |
getText()
Returns the content of this text field, an empty string if the text field's Document
is null or if the content is undefined. |
int |
getTypingUpdateDelay()
Returns the delay, in milliseconds, used between the last typed-in text change and notifications of ActionListener s registered with addTypingListener(java.awt.event.ActionListener, boolean) . |
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. |
boolean |
hasError()
Returns true if the text field is flagged as being in error. |
static boolean |
isCharacterInputEvent(KeyEvent event)
Determine if event represents simple character input, as opposed to action keys, backspaces,
cursor movement, etc. |
boolean |
isCheckingEncodedLength()
Returns true if text field maximum length is being checked using encoded byte length rather than
character length. |
boolean |
isEmpty()
Check if the text 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 |
KTextFieldX()
|
protected void |
paintStatusBorder(Graphics g,
int x,
int y,
int width,
int height)
|
protected void |
processKeyEvent_JTextField(KeyEvent event)
For subclasses of KTextField , access to JComponent.processKeyEvent(KeyEvent) . |
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 text field. |
void |
removeTypingListener(ActionListener listener)
Removes the specified ActionListener so that it no longer receives typing change events from this text field. |
void |
restore()
Restore the text field to its base text, throwing away user changes, and mark the text field as unedited. |
void |
restore(boolean silently)
Restore the text field to its base text, throwing away user changes, and mark the text field as unedited. |
protected void |
restoreTabbing()
|
void |
setBaseText(String s)
Sets the text that the text field will return to when restore() is called. |
void |
setBaseText(String s,
boolean silently)
Sets the text that the text field will return to when restore() is called. |
protected void |
setBorder_JTextField(Border border)
For subclasses of KTextField , access to JComponent.setBorder(Border) . |
void |
setBorder(Border border)
Sets the border for the text field to a new compound border with border as the outer border
and an internal status border as the inside border. |
void |
setCaseMode(KTextField.CaseMode caseMode)
Sets the current character case conversion mode of the text field to CaseMode.NO_CHANGE ,
CaseMode.TO_UPPER , or CaseMode.TO_LOWER . |
void |
setDisabledBackground(Color color)
Sets the background color used to show that the text field is disabled. |
void |
setDocument(Document doc)
|
void |
setEditable(boolean editable)
|
void |
setEditableBackground(Color color)
Sets the background color used to show that the text field is editable. |
void |
setEnabled(boolean enabled)
|
void |
setErrorBackground(Color color)
Sets the background color used to show that the text 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 text field. |
void |
setMaximumLength(int maxLength)
Sets the maximum length allowed for text input. |
void |
setMaximumLength(int maxLength,
boolean checkLengthInBytes)
Sets the maximum length allowed for text input while also specifying if that length should be measured in characters or in encoded bytes. |
void |
setMaximumLength(int maxLength,
String byteEncoding)
Sets the maximum length allowed for text input while also specifying a byte encoding for measuring text length in bytes. |
boolean |
setMaximumLengthNE(int maxLength,
String byteEncoding)
Same as setMaximumLength(int, String) , except will not throw an exception for unsupported
character encodings. |
void |
setModifiedTextColor(Color color)
Sets the color used to show that the text field has been edited by user input. |
void |
setPersistentError()
Sets the error state of the text field. |
void |
setPopupSuggestions(String[] suggestions)
Displays a pop-up list of text completion choices a user can click on (or navigate to via arrow keys, selecting with the Tab key) to fill in the contents of the text 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 text field is both empty and out of focus. |
void |
setSuggestionTextColor(Color color)
Sets the color used to show suggested text. |
protected void |
setText_JTextField(String s)
For subclasses of KTextField , access to JTextComponent.setText(String) . |
void |
setText(String s)
Sets the contents of the text field, sets the base text to which this field can be restored after user editing, and marks the field as unedited. |
void |
setText(String s,
boolean silently)
Sets the contents of the text field, sets the base text to which this field can be restored after user editing, and marks the field as unedited. |
void |
setTextAsIfTyped(String s)
Sets the content of this text field without changing the base text which would be restored by the restore() method. |
void |
setTransientError()
Sets the error state of the text field. |
void |
setTypingUpdateDelay(int delay)
Sets the delay, in milliseconds, to use between the last typed-in text change and notifications of ActionListener s registered with addTypingListener(java.awt.event.ActionListener, boolean) . |
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 void |
updateText(String s)
|
protected void |
updateTextListening()
|
void |
updateUI()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean altIsDown
protected String baseText
protected String byteEncoding
protected KTextField.CaseMode caseMode
protected boolean checkLengthInBytes
protected CharsetEncoder currentEncoder
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 focusRegainedFromPopup
protected boolean hasBeenEdited
protected int ignoreDocumentChange
protected String lastText
protected boolean leftToRight
protected int maxLength
protected Color modifiedTextColor
protected PopupNavigator navigator
protected Container parent
protected JPopupMenu popup
protected PopupMenuListener popupMenuListener
protected String[] popupSuggestions
protected PropertyChangeListener propertyChangeListener
protected Set<AWTKeyStroke> savedForwardTraversalKeys
protected int savedSelectionEnd
protected int savedSelectionStart
protected boolean showModified
protected boolean suggestionShowing
protected String suggestionText
protected Color suggestionTextColor
protected String suppressNextPopupFor
protected int textCheckLength
protected boolean textCheckPending
protected int textCheckStart
protected ListenerHandler textListenerHandler
protected ListenerHandler typingListenerHandler
protected DelayedAction typingDelay
protected Pattern validCharacterPattern
public static final Icon DEFAULT_ERROR_ICON
public static final Color DEFAULT_EDITABLE_BACKGROUND
public static final Color DEFAULT_ERROR_BACKGROUND
public static final Color DEFAULT_MODIFIED_TEXT_COLOR
public static final Color DEFAULT_SUGGESTION_TEXT_COLOR
public static final int DEFAULT_TYPING_UPDATE_DELAY
protected static final int ICON_GAP
Constructor Detail |
---|
public KTextField()
KTextField
. A default model is created,
the initial string is an empty string, and the number of columns is set to 0.
public KTextField(String text)
KTextField
initialized with the specified text.
A default model is created and the number of columns is 0.
text
- the text to be displayed, or null
public KTextField(int columns)
KTextField
with the specified number of
columns. A default model is created and the initial string is an empty string.
columns
- the number of columns to use to calculate
the preferred width; if columns is set to zero, the
preferred width will be whatever naturally results from
the component implementationpublic KTextField(String text, int columns)
KTextField
initialized with the specified text
and column width. A default model is created.
text
- the text to be displayed, or null
columns
- the number of columns to use to calculate
the preferred width; if columns is set to zero, the
preferred width will be whatever naturally results from
the component implementationpublic KTextField(Document doc, String text, int columns)
KTextField
which uses the specified text
storage model, text content, and number of columns.
If doc
is null
, a default model is created.
doc
- the text storage to use; if this is null
,
a default will be provided by calling the createDefaultModel
methodtext
- the initial string to display, or null
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
IllegalArgumentException
- if columns
< 0Method Detail |
---|
protected void KTextFieldX()
public void setBorder(Border border)
border
as the outer border
and an internal status border as the inside border. If border
is null, the text 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_JTextField(Border border)
KTextField
, access to JComponent.setBorder(Border)
.
border
- the border to be rendered for this componentpublic Border getUserBorder()
public void setPopupSuggestions(String[] suggestions)
suggestions
- a list of text completion choices, if null or empty causes any currently displayed pop-up
list to disappear.protected void restoreTabbing()
public void addNotify()
addNotify
in class JComponent
public void removeNotify()
removeNotify
in class JTextComponent
public String getText()
Document
is null or if the content is undefined.
getText
in class JTextComponent
protected final String getText_JTextField()
KTextField
, access to JTextComponent.getText()
.
public boolean isEmpty()
true
if the text field is emptyprotected boolean isReallyEmpty()
true
if the text field is emptypublic void setText(String s)
setText
in class JTextComponent
s
- content of text fieldpublic void setText(String s, boolean silently)
silently
is true.
s
- content of text fieldsilently
- true
if TextListener[s] should not be notified of a text change.protected final void setText_JTextField(String s)
KTextField
, access to JTextComponent.setText(String)
.
s
- content of text fieldpublic void setTextAsIfTyped(String s)
restore()
method. s
will be filtered for invalid characters
and checked against length limitations the same way typed text is checked.
s
- content of text fieldprotected void updateText(String s)
protected void broadcastTextChange()
public void setEnabled(boolean enabled)
setEnabled
in class JComponent
public void setEditable(boolean editable)
setEditable
in class JTextComponent
public String getSuggestionText()
public void setSuggestionText(String s)
setSuggestionTextColor(Color)
.
s
- suggested or example text inputpublic boolean hasError()
true
if the text 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.
public void setErrorState(KTextField.ErrorState state)
ErrorState.NO_ERROR
will change the background color of the text 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
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 text field shows edited text in a different color from unmodified text.
true
if the text 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 text field is editablepublic Color getErrorBackground()
public void setErrorBackground(Color color)
color
- background color used to show that the text 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 String getByteEncoding()
public boolean isCheckingEncodedLength()
true
if text field maximum length is being checked using encoded byte length rather than
character length.
true
if maximum length checked by encoded byte lengthpublic void setMaximumLength(int maxLength)
maxLength
- maximum length allowed for text inputpublic void setMaximumLength(int maxLength, boolean checkLengthInBytes)
maxLength
- maximum length allowed for text inputcheckLengthInBytes
- true
if the length should be measured in encoded bytespublic boolean setMaximumLengthNE(int maxLength, String byteEncoding)
setMaximumLength(int, String)
, except will not throw an exception for unsupported
character encodings.
maxLength
- maximum length allowed for text inputbyteEncoding
- an encoding, such as "UTF-8", for translating characters into bytes, null
for measuring length in characters rather than bytes.
true
if the specified byteEncoding
is supported.public void setMaximumLength(int maxLength, String byteEncoding) throws UnsupportedEncodingException
maxLength
- maximum length allowed for text inputbyteEncoding
- an encoding, such as "UTF-8", for translating characters into bytes, null
for measuring length in characters rather than bytes.
UnsupportedEncodingException
- if byteEncoding
does not represent a supported character encoding.public int getMeasuredLength()
protected int getMeasuredLength(String s)
public void setBaseText(String s)
restore()
is called. If the text field has
not been edited by the user, the text content will immediately change to the new text.
s
- base text for the text fieldpublic void setBaseText(String s, boolean silently)
restore()
is called. If the text field has
not been edited by the user, the text content will immediately change to the new text. If the text changes
TextListener
s will not be notified of the change if silently
is true
.
s
- base text for the text fieldsilently
- true
if TextListener
s should not be notified of text changes.public boolean getHasBeenEdited()
true
if the text field has been edited, that is, if the text field's current content differs from its
current base text.
true
if the text 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 text changes.public KTextField.CaseMode getCaseMode()
CaseMode.NO_CHANGE
,
CaseMode.TO_UPPER
, or CaseMode.TO_LOWER
.
public void setCaseMode(KTextField.CaseMode caseMode)
CaseMode.NO_CHANGE
,
CaseMode.TO_UPPER
, or CaseMode.TO_LOWER
. The default mode is
CaseMode.NO_CHANGE
. The other two modes cause character input to be converted to uppercase
or lowercase, respectively.
caseMode
- case conversion mode for the text fieldpublic 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
public static boolean isCharacterInputEvent(KeyEvent event)
event
represents simple character input, as opposed to action keys, backspaces,
cursor movement, etc. This function may err on the side of false negatives, causing character input to miss
being filtered at the key stroke level, but there will be other opportunities for character filtering via
the monitoring of document events.
event
- event to be tested
true
if event
represents simple character inputprotected final void processKeyEvent_JTextField(KeyEvent event)
KTextField
, access to JComponent.processKeyEvent(KeyEvent)
.
event
- the key eventprotected 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 addTypingListener(ActionListener listener)
ActionListener
which will be called in response to typing changes, once changes have stopped
occurring for a specified typing update delay (which defaults to 250 msec. if not explicitly set). The command
string of the ActionEvent
delivered to the ActionListener
is the text content of the
text field.
Notification will occur on the AWT event dispatch thread.
listener
- ActionListener
to addActionListener
,
ActionEvent
public void addTypingListener(ActionListener listener, boolean awtNotify)
ActionListener
which will be called in response to typing changes, once changes have stopped
occurring for a specified typing update delay (which defaults to 250 msec. if not explicitly set). The command
string of the ActionEvent
delivered to the ActionListener
is the text content of the
text field.
Notification will occur on the AWT event dispatch thread if awtNotify
is true, otherwise on a non-AWT
thread.
listener
- ActionListener
to addawtNotify
- true
for notification to occur on the AWT event dispatch threadActionListener
,
ActionEvent
public void removeTypingListener(ActionListener listener)
ActionListener
so that it no longer receives typing change events from this text field.
listener
- ActionListener
to removeaddTypingListener(ActionListener, boolean)
public int getTypingUpdateDelay()
ActionListener
s registered with addTypingListener(java.awt.event.ActionListener, boolean)
.
public void setTypingUpdateDelay(int delay)
ActionListener
s registered with addTypingListener(java.awt.event.ActionListener, boolean)
.
delay
- typing update delay, in millisecondspublic void setDocument(Document doc)
setDocument
in class JTextField
public int getLength()
protected void beep()
protected boolean isValidCharacter(char ch)
protected void updateAppearance()
public void updateUI()
updateUI
in class JTextComponent
protected Border createOuterBorder()
protected Insets getStatusBorderInsets()
protected void paintStatusBorder(Graphics g, int x, int y, int width, int height)
protected void refreshBorder()
|
Sky View Café - Java | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |