Class ColorLookup

java.lang.Object
noaa.coastwatch.render.ColorLookup

public class ColorLookup extends Object
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 Details

    • ColorLookup

      public ColorLookup() throws IOException
      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

      public ColorLookup(File file) throws FileNotFoundException, IOException
      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

      public ColorLookup(InputStream stream) throws FileNotFoundException, IOException
      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

      public static ColorLookup 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

      public Color getColor(String name)
      Gets the color associated with a name.
      Parameters:
      name - the color name.
      Returns:
      a color, or null if no color was found.
    • convert

      public Color convert(String name)
      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.