Class ColourUtils

java.lang.Object
com.atlassian.confluence.util.ColourUtils

public class ColourUtils extends Object
Color manipulation utilities
Since:
5.0
  • Field Details

    • TEXT_COLOR_RGB_PATTERN

      public static final Pattern TEXT_COLOR_RGB_PATTERN
    • VALID_RGB_COLOR_PATTERN

      public static final Pattern VALID_RGB_COLOR_PATTERN
    • VALID_RGBA_COLOR_PATTERN

      public static final Pattern VALID_RGBA_COLOR_PATTERN
    • VALID_HEX_COLOR_PATTERN

      public static final Pattern VALID_HEX_COLOR_PATTERN
    • VALID_HSL_COLOR_PATTERN

      public static final Pattern VALID_HSL_COLOR_PATTERN
    • VALID_HSLA_COLOR_PATTERN

      public static final Pattern VALID_HSLA_COLOR_PATTERN
    • VALID_COLOR_NAME_PATTERN

      public static final Pattern VALID_COLOR_NAME_PATTERN
    • TEXT_COLOR_DESIGN_TOKEN_PATTERN

      public static final Pattern TEXT_COLOR_DESIGN_TOKEN_PATTERN
    • EPSILON

      public static final Double EPSILON
  • Constructor Details

    • ColourUtils

      public ColourUtils()
  • Method Details

    • colorToHex

      public static String colorToHex(Color color)
      Returns hexadecimal value for a color.
      Parameters:
      color - color object
      Returns:
      color hexadecimal value
    • hexToColor

      public static Color hexToColor(String hexColor)
      Given a color hexadecimal value returns a Color object.
      Parameters:
      hexColor - color hexadecimal value
      Returns:
      Color object
    • darken

      public static String darken(String hexColor, double amount)
      Returns a color darker than the given color
      Parameters:
      hexColor - color hexadecimal value
      amount - value between 0 and 100.
      Returns:
      darker color
    • lighten

      public static String lighten(String hexColor, double amount)
      Returns a color lighter than the given color
      Parameters:
      hexColor - color hexadecimal value
      amount - value between 0 and 100.
      Returns:
      lighter color
    • saturate

      public static String saturate(String hexColor, double amount)
      Returns a color more saturated than the given color
      Parameters:
      hexColor - color hexadecimal value
      amount - value between 0 and 100.
      Returns:
      saturated color
    • desaturate

      public static String desaturate(String hexColor, double amount)
      Returns a color less saturate than the given color
      Parameters:
      hexColor - color hexadecimal value
      amount - value between 0 and 100.
      Returns:
      desaturated color
    • darken

      public static Color darken(Color color, double amount)
      Returns a color darker than the given color
      Parameters:
      color - color onject
      amount - value between 0 and 100.
      Returns:
      darker color
    • lighten

      public static Color lighten(Color color, double amount)
      Returns a color lighter than the given color
      Parameters:
      color - color object
      amount - value between 0 and 100.
      Returns:
      lighter color
    • desaturate

      public static Color desaturate(Color color, double amount)
      Returns a color less saturate than the given color
      Parameters:
      color - color object
      amount - value between 0 and 100.
      Returns:
      desaturated color
    • saturate

      public static Color saturate(Color color, double amount)
      Returns a color more saturated than the given color
      Parameters:
      color - color object
      amount - value between 0 and 100.
      Returns:
      saturated color
    • toHSL

      public static float[] toHSL(Color color)
      Returns the color value in the HSL space
      Parameters:
      color - color object
      Returns:
      { hue, saturation, lightness, alpha }
    • hslToRgb

      public static int[] hslToRgb(float[] hsl)
      Returns the color value in the RGB space
      Parameters:
      hsl - color in hsl space
      Returns:
      rgb values [0, 255]
    • getColorWithInvertedLightness

      public static String getColorWithInvertedLightness(String hexColor)
      Given a HEX color, return a HEX value that is the given color at an inverse lightness percentage.
      Parameters:
      hexColor - a HEX value that whose lightness will be inverted.
      Returns:
      a hex color with inverted lightness.
      Since:
      8.9.0
    • findClosetColor

      public static String findClosetColor(String hexColor, Set<String> colorList)
      Parameters:
      hexColor - the hex color value
      colorList - list of all color which have design-token map value.
      Returns:
      closest hex color
      Since:
      8.9.0
    • getFallbackColorForDesignTokenColor

      public static String getFallbackColorForDesignTokenColor(String styleValue)
      Parameters:
      styleValue - the style attribute that may contain design token color
      Returns:
      the fallback color value of design token color or null
      Since:
      8.9.0
    • isValidColor

      public static boolean isValidColor(String color)