java.lang.Object
org.jfree.svg.SvgColor
Parses the CSS colour forms allowed for graph theme variables.
Graph colours are moving from values hard-coded into the SVG to CSS custom properties, so a theme can set them by name. That means the server has to read whatever the theme author wrote and turn it into a Color, and it has to accept the shorthand forms people actually write.
Supported, all with an optional alpha:
#rgband#rgba—#f0a,#ee9d#rrggbband#rrggbbaa—#00ff99,#00ff9980rgb(r,g,b)andrgba(r,g,b,a)—rgb(0,255,153),rgba(0,255,153,.5)
Alpha is 0–255 as written in hex, or 0–1 as written in rgb/rgba, matching CSS. Shorthand digits are doubled, so #ee9d is #eeee99dd — the CSS rule, not "expand each digit once".
Anything unrecognised returns null rather than a wrong colour: a theme with a typo in one variable should fall back to the built-in value for that one series, not silently render every plot in the default colour.
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static floatclamp01(float f) Limits a fraction to the range 0 to 1.static StringRender a colour the way a theme author would write it: hex, shortened to the smallest form that is still exact, with alpha appended when not opaque.private static Stringhex2(int v) Writes one byte as two hex digits.private static charhexDigit(int v) Writes one nibble as a hex digit.private static inthexValue(char c) Gives the value of one hex digit.private static booleanisShort(int v) Checks whether a byte can be written as a doubled hex digit.static ColorParse a CSS colour.private static IntegerparseChannel(String part) Parses one colour channel, percent or 0-255.private static FloatparseFloat(String s) Parse a decimal withoutFloat.parseFloat, so a stray character yields null instead of an exception propagating out of a theme lookup.private static ColorparseFunctional(String text) Parses an rgb(...) colour value.private static ColorConvert hex digits to a color.
Constructor Details
SvgColor
private SvgColor()Utility class, not intended for instantiation.
Method Details
parse
parseHex
parseFunctional
parseChannel
parseFloat
clamp01
private static float clamp01(float f) Limits a fraction to the range 0 to 1.- Parameters:
f- the fraction to clamp, 0 to 1- Returns:
- the clamped fraction
hexValue
private static int hexValue(char c) Gives the value of one hex digit.- Parameters:
c- the character to convert- Returns:
- its value, -1 if not a hex digit
format
isShort
private static boolean isShort(int v) Checks whether a byte can be written as a doubled hex digit.- Parameters:
v- the value to check- Returns:
- true if the short hex form applies
hex2
Writes one byte as two hex digits.- Parameters:
v- the value to write- Returns:
- the hex text
hexDigit
private static char hexDigit(int v) Writes one nibble as a hex digit.- Parameters:
v- the nibble, 0 to 15- Returns:
- the hex digit for it