Class ColorUtil


  • public class ColorUtil
    extends java.lang.Object
    Utility class for matching and parsing Color objects from String input. Description of supported formats see http://www.w3schools.com/cssref/css_colors_legal.asp
    Since:
    8.4
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern HEX_PATTERN
      Case-insensitive Pattern with regular expression matching the default hexadecimal color presentation pattern:
      '#' followed by six [\da-fA-F] characters.
      static java.util.regex.Pattern HSL_PATTERN
      Case-insensitive Pattern with regular expression matching common HSL presentation patterns:
      'hsl' followed by one [0-360] value and two [0-100] percentage value.
      static java.util.regex.Pattern HSLA_PATTERN
      Case-insensitive Pattern with regular expression matching common HSLA presentation patterns:
      'hsla' followed by one [0-360] value, two [0-100] percentage values, and one [0.0-1.0] value.
      static java.util.regex.Pattern RGB_PATTERN
      Case-insensitive Pattern with regular expression matching common RGB color presentation patterns:
      'rgb' followed by three [0-255] number values.
      static java.util.regex.Pattern RGBA_PATTERN
      Case-insensitive Pattern with regular expression matching common RGBA presentation patterns:
      'rgba' followed by three [0-255] values and one [0.0-1.0] value.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.vaadin.shared.ui.colorpicker.Color getHexPatternColor​(java.util.regex.Matcher matcher)
      Parses Color from matched hexadecimal Matcher.
      static com.vaadin.shared.ui.colorpicker.Color getHSLAPatternColor​(java.util.regex.Matcher matcher)
      Parses Color from matched HSLA Matcher.
      static com.vaadin.shared.ui.colorpicker.Color getHSLPatternColor​(java.util.regex.Matcher matcher)
      Parses Color from matched HSL Matcher.
      static com.vaadin.shared.ui.colorpicker.Color getRGBAPatternColor​(java.util.regex.Matcher matcher)
      Parses Color from matched RGBA Matcher.
      static com.vaadin.shared.ui.colorpicker.Color getRGBPatternColor​(java.util.regex.Matcher matcher)
      Parses Color from matched RGB Matcher.
      static com.vaadin.shared.ui.colorpicker.Color stringToColor​(java.lang.String input)
      Parses Color from any of the following String inputs:
      - RGB hex (e.g.
      • Methods inherited from class java.lang.Object

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

      • HEX_PATTERN

        public static final java.util.regex.Pattern HEX_PATTERN
        Case-insensitive Pattern with regular expression matching the default hexadecimal color presentation pattern:
        '#' followed by six [\da-fA-F] characters.

        Pattern contains named groups red, green, and blue, which represent the individual values.

      • RGB_PATTERN

        public static final java.util.regex.Pattern RGB_PATTERN
        Case-insensitive Pattern with regular expression matching common RGB color presentation patterns:
        'rgb' followed by three [0-255] number values. Values can be separated with either comma or whitespace.

        Pattern contains named groups red, green, and blue, which represent the individual values.

      • RGBA_PATTERN

        public static final java.util.regex.Pattern RGBA_PATTERN
        Case-insensitive Pattern with regular expression matching common RGBA presentation patterns:
        'rgba' followed by three [0-255] values and one [0.0-1.0] value. Values can be separated with either comma or whitespace. The only accepted decimal marker is point ('.').

        Pattern contains named groups red, green, blue, and alpha, which represent the individual values.

      • HSL_PATTERN

        public static final java.util.regex.Pattern HSL_PATTERN
        Case-insensitive Pattern with regular expression matching common HSL presentation patterns:
        'hsl' followed by one [0-360] value and two [0-100] percentage value. Values can be separated with either comma or whitespace. The percent sign ('%') is optional.

        Pattern contains named groups hue,saturation, and light, which represent the individual values.

      • HSLA_PATTERN

        public static final java.util.regex.Pattern HSLA_PATTERN
        Case-insensitive Pattern with regular expression matching common HSLA presentation patterns:
        'hsla' followed by one [0-360] value, two [0-100] percentage values, and one [0.0-1.0] value. Values can be separated with either comma or whitespace. The percent sign ('%') is optional. The only accepted decimal marker is point ('.').

        Pattern contains named groups hue,saturation, light, and alpha, which represent the individual values.

    • Method Detail

      • stringToColor

        public static com.vaadin.shared.ui.colorpicker.Color stringToColor​(java.lang.String input)
        Parses Color from any of the following String inputs:
        - RGB hex (e.g. "#FFAA00"), HEX_PATTERN
        - RGB "function" (e.g. "rgb(128,0,255)"), RGB_PATTERN
        - RGBA "function" (e.g. "rgba(50,50,50,0.2)"), RGBA_PATTERN
        - HSL "function" (e.g. "hsl(50,50,50)"), HSL_PATTERN
        - HSLA "function" (e.g. "hsl(50,50,50,0.2)"), HSLA_PATTERN

        Parsing is case-insensitive.

        Parameters:
        input - String input
        Returns:
        Color parsed from input
        Throws:
        java.lang.NumberFormatException - Input does not match any recognized pattern
      • getHexPatternColor

        public static com.vaadin.shared.ui.colorpicker.Color getHexPatternColor​(java.util.regex.Matcher matcher)
        Parses Color from matched hexadecimal Matcher.
        Parameters:
        matcher - Matcher matching hexadecimal pattern with named regex groups red, green, and blue
        Returns:
        Color parsed from Matcher
      • getRGBPatternColor

        public static com.vaadin.shared.ui.colorpicker.Color getRGBPatternColor​(java.util.regex.Matcher matcher)
        Parses Color from matched RGB Matcher.
        Parameters:
        matcher - Matcher matching RGB pattern with named regex groups red, green, and blue
        Returns:
        Color parsed from Matcher
      • getRGBAPatternColor

        public static com.vaadin.shared.ui.colorpicker.Color getRGBAPatternColor​(java.util.regex.Matcher matcher)
        Parses Color from matched RGBA Matcher.
        Parameters:
        matcher - Matcher matching RGBA pattern with named regex groups red, green, blue, and alpha
        Returns:
        Color parsed from Matcher
      • getHSLPatternColor

        public static com.vaadin.shared.ui.colorpicker.Color getHSLPatternColor​(java.util.regex.Matcher matcher)
        Parses Color from matched HSL Matcher.
        Parameters:
        matcher - Matcher matching HSL pattern with named regex groups hue, saturation, and light
        Returns:
        Color parsed from Matcher
      • getHSLAPatternColor

        public static com.vaadin.shared.ui.colorpicker.Color getHSLAPatternColor​(java.util.regex.Matcher matcher)
        Parses Color from matched HSLA Matcher.
        Parameters:
        matcher - Matcher matching HSLA pattern with named regex groups hue, saturation, light, and alpha
        Returns:
        Color parsed from Matcher