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> colorMap
    Mapping of string gpml:ColorType (older versions of gpml) to a hexBinary String.
  • Constructor Summary

    Constructors
    Constructor Description
    ColorUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String colorToHex​(java.awt.Color color, boolean appendHash)
    Converts a Color object to a hexBinary string.
    static java.awt.Color hexToColor​(java.lang.String hex)
    Converts a hexBinary string to Color (r,g,b) or (r,g,b,a).
    static boolean isTransparent​(java.awt.Color color)
    Returns true if fill color is equal to null or the alpha value is equal to 0.
    static java.awt.Color makeTransparent​(java.awt.Color color, int alpha)
    Returns a new transparent color for given color with given alpha.
    static java.awt.Color stringToColor​(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> colorMap
      Mapping of string gpml:ColorType (older versions of gpml) to a hexBinary String. In stringToColor(java.lang.String), hexToColor(java.lang.String)converts hexBinary String to Color object. 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 a Color object 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 to Color (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 a Color object.
      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.