|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
org.apache.myfaces.trinidad.convert.ColorConverter
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_IDThe getAsString() method expects a value of type Color (or a subclass), and creates a formatted String according to the following algorithm:
| Field Summary | |
|---|---|
static java.lang.String |
CONVERT_MESSAGE_IDThe message identifier of the FacesMessage to be created when input value cannot be converterd to color based on the patterns set. |
static java.lang.String |
CONVERTER_IDStandard converter id for this converter. |
static java.lang.String[] |
DEFAULT_COLOR_FORMAT_PATTERNSDeprecated. use getDefaultColorFormatPatterns() |
| Constructor Summary | |
|---|---|
ColorConverter()Construct a ColorConverter with the default values. |
|
ColorConverter(java.lang.String[] patterns, boolean allowsTransparent)Construct a ColorConverter with preconfigured values. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object obj)Compares this ColorConverter with the specified Object for equality. |
java.lang.Object |
getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String value)Convert the specified string value, which is associated with the specified UIComponent, into a Color object based on the patterns set. |
java.lang.String |
getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)Return a String representation for the Color object based on the first pattern in the given patterns. |
static java.lang.String[] |
getDefaultColorFormatPatterns()Returns the default patterns to be used if the pattern if not supplied. |
java.lang.String |
getHint()Return custom hint message. |
java.lang.String |
getMessageDetailConvert()Return custom detail error message that was set for creating faces message, for values that cannot be converted to Color |
java.lang.String[] |
getPatterns()Retrun the patterns set for this converter. |
protected java.lang.String |
getTransparentString(javax.faces.context.FacesContext context) |
javax.faces.el.ValueBinding |
getValueBinding(java.lang.String name)Deprecated. |
javax.el.ValueExpression |
getValueExpression(java.lang.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 |
isTransient() |
boolean |
isTransparentAllowed()Return if localized transparent text should be supported by this converter. |
void |
restoreState(javax.faces.context.FacesContext context, java.lang.Object state) |
java.lang.Object |
saveState(javax.faces.context.FacesContext context) |
void |
setHint(java.lang.String hintFormat)Custom hint message. |
void |
setMessageDetailConvert(java.lang.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(java.lang.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(java.lang.String name, javax.faces.el.ValueBinding binding)Deprecated. |
void |
setValueExpression(java.lang.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 java.lang.String CONVERTER_ID
Standard converter id for this converter.
public static final java.lang.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 java.lang.String[] DEFAULT_COLOR_FORMAT_PATTERNS
| Constructor Detail |
|---|
public ColorConverter(java.lang.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 java.lang.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 java.lang.Object getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.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.Convertercontext - 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 performedjava.lang.NullPointerException - if context or component is null
public java.lang.String getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.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.Convertercontext - 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 performedjava.lang.NullPointerException - if context or component is nulljava.lang.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(java.lang.String[] patterns)
throws java.lang.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 -java.lang.IllegalArgumentException - if a value of pattern is null or if an invalid pattern is passed.public java.lang.String[] getPatterns()
Retrun the patterns set for this converter.
public boolean isTransparentAllowed()
Return if localized transparent text should be supported by this converter.
public boolean equals(java.lang.Object obj)
Compares this ColorConverter with the specified Object for equality.
equals in class java.lang.Objectobj - Object to which this ColorConverter is to be compared.public int hashCode()
Returns the hash code for this converter.
hashCode in class java.lang.Objectpublic boolean isTransient()
isTransient in interface javax.faces.component.StateHolderpublic void setTransient(boolean isTransient)
setTransient in interface javax.faces.component.StateHolderpublic java.lang.Object saveState(javax.faces.context.FacesContext context)
saveState in interface javax.faces.component.StateHolder
public void restoreState(javax.faces.context.FacesContext context,
java.lang.Object state)
restoreState in interface javax.faces.component.StateHolder
public void setValueExpression(java.lang.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 ValueExpressionexpression - The ValueExpression to set, or null to remove any currently set ValueExpressionjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic javax.el.ValueExpression getValueExpression(java.lang.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 ValueExpressionjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converter
public void setValueBinding(java.lang.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 ValueBindingbinding - The ValueBinding to set, or null to remove any currently set ValueBindingjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic javax.faces.el.ValueBinding getValueBinding(java.lang.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 ValueBindingjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic void setMessageDetailConvert(java.lang.String convertMessageDetail)
value cannot be converted to Color. Overrides the detail message identified by CONVERT_MESSAGE_IDconvertMessageDetail - Custom error message.CONVERT_MESSAGE_IDpublic java.lang.String getMessageDetailConvert()
ColorsetMessageDetailConvert(String)public void setHint(java.lang.String hintFormat)
Custom hint message.
Overrides default hint messagehintFormat - Custom hint message.public java.lang.String getHint()
Return custom hint message.
setHint(String)protected java.lang.String getTransparentString(javax.faces.context.FacesContext context)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.