Package org.openjdk.jmc.common.util
Class ColorToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.ColorToolkit
-
public class ColorToolkit extends Object
Toolkit for working withAWT colors.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Colorblend(Color fg, Color bg)static Colordecode(String hexColor)Decode a string created byencode(Color)and create a corresponding color instance.static Stringencode(Color color)Encode a color as a hexadecimal string starting with '#'.static ColorgetDistinguishableColor(Object o)Generate a color based on an object.static GradientPaintgetGradientPaint(Color topColor, int top)Get a gradient paint based on a top color.static ColorwithAlpha(Color color, int alpha)Create a color with a specified alpha value.
-
-
-
Method Detail
-
encode
public static String encode(Color color)
Encode a color as a hexadecimal string starting with '#'. This string can be decoded usingdecode(String).- Parameters:
color- color to encode- Returns:
- a hexadecimal string representing the color
-
decode
public static Color decode(String hexColor) throws NumberFormatException
Decode a string created byencode(Color)and create a corresponding color instance.- Parameters:
hexColor- hexadecimal string to decode- Returns:
- a color instance
- Throws:
NumberFormatException- if the string can't be decoded
-
getDistinguishableColor
public static Color getDistinguishableColor(Object o)
Generate a color based on an object. The goal is to be able to run this on a number of different objects and get colors that are distinguishable from each other.The algorithm for generating colors is arbitrary and may be changed.
- Parameters:
o- object to get a color for- Returns:
- a color instance
-
getGradientPaint
public static GradientPaint getGradientPaint(Color topColor, int top)
Get a gradient paint based on a top color. The bottom color will be generated based on the top color.- Parameters:
topColor- color for the top of the gradienttop- X coordinate for the top color- Returns:
- a gradient with a generated bottom color at X=0 and the top color at X=
top
-
withAlpha
public static Color withAlpha(Color color, int alpha)
Create a color with a specified alpha value.- Parameters:
color- base coloralpha- alpha value- Returns:
- a color based on the base color and with the specified alpha value
-
-