Package org.geotools.data.util
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 Summary
Fields Modifier and Type Field Description static Converter
CONVERT_COLOR_TO_STRING
Converts color to hex representation.static Converter
CONVERT_CSS_TO_COLOR
Converts CSS Color Module 4 names to colors, with a fallback to the basicCONVERT_STRING
converter if the provided source String is not found in theCSS_COLORS
map.static Converter
CONVERT_NUMBER_TO_COLOR
Converts provided integer to color, taking care to allow rgb and rgba support.static Converter
CONVERT_STRING
UsesColor.decode(String)
to convert String to Color.static Map<String,Color>
CSS_COLORS
A mapping from CSS Color Module 4 names to Color objects.protected static DecimalFormat
FORMAT
-
Fields inherited from interface ConverterFactory
SAFE_CONVERSION
-
-
Constructor Summary
Constructors Constructor Description ColorConverterFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Converter
createConverter(Class source, Class target, Hints hints)
Creates aConverter
instance for converting one type of object to another.
-
-
-
Field Detail
-
CONVERT_STRING
public static Converter CONVERT_STRING
UsesColor.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:
- https://www.w3.org/TR/css-color-4/#named-colors for more information.
-
CONVERT_CSS_TO_COLOR
public static Converter CONVERT_CSS_TO_COLOR
Converts CSS Color Module 4 names to colors, with a fallback to the basicCONVERT_STRING
converter if the provided source String is not found in theCSS_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.
-
-
Method Detail
-
createConverter
public Converter createConverter(Class source, Class target, Hints hints)
Description copied from interface:ConverterFactory
Creates aConverter
instance for converting one type of object to another.- Specified by:
createConverter
in interfaceConverterFactory
- 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.
-
-