Class GradientMapper
- java.lang.Object
-
- org.biojava.nbio.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
-
-
Field Summary
Fields Modifier and Type Field Description static intBLACK_WHITE_GRADIENTstatic intRAINBOW_GRADIENTstatic intRAINBOW_INTENSITY_GRADIENTstatic intRED_BLUE_GRADIENTstatic intWHITE_BLACK_GRADIENT
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all finite endpointsbooleancontainsKey(java.lang.Object position)booleancontainsValue(java.lang.Object color)java.util.Set<java.util.Map.Entry<java.lang.Double,java.awt.Color>>entrySet()java.awt.Colorget(java.lang.Object position)java.awt.ColorgetColor(double value)static GradientMappergetGradientMapper(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)ColorInterpolatorgetInterpolator()booleanisEmpty()java.util.Set<java.lang.Double>keySet()static voidmain(java.lang.String[] args)java.awt.Colorput(java.lang.Double position, java.awt.Color color)Adds a gradient endpoint at the specified position.voidputAll(java.util.Map<? extends java.lang.Double,? extends java.awt.Color> m)java.awt.Colorremove(java.lang.Object position)voidsetInterpolator(ColorInterpolator interpolator)intsize()java.util.Collection<java.awt.Color>values()
-
-
-
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
-
-
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_GRADIENTmin- Start of the gradientmax- End of the gradient- Returns:
-
getColor
public java.awt.Color getColor(double value)
- Specified by:
getColorin interfaceContinuousColorMapper- Parameters:
value-- Returns:
- See Also:
ContinuousColorMapper.getColor(double)
-
clear
public void clear()
Clears all finite endpoints- Specified by:
clearin interfacejava.util.Map<java.lang.Double,java.awt.Color>- See Also:
Map.clear()
-
containsKey
public boolean containsKey(java.lang.Object position)
- Specified by:
containsKeyin interfacejava.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:
containsValuein interfacejava.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:
entrySetin interfacejava.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:
getin interfacejava.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:
isEmptyin interfacejava.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:
keySetin interfacejava.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:
putin interfacejava.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:
putAllin interfacejava.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:
removein interfacejava.util.Map<java.lang.Double,java.awt.Color>- Parameters:
position-- Returns:
- See Also:
Map.remove(java.lang.Object)
-
size
public int size()
- Specified by:
sizein interfacejava.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:
valuesin interfacejava.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-
-
-