org.geotools.image.io
Class PaletteFactory

java.lang.Object
  extended byorg.geotools.image.io.PaletteFactory

public class PaletteFactory
extends java.lang.Object

A factory class for IndexColorModel objects. Default implementation for this class create IndexColorModel objects from palette definition files. Definition files are text files containing an arbitrary number of lines, each line containing RGB components ranging from 0 to 255 inclusive. Empty line and line starting with '#' are ignored. Example:

 # RGB codes for SeaWiFs images
 # (chlorophylle-a concentration)

   033   000   096
   032   000   097
   031   000   099
   030   000   101
   029   000   102
   028   000   104
   026   000   106
   025   000   107
 etc...
 
The number of RGB codes doesn't have to match an IndexColorModel's map size. RGB codes will be automatically interpolated RGB values when needed.

Since:
2.1
Version:
$Id: PaletteFactory.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Constructor Summary
PaletteFactory(PaletteFactory parent, java.lang.Class loader, java.io.File directory, java.lang.String extension, java.nio.charset.Charset charset, java.util.Locale locale)
          Constructs a palette factory using an optional class for loading palette definition files.
PaletteFactory(PaletteFactory parent, java.lang.ClassLoader loader, java.io.File directory, java.lang.String extension, java.nio.charset.Charset charset, java.util.Locale locale)
          Constructs a palette factory using an optional class loader for loading palette definition files.
 
Method Summary
 java.lang.String[] getAvailableNames()
          Returns the list of available palette names.
 java.awt.Color[] getColors(java.lang.String name)
          Load colors from a definition file.
 java.awt.Color[] getColors(java.net.URL url)
          Load colors from an URL.
 java.awt.image.IndexColorModel getIndexColorModel(java.lang.String name)
          Load an index color model from a definition file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaletteFactory

public PaletteFactory(PaletteFactory parent,
                      java.lang.ClassLoader loader,
                      java.io.File directory,
                      java.lang.String extension,
                      java.nio.charset.Charset charset,
                      java.util.Locale locale)
Constructs a palette factory using an optional class loader for loading palette definition files.

Parameters:
parent - An optional parent factory, or if there is none. The parent factory will be queried if a palette was not found in the current factory.
loader - An optional class loader to use for loading the palette definition files. If , loading will occurs from the system current working directory.
directory - The base directory for palette definition files. It may be a Java package if a were specified. If , then is assumed.
extension - File name extension, or if there is no extension to add to filename. If non-null, this extension will be automatically appended to filename. It should starts with the character.
charset - The charset to use for parsing files, or for the default.
locale - The locale to use for parsing files. or for the default.

PaletteFactory

public PaletteFactory(PaletteFactory parent,
                      java.lang.Class loader,
                      java.io.File directory,
                      java.lang.String extension,
                      java.nio.charset.Charset charset,
                      java.util.Locale locale)
Constructs a palette factory using an optional class for loading palette definition files. Using a class instead of a class loader can avoid security issue on some platforms (some platforms do not allow to load resources from a because it can load from the root package).

Parameters:
parent - An optional parent factory, or if there is none. The parent factory will be queried if a palette was not found in the current factory.
loader - An optional class to use for loading the palette definition files. If , loading will occurs from the system current working directory.
directory - The base directory for palette definition files. It may be a Java package if a were specified. If , then is assumed.
extension - File name extension, or if there is no extension to add to filename. If non-null, this extension will be automatically appended to filename. It should starts with the character.
charset - The charset to use for parsing files, or for the default.
locale - The locale to use for parsing files. or for the default.
Since:
2.2
Method Detail

getAvailableNames

public java.lang.String[] getAvailableNames()
Returns the list of available palette names. Any item in this list can be specified as argument to getColors(String) or getIndexColorModel(String) methods.

Returns:
The list of available palette name, or if this method is unable to fetch this information.

getColors

public java.awt.Color[] getColors(java.lang.String name)
                           throws java.io.IOException
Load colors from a definition file.

Parameters:
name - The palette's name to load. This name doesn't need to contains a path or an extension. Path and extension are set according value specified at construction time.
Returns:
The set of colors, or if the set was not found.
Throws:
java.io.IOException - if an error occurs during reading.
javax.imageio.IIOException - if an error occurs during parsing.

getColors

public java.awt.Color[] getColors(java.net.URL url)
                           throws java.io.IOException
Load colors from an URL.

Parameters:
url - The palette's URL.
Returns:
The set of colors, or if the set was not found.
Throws:
java.io.IOException - if an error occurs during reading.
javax.imageio.IIOException - if an error occurs during parsing.

getIndexColorModel

public java.awt.image.IndexColorModel getIndexColorModel(java.lang.String name)
                                                  throws java.io.IOException
Load an index color model from a definition file. The returned model will use index from 0 to 255 inclusive.

Parameters:
name - The palette's name to load. This name doesn't need to contains a path or an extension. Path and extension are set according value specified at construction time.
Returns:
The index color model, or if the palettes was not found.
Throws:
java.io.IOException - if an error occurs during reading.
javax.imageio.IIOException - if an error occurs during parsing.


Copyright © GeoTools. All Rights Reserved.