Class ColorConverterFactory

Object
ColorConverterFactory
All Implemented Interfaces:
ConverterFactory

public class ColorConverterFactory extends Object implements ConverterFactory
ConverterFactory for handling color conversions.

Supported conversions:

  • "#FF0000" (String) -> Color.RED
  • 0xCC0000FF (Integer) -> RED with 80% alpha
  • "gray" (String) --> Color.GRAY

This code was previously part of the SLD utility class, it is being made available as part of the Converters framework to allow for broader use.

Since:
2.5
Author:
Jody Garnett (Refractions Research)
  • Field Details

    • CONVERT_STRING

      public static Converter CONVERT_STRING
      Uses Color.decode(String) to convert String to Color.
    • CONVERT_NUMBER_TO_COLOR

      public static Converter CONVERT_NUMBER_TO_COLOR
      Converts provided integer to color, taking care to allow rgb and rgba support.
    • FORMAT

      protected static DecimalFormat FORMAT
    • CSS_COLORS

      public static final Map<String,Color> CSS_COLORS
      A mapping from CSS Color Module 4 names to Color objects.
      See Also:
    • CONVERT_CSS_TO_COLOR

      public static Converter CONVERT_CSS_TO_COLOR
      Converts CSS Color Module 4 names to colors, with a fallback to the basic CONVERT_STRING converter if the provided source String is not found in the CSS_COLORS map.

      This converter is willing to work with:

      • CSS_COLORS names such as "aliceblue".
      • rgb representation of the form rgb(0,0,255)
      • rgba representation of the form rgba(0,0,255,255)
      • Hex representation of the form #RRGGBB and #RRGGBBAA
    • CONVERT_COLOR_TO_STRING

      public static Converter CONVERT_COLOR_TO_STRING
      Converts color to hex representation.
  • Constructor Details

    • ColorConverterFactory

      public ColorConverterFactory()
  • Method Details

    • createConverter

      public Converter createConverter(Class source, Class target, Hints hints)
      Description copied from interface: ConverterFactory
      Creates a Converter instance for converting one type of object to another.
      Specified by:
      createConverter in interface ConverterFactory
      Parameters:
      source - The type to convert from.
      target - The type to convert to.
      hints - Hints used to be used while creating a converter.
      Returns:
      The converter, or null if one could not be found.