Class ColorUtil


  • public class ColorUtil
    extends java.lang.Object
    This class provides utility methods to manage colors.
    Since:
    jcms-5.5.0
    Version:
    $Revision: 134720 $
    Author:
    Olivier Dedieu
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String REVISION  
    • Constructor Summary

      Constructors 
      Constructor Description
      ColorUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Color addOffset​(java.awt.Color color, int offset)
      Add an offset to the given color and return the corresponding color
      static java.lang.String addOffset​(java.lang.String colorStr, int offset)
      Add an offset to the given color and return an hexadecimal representation of the corresponding color
      static java.awt.Color getColor​(java.lang.String colorStr)
      Return a color from a given hexadecimal string (eg #FF0000 will return a pure red.
      static java.awt.Color getForegroundColor​(java.awt.Color bgColor)  
      static java.awt.Color getForegroundColor​(java.awt.Color bgColor, int threshold)  
      static java.lang.String getForegroundColor​(java.lang.String bgColorStr)  
      static java.lang.String getForegroundColor​(java.lang.String bgColorStr, int threshold)  
      static java.lang.String getStringColor​(java.awt.Color color)
      Returns the hexadecimal represention of this 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

      • getColor

        public static java.awt.Color getColor​(java.lang.String colorStr)
        Return a color from a given hexadecimal string (eg #FF0000 will return a pure red. Leading # is optional).
        Parameters:
        colorStr - the string to be parsed
        Returns:
        a Color (or null if a parsing error occured)
        Since:
        jcms-5.5.0
      • getStringColor

        public static java.lang.String getStringColor​(java.awt.Color color)
        Returns the hexadecimal represention of this color. Eg for a pure red color (100%, 0, 0), it returns "#ff0000"
        Parameters:
        color - the color to process
        Returns:
        the hexadecimal represention of this color.
        Since:
        jcms-5.5.0
      • addOffset

        public static java.lang.String addOffset​(java.lang.String colorStr,
                                                 int offset)
        Add an offset to the given color and return an hexadecimal representation of the corresponding color
        Parameters:
        colorStr - the hexadecimal representation of the color (eg. "#ff0000");
        offset - the offset to apply
        Returns:
        an hexadecimal representation of the modified color
        Since:
        jcms-5.5.0
        See Also:
        addOffset(Color, int)
      • addOffset

        public static java.awt.Color addOffset​(java.awt.Color color,
                                               int offset)
        Add an offset to the given color and return the corresponding color
        Parameters:
        color - the color to process
        offset - the offset to apply
        Returns:
        the modified color
        Since:
        jcms-5.5.0
        See Also:
        addOffset(String, int)
      • getForegroundColor

        public static java.lang.String getForegroundColor​(java.lang.String bgColorStr)
        Parameters:
        bgColorStr - an hexadecimal string of the background color (eg "#FF0000" for red background)
        Returns:
        the foreground color ("#000000" or "#FFFFFF") to use according the given background color.
        Since:
        jcms-10.0.7
      • getForegroundColor

        public static java.lang.String getForegroundColor​(java.lang.String bgColorStr,
                                                          int threshold)
        Parameters:
        bgColorStr - an hexadecimal string of the background color (eg "#FF0000" for red background)
        threshold - the brightness threshold (e.g. 125)
        Returns:
        the foreground color ("#000000" or "#FFFFFF") to use according the given background color.
        Since:
        jcms-10.0.7
      • getForegroundColor

        public static java.awt.Color getForegroundColor​(java.awt.Color bgColor)
        Parameters:
        bgColor - the background color
        Returns:
        the foreground color (back or white) to use according the given background color.
        Since:
        jcms-10.0.7
      • getForegroundColor

        public static java.awt.Color getForegroundColor​(java.awt.Color bgColor,
                                                        int threshold)
        Parameters:
        bgColor - the background color
        threshold - the brightness threshold (e.g. 125)
        Returns:
        the foreground color (back or white) to use according the given background color.
        Since:
        jcms-10.0.7