Package org.openstreetmap.josm.tools
Class ColorHelper
- java.lang.Object
-
- org.openstreetmap.josm.tools.ColorHelper
-
public final class ColorHelper extends Object
Helper to convert from color to HTML string and back.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ColorHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Color
alphaMultiply(Color color, float alphaFactor)
Multiply the alpha value of the given color with the factor.static String
color2html(Color col)
Returns the HTML color code (6 or 8 digit).static String
color2html(Color color, boolean withAlpha)
Returns the HTML color code (6 or 8 digit).static Color
complement(Color clr)
Returns the complementary color ofclr
.static Integer
float2int(Float val)
convert float range 0 <= x <= 1 to integer range 0..255 when dealing with colors and color alpha valuestatic Color
getForegroundColor(Color bg)
Determines the correct foreground color (black or white) to use for the given background, so the text will be readable.static Color
html2color(String html)
Returns theColor
for the given HTML code.static Float
int2float(Integer val)
convert integer range 0..255 to float range 0 <= x <= 1 when dealing with colors and color alpha value
-
-
-
Constructor Detail
-
ColorHelper
private ColorHelper()
-
-
Method Detail
-
html2color
public static Color html2color(String html)
Returns theColor
for the given HTML code.- Parameters:
html
- the color code- Returns:
- the color
-
color2html
public static String color2html(Color col)
Returns the HTML color code (6 or 8 digit).- Parameters:
col
- The color to convert- Returns:
- the HTML color code (6 or 8 digit)
-
color2html
public static String color2html(Color color, boolean withAlpha)
Returns the HTML color code (6 or 8 digit).- Parameters:
color
- The color to convertwithAlpha
- iftrue
and alpha value < 255, return 8-digit color code, else always 6-digit- Returns:
- the HTML color code (6 or 8 digit)
- Since:
- 6655
-
getForegroundColor
public static Color getForegroundColor(Color bg)
Determines the correct foreground color (black or white) to use for the given background, so the text will be readable.- Parameters:
bg
- background color- Returns:
Color#BLACK
orColor#WHITE
- Since:
- 9223
-
float2int
public static Integer float2int(Float val)
convert float range 0 <= x <= 1 to integer range 0..255 when dealing with colors and color alpha value- Parameters:
val
- float value between 0 and 1- Returns:
- null if val is null, the corresponding int if val is in the range 0...1. If val is outside that range, return 255
-
int2float
public static Float int2float(Integer val)
convert integer range 0..255 to float range 0 <= x <= 1 when dealing with colors and color alpha value- Parameters:
val
- integer value- Returns:
- corresponding float value in range 0 <= x <= 1
-
alphaMultiply
public static Color alphaMultiply(Color color, float alphaFactor)
Multiply the alpha value of the given color with the factor. The alpha value is clamped to 0..255- Parameters:
color
- The coloralphaFactor
- The factor to multiply alpha with.- Returns:
- The new color.
- Since:
- 11692
-
complement
public static Color complement(Color clr)
Returns the complementary color ofclr
.- Parameters:
clr
- the color to complement- Returns:
- the complementary color of
clr
-
-