Class GradientMapper
- java.lang.Object
-
- org.biojava.nbio.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
-
-
Field Summary
Fields Modifier and Type Field Description 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
Constructors Constructor Description GradientMapper()
GradientMapper(Color negInf, Color posInf)
GradientMapper(Color negInf, Color posInf, ColorSpace cspace)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all finite endpointsboolean
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
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
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_GRADIENTmin
- Start of the gradientmax
- End of the gradient- Returns:
-
getColor
public Color getColor(double value)
- Specified by:
getColor
in interfaceContinuousColorMapper
- Parameters:
value
-- Returns:
- See Also:
ContinuousColorMapper.getColor(double)
-
clear
public void clear()
Clears all finite endpoints- Specified by:
clear
in interfaceMap<Double,Color>
- See Also:
Map.clear()
-
containsKey
public boolean containsKey(Object position)
- Specified by:
containsKey
in interfaceMap<Double,Color>
- Parameters:
position
-- Returns:
- See Also:
Map.containsKey(java.lang.Object)
-
containsValue
public boolean containsValue(Object color)
- Specified by:
containsValue
in interfaceMap<Double,Color>
- Parameters:
color
-- Returns:
- See Also:
Map.containsValue(java.lang.Object)
-
entrySet
public Set<Map.Entry<Double,Color>> entrySet()
- Specified by:
entrySet
in interfaceMap<Double,Color>
- Returns:
- See Also:
Map.entrySet()
-
get
public Color get(Object position)
- Specified by:
get
in interfaceMap<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 interfaceMap<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 interfaceMap<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 interfaceMap<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 interfaceMap<Double,Color>
- Parameters:
m
-- See Also:
Map.putAll(java.util.Map)
-
remove
public Color remove(Object position)
- Specified by:
remove
in interfaceMap<Double,Color>
- Parameters:
position
-- Returns:
- See Also:
Map.remove(java.lang.Object)
-
size
public int size()
- Specified by:
size
in interfaceMap<Double,Color>
- Returns:
- Number of finite endpoints
- See Also:
Map.size()
-
values
public Collection<Color> values()
- Specified by:
values
in interfaceMap<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
-
-