|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.swing.visuals.util.JTextFieldValidator
public class JTextFieldValidator
JTextFieldValidator is used as a error-handler/validator on a JTextField. The validation of the text occurs
when an actionPerformed event or
focusLost occurs on the JTextField. The default error handler used
is the JOptionPaneErrorHandler, and the default validator
used is the BoundedLong. If the value is valid, the JTextField will remain as is, if
not, the JTextField will get set back to its previous value.
Creating a JTextFieldValidator
The following code shows how to use the JTextFieldValidator on a JTextField to validate integer numbers greater than 0:
JTextField jTextField1 = new JTextField(); ... JTextFieldValidator fieldValidator = new JTextFieldValidator(jTextField1, 0, Integer.MAX_VALUE);
This will use the default error handler (JOptionPaneErrorHandler), but and valid instance of
com.sas.net.errorhandlers.GenericErrorHandlerInterface will work.
Now in order to detect if the value was valid, the user should add a PropertyChangeListener
to the validator and listen for a "evalid"e event.
JTextField,
GenericErrorHandlerInterface,
| Field Summary | |
|---|---|
protected javax.swing.event.SwingPropertyChangeSupport |
spcs
|
| Constructor Summary | |
|---|---|
JTextFieldValidator(javax.swing.JTextField textField)
Creates a JTextFieldValidator with a BoundedLong as the validator, with Integer.MIN_VALUE and Integer.MAX_VALUE as its limits. |
|
JTextFieldValidator(javax.swing.JTextField textField,
double minValue,
double maxValue)
Creates a JTextFieldValidator with a BoundedDouble as the validator, with minVaue and maxValue as its limits. |
|
JTextFieldValidator(javax.swing.JTextField textField,
double minValue,
double maxValue,
java.lang.String errorMessage)
Creates a JTextFieldValidator with a BoundedDouble as the validator, with minVaue and maxValue as its limits. |
|
JTextFieldValidator(javax.swing.JTextField textField,
int minValue,
int maxValue)
Creates a JTextFieldValidator with a BoundedLong as the validator, with minVaue and maxValue as its limits. |
|
JTextFieldValidator(javax.swing.JTextField textField,
int minValue,
int maxValue,
java.lang.String errorMessage)
Creates a JTextFieldValidator with a BoundedLong as the validator, with minVaue and maxValue as its limits. |
|
JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator)
Creates a JTextFieldValidator with the ValidationInterface being the validator. |
|
JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator,
GenericErrorHandlerInterface errorHandler)
Creates a JTextFieldValidator with the ValidationInterface being the validator and the errorHandler used to handle invalid values entered in the JTextField, as evaluated by the validator. |
|
JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator,
java.lang.String errorMessage)
Creates a JTextFieldValidator with the ValidationInterface being the validator. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(java.awt.event.ActionEvent ev)
Handles the actionPerformed event on the JTextField. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
|
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
|
void |
firePropertyChange(java.beans.PropertyChangeEvent evt)
Fire an existing PropertyChangeEvent to any registered listeners. |
void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Report a bound property update to any registered listeners. |
void |
focusGained(java.awt.event.FocusEvent ev)
Handles the focusGained event on the JTextField. |
void |
focusLost(java.awt.event.FocusEvent ev)
Handles the focusLost event on the JTextField. |
GenericErrorHandlerInterface |
getErrorHandler()
Returns the error handler used to notify the user of an invalid value entered in the JTextField. |
ValidationInterface |
getValidator()
Returns the validator used to evaluate the text entered in the JTextField, notifies the error handler if the value is not valid. |
boolean |
isValid()
Returns whether the evaluation of the text was valid or not. |
void |
removeListenersOnTextField()
Removes the listeners on teh textField that the validator uses to be notified of when the text changes. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
|
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
|
void |
setErrorHandler(GenericErrorHandlerInterface errorHandler)
Sets the error handler used to notify the user of an invalid value entered in the JTextField. |
void |
setValidator(ValidationInterface validator)
Sets the validator used to evaluate the text entered in the JTextField, notifies the error handler if the value is not valid. |
| Field Detail |
|---|
protected javax.swing.event.SwingPropertyChangeSupport spcs
| Constructor Detail |
|---|
public JTextFieldValidator(javax.swing.JTextField textField)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.BoundedLong,
JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
double minValue,
double maxValue)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.minValue - The minimum value limit used on the validatormaxValue - The maximum value limit used on the validatorBoundedDouble,
JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
double minValue,
double maxValue,
java.lang.String errorMessage)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.minValue - The minimum value limit used on the validatormaxValue - The maximum value limit used on the validatorerrorMessage - The error message to display in the error-handler, used instead of the default message
of the validatorBoundedDouble,
JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
int minValue,
int maxValue)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.minValue - The minimum value limit used on the validatormaxValue - The maximum value limit used on the validatorBoundedLong,
JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
int minValue,
int maxValue,
java.lang.String errorMessage)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.minValue - The minimum value limit used on the validatormaxValue - The maximum value limit used on the validatorerrorMessage - The error message to display in the error-handler, used instead of the default message
of the validatorBoundedLong,
JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.validator - The instance of ValidationInterface the is used to validate the text in the JTextField. If the
validator returns false, the error-handler will notify the user.JTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator,
java.lang.String errorMessage)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.validator - The instance of ValidationInterface the is used to validate the text in the JTextField. If the
validator returns false, the error-handler will notify the user.errorMessage - The error message to display in the error-handler, used instead of the default message
of the validatorJTextField,
GenericErrorHandlerInterface,
ValidationInterface
public JTextFieldValidator(javax.swing.JTextField textField,
ValidationInterface validator,
GenericErrorHandlerInterface errorHandler)
FocusListener and a ActionListener
and added to the JTextField to listen to the updates made to the text.
textField - The JTextField to preform the validation on whenever a actionPerformed or focusLost event
occurs on it.validator - The instance of ValidationInterface the is used to validate the text in the JTextField. If the
validator returns false, the error-handler will notify the user.errorHandler - The error-handler used to handler invalid values in the JTextFieldJTextField,
GenericErrorHandlerInterface,
ValidationInterface| Method Detail |
|---|
public void removeListenersOnTextField()
public void setErrorHandler(GenericErrorHandlerInterface errorHandler)
errorHandler - The instance of the GenericErrorHandlerInterface used to display the errorGenericErrorHandlerInterface,
ValidationInterfacepublic GenericErrorHandlerInterface getErrorHandler()
GenericErrorHandlerInterface,
ValidationInterfacepublic void setValidator(ValidationInterface validator)
validator - The instance of the ValidationInterface used to validate the textGenericErrorHandlerInterface,
ValidationInterfacepublic ValidationInterface getValidator()
GenericErrorHandlerInterface,
ValidationInterfacepublic boolean isValid()
ValidationInterfacepublic void focusGained(java.awt.event.FocusEvent ev)
focusGained in interface java.awt.event.FocusListenerev - The focusGained eventpublic void focusLost(java.awt.event.FocusEvent ev)
focusLost in interface java.awt.event.FocusListenerev - The focusLost event, validation is performed unless validation is currently occuring do
to an actionPerformed event.public void actionPerformed(java.awt.event.ActionEvent ev)
actionPerformed in interface java.awt.event.ActionListenerev - The actionPerformed event, validation is performed unless validation is currently occuring do
to a focusLost event.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
public void addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
public void firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
propertyName - The programmatic name of the property that was changed.oldValue - The old value of the property.newValue - The new value of the property.public void firePropertyChange(java.beans.PropertyChangeEvent evt)
evt - The PropertyChangeEvent object.
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||