Package org.openstreetmap.josm.tools
Class ColorScale
java.lang.Object
org.openstreetmap.josm.tools.ColorScale
Utility class that helps to work with color scale for coloring GPX tracks etc.
- Since:
- 7319
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Colorprivate Colorprivate String[]private Color[]private static final Stringprivate intprivate static final Colorprivate static final Colorprivate static final Colorprivate static final Colorprivate doubleprivate doubleprivate Colorprivate static final bytePadding for the legend (from the text to the edge of the rectangle)private static final Stringprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd standard colors for values below min or above max valueaddColorBarTitles(String[] titles) Adds titles to the color bar for a fixed scaleAdds a title to this scaleprivate static FontMetricsstatic ColorScalecreateCyclicScale(int count) Creates a cyclic color scale (red yellow green blue red)static ColorScalecreateFixedScale(Color[] colors) Gets a fixed color range.static ColorScalecreateHSBScale(int count) Gets a HSB color range.private int[]drawBackgroundRectangle(Graphics2D g, int x, int y, int w, int h, int fw, int fh, int titleWidth) Draw the background rectanglevoiddrawColorBar(Graphics2D g, int x, int y, int w, int h, double valueScale) Draws a color bar representing this scale on the given graphicsvoiddrawColorBarTime(Graphics2D g, int x, int y, int w, int h, double minVal, double maxVal) Draws a color bar representing the time scale on the given graphicsprivate voiddrawLegend(Graphics2D g, int y, int w, int h, double valueScale, int fh, int fw, int xText) Draws the legend for the color bar representing the time scale on the given graphicsprivate voiddrawLegendText(Graphics2D g, int y, int w, int h, int fh, int fw, int xText, int i, Color color, String txt) Draws the legend for the color bar representing the time scale on the given graphicsprivate voiddrawOutline(Graphics2D g, String txt, int x, int y, Color color) draws an outline for the legend textsprivate voiddrawTimeLegend(Graphics2D g, int y, int w, int h, double minVal, double maxVal, int fh, int fw, int xText) Draws the legend for the color bar representing the time scale on the given graphicsgetColor(double value) Gets a color for the given value.Gets a color for the given value.Get the color to use if there is no dataReverses this scalemakeTransparent(int alpha) Make all colors transparentsetIntervalCount(int intervalCount) Sets the interval count for this scalevoidsetNoDataColor(Color noDataColor) Sets the color to use if there is no datavoidsetRange(double min, double max) Sets the hint on the range this scale is forprivate static floatweighted(float x) transition function: w(0)=1, w(1)=0, 0<=w(x)<=1
-
Field Details
-
LEGEND_BACKGROUND
-
LEGEND_TEXT_OUTLINE_DARK
-
LEGEND_TEXT_OUTLINE_BRIGHT
-
LEGEND_TITLE
-
DAY_TIME_FORMAT
- See Also:
-
TIME_FORMAT
- See Also:
-
PADDING
Padding for the legend (from the text to the edge of the rectangle)- See Also:
-
min
-
max
-
noDataColor
-
belowMinColor
-
aboveMaxColor
-
colors
-
colorBarTitles
-
title
-
intervalCount
-
-
Constructor Details
-
ColorScale
private ColorScale()
-
-
Method Details
-
createFixedScale
Gets a fixed color range.- Parameters:
colors- the fixed colors list- Returns:
- The scale
- Since:
- 15247
-
createHSBScale
Gets a HSB color range.- Parameters:
count- The number of colors the scale should have- Returns:
- The scale
-
createCyclicScale
Creates a cyclic color scale (red yellow green blue red)- Parameters:
count- The number of colors the scale should have- Returns:
- The scale
-
weighted
transition function: w(0)=1, w(1)=0, 0<=w(x)<=1- Parameters:
x- number: 0<=x<=1- Returns:
- the weighted value
-
setRange
Sets the hint on the range this scale is for- Parameters:
min- The minimum valuemax- The maximum value
-
addBounds
Add standard colors for values below min or above max value -
getColor
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
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
Get the color to use if there is no data- Returns:
- The color
-
setNoDataColor
Sets the color to use if there is no data- Parameters:
noDataColor- The color
-
makeTransparent
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
Adds a title to this scale- Parameters:
title- The new title- Returns:
- This scale, for chaining
-
addColorBarTitles
Adds titles to the color bar for a fixed scale- Parameters:
titles- Array of String, same length as the colors array- Returns:
- This scale, for chaining
- Since:
- 18396
-
setIntervalCount
Sets the interval count for this scale- Parameters:
intervalCount- The interval count hint- Returns:
- This scale, for chaining
-
makeReversed
Reverses this scale- Returns:
- This scale, for chaining
-
drawOutline
draws an outline for the legend texts- Parameters:
g- The graphics to draw ontxt- The text to draw the outlinex- Text xy- Text ycolor- The color of the text
-
drawColorBar
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
-
drawColorBarTime
public void drawColorBarTime(Graphics2D g, int x, int y, int w, int h, double minVal, double maxVal) Draws a color bar representing the time scale on the given graphics- Parameters:
g- The graphics to draw onx- Rect xy- Rect yw- Color bar widthh- Color bar heightminVal- start time of the trackmaxVal- end time of the track
-
calculateFontMetrics
-
drawBackgroundRectangle
private int[] drawBackgroundRectangle(Graphics2D g, int x, int y, int w, int h, int fw, int fh, int titleWidth) Draw the background rectangle- Parameters:
g- The graphics to draw onx- Rect xy- Rect yw- Color bar widthh- Color bar heightfw- The font widthfh- The font heighttitleWidth- The width of the title- Returns:
- an @{code int[]} of [xRect, rectWidth, xText, titleWidth] TODO investigate using records in Java 17
-
drawLegend
private void drawLegend(Graphics2D g, int y, int w, int h, double valueScale, int fh, int fw, int xText) Draws the legend for the color bar representing the time scale on the given graphics- Parameters:
g- The graphics to draw ony- Rect yw- Color bar widthh- Color bar heightfw- The font widthfh- The font heightvalueScale- The scale factor of the valuesxText- The location to start drawing the text (x-axis)
-
drawTimeLegend
private void drawTimeLegend(Graphics2D g, int y, int w, int h, double minVal, double maxVal, int fh, int fw, int xText) Draws the legend for the color bar representing the time scale on the given graphics- Parameters:
g- The graphics to draw ony- Rect yw- Color bar widthh- Color bar heightminVal- start time of the trackmaxVal- end time of the trackfw- The font widthfh- The font heightxText- The location to start drawing the text (x-axis)
-
drawLegendText
private void drawLegendText(Graphics2D g, int y, int w, int h, int fh, int fw, int xText, int i, Color color, String txt) Draws the legend for the color bar representing the time scale on the given graphics- Parameters:
g- The graphics to draw ony- Rect yw- Color bar widthh- Color bar heightfw- The font widthfh- The font heightxText- The location to start drawing the text (x-axis)color- The color of the text to drawtxt- The text string to drawi- The index of the legend (so we can calculate the y location)
-