Package org.pathvisio.libgpml.util
Class ColorUtils
java.lang.Object
org.pathvisio.libgpml.util.ColorUtils
public class ColorUtils
extends java.lang.Object
This utils class contains methods for converting
Color to hexBinary
or color name String, and vice versa.- Author:
- finterly
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.String>colorMapMapping of string gpml:ColorType (older versions of gpml) to a hexBinaryString. -
Constructor Summary
Constructors Constructor Description ColorUtils() -
Method Summary
Modifier and Type Method Description static java.lang.StringcolorToHex(java.awt.Color color, boolean appendHash)Converts aColorobject to a hexBinary string.static java.awt.ColorhexToColor(java.lang.String hex)Converts a hexBinary string toColor(r,g,b) or (r,g,b,a).static booleanisTransparent(java.awt.Color color)Returns true if fill color is equal to null or the alpha value is equal to 0.static java.awt.ColormakeTransparent(java.awt.Color color, int alpha)Returns a new transparent color for given color with given alpha.static java.awt.ColorstringToColor(java.lang.String stringColor)Converts a (gpml) string containing either a named color, e.g.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
colorMap
private static final java.util.Map<java.lang.String,java.lang.String> colorMapMapping of string gpml:ColorType (older versions of gpml) to a hexBinaryString. InstringToColor(java.lang.String),hexToColor(java.lang.String)converts hexBinary String toColorobject. Color name string matching is case insensitive.
-
-
Constructor Details
-
ColorUtils
public ColorUtils()
-
-
Method Details
-
colorToHex
public static java.lang.String colorToHex(java.awt.Color color, boolean appendHash)Converts aColorobject to a hexBinary string.- Parameters:
color- the color object.appendHash- the boolean, if true appends "#" to beginning of hex string.- Returns:
- the resulting hex string.
-
hexToColor
public static java.awt.Color hexToColor(java.lang.String hex)Converts a hexBinary string toColor(r,g,b) or (r,g,b,a). If it can't be converted null is returned.- Parameters:
hex-
-
stringToColor
public static java.awt.Color stringToColor(java.lang.String stringColor)Converts a (gpml) string containing either a named color, e.g. "White", or a hexBinary number to aColorobject.- Parameters:
stringColor-
-
isTransparent
public static boolean isTransparent(java.awt.Color color)Returns true if fill color is equal to null or the alpha value is equal to 0.- Returns:
- true if fill color is transparent.
-
makeTransparent
public static java.awt.Color makeTransparent(java.awt.Color color, int alpha)Returns a new transparent color for given color with given alpha.- Parameters:
color- the source color.alpha- the integer alpha value.- Returns:
- new color created from given color and alpha.
-