public class ColorFieldMarker extends Object implements FormControllerValidationListener, FormControllerFieldStatusListener
A specialized FormControllerValidationListener implementation that
can change the colors of fields depending on their validation status.
An instance of this class can be registered at a FormController as
FormControllerValidationListener and
FormControllerFieldStatusListener. Whenever an event is received from
the FormController the current status of the affected field(s) is
checked. The instance can be configured with multiple colors corresponding to
the possible field states:
Valid fields do not change their colors. If colors for a certain field status are undefined, the default colors are used, too. For instance, if fields for which a validation warning exists should not be highlighted in a special way, just leave the properties for these colors undefined. This class implements a very simple means for marking invalid input fields. If the background color of a text field is changed to, say, red, it will be pretty obvious that something is wrong with this field.
Instances of this class can be associated with a single form controller only
and should not be reused (because they keep an internal state about the input
fields involved). If they are declared in a bean definition file of the
dependency injection framework, the singleton attribute should be set
to false.
| Constructor and Description |
|---|
ColorFieldMarker()
Creates a new instance of
ColorFieldMarker. |
| Modifier and Type | Method and Description |
|---|---|
void |
fieldStatusChanged(FormControllerFieldStatusEvent event)
The visited status of a field managed by the
FormController has
changed. |
Color |
getBackgroundColor(FieldValidationStatus status)
Returns the background color for fields with the specified
FieldValidationStatus. |
Color |
getForegroundColor(FieldValidationStatus status)
Returns the foreground color for fields with the specified
FieldValidationStatus. |
Color |
getInvalidBackground()
Returns the background color to be set for invalid input fields.
|
Color |
getInvalidForeground()
Returns the foreground color to be set for invalid input fields.
|
protected FieldValidationStatus |
getLastValidationStatus(String field)
Returns the last known validation status of the specified field.
|
Color |
getNotVisitedInvalidBackground()
Returns the background color to be set for input fields in the state
not visited, invalid.
|
Color |
getNotVisitedInvalidForeground()
Returns the foreground color to be set for input fields in the state
not visited, invalid.
|
Color |
getNotVisitedWarningBackground()
Returns the background color for input fields in the state
not visited,
warning.
|
Color |
getNotVisitedWarningForeground()
Returns the foreground color for input fields in the state
not visited,
warning.
|
Color |
getWarningBackground()
Returns the background color for input fields in the state
warning.
|
Color |
getWarningForeground()
Returns the foreground color for input fields in the state
warning.
|
protected Color |
getWidgetBackgroundColor(FormController controller,
String field)
Returns the default background color of the specified widget.
|
protected Color |
getWidgetForegroundColor(FormController controller,
String field)
Returns the default foreground color of the specified widget.
|
void |
setBackgroundColor(FieldValidationStatus status,
Color c)
Sets the background color for fields with the specified
FieldValidationStatus. |
void |
setForegroundColor(FieldValidationStatus status,
Color c)
Sets the foreground color for fields with the specified
FieldValidationStatus. |
void |
setInvalidBackground(Color invalidBackground)
Sets the background color for invalid input fields.
|
void |
setInvalidForeground(Color invalidForeground)
Sets the foreground color for invalid input fields.
|
protected void |
setLastValidationStatus(String field,
FieldValidationStatus status)
Sets the last
FieldValidationStatus for the specified field. |
void |
setNotVisitedInvalidBackground(Color c)
Sets the background color for input fields in the state not visited,
invalid.
|
void |
setNotVisitedInvalidForeground(Color c)
Sets the foreground color for input fields in the state not visited,
invalid.
|
void |
setNotVisitedWarningBackground(Color c)
Sets the background color for input fields in the state not visited,
warning.
|
void |
setNotVisitedWarningForeground(Color c)
Sets the foreground color for input fields in the state not visited,
warning.
|
void |
setWarningBackground(Color c)
Sets the background color for input fields in the state warning.
|
void |
setWarningForeground(Color c)
Sets the foreground color for input fields in the state warning.
|
protected void |
updateField(FormController controller,
String field,
FormValidatorResults validationResults,
boolean visited)
Updates the colors for the given field.
|
void |
validationPerformed(FormControllerValidationEvent event)
A validation operation was performed by the
FormController. |
public ColorFieldMarker()
ColorFieldMarker.public Color getInvalidBackground()
public void setInvalidBackground(Color invalidBackground)
invalidBackground - the background color for invalid input fieldspublic Color getInvalidForeground()
public void setInvalidForeground(Color invalidForeground)
invalidForeground - the foreground color for invalid input fieldspublic Color getNotVisitedInvalidBackground()
public void setNotVisitedInvalidBackground(Color c)
c - the background color for not visited invalid input fieldspublic Color getNotVisitedInvalidForeground()
public void setNotVisitedInvalidForeground(Color c)
c - the foreground color for not visited invalid input fieldspublic Color getWarningForeground()
public void setWarningForeground(Color c)
c - the foreground color for fields with a validation warningpublic Color getWarningBackground()
public void setWarningBackground(Color c)
c - the background color for fields with a validation warningpublic Color getNotVisitedWarningForeground()
public void setNotVisitedWarningForeground(Color c)
c - the foreground color for fields with a validation warning that
have not yet been visitedpublic Color getNotVisitedWarningBackground()
public void setNotVisitedWarningBackground(Color c)
c - the background color for fields with a validation warning that
have not yet been visitedpublic Color getForegroundColor(FieldValidationStatus status)
FieldValidationStatus.status - the FieldValidationStatuspublic void setForegroundColor(FieldValidationStatus status, Color c)
FieldValidationStatus. This is a generic method for setting foreground
colors. Internally, the other set methods for foreground colors delegate
to this method.status - the FieldValidationStatus (must not be null)c - the new foreground colorIllegalArgumentException - if the FieldValidationStatus is
nullpublic Color getBackgroundColor(FieldValidationStatus status)
FieldValidationStatus.status - the FieldValidationStatuspublic void setBackgroundColor(FieldValidationStatus status, Color c)
FieldValidationStatus. This is a generic method for setting background
colors. Internally, the other set methods for background colors delegate
to this method.status - the FieldValidationStatus (must not be null)c - the new background colorIllegalArgumentException - if the ValidationMessageLevel is
nullpublic void validationPerformed(FormControllerValidationEvent event)
FormController. This
implementation checks which fields need to be updated and sets the
corresponding new colors.validationPerformed in interface FormControllerValidationListenerevent - the validation eventpublic void fieldStatusChanged(FormControllerFieldStatusEvent event)
FormController has
changed. This implementation checks whether new colors need to be set for
this field.fieldStatusChanged in interface FormControllerFieldStatusListenerevent - the FormControllerFieldStatusEventprotected FieldValidationStatus getLastValidationStatus(String field)
field - the name of the field in questionFieldValidationStatus of this fieldprotected void setLastValidationStatus(String field, FieldValidationStatus status)
FieldValidationStatus for the specified field. With
this method the status of a field can be updated.field - the name of the field in questionstatus - the new FieldValidationStatus for this fieldprotected Color getWidgetForegroundColor(FormController controller, String field)
controller - the FormControllerfield - the name of the fieldprotected Color getWidgetBackgroundColor(FormController controller, String field)
controller - the FormControllerfield - the name of the fieldprotected void updateField(FormController controller, String field, FormValidatorResults validationResults, boolean visited)
FormController that indicates a status
change of a field. This implementation checks whether the status of the
given field has actually changed. If this is the case, the colors for the
new status are obtained and set.controller - the FormControllerfield - the name of the field affected by the changevalidationResults - the current FormValidatorResults objectvisited - the visited state of the current fieldFormBuilderRuntimeException - if the field name cannot be resolvedCopyright © 2016 The JGUIraffe Team. All rights reserved.