Class LightHelper


  • public class LightHelper
    extends Object
    Color utilities regarding lightness.
    • Method Detail

      • getDarkestColor

        public static int getDarkestColor​(int color1,
                                          int color2)
        Gets the darkest of two colors.
        Parameters:
        color1 - first color.
        color2 - second color.
        Returns:
        color1 if its light level is lower than the one of color2, color2 otherwise.
      • getLightestColor

        public static int getLightestColor​(int color1,
                                           int color2)
        Gets the lightest of two colors.
        Parameters:
        color1 - first color.
        color2 - second color.
        Returns:
        color1 if its light level is higher than the one of color2, color2 otherwise.
      • darkenColor

        public static int darkenColor​(int color,
                                      int factor)
        Gets a darkened version of a color.

        Note that passing a negative factor value, the method will return a lighter color.

        Parameters:
        color - the color to darken.
        factor - the darkening factor.
        Returns:
        the darkened color.
      • lightenColor

        public static int lightenColor​(int color,
                                       int factor)
        Gets a lightened version of a color.

        Note that passing a negative factor value, the method will return a darker color.

        Parameters:
        color - the color to lighten.
        factor - the lightening factor.
        Returns:
        the lightened color.
      • isLightColor

        public static boolean isLightColor​(int color)
        Gets whether a color is light or dark.
        Parameters:
        color - the color to test.
        Returns:
        true if the color is a light one, false otherwise.
      • getLight

        public static int getLight​(int color)
        Gets the light level of a color.
        Parameters:
        color - the color.
        Returns:
        the light level of the given color.
      • getMostContrastingColor

        public static int getMostContrastingColor​(int colorToContrast)
        Gets the color that best contrasts against a given color. Result is either Colors.WHITE or Colors.BLACK.
        Parameters:
        colorToContrast - the color to contrast.
        Returns:
        Colors.BLACK if the given color is light, Colors.WHITE otherwise.
        See Also:
        isLightColor(int)
      • getMostContrastingColor

        public static int getMostContrastingColor​(int colorToContrast,
                                                  int color1,
                                                  int color2)
        Gets the color that best contrasts against a given color.
        Parameters:
        colorToContrast - the color to contrast.
        color1 - the first color.
        color2 - the second color.
        Returns:
        the darkest color of {first color,second color} if the given color is light, the lightest color otherwise.
        See Also:
        isLightColor(int)