|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.myfaces.trinidad.convert.ColorConverter
@JSFConverter(configExcluded=true) public class ColorConverter
Converters string to Color object and vice versa based on the patterns and the transparency set.
Pattern format for colors:Color Format Syntax:
To specify the color format use a color pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:
Symbol Meaning Presentation Example ------ ------- ------------ ------- r red component (Number) 242 g green component (Number) 242 b blue component (Number) 242 a alpha component (Number) 255 R red component (Hex) F2 G green component (Hex) F2 B blue component (Hex) F2 A alpha component (Hex) FF ' escape for text (Delimiter) '' single quote (Literal) '
Examples:
Format Pattern Result -------------- ------- "#RRGGBB" ->> #6609CC "rrr,ggg,bbb" ->> 102,009,204 "t" ->> Transparent (when alpha is zero)
If patterns is not set then it defaults to patterns "#RRGGBB", "r,g,b" The first pattern is special - it is always used for formatting color values. For default case, getAsString() will use "#RRGGBB" format to represent the color. Object as String.
The getAsObject()
method parses a String into a Color
,
according to the following algorithm:
null
. Otherwise, trim leading and trailing
whitespace before proceeding.null
.ConverterException
containing a CONVERT_MESSAGE_ID
message.
The detail message of CONVERT_MESSAGE_ID
can be overridden
by setting a custom error message, by calling
method setMessageDetailConvert()
. The custom message
can contain placeholders as specified in CONVERT_MESSAGE_ID
.
The placeholders will be replaced by appropriate values as mentioned
in CONVERT_MESSAGE_ID
The getAsString()
method expects a value of type
Color
(or a subclass), and creates a formatted
String according to the following algorithm:
Field Summary | |
---|---|
static String |
CONVERT_MESSAGE_ID
The message identifier of the FacesMessage to be created when
input value cannot be converterd to color based on the patterns set. |
static String |
CONVERTER_ID
Standard converter id for this converter. |
static String[] |
DEFAULT_COLOR_FORMAT_PATTERNS
Deprecated. use getDefaultColorFormatPatterns() |
Constructor Summary | |
---|---|
ColorConverter()
Construct a ColorConverter with the default values. |
|
ColorConverter(String[] patterns,
boolean allowsTransparent)
Construct a ColorConverter with preconfigured values. |
Method Summary | |
---|---|
boolean |
equals(Object obj)
Compares this ColorConverter with the specified Object for equality. |
Object |
getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
String value)
Convert the specified string value, which is associated with the specified UIComponent , into a Color object
based on the patterns set. |
String |
getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
Object value)
Return a String representation for the Color object based on the first pattern in the given patterns. |
static String[] |
getDefaultColorFormatPatterns()
Returns the default patterns to be used if the pattern if not supplied. |
String |
getHint()
Return custom hint message. |
String |
getMessageDetailConvert()
Return custom detail error message that was set for creating faces message, for values that cannot be converted to Color |
String[] |
getPatterns()
Retrun the patterns set for this converter. |
protected String |
getTransparentString(javax.faces.context.FacesContext context)
|
javax.faces.el.ValueBinding |
getValueBinding(String name)
Deprecated. |
javax.el.ValueExpression |
getValueExpression(String name)
Return the ValueExpression used to calculate the value for the
specified attribute name, if any. |
int |
hashCode()
Returns the hash code for this converter. |
boolean |
isDisabled()
Return whether it is disabled. |
boolean |
isTransient()
|
boolean |
isTransparentAllowed()
Return if localized transparent text should be supported by this converter. |
void |
restoreState(javax.faces.context.FacesContext context,
Object state)
|
Object |
saveState(javax.faces.context.FacesContext context)
|
void |
setDisabled(boolean isDisabled)
Set the value to property disabled . |
void |
setHint(String hintFormat)
Custom hint message. |
void |
setMessageDetailConvert(String convertMessageDetail)
Custom error message to be used, for creating detail part of the faces message, when value cannot be converted
to Color . |
void |
setPatterns(String[] patterns)
Set the R,G, B patterns, based on the patterns set, Color object is created during call to getAsObject(FacesContext,UIComponent, String), while based on the first pattern which is at index 0, the String representation for the object is determined with call to getAsString(FacesContext, UIComponent, Object). |
void |
setTransient(boolean isTransient)
|
void |
setTransparentAllowed(boolean isTransparentAllowed)
Set if localized transparent text should be supported by this converter. |
void |
setValueBinding(String name,
javax.faces.el.ValueBinding binding)
Deprecated. |
void |
setValueExpression(String name,
javax.el.ValueExpression expression)
Set the ValueExpression used to calculate the value for the
specified attribute if any. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CONVERTER_ID
Standard converter id for this converter.
public static final String CONVERT_MESSAGE_ID
The message identifier of the FacesMessage
to be created when
input value cannot be converterd to color based on the patterns set.
The message format string for this message may optionally include a
{0}
, {1}
, {4}
placeholdes,
which will be replaced by input value, component label and the pattern
set in the converter.
@Deprecated public static final String[] DEFAULT_COLOR_FORMAT_PATTERNS
Constructor Detail |
---|
public ColorConverter(String[] patterns, boolean allowsTransparent)
Construct a ColorConverter with preconfigured values.
patterns
- The set of R,G,B format patterns that
are accepted by this Converter. The first
pattern is special - it is always used for
formatting color values.allowsTransparent
- Indicates whether or not transparent
colors are considered valid.public ColorConverter()
Construct a ColorConverter with the default values. The defualt patterns being "#RRGGBB", "r,g,b" and allowsTransparent is set to false.
Method Detail |
---|
public static final String[] getDefaultColorFormatPatterns()
Returns the default patterns to be used if the pattern if not supplied.
The default patterns is "#RRGGBB", "r,g,b"
The first pattern is special, it is always used for formatting color
values
public Object getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String value)
Convert the specified string value, which is associated with
the specified UIComponent
, into a Color object
based on the patterns set.
getAsObject
in interface javax.faces.convert.Converter
context
- FacesContext
for the request being processedcomponent
- UIComponent
with which this model object
value is associatedvalue
- String value to be converted (may be null
)
null
if the value to convert is null
,
otherwise return a Color object.
javax.faces.convert.ConverterException
- if conversion cannot be successfully
performed
NullPointerException
- if context
or
component
is null
public String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
Return a String representation for the Color object based on the first pattern in the given patterns.
getAsString
in interface javax.faces.convert.Converter
context
- FacesContext
for the request being processedcomponent
- UIComponent
with which this model object
value is associated.value
- Model object value to be converted (may be null
)
null
,
otherwise String representation for the Color object based on the first
pattern in the specified patterns.
javax.faces.convert.ConverterException
- if conversion cannot be successfully
performed
NullPointerException
- if context
or
component
is null
IllegalArgumentException
- if the value
is not of
type other than Color
, String
or
value
can be null.public void setTransparentAllowed(boolean isTransparentAllowed)
Set if localized transparent text should be supported by this converter.
isTransparentAllowed
- public void setPatterns(String[] patterns) throws IllegalArgumentException
Set the R,G, B patterns, based on the patterns set, Color object is
created during call to getAsObject(FacesContext,UIComponent, String),
while based on the first pattern which is at index 0, the String
representation for the object is determined with call to
getAsString(FacesContext, UIComponent, Object). null
value for patterns result in IllegalArgumentException.
patterns
-
IllegalArgumentException
- if a value of pattern is null or if an invalid pattern is passed.@JSFProperty public String[] getPatterns()
Retrun the patterns set for this converter.
@JSFProperty(defaultValue="false") public boolean isTransparentAllowed()
Return if localized transparent text should be supported by this converter.
public boolean equals(Object obj)
Compares this ColorConverter with the specified Object for equality.
equals
in class Object
obj
- Object to which this ColorConverter is to be compared.
public int hashCode()
Returns the hash code for this converter.
hashCode
in class Object
public boolean isTransient()
isTransient
in interface javax.faces.component.StateHolder
public void setTransient(boolean isTransient)
setTransient
in interface javax.faces.component.StateHolder
public Object saveState(javax.faces.context.FacesContext context)
saveState
in interface javax.faces.component.StateHolder
public void restoreState(javax.faces.context.FacesContext context, Object state)
restoreState
in interface javax.faces.component.StateHolder
public void setValueExpression(String name, javax.el.ValueExpression expression)
Set the ValueExpression
used to calculate the value for the
specified attribute if any.
name
- Name of the attribute for which to set a ValueExpression
expression
- The ValueExpression
to set, or null
to remove any currently set ValueExpression
NullPointerException
- if name
is null
IllegalArgumentException
- if name
is not a valid
attribute of this converterpublic javax.el.ValueExpression getValueExpression(String name)
Return the ValueExpression
used to calculate the value for the
specified attribute name, if any.
name
- Name of the attribute or property for which to retrieve a
ValueExpression
NullPointerException
- if name
is null
IllegalArgumentException
- if name
is not a valid
attribute of this converterpublic void setValueBinding(String name, javax.faces.el.ValueBinding binding)
Set the ValueBinding
used to calculate the value for the
specified attribute if any.
name
- Name of the attribute for which to set a ValueBinding
binding
- The ValueBinding
to set, or null
to remove any currently set ValueBinding
NullPointerException
- if name
is null
IllegalArgumentException
- if name
is not a valid
attribute of this converterpublic javax.faces.el.ValueBinding getValueBinding(String name)
Return the ValueBinding
used to calculate the value for the
specified attribute name, if any.
name
- Name of the attribute or property for which to retrieve a
ValueBinding
NullPointerException
- if name
is null
IllegalArgumentException
- if name
is not a valid
attribute of this converterpublic void setMessageDetailConvert(String convertMessageDetail)
value
cannot be converted
to Color
. Overrides the detail message identified by
CONVERT_MESSAGE_ID
convertMessageDetail
- Custom error message.CONVERT_MESSAGE_ID
@JSFProperty public String getMessageDetailConvert()
Color
setMessageDetailConvert(String)
public void setHint(String hintFormat)
Custom hint message.
Overrides default hint message
hintFormat
- Custom hint message.@JSFProperty(tagExcluded=true) public String getHint()
Return custom hint message.
setHint(String)
public void setDisabled(boolean isDisabled)
Set the value to property disabled
. Default value is false.
isDisabled
- true
if it's disabled, false
otherwise.public boolean isDisabled()
protected String getTransparentString(javax.faces.context.FacesContext context)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |