public class ColorDecoder
extends java.lang.Object
java.awt.Color.decode()
.
It understands color names (either from the X11 or the HTML domain) and the following HTML color encodings:
Modifier and Type | Class and Description |
---|---|
static class |
ColorDecoder.Domain
Private class use as a typed enum.
|
Modifier and Type | Field and Description |
---|---|
static ColorDecoder.Domain |
DOMAIN_HTML
The color names in the domain of HTML 4.01.
|
static ColorDecoder.Domain |
DOMAIN_X11
The color names in the domain of X11.
|
static java.lang.Iterable<ColorDecoder.Domain> |
DOMAINS_HTML_FIRST
The domains sorted in a way that HTML names are tested first.
|
static java.lang.Iterable<ColorDecoder.Domain> |
DOMAINS_X11_FIRST
The domains sorted in a way that X11 names are tested first.
|
Constructor and Description |
---|
ColorDecoder() |
Modifier and Type | Method and Description |
---|---|
static java.awt.Color |
decode(java.lang.String descr)
Get a color by name or description.
|
static java.awt.Color |
decode(java.lang.String descr,
boolean htmlFirst)
Get a color by name or description.
|
static java.awt.Color |
decode(java.lang.String descr,
ColorDecoder.Domain... domains)
Get a color by name or description.
|
static java.awt.Color |
decode(java.lang.String descr,
ColorDecoder.Domain domain)
Get a color by name or description.
|
static java.awt.Color |
decode(java.lang.String descr,
java.lang.Iterable<? extends ColorDecoder.Domain> domains)
Get a color by name or description.
|
public static final ColorDecoder.Domain DOMAIN_X11
public static final ColorDecoder.Domain DOMAIN_HTML
public static final java.lang.Iterable<ColorDecoder.Domain> DOMAINS_HTML_FIRST
public static final java.lang.Iterable<ColorDecoder.Domain> DOMAINS_X11_FIRST
@Nullable public static java.awt.Color decode(@NotNull java.lang.String descr)
This method tries X11 first, then HTML.
descr
- color description: either a color name, a HTML-like definition
like #0fad78 or rgb(15,178,120) or an integer like expected by
Java's Color.decode() methodnull
if the decoding failed.@Nullable public static java.awt.Color decode(@NotNull java.lang.String descr, boolean htmlFirst)
descr
- color description: either a color name, a HTML-like definition
like #0fad78 or rgb(15,178,120) or an integer like expected by
Java's Color.decode() methodhtmlFirst
- if names are defined differently in different domains,
what color is preferred? true
: HTML, false
: X11null
if the decoding failed.@Nullable public static java.awt.Color decode(@NotNull java.lang.String descr, ColorDecoder.Domain domain)
descr
- color description: either a color name, a HTML-like definition
like #0fad78 or rgb(15,178,120) or an integer like expected by
Java's Color.decode() methoddomain
- domain to use to resolve named colorsnull
if the decoding failed.@Nullable public static java.awt.Color decode(@NotNull java.lang.String descr, ColorDecoder.Domain... domains)
descr
- color description: either a color name, a HTML-like definition
like #0fad78 or rgb(15,178,120) or an integer like expected by
Java's Color.decode() methoddomains
- the sequence in which domains are tested for the color if the color is namednull
if the decoding failed.@Nullable public static java.awt.Color decode(@NotNull java.lang.String descr, @NotNull java.lang.Iterable<? extends ColorDecoder.Domain> domains)
descr
- color description: either a color name, a HTML-like definition
like #0fad78 or rgb(15,178,120) or an integer like expected by
Java's Color.decode() methoddomains
- the sequence in which domains are tested for the color if the color is namednull
if the decoding failed.