org.biojava.bio.structure.gui.util.color
Class GradientMapper

java.lang.Object
  extended by org.biojava.bio.structure.gui.util.color.GradientMapper
All Implemented Interfaces:
java.util.Map<java.lang.Double,java.awt.Color>, ContinuousColorMapper

public class GradientMapper
extends java.lang.Object
implements ContinuousColorMapper, java.util.Map<java.lang.Double,java.awt.Color>

Maps a set of real values onto a gradient. The real line is partitioned into segments [a,b). The endpoint of each segment is labeled with a color. Colors are linearly interpolated between finite endpoints. Endpoints implicitly exist for Double.NEGATIVE_INFINITY and Double.POSITIVE_INFINITY, representing default colors. Thus any point in the segment [-Inf,a) is labeled with the negInf color, and any point in [b,Inf] is labeled with the posInf color. If no endpoints are present, the posInf color is used as default. Common gradients are predefined an may be instantiated through GradientMapper.getGradientMapper().

Author:
Spencer Bliven

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static int BLACK_WHITE_GRADIENT
           
static int RAINBOW_GRADIENT
           
static int RAINBOW_INTENSITY_GRADIENT
           
static int RED_BLUE_GRADIENT
           
static int WHITE_BLACK_GRADIENT
           
 
Constructor Summary
GradientMapper()
           
GradientMapper(java.awt.Color negInf, java.awt.Color posInf)
           
GradientMapper(java.awt.Color negInf, java.awt.Color posInf, java.awt.color.ColorSpace cspace)
           
 
Method Summary
 void clear()
          Clears all finite endpoints
 boolean containsKey(java.lang.Object position)
           
 boolean containsValue(java.lang.Object color)
           
 java.util.Set<java.util.Map.Entry<java.lang.Double,java.awt.Color>> entrySet()
           
 java.awt.Color get(java.lang.Object position)
           
 java.awt.Color getColor(double value)
           
static GradientMapper getGradientMapper(int gradientType, double min, double max)
          Constructs a gradientMapper to draw one of the pre-defined gradients For example, GradientMapper.getGradientMapper(GradientMapper.RAINBOW_GRADIENT, 0, 10)
 ColorInterpolator getInterpolator()
           
 boolean isEmpty()
           
 java.util.Set<java.lang.Double> keySet()
           
static void main(java.lang.String[] args)
           
 java.awt.Color put(java.lang.Double position, java.awt.Color color)
          Adds a gradient endpoint at the specified position.
 void putAll(java.util.Map<? extends java.lang.Double,? extends java.awt.Color> m)
           
 java.awt.Color remove(java.lang.Object position)
           
 void setInterpolator(ColorInterpolator interpolator)
           
 int size()
           
 java.util.Collection<java.awt.Color> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

BLACK_WHITE_GRADIENT

public static final int BLACK_WHITE_GRADIENT
See Also:
Constant Field Values

WHITE_BLACK_GRADIENT

public static final int WHITE_BLACK_GRADIENT
See Also:
Constant Field Values

RED_BLUE_GRADIENT

public static final int RED_BLUE_GRADIENT
See Also:
Constant Field Values

RAINBOW_GRADIENT

public static final int RAINBOW_GRADIENT
See Also:
Constant Field Values

RAINBOW_INTENSITY_GRADIENT

public static final int RAINBOW_INTENSITY_GRADIENT
See Also:
Constant Field Values
Constructor Detail

GradientMapper

public GradientMapper()

GradientMapper

public GradientMapper(java.awt.Color negInf,
                      java.awt.Color posInf)

GradientMapper

public GradientMapper(java.awt.Color negInf,
                      java.awt.Color posInf,
                      java.awt.color.ColorSpace cspace)
Method Detail

getGradientMapper

public static GradientMapper getGradientMapper(int gradientType,
                                               double min,
                                               double max)
Constructs a gradientMapper to draw one of the pre-defined gradients For example, GradientMapper.getGradientMapper(GradientMapper.RAINBOW_GRADIENT, 0, 10)

Parameters:
gradientType - One of the gradient types, eg GradientMapper.BLACK_WHITE_GRADIENT
min - Start of the gradient
max - End of the gradient
Returns:

getColor

public java.awt.Color getColor(double value)
Specified by:
getColor in interface ContinuousColorMapper
Parameters:
value -
Returns:
See Also:
ContinuousColorMapper.getColor(double)

clear

public void clear()
Clears all finite endpoints

Specified by:
clear in interface java.util.Map<java.lang.Double,java.awt.Color>
See Also:
Map.clear()

containsKey

public boolean containsKey(java.lang.Object position)
Specified by:
containsKey in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
position -
Returns:
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object color)
Specified by:
containsValue in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
color -
Returns:
See Also:
Map.containsValue(java.lang.Object)

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.Double,java.awt.Color>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.Double,java.awt.Color>
Returns:
See Also:
Map.entrySet()

get

public java.awt.Color get(java.lang.Object position)
Specified by:
get in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
position -
Returns:
The color of the endpoint at position, or null if no endpoint exists there
See Also:
Map.get(java.lang.Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.Double,java.awt.Color>
Returns:
true if this gradient does not contain finite endpoints
See Also:
Map.isEmpty()

keySet

public java.util.Set<java.lang.Double> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.Double,java.awt.Color>
Returns:
See Also:
Map.keySet()

put

public java.awt.Color put(java.lang.Double position,
                          java.awt.Color color)
Adds a gradient endpoint at the specified position.

Specified by:
put in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
position - The endpoint position. May be Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY for endpoints.
color -
Returns:
See Also:
Map.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(java.util.Map<? extends java.lang.Double,? extends java.awt.Color> m)
Specified by:
putAll in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
m -
See Also:
Map.putAll(java.util.Map)

remove

public java.awt.Color remove(java.lang.Object position)
Specified by:
remove in interface java.util.Map<java.lang.Double,java.awt.Color>
Parameters:
position -
Returns:
See Also:
Map.remove(java.lang.Object)

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.Double,java.awt.Color>
Returns:
Number of finite endpoints
See Also:
Map.size()

values

public java.util.Collection<java.awt.Color> values()
Specified by:
values in interface java.util.Map<java.lang.Double,java.awt.Color>
Returns:
See Also:
Map.values()

getInterpolator

public ColorInterpolator getInterpolator()
Returns:
the interpolator

setInterpolator

public void setInterpolator(ColorInterpolator interpolator)
Parameters:
interpolator - the interpolator to set

main

public static void main(java.lang.String[] args)
Parameters:
args -