kiwi.ui
Class DataField
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.text.JTextComponent
|
+--javax.swing.JTextField
|
+--kiwi.ui.DataField
Direct Known Subclasses: NumericField
public abstract class DataField extends JTextField implements FormatConstants
An abstract 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 abstract method
checkInput() must be implemented 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.
Version: 1.0 (07/99)
Author: Mark Lindner, PING Software Group
See Also: Serialized Form
Field Summary
protected boolean
invalid
A state flag for representing validation state.
Constructor Summary
DataField ()
Construct a new DataField.
DataField (int width)
Construct a new DataField with the specified width.
Method Summary
void
addChangeListener (ChangeListener listener)
Add a ChangeListener to this component's list of listeners.
protected abstract boolean
checkInput ()
Determine if the given input is valid for this field.
int
getMaximumLength ()
Get the maxmium number of characters that may be entered into 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
setMaximumLength (int length)
Set the maximum number of characters that may be entered into 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 javax.swing.JTextField
addActionListener ,
createDefaultModel ,
fireActionPerformed ,
getAccessibleContext ,
getActions ,
getColumns ,
getColumnWidth ,
getHorizontalAlignment ,
getHorizontalVisibility ,
getPreferredSize ,
getScrollOffset ,
getUIClassID ,
isValidateRoot ,
paramString ,
postActionEvent ,
removeActionListener ,
scrollRectToVisible ,
setActionCommand ,
setColumns ,
setFont ,
setHorizontalAlignment ,
setScrollOffset
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener ,
addKeymap ,
copy ,
cut ,
fireCaretUpdate ,
getCaret ,
getCaretColor ,
getCaretPosition ,
getDisabledTextColor ,
getDocument ,
getFocusAccelerator ,
getHighlighter ,
getInputMethodRequests ,
getKeymap ,
getKeymap ,
getMargin ,
getPreferredScrollableViewportSize ,
getScrollableBlockIncrement ,
getScrollableTracksViewportHeight ,
getScrollableTracksViewportWidth ,
getScrollableUnitIncrement ,
getSelectedText ,
getSelectedTextColor ,
getSelectionColor ,
getSelectionEnd ,
getSelectionStart ,
getText ,
getText ,
getUI ,
isEditable ,
isFocusTraversable ,
isOpaque ,
loadKeymap ,
modelToView ,
moveCaretPosition ,
paste ,
processComponentKeyEvent ,
processInputMethodEvent ,
read ,
removeCaretListener ,
removeKeymap ,
removeNotify ,
replaceSelection ,
select ,
selectAll ,
setCaret ,
setCaretColor ,
setCaretPosition ,
setDisabledTextColor ,
setEnabled ,
setFocusAccelerator ,
setHighlighter ,
setKeymap ,
setMargin ,
setOpaque ,
setSelectedTextColor ,
setSelectionColor ,
setSelectionEnd ,
setSelectionStart ,
setUI ,
updateUI ,
viewToModel ,
write
Methods inherited from class javax.swing.JComponent
addAncestorListener ,
addNotify ,
addPropertyChangeListener ,
addVetoableChangeListener ,
computeVisibleRect ,
contains ,
createToolTip ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
firePropertyChange ,
fireVetoableChange ,
getActionForKeyStroke ,
getAlignmentX ,
getAlignmentY ,
getAutoscrolls ,
getBorder ,
getBounds ,
getClientProperty ,
getComponentGraphics ,
getConditionForKeyStroke ,
getDebugGraphicsOptions ,
getGraphics ,
getHeight ,
getInsets ,
getInsets ,
getLocation ,
getMaximumSize ,
getMinimumSize ,
getNextFocusableComponent ,
getRegisteredKeyStrokes ,
getRootPane ,
getSize ,
getToolTipLocation ,
getToolTipText ,
getToolTipText ,
getTopLevelAncestor ,
getVisibleRect ,
getWidth ,
getX ,
getY ,
grabFocus ,
hasFocus ,
isDoubleBuffered ,
isFocusCycleRoot ,
isLightweightComponent ,
isManagingFocus ,
isOptimizedDrawingEnabled ,
isPaintingTile ,
isRequestFocusEnabled ,
paint ,
paintBorder ,
paintChildren ,
paintComponent ,
paintImmediately ,
paintImmediately ,
processFocusEvent ,
processKeyEvent ,
processMouseMotionEvent ,
putClientProperty ,
registerKeyboardAction ,
registerKeyboardAction ,
removeAncestorListener ,
removePropertyChangeListener ,
removeVetoableChangeListener ,
repaint ,
repaint ,
requestDefaultFocus ,
requestFocus ,
resetKeyboardActions ,
reshape ,
revalidate ,
setAlignmentX ,
setAlignmentY ,
setAutoscrolls ,
setBackground ,
setBorder ,
setDebugGraphicsOptions ,
setDoubleBuffered ,
setForeground ,
setMaximumSize ,
setMinimumSize ,
setNextFocusableComponent ,
setPreferredSize ,
setRequestFocusEnabled ,
setToolTipText ,
setUI ,
setVisible ,
unregisterKeyboardAction ,
update
Methods inherited from class java.awt.Container
add ,
add ,
add ,
add ,
add ,
addContainerListener ,
addImpl ,
countComponents ,
deliverEvent ,
doLayout ,
findComponentAt ,
findComponentAt ,
getComponent ,
getComponentAt ,
getComponentAt ,
getComponentCount ,
getComponents ,
getLayout ,
insets ,
invalidate ,
isAncestorOf ,
layout ,
list ,
list ,
locate ,
minimumSize ,
paintComponents ,
preferredSize ,
print ,
printComponents ,
processContainerEvent ,
processEvent ,
remove ,
remove ,
removeAll ,
removeContainerListener ,
setLayout ,
validate ,
validateTree
Methods inherited from class java.awt.Component
action ,
add ,
addComponentListener ,
addFocusListener ,
addInputMethodListener ,
addKeyListener ,
addMouseListener ,
addMouseMotionListener ,
addPropertyChangeListener ,
bounds ,
checkImage ,
checkImage ,
coalesceEvents ,
contains ,
createImage ,
createImage ,
disable ,
disableEvents ,
dispatchEvent ,
enable ,
enable ,
enableEvents ,
enableInputMethods ,
getBackground ,
getBounds ,
getColorModel ,
getComponentOrientation ,
getCursor ,
getDropTarget ,
getFont ,
getFontMetrics ,
getForeground ,
getInputContext ,
getLocale ,
getLocation ,
getLocationOnScreen ,
getName ,
getParent ,
getPeer ,
getSize ,
getToolkit ,
getTreeLock ,
gotFocus ,
handleEvent ,
hide ,
imageUpdate ,
inside ,
isDisplayable ,
isEnabled ,
isLightweight ,
isShowing ,
isValid ,
isVisible ,
keyDown ,
keyUp ,
list ,
list ,
list ,
location ,
lostFocus ,
mouseDown ,
mouseDrag ,
mouseEnter ,
mouseExit ,
mouseMove ,
mouseUp ,
move ,
nextFocus ,
paintAll ,
postEvent ,
prepareImage ,
prepareImage ,
printAll ,
processComponentEvent ,
processMouseEvent ,
remove ,
removeComponentListener ,
removeFocusListener ,
removeInputMethodListener ,
removeKeyListener ,
removeMouseListener ,
removeMouseMotionListener ,
removePropertyChangeListener ,
repaint ,
repaint ,
repaint ,
resize ,
resize ,
setBounds ,
setBounds ,
setComponentOrientation ,
setCursor ,
setDropTarget ,
setLocale ,
setLocation ,
setLocation ,
setName ,
setSize ,
setSize ,
show ,
show ,
size ,
toString ,
transferFocus
invalid
protected boolean invalid
A state flag for representing validation state.
DataField
public DataField ()
Construct a new DataField.
DataField
public DataField (int width)
Construct a new DataField with the specified width.
setDocument
public void setDocument (Document doc)
Overrides: setDocument in class JTextComponent
addChangeListener
public void addChangeListener (ChangeListener listener)
Add a ChangeListener to this component's list of listeners.
ChangeEvents are fired when this text field's document model
changes.
Parameters: listener - The listener to add.
removeChangeListener
public void removeChangeListener (ChangeListener listener)
Add a ChangeListener to this component's list of listeners.
ChangeEvents are fired when this text field's document model
changes.
Parameters: listener - The listener to add.
setText
public final void setText (String text)
Set the text to be displayed by this field. A ChangeEvent
will not be fired when the data in the field is modified via this
call.
Parameters: text - The text to set.Overrides: setText in class JTextComponent
paintInvalid
protected void paintInvalid (boolean invalid)
Paint the necessary decorations for the field to denote invalid (or
valid) input. The default implementation sets the text color to red
if the input is invalid and black otherwise. This method may be
overridden by subclassers who wish to customize the method of visual
feedback.
Parameters: invalid - A flag specifying whether the input in the field is
currently valid or invalid.
setEditable
public void setEditable (boolean flag)
Set the editable state of this field.
Parameters: flag - A flag specifying whether this field should be editable.
Non-editable fields are made transparent.Overrides: setEditable in class JTextComponent
setInputRequired
public void setInputRequired (boolean flag)
Specify whether an input is required in this field. If no input is
required, the validateInput() method will return true
if the field is left empty; otherwise it will return false .
Parameters: flag - The flag.See Also: validateInput() ,
isInputRequired()
isInputRequired
public boolean isInputRequired ()
Determine if input is required in this field.
Returns: true if input is required in this field, and false
otherwise.
validateInput
public final boolean validateInput ()
Validate the input in this field.
Returns: true if the field contains valid input or if the field
contains no input and input is not required, and false
otherwise.
checkInput
protected abstract boolean checkInput ()
Determine if the given input is valid for this field.
Returns: true if the input is valid, and false otherwise.
setMaximumLength
public void setMaximumLength (int length)
Set the maximum number of characters that may be entered into this field.
This method will have no effect if the document has been changed from
a KDocument via a call to setDocument().
Parameters: length - The new maximum length, or KDocument.NO_LIMIT
for unlimited length.See Also: KDocument
getMaximumLength
public int getMaximumLength ()
Get the maxmium number of characters that may be entered into this field.
Returns: The maximum length, or KDocument.NO_LIMIT if there
is no limit.