Package jmri.util
Class ColorUtil
java.lang.Object
jmri.util.ColorUtil
A collection of utilities related to colors.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Colorstatic final Colorstatic final Colorstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcolorToColorName(Color color) Returns known color name or hex value in form #RRGGBB.static StringcolorToHexString(Color color) Convert a color into hex value of form #RRGGBB.static StringcolorToLocalizedName(Color color) Returns localized color name or hex value in form #RRGGBB.static StringcolorToString(Color color) Handles known colors plus special value for track.static ColorReturn the color (Black/White) that most contrasts with the specified color.static ColorCalculate the linear interpolation between two colors.static ColorSet the alpha component of a color.static ColorSet the alpha component of a color.static ColorstringToColor(String string)
-
Field Details
-
ColorTrack
- See Also:
-
ColorBlack
- See Also:
-
ColorDarkGray
- See Also:
-
ColorGray
- See Also:
-
ColorLightGray
- See Also:
-
ColorWhite
- See Also:
-
ColorRed
- See Also:
-
ColorPink
- See Also:
-
ColorOrange
- See Also:
-
ColorYellow
- See Also:
-
ColorGreen
- See Also:
-
ColorBlue
- See Also:
-
ColorMagenta
- See Also:
-
ColorCyan
- See Also:
-
ColorClear
- See Also:
-
ColorBrown
- See Also:
-
clear
-
CLEAR
-
BROWN
-
-
Constructor Details
-
ColorUtil
public ColorUtil()
-
-
Method Details
-
colorToString
Handles known colors plus special value for track.- Parameters:
color- the color or null- Returns:
- the name of the color or "black" if a color was provided; "track" if color is null
-
colorToColorName
Returns known color name or hex value in form #RRGGBB.- Parameters:
color- the color- Returns:
- the name or hex value of color; returns null if color is null
-
colorToLocalizedName
Returns localized color name or hex value in form #RRGGBB.- Parameters:
color- the color object- Returns:
- the localized name or hex value of color; returns null if color is null
- Since:
- 4.13.1
-
stringToColor
- Parameters:
string- Either a hexadecimal representation of the rgb value of a color or a color name defined as a constant.- Returns:
- the color from the string or null if the string equals "track" or equals the localized value for "None"
- Throws:
IllegalArgumentException- if string cannot be converted into a Color
-
colorToHexString
Convert a color into hex value of form #RRGGBB.- Parameters:
color- the color or null- Returns:
- the hex string or null if color is null
-
contrast
Return the color (Black/White) that most contrasts with the specified color.- Parameters:
color- the source color- Returns:
- the contrasting color
-
lerp
Calculate the linear interpolation between two colors.- Parameters:
colorA- the first colorcolorB- the second colort- the fraction (between 0 and 1)- Returns:
- the linear interpolation between a and b for t
-
setAlpha
Set the alpha component of a color.- Parameters:
color- the coloralpha- the alpha component (integer 0 - 255)- Returns:
- the new color with the specified alpha
-
setAlpha
Set the alpha component of a color.- Parameters:
color- the coloralpha- the alpha component (double 0.0 - 1.0)- Returns:
- the new color with the specified alpha
-