sim.util.gui
Class SimpleColorMap

java.lang.Object
  extended bysim.util.gui.SimpleColorMap
All Implemented Interfaces:
ColorMap

public class SimpleColorMap
extends java.lang.Object
implements ColorMap

Maps numerical levels to colors using either a lookup table, color interpolation, or both. A simple implementation of the ColorMap interface.

  1. Method 1: a color table. The user can provide an array of Colors; if the numerical value, cast into an integer, is between 0 and (the length of this array - 1), then the appropriate Color is returned.
  2. Method 2: color interpolation. The user can provide a min-level, min-Color, max-level, and max-Color. If the numerical value is below min-level, then minColor is provided. If it's above max-level, then max-Color is provided. If it's between min-level and max-level, then a linear interpolation between min-Color and max-Color is provided.

The user can provide both a color table and an interpolation; in this case, the color table takes precedence over the interpolation in that region where the color table is relevant. You specify a color table with setColorTable(), and you specify an interpolation range with setLevels().

validLevel() is set to return true if the level range is between min-level and max-level, or if it's inside the color table range.

defaultValue() is set to return 0 if the color table exists, else min-level is provided.


Field Summary
 java.awt.Color clearColor
           
static int COLOR_DISCRETIZATION
           
 java.awt.Color[] colors
          User-provided color table
 int maxAlpha
           
 int maxBlue
           
 int maxGreen
           
 double maxLevel
           
 int maxRed
           
 int minAlpha
           
 int minBlue
           
 java.awt.Color minColor
           
 int minGreen
           
 double minLevel
           
 int minRed
           
 
Constructor Summary
SimpleColorMap()
           
SimpleColorMap(java.awt.Color[] colorTable)
           
SimpleColorMap(java.awt.Color[] colorTable, double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
           
SimpleColorMap(double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
           
 
Method Summary
 double defaultValue()
          Returns some level which is valid (that is, validLevel(defaultValue()) should always return true).
 int getAlpha(double level)
          Returns the alpha value for a color for the given level.
 java.awt.Color getColor(double level)
          Override this if you'd like to customize the color for values in the portrayal.
 int getRGB(double level)
          Returns the RGB values, plus alpha, for a color for the given level.
 java.awt.Color[] setColorTable(java.awt.Color[] colorTable)
          Specifies that if a value (cast into an int) in the IntGrid2D or DoubleGrid2D falls in the range 0 ...
 void setLevels(double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
          Sets the color levels for the ValueGridPortrayal2D values for use by the default getColor(...) method.
 boolean validLevel(double value)
          Returns true if a level is "valid" (it provides a meaningful color)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minRed

public int minRed

minBlue

public int minBlue

minGreen

public int minGreen

minAlpha

public int minAlpha

maxRed

public int maxRed

maxBlue

public int maxBlue

maxGreen

public int maxGreen

maxAlpha

public int maxAlpha

maxLevel

public double maxLevel

minLevel

public double minLevel

clearColor

public final java.awt.Color clearColor

minColor

public java.awt.Color minColor

COLOR_DISCRETIZATION

public static final int COLOR_DISCRETIZATION
See Also:
Constant Field Values

colors

public java.awt.Color[] colors
User-provided color table

Constructor Detail

SimpleColorMap

public SimpleColorMap()

SimpleColorMap

public SimpleColorMap(double minLevel,
                      double maxLevel,
                      java.awt.Color minColor,
                      java.awt.Color maxColor)

SimpleColorMap

public SimpleColorMap(java.awt.Color[] colorTable)

SimpleColorMap

public SimpleColorMap(java.awt.Color[] colorTable,
                      double minLevel,
                      double maxLevel,
                      java.awt.Color minColor,
                      java.awt.Color maxColor)
Method Detail

setLevels

public void setLevels(double minLevel,
                      double maxLevel,
                      java.awt.Color minColor,
                      java.awt.Color maxColor)
Sets the color levels for the ValueGridPortrayal2D values for use by the default getColor(...) method. These are overridden by any array provided in setColorTable(). If the value in the IntGrid2D or DoubleGrid2D is less than or equal to minLevel, then minColor is used. If the value is greater than or equal to maxColor, then maxColor is used. Otherwise a linear interpolation from minColor to maxColor is used.


setColorTable

public java.awt.Color[] setColorTable(java.awt.Color[] colorTable)
Specifies that if a value (cast into an int) in the IntGrid2D or DoubleGrid2D falls in the range 0 ... colors.length, then that index in the colors table should be used to represent that value. Otherwise, values in setLevels(...) are used. You can remove the color table by passing in null here. Returns the old color table.


getColor

public java.awt.Color getColor(double level)
Override this if you'd like to customize the color for values in the portrayal. The default version looks up the value in the colors[] table, else computes the interpolated color and grabs it out of a predefined color cache (there can't be more than about 1024 or so interpolated colors, max).

Specified by:
getColor in interface ColorMap

getAlpha

public int getAlpha(double level)
Description copied from interface: ColorMap
Returns the alpha value for a color for the given level. This could be simply written as

return getRGB(level) >>> 24 ;

...or it could be written as:

return getColor(level).getAlpha()

...however it's likely that it thie method could be written more efficiently than either of these.

Specified by:
getAlpha in interface ColorMap

getRGB

public int getRGB(double level)
Description copied from interface: ColorMap
Returns the RGB values, plus alpha, for a color for the given level. The byte ordering should be in the same fashion that Color.getRGB() is provided.

Specified by:
getRGB in interface ColorMap

validLevel

public boolean validLevel(double value)
Description copied from interface: ColorMap
Returns true if a level is "valid" (it provides a meaningful color)

Specified by:
validLevel in interface ColorMap

defaultValue

public double defaultValue()
Description copied from interface: ColorMap
Returns some level which is valid (that is, validLevel(defaultValue()) should always return true). This is commonly provided to give the user a level to replace an "invalid" level he's typed in.

Specified by:
defaultValue in interface ColorMap