java.lang.Object
org.jfree.svg.SvgColor

public final class SvgColorextends Object
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:

  • #rgb and #rgba — #f0a, #ee9d
  • #rrggbb and #rrggbbaa — #00ff99, #00ff9980
  • rgb(r,g,b) and rgba(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.

  • Method Details

    • parse

      public static Color parse(String value)
      Parse a CSS colour.
      Parameters:
      value - the text to parse, may be null
      Returns:
      the colour, or null if value is not a form this understands
    • format

      public static String format(Color color)
      Render 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.
      Parameters:
      color - the colour to render, may be null
      Returns:
      a CSS colour string, or null when color is null