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:
Map<Double,Color>, ContinuousColorMapper

public class GradientMapper
extends Object
implements ContinuousColorMapper, Map<Double,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
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(Color negInf, Color posInf)
           
GradientMapper(Color negInf, Color posInf, ColorSpace cspace)
           
 
Method Summary
 void clear()
          Clears all finite endpoints
 boolean containsKey(Object position)
           
 boolean containsValue(Object color)
           
 Set<Map.Entry<Double,Color>> entrySet()
           
 Color get(Object position)
           
 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()
           
 Set<Double> keySet()
           
static void main(String[] args)
           
 Color put(Double position, Color color)
          Adds a gradient endpoint at the specified position.
 void putAll(Map<? extends Double,? extends Color> m)
           
 Color remove(Object position)
           
 void setInterpolator(ColorInterpolator interpolator)
           
 int size()
           
 Collection<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(Color negInf,
                      Color posInf)

GradientMapper

public GradientMapper(Color negInf,
                      Color posInf,
                      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 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 Map<Double,Color>
See Also:
Map.clear()

containsKey

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

containsValue

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

entrySet

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

get

public Color get(Object position)
Specified by:
get in interface Map<Double,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 Map<Double,Color>
Returns:
true if this gradient does not contain finite endpoints
See Also:
Map.isEmpty()

keySet

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

put

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

Specified by:
put in interface Map<Double,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(Map<? extends Double,? extends Color> m)
Specified by:
putAll in interface Map<Double,Color>
Parameters:
m -
See Also:
Map.putAll(java.util.Map)

remove

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

size

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

values

public Collection<Color> values()
Specified by:
values in interface Map<Double,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(String[] args)
Parameters:
args -