Package org.openstreetmap.josm.tools
Class ColorScale
- java.lang.Object
-
- org.openstreetmap.josm.tools.ColorScale
-
public final class ColorScale extends Object
Utility class that helps to work with color scale for coloring GPX tracks etc.- Since:
- 7319
-
-
Field Summary
Fields Modifier and Type Field Description private Color
aboveMaxColor
private Color
belowMinColor
private Color[]
colors
private int
intervalCount
private double
max
private double
min
private Color
noDataColor
private String
title
-
Constructor Summary
Constructors Modifier Constructor Description private
ColorScale()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBounds()
Add standard colors for values below min or above max valueColorScale
addTitle(String title)
Adds a title to this scalestatic ColorScale
createCyclicScale(int count)
Creates a cyclic color scale (red yellow green blue red)static ColorScale
createFixedScale(Color[] colors)
Gets a fixed color range.static ColorScale
createHSBScale(int count)
Gets a HSB color range.void
drawColorBar(Graphics2D g, int x, int y, int w, int h, double valueScale)
Draws a color bar representing this scale on the given graphicsColor
getColor(double value)
Gets a color for the given value.Color
getColor(Number value)
Gets a color for the given value.Color
getNoDataColor()
Get the color to use if there is no dataColorScale
makeReversed()
Reverses this scaleColorScale
makeTransparent(int alpha)
Make all colors transparentColorScale
setIntervalCount(int intervalCount)
Sets the interval count for this scalevoid
setNoDataColor(Color noDataColor)
Sets the color to use if there is no datavoid
setRange(double min, double max)
Sets the hint on the range this scale is forprivate static float
weighted(float x)
transition function: w(0)=1, w(1)=0, 0<=w(x)<=1
-
-
-
Field Detail
-
min
private double min
-
max
private double max
-
noDataColor
private Color noDataColor
-
belowMinColor
private Color belowMinColor
-
aboveMaxColor
private Color aboveMaxColor
-
intervalCount
private int intervalCount
-
-
Constructor Detail
-
ColorScale
private ColorScale()
-
-
Method Detail
-
createFixedScale
public static ColorScale createFixedScale(Color[] colors)
Gets a fixed color range.- Parameters:
colors
- the fixed colors list- Returns:
- The scale
- Since:
- 15247
-
createHSBScale
public static ColorScale createHSBScale(int count)
Gets a HSB color range.- Parameters:
count
- The number of colors the scale should have- Returns:
- The scale
-
createCyclicScale
public static ColorScale createCyclicScale(int count)
Creates a cyclic color scale (red yellow green blue red)- Parameters:
count
- The number of colors the scale should have- Returns:
- The scale
-
weighted
private static float weighted(float x)
transition function: w(0)=1, w(1)=0, 0<=w(x)<=1- Parameters:
x
- number: 0<=x<=1- Returns:
- the weighted value
-
setRange
public void setRange(double min, double max)
Sets the hint on the range this scale is for- Parameters:
min
- The minimum valuemax
- The maximum value
-
addBounds
public void addBounds()
Add standard colors for values below min or above max value
-
getColor
public Color getColor(double value)
Gets a color for the given value.- Parameters:
value
- The value- Returns:
- The color for this value, this may be a special color if the value is outside the range but never null.
-
getColor
public Color getColor(Number value)
Gets a color for the given value.- Parameters:
value
- The value, may benull
- Returns:
- The color for this value, this may be a special color if the value is outside the range or the value is null but never null.
-
getNoDataColor
public Color getNoDataColor()
Get the color to use if there is no data- Returns:
- The color
-
setNoDataColor
public void setNoDataColor(Color noDataColor)
Sets the color to use if there is no data- Parameters:
noDataColor
- The color
-
makeTransparent
public ColorScale makeTransparent(int alpha)
Make all colors transparent- Parameters:
alpha
- The alpha value all colors in the range should have, range 0..255- Returns:
- This scale, for chaining
-
addTitle
public ColorScale addTitle(String title)
Adds a title to this scale- Parameters:
title
- The new title- Returns:
- This scale, for chaining
-
setIntervalCount
public ColorScale setIntervalCount(int intervalCount)
Sets the interval count for this scale- Parameters:
intervalCount
- The interval count hint- Returns:
- This scale, for chaining
-
makeReversed
public ColorScale makeReversed()
Reverses this scale- Returns:
- This scale, for chaining
-
drawColorBar
public void drawColorBar(Graphics2D g, int x, int y, int w, int h, double valueScale)
Draws a color bar representing this scale on the given graphics- Parameters:
g
- The graphics to draw onx
- Rect xy
- Rect yw
- Rect widthh
- Rect heightvalueScale
- The scale factor of the values
-
-