Class WebColors

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​int[]>

    public class WebColors
    extends java.util.HashMap<java.lang.String,​int[]>
    This class is a HashMap that contains the names of colors as a key and the corresponding Color as value. (Source: Wikipedia http://en.wikipedia.org/wiki/Web_colors )

    CSS4 Implementation based on: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static WebColors NAMES
      HashMap containing all the names and corresponding color values.
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      WebColors()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int getFromPercent​(java.lang.String v, int max)  
      static java.awt.Color getRGBColor​(java.lang.String name)
      Gives you a Color based on a name.
      private static java.awt.Color getRGBFromHex​(java.lang.String colorName)  
      private static java.awt.Color getRGBFromHSL​(java.lang.String colorName)  
      private static java.awt.Color getRGBFromName​(java.lang.String colorName)  
      private static java.awt.Color getRGBFromRGB​(java.lang.String colorName)  
      private static int[] hsl2rgb​(float hue, float saturation, float lightness)
      Convert from hsl to rgb
      private static float hue2rgb​(float p, float q, float t)  
      private static double toDegrees​(java.lang.String hueString)  
      • Methods inherited from class java.util.HashMap

        clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
    • Field Detail

      • NAMES

        public static final WebColors NAMES
        HashMap containing all the names and corresponding color values.
    • Constructor Detail

      • WebColors

        public WebColors()
    • Method Detail

      • getRGBColor

        public static java.awt.Color getRGBColor​(java.lang.String name)
                                          throws java.lang.IllegalArgumentException
        Gives you a Color based on a name.
        Parameters:
        name - the css color name to convert. You can use CSS4 color values
        • a name such as black, violet, cornflowerblue
        • #RGB, #RRGGBB, #RGBA or #RRGGBBAA
        • rgb(R, G, B) rgb(R,G,B,A) or rgba(R,G,B) or rgba(R,G,B,A)
        • hsl(H, S, L) hsl(H,S,L,A) or hslq(H,S,L) or hsla(H,S,L,A)
        Returns:
        the corresponding Color object
        Throws:
        java.lang.IllegalArgumentException - if the String isn't a know representation of a color.
      • getRGBFromHex

        private static java.awt.Color getRGBFromHex​(java.lang.String colorName)
      • getRGBFromRGB

        private static java.awt.Color getRGBFromRGB​(java.lang.String colorName)
      • getFromPercent

        private static int getFromPercent​(java.lang.String v,
                                          int max)
      • getRGBFromName

        private static java.awt.Color getRGBFromName​(java.lang.String colorName)
      • getRGBFromHSL

        private static java.awt.Color getRGBFromHSL​(java.lang.String colorName)
      • toDegrees

        private static double toDegrees​(java.lang.String hueString)
      • hsl2rgb

        private static int[] hsl2rgb​(float hue,
                                     float saturation,
                                     float lightness)
        Convert from hsl to rgb
        Parameters:
        hue - Hue angle in degrees
        saturation - saturation (0 to 1)
        lightness - lightness (0 to 1)
        Returns:
        int[] rgb
      • hue2rgb

        private static float hue2rgb​(float p,
                                     float q,
                                     float t)