Class ColorUtil


  • public class ColorUtil
    extends Object
    • Constructor Detail

      • ColorUtil

        public ColorUtil()
    • Method Detail

      • colorTag

        public static String colorTag​(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 String prependColorTag​(String str,
                                             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 String wrapWithColorTag​(String str,
                                              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 String toHexColor​(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 Color colorLerp​(Color a,
                                      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 String colorToHexCode​(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 String colorToAlphaHexCode​(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 Color colorWithAlpha​(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​(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​(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 Color fromString​(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 Color fromHex​(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 Color fromObject​(@Nonnull
                                       Object object)
        Creates color from passed object hash code
        Parameters:
        object - object with hashCode
        Returns:
        color