Package org.openjdk.jmc.common.util
Class ColorToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.ColorToolkit
-
public class ColorToolkit extends java.lang.Object
Toolkit for working withAWT colors
.
-
-
Field Summary
Fields Modifier and Type Field Description private static float
normalHashValue
-
Constructor Summary
Constructors Modifier Constructor Description private
ColorToolkit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Color
blend(java.awt.Color fg, java.awt.Color bg)
static java.awt.Color
decode(java.lang.String hexColor)
Decode a string created byencode(Color)
and create a corresponding color instance.static java.lang.String
encode(java.awt.Color color)
Encode a color as a hexadecimal string starting with '#'.static java.awt.Color
getDistinguishableColor(java.lang.Object o)
Generate a color based on an object.private static java.awt.Color
getGradientBottomColor(java.awt.Color topColor)
private static int
getGradientComponent(int c)
static java.awt.GradientPaint
getGradientPaint(java.awt.Color topColor, int top)
Get a gradient paint based on a top color.static java.awt.Color
withAlpha(java.awt.Color color, int alpha)
Create a color with a specified alpha value.
-
-
-
Method Detail
-
encode
public static java.lang.String encode(java.awt.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 java.awt.Color decode(java.lang.String hexColor) throws java.lang.NumberFormatException
Decode a string created byencode(Color)
and create a corresponding color instance.- Parameters:
hexColor
- hexadecimal string to decode- Returns:
- a color instance
- Throws:
java.lang.NumberFormatException
- if the string can't be decoded
-
getDistinguishableColor
public static java.awt.Color getDistinguishableColor(java.lang.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 java.awt.GradientPaint getGradientPaint(java.awt.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
-
getGradientBottomColor
private static java.awt.Color getGradientBottomColor(java.awt.Color topColor)
-
getGradientComponent
private static int getGradientComponent(int c)
-
withAlpha
public static java.awt.Color withAlpha(java.awt.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
-
blend
public static java.awt.Color blend(java.awt.Color fg, java.awt.Color bg)
-
-