com.approximatrix.charting.render.colorscale
Class IndexedColorScale

java.lang.Object
  extended by com.approximatrix.charting.render.colorscale.AbstractColorScale
      extended by com.approximatrix.charting.render.colorscale.IndexedColorScale
All Implemented Interfaces:
ColorScale

public class IndexedColorScale
extends AbstractColorScale

Provides a color scale object that looks up colors based on an index passed. The index/Color pairs must be assigned prior to calling a conversion method. Returns FAILED_LOOKUP when the index does not exist in the Map.

Author:
armstrong

Field Summary
protected static java.awt.Color FAILED_LOOKUP
          The color to return if the index does not exist
protected  java.util.Map<java.lang.Integer,java.awt.Color> map
          Maps integers to Colors
 
Constructor Summary
IndexedColorScale()
          Constructs the IndexedColorScale object and initializes an empty color map.
IndexedColorScale(java.util.Map<java.lang.Integer,java.awt.Color> map)
          Constructs the IndexedColorScale object based on the passed map of index/Color pairs.
 
Method Summary
 java.awt.Color getColor(double value)
          Retrieves the color by converting the value by rounding to an integer before requesting the Color of the rounded index.
 java.awt.Color getColor(int value)
          Returns a color based on an integer data value
 void setColor(int i, java.awt.Color val)
          Assigns the specified Color to the specified index in the map.
 
Methods inherited from class com.approximatrix.charting.render.colorscale.AbstractColorScale
getColors, getColors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAILED_LOOKUP

protected static final java.awt.Color FAILED_LOOKUP
The color to return if the index does not exist


map

protected java.util.Map<java.lang.Integer,java.awt.Color> map
Maps integers to Colors

Constructor Detail

IndexedColorScale

public IndexedColorScale()
Constructs the IndexedColorScale object and initializes an empty color map.


IndexedColorScale

public IndexedColorScale(java.util.Map<java.lang.Integer,java.awt.Color> map)
Constructs the IndexedColorScale object based on the passed map of index/Color pairs.

Parameters:
map - a Map with Integer keys and Color values
Method Detail

setColor

public void setColor(int i,
                     java.awt.Color val)
Assigns the specified Color to the specified index in the map. Overwrites existing matching indices.

Parameters:
i - index of the added color
val - the Color value

getColor

public java.awt.Color getColor(double value)
Retrieves the color by converting the value by rounding to an integer before requesting the Color of the rounded index.

Parameters:
value - the data space value
Returns:
a valid Color object

getColor

public java.awt.Color getColor(int value)
Description copied from interface: ColorScale
Returns a color based on an integer data value

Parameters:
value - the data space value
Returns:
a valid Color object