Class ColorHelper


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

      Constructors 
      Constructor Description
      ColorHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Color brighter​(java.awt.Color c, float factor)
      Creates a new Color that is a brighter version of this Color.
      static java.awt.Color createColor​(java.awt.Color c, float perceivedBrightness)
      Creates a new color with the hue taken from color c, but adjusted in brightness to match the desired perceived brightness.
      static java.awt.Color darker​(java.awt.Color c, float factor)
      Creates a new Color that is a darker version of this Color.
      static java.awt.Color getContrastColor​(java.awt.Color fg, java.awt.Color bg)
      Based on the differences of hue and perceived brightness of foreground color fg and background color bg, this method checks and possibly adjusts the given foreground color fg such that its hue stays unchanged, but its brightness is adapted to make it better perceivable on the background.
      static java.awt.Color intermediateColor​(java.awt.Color c1, java.awt.Color c2, float ratio)
      Creates an intermediate color between color c1 and color c2 in the RGB color space.
      static float perceivedBrightness​(java.awt.Color c)
      This is a color's perceived brightness by the human eye
      • Methods inherited from class java.lang.Object

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

      • ColorHelper

        public ColorHelper()
    • Method Detail

      • intermediateColor

        public static java.awt.Color intermediateColor​(java.awt.Color c1,
                                                       java.awt.Color c2,
                                                       float ratio)
        Creates an intermediate color between color c1 and color c2 in the RGB color space.
        Parameters:
        c1 -
        c2 -
        ratio - 0.0 -> returns c1; 1.0 -> returns c2
        Returns:
        color in between c1 and c2
      • brighter

        public static java.awt.Color brighter​(java.awt.Color c,
                                              float factor)
        Creates a new Color that is a brighter version of this Color. This is a copy of Color.brighter(), but lets you choose the factor.
        Parameters:
        c - the color to be brightened
        factor - value < 1.0; Color.brighter() uses 0.7
        Returns:
        a new Color object that is a brighter version of this Color with the same alpha value.
      • darker

        public static java.awt.Color darker​(java.awt.Color c,
                                            float factor)
        Creates a new Color that is a darker version of this Color. This is a copy of Color.darker(), but lets you choose the factor.
        Parameters:
        c - the color to be darkened
        factor - value < 1.0; Color.darker() uses 0.7
        Returns:
        a new Color object that is a darker version of this Color with the same alpha value.
      • perceivedBrightness

        public static float perceivedBrightness​(java.awt.Color c)
        This is a color's perceived brightness by the human eye
        Parameters:
        c -
        Returns:
        brightness from 0.0 to 1.0
      • createColor

        public static java.awt.Color createColor​(java.awt.Color c,
                                                 float perceivedBrightness)
        Creates a new color with the hue taken from color c, but adjusted in brightness to match the desired perceived brightness.
        Parameters:
        c -
        perceivedBrightness -
        Returns:
      • getContrastColor

        public static java.awt.Color getContrastColor​(java.awt.Color fg,
                                                      java.awt.Color bg)
        Based on the differences of hue and perceived brightness of foreground color fg and background color bg, this method checks and possibly adjusts the given foreground color fg such that its hue stays unchanged, but its brightness is adapted to make it better perceivable on the background.
        Parameters:
        fg - foreground color
        bg - background color // * @param minContrast the minimum desired contrast (0 to 0.5)
        Returns:
        unchanged or adjusted fg