Class ColorParser

java.lang.Object
org.mapfish.print.map.style.json.ColorParser

public final class ColorParser extends Object
Parses colors from text strings. Supports formats:
  • #F00
  • #FFAABB
  • rgb(100,100,100)
  • rgba(100,100,100, 100)
  • hsl(100,100,100)
  • hsla(100,100,100, 100)
  • -65536
  • red
The numbers in the rgb(..) and hsl(..) can have the following formats:
  • 0-255
  • 0%-100%
  • 0.0%-100.0%
  • 0.0-1.0
  • 0f-1f
  • 0.0f-1.0f
  • Method Details

    • toColor

      public static Color toColor(String colorString)
      Parse the string and convert it to a Color. See class description for details on the supported color formats.
      Parameters:
      colorString - the color string encoded.
      Returns:
      Always return a Color or an exception
      Throws:
      NumberFormatException - when the colorString cannot be parsed
    • canParseColor

      public static boolean canParseColor(String colorString)
      Check if the given color string can be parsed.
      Parameters:
      colorString - The color to parse.
    • toRGB

      public static String toRGB(Color color)
      Get the "rgb(...)" representation for a color.
      Parameters:
      color - The color.