public class ColorFormatter extends AbstractFormatter<java.awt.Color>
A Formatter
that can parse Strings into java.awt.Color
and back
using several patterns
Supported patterns are:
#RGB
#RGBA
#RRGGBB
#RRGGBBAA
R
- redG
- greenB
- blueA
- alphaFormatter
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PATTERN
"#RRGGBB"
|
static ColorFormatter |
LONG
ColorFormatter that uses the PATTERN_LONG pattern |
static ColorFormatter |
LONG_WITH_ALPHA
ColorFormatter that uses the PATTERN_LONG_WITH_ALPHA pattern |
static java.lang.String |
PATTERN_LONG
"#RRGGBB"
|
static java.lang.String |
PATTERN_LONG_WITH_ALPHA
"#RRGGBBAA"
|
static java.lang.String |
PATTERN_SHORT
"#RGB"
|
static java.lang.String |
PATTERN_SHORT_WITH_ALPHA
"#RGBA"
|
static ColorFormatter |
SHORT
ColorFormatter that uses the PATTERN_SHORT pattern |
static ColorFormatter |
SHORT_WITH_ALPHA
ColorFormatter that uses the PATTERN_SHORT_WITH_ALPHA pattern |
Modifier | Constructor and Description |
---|---|
protected |
ColorFormatter(java.lang.String pattern) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.awt.Color color)
Formats an instance into its literal representation.
|
static ColorFormatter |
getInstance(java.lang.String pattern)
Returns a
ColorFormatter given a color pattern. |
java.lang.String |
getPattern()
Returns the pattern used by this
ColorFormatter |
java.awt.Color |
parse(java.lang.String str)
Parses a literal representation into an instance of type
T . |
static java.awt.Color |
parseColor(java.lang.String str)
Parses a string into a
java.awt.Color instance. |
parseError, parseError, parseHexInt, parseHexInt
public static final java.lang.String PATTERN_SHORT
public static final java.lang.String PATTERN_SHORT_WITH_ALPHA
public static final java.lang.String PATTERN_LONG
public static final java.lang.String PATTERN_LONG_WITH_ALPHA
public static final java.lang.String DEFAULT_PATTERN
public static final ColorFormatter SHORT
ColorFormatter
that uses the PATTERN_SHORT
patternpublic static final ColorFormatter SHORT_WITH_ALPHA
ColorFormatter
that uses the PATTERN_SHORT_WITH_ALPHA
patternpublic static final ColorFormatter LONG
ColorFormatter
that uses the PATTERN_LONG
patternpublic static final ColorFormatter LONG_WITH_ALPHA
ColorFormatter
that uses the PATTERN_LONG_WITH_ALPHA
pattern@Nonnull public static ColorFormatter getInstance(@Nullable java.lang.String pattern)
Returns a ColorFormatter
given a color pattern.
pattern
- the input pattern. Must be one of the 4 supported color patterns.ColorPattern
instancejava.lang.IllegalArgumentException
- if the supplied pattern
is not supported@Nullable public java.lang.String format(@Nullable java.awt.Color color)
Formatter
Formats an instance into its literal representation.
The resulting String
may be set as an argument to Formatter.parse(java.lang.String)
resulting in a similar instance as the input.
color
- the instance to be formattedString
representing the instance's state.@Nullable public java.awt.Color parse(@Nullable java.lang.String str) throws ParseException
Formatter
Parses a literal representation into an instance of type T
.
The resulting instance T
may be set as an argument to Formatter.format(T)
resulting in an equal String
as the input.
str
- the String
to be parsedT
whose state is initialized given the
parameters of the input String
.ParseException
- if the String
cannot be parsed.@Nonnull public java.lang.String getPattern()
ColorFormatter
ColorFormatter
uses for parsing/formatting.@Nonnull public static java.awt.Color parseColor(@Nonnull java.lang.String str) throws ParseException
Parses a string into a java.awt.Color
instance.
The parsing pattern is chosen given the length of the input string
#RGB
#RGBA
#RRGGBB
#RRGGBBAA
griffon.swing.support.Colors
.str
- the string representation of a java.awt.Color
java.awt.Color
instance matching the supplied RGBA color componentsParseException
- if the string cannot be parsed by the chosen patternColors