Package edu.cnu.mdi.ui.colors
Class X11Colors
java.lang.Object
edu.cnu.mdi.ui.colors.X11Colors
Look up colors by their standard web ("X11") name.
Despite the class name, the values here are the HTML4/CSS/SVG web
color set (the so-called "X11 web colors"), not the classic X.Org
rgb.txt palette. The two clash for a handful of names: web
gray/green/maroon/purple differ from the
brighter X11 originals (for example X11 green is 0,255,0,
which CSS calls lime). All 148-ish web names resolve to the CSS
standard RGB values.
Lookups are forgiving. A queried name is matched after:
- trimming and lower-casing
- removing all internal whitespace, so
"Deep Sky Blue","deepskyblue"and"deep sky blue"all resolve to the same color
grey spellings are accepted as aliases for every gray
name. getAllColors() still exposes the canonical names in their
readable, single-spaced form.
Color c1 = X11Colors.getX11Color("Deep Sky Blue");
Color c2 = X11Colors.getX11Color("deepskyblue", 128); // half transparent
-
Method Summary
Modifier and TypeMethodDescriptionReturns an unmodifiable view of all available colors, keyed by their canonical display names (lower-case, single-spaced).static ColorgetX11Color(String name) Gets a color by its web/X11 name.static ColorgetX11Color(String name, int alpha) Gets a web/X11 color and applies the given alpha.
-
Method Details
-
getX11Color
Gets a web/X11 color and applies the given alpha.- Parameters:
name- the color name (case- and whitespace-insensitive)alpha- alpha channel, 0..255 (255 is fully opaque)- Returns:
- a new
Colorwith the given alpha, ornullif the name is unknown - Throws:
IllegalArgumentException- ifalphais outside 0..255
-
getX11Color
Gets a color by its web/X11 name.Matching ignores case and all whitespace, and accepts British
greyspellings, so"Light Gray","lightgrey"and" LIGHT GREY "all resolve to the same color.- Parameters:
name- the color name; may benull- Returns:
- the named color, or
nullifnameisnullor unknown
-
getAllColors
Returns an unmodifiable view of all available colors, keyed by their canonical display names (lower-case, single-spaced).- Returns:
- the immutable name-to-color map
-