|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.text.JTextComponent javax.swing.JTextField net.sourceforge.doyen.DataField
A class that implements basic functionality for a text field that places
constraints on its input.
DataField
validates its input when it loses or gains focus,
generates an action event, or when messaged with the
validateInput()
method. The no-op method
checkInput()
must be overridden by subclassers to perform
the actual data validation.
Invalid input is flagged by repainting the contents of the field in red. If a key is typed into a field so highlighted, the text reverts back to black (non-flagged). Validation is not performed whenever the contents of the field change, as the necessary parsing is an expensive operation.
Nested Class Summary | |
private class |
DataField._DocumentListener
document listener |
private static class |
DataField.ChangeSupport
|
Nested classes inherited from class javax.swing.JTextField |
JTextField.AccessibleJTextField |
Nested classes inherited from class javax.swing.text.JTextComponent |
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding |
Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
private boolean |
adjusting
|
private DataField.ChangeSupport |
csupport
|
private DataField._DocumentListener |
documentListener
|
private boolean |
inputRequired
|
protected boolean |
invalid
A state flag for representing validation state. |
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.Container |
|
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 | |
DataField()
Construct a new DataField . |
|
DataField(int width)
Construct a new DataField with the specified width. |
Method Summary | |
private void |
_fireChange()
Delay-fire a change event, but only if the current DocumentEvent is not the result of a call to setText(). |
private void |
_init()
initialization |
void |
addChangeListener(ChangeListener listener)
Add a ChangeListener to this component's list of listeners. |
protected boolean |
checkInput()
Determine if the given input is valid for this field. |
boolean |
isInputRequired()
Determine if input is required in this field. |
protected void |
paintInvalid(boolean invalid)
Paint the necessary decorations for the field to denote invalid (or valid) input. |
void |
removeChangeListener(ChangeListener listener)
Add a ChangeListener to this component's list of listeners. |
void |
setDocument(Document doc)
|
void |
setEditable(boolean flag)
Set the editable state of this field. |
void |
setInputRequired(boolean flag)
Specify whether an input is required in this field. |
void |
setText(String text)
Set the text to be displayed by this field. |
boolean |
validateInput()
Validate the input in this field. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private DataField.ChangeSupport csupport
private DataField._DocumentListener documentListener
private boolean inputRequired
protected boolean invalid
private boolean adjusting
Constructor Detail |
public DataField()
DataField
.
public DataField(int width)
DataField
with the specified width.
Method Detail |
private void _init()
public void setDocument(Document doc)
public void addChangeListener(ChangeListener listener)
ChangeListener
to this component's list of listeners.
ChangeEvent
s are fired when this text field's document model
changes.
listener
- The listener to add.public void removeChangeListener(ChangeListener listener)
ChangeListener
to this component's list of listeners.
ChangeEvent
s are fired when this text field's document model
changes.
listener
- The listener to add.private void _fireChange()
public final void setText(String text)
ChangeEvent
will not be fired when the data in the field is modified via this
call.
text
- The text to set.protected void paintInvalid(boolean invalid)
invalid
- A flag specifying whether the input in the field is
currently valid or invalid.public void setEditable(boolean flag)
flag
- A flag specifying whether this field should be editable.
Non-editable fields are made transparent.public void setInputRequired(boolean flag)
validateInput()
method will return
true
if the field is left empty; otherwise it will return
false
.
flag
- The flag.validateInput()
,
isInputRequired()
public boolean isInputRequired()
true
if input is required in this field, and
false
otherwise.public final boolean validateInput()
true
if the field contains valid input or if the
field contains no input and input is not required, and false
otherwise.protected boolean checkInput()
true
.
true
if the input is valid, and false
otherwise.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |