public class ColorFormatter extends AbstractFormatter<Color>
A Formatter that can parse Strings into javafx.scene.paint.Color and back
using several patterns
Supported patterns are:
#RGB#RGBA#RRGGBB#RRGGBBAAR - redG - greenB - blueA - alphaFormatter| Modifier and Type | Field and Description |
|---|---|
static 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 String |
PATTERN_LONG
"#RRGGBB"
|
static String |
PATTERN_LONG_WITH_ALPHA
"#RRGGBBAA"
|
static String |
PATTERN_SHORT
"#RGB"
|
static 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(String pattern) |
| Modifier and Type | Method and Description |
|---|---|
String |
format(Color color)
Formats an instance into its literal representation.
|
static ColorFormatter |
getInstance(String pattern)
Returns a
ColorFormatter given a color pattern. |
String |
getPattern()
Returns the pattern used by this
ColorFormatter |
Color |
parse(String str)
Parses a literal representation into an instance of type
T. |
static Color |
parseColor(String str)
Parses a string into a
javafx.scene.paint.Color instance. |
parseError, parseError, parseHexInt, parseHexIntpublic static final String PATTERN_SHORT
public static final String PATTERN_SHORT_WITH_ALPHA
public static final String PATTERN_LONG
public static final String PATTERN_LONG_WITH_ALPHA
public static final 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 patternpublic static ColorFormatter getInstance(@Nonnull String pattern)
Returns a ColorFormatter given a color pattern.
pattern - the input pattern. Must be one of the 4 supported color patterns.ColorPattern instanceIllegalArgumentException - if the supplied pattern is not supported@Nullable public String format(@Nullable Color color)
FormatterFormats 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 Color parse(@Nullable String str) throws ParseException
FormatterParses 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.public String getPattern()
ColorFormatterColorFormatter uses for parsing/formatting.public static Color parseColor(@Nonnull String str) throws ParseException
Parses a string into a javafx.scene.paint.Color instance.
The parsing pattern is chosen given the length of the input string
#RGB#RGBA#RRGGBB#RRGGBBAAjavafx.scene.paint.Color.str - the string representation of a javafx.scene.paint.Colorjavafx.scene.paint.Color instance matching the supplied RGBA color componentsParseException - if the string cannot be parsed by the chosen patternColor