uchicago.src.sim.gui
Class ColorMap

java.lang.Object
  extended by uchicago.src.sim.gui.ColorMap

public class ColorMap
extends java.lang.Object

A customizable map of java.awt.Color(s) to Integers. Useful for displaying collections of Integers, such as an Object2DGrid, as colors.

Note that using the method that take int arguments is faster than those that take the Integer arguments.

Version:
$Revision: 1.6 $ $Date: 2005/07/12 21:43:56 $
Author:
Nick Collier

Field Summary
static java.awt.Color black
           
static java.awt.Color blue
           
static java.awt.Color cyan
           
static java.awt.Color darkGray
           
static java.awt.Color gray
           
static java.awt.Color green
           
static java.awt.Color lightGray
           
static java.awt.Color magenta
           
static java.awt.Color orange
           
static java.awt.Color pink
           
static java.awt.Color red
           
static java.awt.Color white
           
static java.awt.Color yellow
           
 
Constructor Summary
ColorMap()
           
 
Method Summary
 java.awt.Color getColor(int i)
          Gets the color mapped to the specified int
 java.awt.Color getColor(java.lang.Integer i)
          Gets the color mapped to the specified Integer
 void mapColor(int i, java.awt.Color c)
          Maps the specified color to the specified int
 void mapColor(int i, double red, double green, double blue)
          This is the same as mapColor(int, double, double, double, double) with an alpha of 1.0
 void mapColor(int i, double red, double green, double blue, double alpha)
          Maps the color specified by the red, green, blue, and alpha values to to the int i.
 void mapColor(java.lang.Integer i, java.awt.Color c)
          Maps the specified color to the specified Integer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

white

public static final java.awt.Color white

lightGray

public static final java.awt.Color lightGray

gray

public static final java.awt.Color gray

darkGray

public static final java.awt.Color darkGray

black

public static final java.awt.Color black

red

public static final java.awt.Color red

pink

public static final java.awt.Color pink

orange

public static final java.awt.Color orange

yellow

public static final java.awt.Color yellow

green

public static final java.awt.Color green

magenta

public static final java.awt.Color magenta

cyan

public static final java.awt.Color cyan

blue

public static final java.awt.Color blue
Constructor Detail

ColorMap

public ColorMap()
Method Detail

mapColor

public void mapColor(java.lang.Integer i,
                     java.awt.Color c)
Maps the specified color to the specified Integer

Parameters:
i - the integer to map the color to
c - the color to map to the Integer

mapColor

public void mapColor(int i,
                     java.awt.Color c)
Maps the specified color to the specified int

Parameters:
i - the int to map the color to
c - the color to map to the int

mapColor

public void mapColor(int i,
                     double red,
                     double green,
                     double blue,
                     double alpha)
Maps the color specified by the red, green, blue, and alpha values to to the int i. Red, green, blue, and alpha should be doubles in the range [0, 1] where 1 is the equivalent of the full color (255), and 0 is no color. This system makes it easy to set color values within a loop. For example, for (int i = 0; i < 64; i++) { map.setColor(i, i / 63.0, 0, 0, 1) } This will set 64 shades of red.

Parameters:
i - the int to map the color to
red - a double in the range of [0, 1]
blue - a double in the range of [0, 1]
green - a double in the range of [0, 1]
alpha - a double in the range of [0, 1] (as you approach 0 you get more transparent)

mapColor

public void mapColor(int i,
                     double red,
                     double green,
                     double blue)
This is the same as mapColor(int, double, double, double, double) with an alpha of 1.0

Parameters:
i - the int to map the color to
red - a double in the range of [0, 1]
blue - a double in the range of [0, 1]
green - a double in the range of [0, 1]
See Also:
mapColor(int, double, double, double, double)

getColor

public java.awt.Color getColor(java.lang.Integer i)
Gets the color mapped to the specified Integer


getColor

public java.awt.Color getColor(int i)
Gets the color mapped to the specified int