Package noaa.coastwatch.render
Class ColorLookup
java.lang.Object
noaa.coastwatch.render.ColorLookup
The color lookup class translates color names to red, green, blue
values based on a color names data file. The data file has an
XML format as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE colorlookup SYSTEM "http://coastwatch.noaa.gov/xml/colorlookup.dtd">
<colorlookup>
<color name="snow" r="255" g="250" b="250" />
<color name="ghost white" r="248" g="248" b="255" />
<color name="GhostWhite" r="248" g="248" b="255" />
<color name="white smoke" r="245" g="245" b="245" />
...
</colorlookup>
- Since:
- 3.1.1
- Author:
- Peter Hollemans
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new color lookup based on a predefined color names file.ColorLookup(File file) Constructs a new color lookup from the specified file.ColorLookup(InputStream stream) Constructs a new color lookup from an input stream. -
Method Summary
Modifier and TypeMethodDescriptionConverts a color name or hexadecimal value to an object.Gets the color associated with a name.static ColorLookupCreates a static instance of this class using the default constructor.
-
Constructor Details
-
ColorLookup
Creates a new color lookup based on a predefined color names file.- Throws:
IOException- if an error occurred reading the predefined color names file. Under normal circimstances, this should never happen.
-
ColorLookup
Constructs a new color lookup from the specified file.- Parameters:
file- the file to read.- Throws:
FileNotFoundException- if the file is not valid.IOException- if the file had input format errors.
-
ColorLookup
Constructs a new color lookup from an input stream.- Parameters:
stream- the input stream to read palette data from.- Throws:
IOException- if the file had input format errors.FileNotFoundException
-
-
Method Details
-
getInstance
Creates a static instance of this class using the default constructor.- Returns:
- the static instance, or null if one could not be created.
-
getColor
Gets the color associated with a name.- Parameters:
name- the color name.- Returns:
- a color, or null if no color was found.
-
convert
Converts a color name or hexadecimal value to an object.- Parameters:
name- the color name or hexadecimal value with "0x" prepended. If a color name is used, the name may be extended with an optional colon ":" and transparency value in percent. A transparency of 0 is completely opaque and 100 is completely transparent.- Returns:
- the converted color with possible alpha component.
- Throws:
RuntimeException- if the value cannot be converted.
-