public class ColorFormatter extends AbstractFormatter<javafx.scene.paint.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 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(javafx.scene.paint.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 |
javafx.scene.paint.Color |
parse(java.lang.String str)
Parses a literal representation into an instance of type
T. |
static javafx.scene.paint.Color |
parseColor(java.lang.String str)
Parses a string into a
javafx.scene.paint.Color instance. |
parseError, parseError, parseHexInt, parseHexIntpublic 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(@Nonnull 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
javafx.scene.paint.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 javafx.scene.paint.Color parse(@Nullable
java.lang.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.@Nonnull public java.lang.String getPattern()
ColorFormatterColorFormatter uses for parsing/formatting.@Nonnull
public static javafx.scene.paint.Color parseColor(@Nonnull
java.lang.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