Class ColorUtil


  • public class ColorUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ColorUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Color colorLerp​(java.awt.Color a, java.awt.Color b, double t)
      Linearly interpolates between colors a and b by t.
      static java.lang.String colorTag​(java.awt.Color color)
      Creates a color tag from the given color.
      static java.lang.String colorToAlphaHexCode​(java.awt.Color color)
      Gets the ARGB hex color code of the passed color.
      static java.lang.String colorToHexCode​(java.awt.Color color)
      Gets the RGB hex color code of the passed color.
      static java.awt.Color colorWithAlpha​(java.awt.Color color, int alpha)
      Gets the same RGB color with the specified alpha value.
      static int constrainValue​(int value)
      Limits an int to the rgba value range (0-255)
      static java.awt.Color fromHex​(java.lang.String hex)
      Gets the Color from the passed hex string.
      static java.awt.Color fromObject​(java.lang.Object object)
      Creates color from passed object hash code
      static java.awt.Color fromString​(java.lang.String string)
      Gets the Color from the passed int string.
      static boolean isAlphaHex​(java.lang.String hex)
      Determines if the passed hex string is an alpha hex color.
      static boolean isHex​(java.lang.String hex)
      Determines if the passed hex string is a hex color.
      static java.lang.String prependColorTag​(java.lang.String str, java.awt.Color color)
      Prepends the given str with an opening color tag of the given color.
      static java.lang.String toHexColor​(java.awt.Color color)
      Converts a given color to it's hexadecimal equivalent.
      static java.lang.String wrapWithColorTag​(java.lang.String str, java.awt.Color color)
      Wraps the given str with a color tag of the given color.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ColorUtil

        public ColorUtil()
    • Method Detail

      • colorTag

        public static java.lang.String colorTag​(java.awt.Color color)
        Creates a color tag from the given color.
        Parameters:
        color - The Color to create a tag from.
        Returns:
        A string of the color tag for the given color.
      • prependColorTag

        public static java.lang.String prependColorTag​(java.lang.String str,
                                                       java.awt.Color color)
        Prepends the given str with an opening color tag of the given color.
        Parameters:
        str - The string to be colorized.
        color - The color to be used in the color tag.
        Returns:
        The passed str with a prepended color tag.
      • wrapWithColorTag

        public static java.lang.String wrapWithColorTag​(java.lang.String str,
                                                        java.awt.Color color)
        Wraps the given str with a color tag of the given color.
        Parameters:
        str - The string to be colorized.
        color - The color to be used in the color tag.
        Returns:
        The passed str wrapped with opening and closing color tags.
      • toHexColor

        public static java.lang.String toHexColor​(java.awt.Color color)
        Converts a given color to it's hexadecimal equivalent.
        Parameters:
        color - Color to get hexadecimal string from.
        Returns:
        Hexadecimal string representing the given color, in the form "#abcdef".
      • colorLerp

        public static java.awt.Color colorLerp​(java.awt.Color a,
                                               java.awt.Color b,
                                               double t)
        Linearly interpolates between colors a and b by t.
        Parameters:
        a - first color
        b - second color
        t - factor
        Returns:
        interpolated color
      • colorToHexCode

        public static java.lang.String colorToHexCode​(java.awt.Color color)
        Gets the RGB hex color code of the passed color.
        Parameters:
        color - The color to get a hex code from.
        Returns:
        A lower-cased string of the RGB hex code of color.
      • colorToAlphaHexCode

        public static java.lang.String colorToAlphaHexCode​(java.awt.Color color)
        Gets the ARGB hex color code of the passed color.
        Parameters:
        color - The color to get a hex code from.
        Returns:
        A lower-cased string of the ARGB hex code of color.
      • colorWithAlpha

        public static java.awt.Color colorWithAlpha​(java.awt.Color color,
                                                    int alpha)
        Gets the same RGB color with the specified alpha value.
        Parameters:
        color - The RGB color to use.
        alpha - The alpha value to use (0-255).
        Returns:
        A Color with the given RGB and alpha.
      • isAlphaHex

        public static boolean isAlphaHex​(java.lang.String hex)
        Determines if the passed hex string is an alpha hex color.
        Parameters:
        hex - The hex to test.
        Returns:
        boolean
      • isHex

        public static boolean isHex​(java.lang.String hex)
        Determines if the passed hex string is a hex color.
        Parameters:
        hex - The hex to test.
        Returns:
        boolean
      • constrainValue

        public static int constrainValue​(int value)
        Limits an int to the rgba value range (0-255)
        Parameters:
        value - The value for the r, g, b, or a.
        Returns:
        An int between 0 - 255.
      • fromString

        public static java.awt.Color fromString​(java.lang.String string)
        Gets the Color from the passed int string.
        Parameters:
        string - The int to get a Color object from.
        Returns:
        A Color of the int of color.
      • fromHex

        public static java.awt.Color fromHex​(java.lang.String hex)
        Gets the Color from the passed hex string.
        Parameters:
        hex - The hex to get a Color object from.
        Returns:
        A Color of the hex code of color.
      • fromObject

        public static java.awt.Color fromObject​(@Nonnull
                                                java.lang.Object object)
        Creates color from passed object hash code
        Parameters:
        object - object with hashCode
        Returns:
        color