Class ColorToolkit

    • Method Detail

      • encode

        public static String encode​(Color color)
        Encode a color as a hexadecimal string starting with '#'. This string can be decoded using decode(String).
        Parameters:
        color - color to encode
        Returns:
        a hexadecimal string representing the color
      • getDistinguishableColor

        public static Color getDistinguishableColor​(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 GradientPaint getGradientPaint​(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 gradient
        top - X coordinate for the top color
        Returns:
        a gradient with a generated bottom color at X=0 and the top color at X=top
      • withAlpha

        public static Color withAlpha​(Color color,
                                      int alpha)
        Create a color with a specified alpha value.
        Parameters:
        color - base color
        alpha - alpha value
        Returns:
        a color based on the base color and with the specified alpha value