001package com.hfg.html.attribute;
002
003import java.awt.Color;
004import java.util.Collection;
005import java.util.Collections;
006import java.util.Map;
007import java.util.regex.Matcher;
008import java.util.regex.Pattern;
009
010import com.hfg.graphics.ColorUtil;
011import com.hfg.util.CompareUtil;
012import com.hfg.util.StringUtil;
013import com.hfg.util.collection.OrderedMap;
014
015//------------------------------------------------------------------------------
016/**
017 * Standard HTML colors.
018 *
019 * @author J. Alex Taylor, hairyfatguy.com
020 */
021//------------------------------------------------------------------------------
022// com.hfg XML/HTML Coding Library
023//
024// This library is free software; you can redistribute it and/or
025// modify it under the terms of the GNU Lesser General Public
026// License as published by the Free Software Foundation; either
027// version 2.1 of the License, or (at your option) any later version.
028//
029// This library is distributed in the hope that it will be useful,
030// but WITHOUT ANY WARRANTY; without even the implied warranty of
031// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
032// Lesser General Public License for more details.
033//
034// You should have received a copy of the GNU Lesser General Public
035// License along with this library; if not, write to the Free Software
036// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
037//
038// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
039// jataylor@hairyfatguy.com
040//------------------------------------------------------------------------------
041
042public class HTMLColor extends Color implements Comparable
043{
044   private static Map<String, HTMLColor> sStandardColorMap = new OrderedMap<>();
045   private static Map<String, HTMLColor> sStandardColorHexMap = new OrderedMap<>();
046
047   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 250, 250)' >&nbsp;</span> (255, 250, 250) */
048   public static final HTMLColor SNOW              = new HTMLColor("SNOW", 255, 250, 250);
049   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(248, 248, 255)' >&nbsp;</span> (248, 248, 255) */
050   public static final HTMLColor GHOST_WHITE       = new HTMLColor("GHOST_WHITE", 248, 248, 255);
051   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(245, 245, 245)' >&nbsp;</span> (245, 245, 245) */
052   public static final HTMLColor WHITE_SMOKE       = new HTMLColor("WHITE_SMOKE", 245, 245, 245);
053   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(220, 220, 220)' >&nbsp;</span> (220, 220, 220) */
054   public static final HTMLColor GAINSBORO         = new HTMLColor("GAINSBORO", 220, 220, 220);
055   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 250, 240)' >&nbsp;</span> (255, 250, 240) */
056   public static final HTMLColor FLORAL_WHITE      = new HTMLColor("FLORAL_WHITE", 255, 250, 240);
057   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(253, 245, 230)' >&nbsp;</span> (253, 245, 230) */
058   public static final HTMLColor OLD_LACE          = new HTMLColor("OLD_LACE", 253, 245, 230);
059   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(250, 240, 230)' >&nbsp;</span> (250, 240, 230) */
060   public static final HTMLColor LINEN             = new HTMLColor("LINEN", 250, 240, 230);
061   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(250, 235, 215)' >&nbsp;</span> (250, 235, 215) */
062   public static final HTMLColor ANTIQUE_WHITE     = new HTMLColor("ANTIQUE_WHITE", 250, 235, 215);
063   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 239, 213)' >&nbsp;</span> (255, 239, 213) */
064   public static final HTMLColor PAPAYA_WHIP       = new HTMLColor("PAPAYA_WHIP", 255, 239, 213);
065   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 235, 205)' >&nbsp;</span> (255, 235, 205) */
066   public static final HTMLColor BLANCHED_ALMOND   = new HTMLColor("BLANCHED_ALMOND", 255, 235, 205);
067   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 228, 196)' >&nbsp;</span> (255, 228, 196) */
068   public static final HTMLColor BISQUE            = new HTMLColor("BISQUE", 255, 228, 196);
069   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 218, 185)' >&nbsp;</span> (255, 218, 185) */
070   public static final HTMLColor PEACH_PUFF        = new HTMLColor("PEACH_PUFF", 255, 218, 185);
071   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 222, 173)' >&nbsp;</span> (255, 222, 173) */
072   public static final HTMLColor NAVAJO_WHITE      = new HTMLColor("NAVAJO_WHITE", 255, 222, 173);
073   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 228, 181)' >&nbsp;</span> (255, 228, 181) */
074   public static final HTMLColor MOCCASIN          = new HTMLColor("MOCCASIN", 255, 228, 181);
075   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 248, 220)' >&nbsp;</span> (255, 248, 220) */
076   public static final HTMLColor CORNSILK          = new HTMLColor("CORNSILK", 255, 248, 220);
077   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 255, 240)' >&nbsp;</span> (255, 255, 240) */
078   public static final HTMLColor IVORY             = new HTMLColor("IVORY", 255, 255, 240);
079   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 250, 205)' >&nbsp;</span> (255, 250, 205) */
080   public static final HTMLColor LEMON_CHIFFON     = new HTMLColor("LEMON_CHIFFON", 255, 250, 205);
081   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 245, 238)' >&nbsp;</span> (255, 245, 238) */
082   public static final HTMLColor SEASHELL          = new HTMLColor("SEASHELL", 255, 245, 238);
083   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(240, 255, 240)' >&nbsp;</span> (240, 255, 240) */
084   public static final HTMLColor HONEYDEW          = new HTMLColor("HONEYDEW", 240, 255, 240);
085   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(245, 255, 250)' >&nbsp;</span> (245, 255, 250) */
086   public static final HTMLColor MINT_CREAM        = new HTMLColor("MINT_CREAM", 245, 255, 250);
087   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(240, 255, 255)' >&nbsp;</span> (240, 255, 255) */
088   public static final HTMLColor AZURE             = new HTMLColor("AZURE", 240, 255, 255);
089   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(240, 248, 255)' >&nbsp;</span> (240, 248, 255) */
090   public static final HTMLColor ALICE_BLUE        = new HTMLColor("ALICE_BLUE", 240, 248, 255);
091   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(230, 230, 250)' >&nbsp;</span> (230, 230, 250) */
092   public static final HTMLColor LAVENDER          = new HTMLColor("LAVENDER", 230, 230, 250);
093   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 240, 245)' >&nbsp;</span> (255, 240, 245) */
094   public static final HTMLColor LAVENDER_BLUSH    = new HTMLColor("LAVENDER_BLUSH", 255, 240, 245);
095   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 228, 225)' >&nbsp;</span> (255, 228, 225) */
096   public static final HTMLColor MISTY_ROSE        = new HTMLColor("MISTY_ROSE", 255, 228, 225);
097   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 255, 255)' >&nbsp;</span> (255, 255, 255) */
098   public static final HTMLColor WHITE             = new HTMLColor("WHITE", 255, 255, 255);
099   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0,   0,   0)' >&nbsp;</span> (  0,   0,   0) */
100   public static final HTMLColor BLACK             = new HTMLColor("BLACK", 0, 0, 0);
101   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 47,  79,  79)' >&nbsp;</span> ( 47,  79,  79) */
102   public static final HTMLColor DARK_SLATE_GRAY   = new HTMLColor("DARK_SLATE_GRAY", 47, 79, 79);
103   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(105, 105, 105)' >&nbsp;</span> (105, 105, 105) */
104   public static final HTMLColor DIM_GRAY          = new HTMLColor("DIM_GRAY", 105, 105, 105);
105   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(112, 128, 144)' >&nbsp;</span> (112, 128, 144) */
106   public static final HTMLColor SLATE_GRAY        = new HTMLColor("SLATE_GRAY", 112, 128, 144);
107   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(119, 136, 153)' >&nbsp;</span> (119, 136, 153) */
108   public static final HTMLColor LIGHT_SLATE_GRAY  = new HTMLColor("LIGHT_SLATE_GRAY", 119, 136, 153);
109   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(190, 190, 190)' >&nbsp;</span> (190, 190, 190) */
110   public static final HTMLColor GREY              = new HTMLColor("GREY", 190, 190, 190);
111   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(211, 211, 211)' >&nbsp;</span> (211, 211, 211) */
112   public static final HTMLColor LIGHT_GRAY        = new HTMLColor("LIGHT_GRAY", 211, 211, 211);
113   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 25,  25, 112)' >&nbsp;</span> ( 25,  25, 112) */
114   public static final HTMLColor MIDNIGHT_BLUE     = new HTMLColor("MIDNIGHT_BLUE", 25, 25, 112);
115   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0,   0, 125)' >&nbsp;</span> (  0,   0, 125) */
116   public static final HTMLColor NAVY              = new HTMLColor("NAVY", 0, 0, 125);
117   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(100, 149, 237)' >&nbsp;</span> (100, 149, 237) */
118   public static final HTMLColor CORNFLOWER_BLUE   = new HTMLColor("CORNFLOWER_BLUE", 100, 149, 237);
119   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 72,  61, 139)' >&nbsp;</span> ( 72,  61, 139) */
120   public static final HTMLColor DARK_SLATE_BLUE   = new HTMLColor("DARK_SLATE_BLUE", 72, 61, 139);
121   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(106,  90, 205)' >&nbsp;</span> (106,  90, 205) */
122   public static final HTMLColor SLATE_BLUE        = new HTMLColor("SLATE_BLUE", 106, 90, 205);
123   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(123, 104, 238)' >&nbsp;</span> (123, 104, 238) */
124   public static final HTMLColor MEDIUM_SLATE_BLUE = new HTMLColor("MEDIUM_SLATE_BLUE", 123, 104, 238);
125   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(132, 112, 255)' >&nbsp;</span> (132, 112, 255) */
126   public static final HTMLColor LIGHT_SLATE_BLUE  = new HTMLColor("LIGHT_SLATE_BLUE", 132, 112, 255);
127   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0,   0, 205)' >&nbsp;</span> (  0,   0, 205) */
128   public static final HTMLColor MEDIUM_BLUE       = new HTMLColor("MEDIUM_BLUE", 0, 0, 205);
129   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 65, 105, 225)' >&nbsp;</span> ( 65, 105, 225) */
130   public static final HTMLColor ROYAL_BLUE        = new HTMLColor("ROYAL_BLUE", 65, 105, 225);
131   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0,   0, 255)' >&nbsp;</span> (  0,   0, 255) */
132   public static final HTMLColor BLUE              = new HTMLColor("BLUE", 0, 0, 255);
133   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0,   0, 139)' >&nbsp;</span> (  0,   0, 139) */
134   public static final HTMLColor DARK_BLUE         = new HTMLColor("DARK_BLUE", 0, 0, 139);
135   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 30, 144, 255)' >&nbsp;</span> ( 30, 144, 255) */
136   public static final HTMLColor DODGER_BLUE       = new HTMLColor("DODGER_BLUE", 30, 144, 255);
137   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 191, 255)' >&nbsp;</span> (  0, 191, 255) */
138   public static final HTMLColor DEEP_SKY_BLUE     = new HTMLColor("DEEP_SKY_BLUE", 0, 191, 255);
139   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(135, 206, 235)' >&nbsp;</span> (135, 206, 235) */
140   public static final HTMLColor SKY_BLUE          = new HTMLColor("SKY_BLUE", 135, 206, 235);
141   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(135, 206, 250)' >&nbsp;</span> (135, 206, 250) */
142   public static final HTMLColor LIGHT_SKY_BLUE    = new HTMLColor("LIGHT_SKY_BLUE", 135, 206, 250);
143   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 70, 130, 180)' >&nbsp;</span> ( 70, 130, 180) */
144   public static final HTMLColor STEEL_BLUE        = new HTMLColor("STEEL_BLUE", 70, 130, 180);
145   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(176, 196, 222)' >&nbsp;</span> (176, 196, 222) */
146   public static final HTMLColor LIGHT_STEEL_BLUE  = new HTMLColor("LIGHT_STEEL_BLUE", 176, 196, 222);
147   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(173, 216, 230)' >&nbsp;</span> (173, 216, 230) */
148   public static final HTMLColor LIGHT_BLUE        = new HTMLColor("LIGHT_BLUE", 173, 216, 230);
149   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(176, 224, 230)' >&nbsp;</span> (176, 224, 230) */
150   public static final HTMLColor POWDER_BLUE       = new HTMLColor("POWDER_BLUE", 176, 224, 230);
151   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(175, 238, 238)' >&nbsp;</span> (175, 238, 238) */
152   public static final HTMLColor PALE_TURQUOISE    = new HTMLColor("PALE_TURQUOISE", 175, 238, 238);
153   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 206, 209)' >&nbsp;</span> (  0, 206, 209) */
154   public static final HTMLColor DARK_TURQUOISE    = new HTMLColor("DARK_TURQUOISE", 0, 206, 209);
155   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 72, 209, 204)' >&nbsp;</span> ( 72, 209, 204) */
156   public static final HTMLColor MEDIUM_TURQUOISE  = new HTMLColor("MEDIUM_TURQUOISE", 72, 209, 204);
157   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 64, 224, 208)' >&nbsp;</span> ( 64, 224, 208) */
158   public static final HTMLColor TURQUOISE         = new HTMLColor("TURQUOISE", 64, 224, 208);
159   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 255, 255)' >&nbsp;</span> (  0, 255, 255) */
160   public static final HTMLColor CYAN              = new HTMLColor("CYAN", 0, 255, 255);
161   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 139, 139)' >&nbsp;</span> (  0, 139, 139) */
162   public static final HTMLColor DARK_CYAN         = new HTMLColor("DARK_CYAN", 0, 139, 139);
163   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(224, 255, 255)' >&nbsp;</span> (224, 255, 255) */
164   public static final HTMLColor LIGHT_CYAN        = new HTMLColor("LIGHT_CYAN", 224, 255, 255);
165   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 95, 158, 160)' >&nbsp;</span> ( 95, 158, 160) */
166   public static final HTMLColor CADET_BLUE        = new HTMLColor("CADET_BLUE", 95, 158, 160);
167   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(102, 205, 170)' >&nbsp;</span> (102, 205, 170) */
168   public static final HTMLColor MEDIUM_AQUAMARINE = new HTMLColor("MEDIUM_AQUAMARINE", 102, 205, 170);
169   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(127, 255, 212)' >&nbsp;</span> (127, 255, 212) */
170   public static final HTMLColor AQUAMARINE        = new HTMLColor("AQUAMARINE", 127, 255, 212);
171   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 100,   0)' >&nbsp;</span> (  0, 100,   0) */
172   public static final HTMLColor DARK_GREEN        = new HTMLColor("DARK_GREEN", 0, 100, 0);
173   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 85, 107,  47)' >&nbsp;</span> ( 85, 107,  47) */
174   public static final HTMLColor DARK_OLIVE_GREEN  = new HTMLColor("DARK_OLIVE_GREEN", 85, 107, 47);
175   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(143, 188, 143)' >&nbsp;</span> (143, 188, 143) */
176   public static final HTMLColor DARK_SEA_GREEN    = new HTMLColor("DARK_SEA_GREEN", 143, 188, 143);
177   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 46, 139,  87)' >&nbsp;</span> ( 46, 139,  87) */
178   public static final HTMLColor SEA_GREEN         = new HTMLColor("SEA_GREEN", 46, 139, 87);
179   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 60, 179, 113)' >&nbsp;</span> ( 60, 179, 113) */
180   public static final HTMLColor MEDIUM_SEA_GREEN  = new HTMLColor("MEDIUM_SEA_GREEN", 60, 179, 113);
181   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 32, 178, 170)' >&nbsp;</span> ( 32, 178, 170) */
182   public static final HTMLColor LIGHT_SEA_GREEN   = new HTMLColor("LIGHT_SEA_GREEN", 32, 178, 170);
183   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(152, 251, 152)' >&nbsp;</span> (152, 251, 152) */
184   public static final HTMLColor PALE_GREEN        = new HTMLColor("PALE_GREEN", 152, 251, 152);
185   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 255, 127)' >&nbsp;</span> (  0, 255, 127) */
186   public static final HTMLColor SPRING_GREEN      = new HTMLColor("SPRING_GREEN", 0, 255, 127);
187   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(124, 252,   0)' >&nbsp;</span> (124, 252,   0) */
188   public static final HTMLColor LAWN_GREEN        = new HTMLColor("LAWN_GREEN", 124, 252, 0);
189   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 255,   0)' >&nbsp;</span> (  0, 255,   0) */
190   public static final HTMLColor GREEN             = new HTMLColor("GREEN", 0, 255, 0);
191   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(144, 238, 144)' >&nbsp;</span> (144, 238, 144) */
192   public static final HTMLColor LIGHT_GREEN       = new HTMLColor("LIGHT_GREEN", 144, 238, 144);
193   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(127, 255,   0)' >&nbsp;</span> (127, 255,   0) */
194   public static final HTMLColor CHARTREUSE        = new HTMLColor("CHARTREUSE", 127, 255, 0);
195   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(  0, 250, 154)' >&nbsp;</span> (  0, 250, 154) */
196   public static final HTMLColor MED_SPRING_GREEN  = new HTMLColor("MED_SPRING_GREEN", 0, 250, 154);
197   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(173, 255,  47)' >&nbsp;</span> (173, 255,  47) */
198   public static final HTMLColor GREEN_YELLOW      = new HTMLColor("GREEN_YELLOW", 173, 255, 47);
199   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 50, 205,  50)' >&nbsp;</span> ( 50, 205,  50) */
200   public static final HTMLColor LIME_GREEN        = new HTMLColor("LIME_GREEN", 50, 205, 50);
201   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(154, 205,  50)' >&nbsp;</span> (154, 205,  50) */
202   public static final HTMLColor YELLOW_GREEN      = new HTMLColor("YELLOW_GREEN", 154, 205, 50);
203   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb( 34, 139,  34)' >&nbsp;</span> ( 34, 139,  34) */
204   public static final HTMLColor FOREST_GREEN      = new HTMLColor("FOREST_GREEN", 34, 139, 34);
205   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(107, 142,  35)' >&nbsp;</span> (107, 142,  35) */
206   public static final HTMLColor OLIVE_DRAB        = new HTMLColor("OLIVE_DRAB", 107, 142, 35);
207   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(189, 183, 107)' >&nbsp;</span> (189, 183, 107) */
208   public static final HTMLColor DARK_KHAKI        = new HTMLColor("DARK_KHAKI", 189, 183, 107);
209   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(238, 232, 170)' >&nbsp;</span> (238, 232, 170) */
210   public static final HTMLColor PALE_GOLDENROD    = new HTMLColor("PALE_GOLDENROD", 238, 232, 170);
211   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(250, 250, 210)' >&nbsp;</span> (250, 250, 210) */
212   public static final HTMLColor LT_GOLDENROD_YELLOW= new HTMLColor("LT_GOLDENROD_YELLOW", 250, 250, 210);
213   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 255, 224)' >&nbsp;</span> (255, 255, 224) */
214   public static final HTMLColor LIGHT_YELLOW      = new HTMLColor("LIGHT_YELLOW", 255, 255, 224);
215   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 255,   0)' >&nbsp;</span> (255, 255,   0) */
216   public static final HTMLColor YELLOW            = new HTMLColor("YELLOW", 255, 255, 0);
217   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 215,   0)' >&nbsp;</span> (255, 215,   0) */
218   public static final HTMLColor GOLD              = new HTMLColor("GOLD", 255, 215, 0);
219   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(238, 221, 130)' >&nbsp;</span> (238, 221, 130) */
220   public static final HTMLColor LIGHT_GOLDENROD   = new HTMLColor("LIGHT_GOLDENROD", 238, 221, 130);
221   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(218, 165,  32)' >&nbsp;</span> (218, 165,  32) */
222   public static final HTMLColor GOLDENROD         = new HTMLColor("GOLDENROD", 218, 165, 32);
223   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(184, 134,  11)' >&nbsp;</span> (184, 134,  11) */
224   public static final HTMLColor DARK_GOLDENROD    = new HTMLColor("DARK_GOLDENROD", 184, 134, 11);
225   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(188, 143, 143)' >&nbsp;</span> (188, 143, 143) */
226   public static final HTMLColor ROSY_BROWN        = new HTMLColor("ROSY_BROWN", 188, 143, 143);
227   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(205,  92,  92)' >&nbsp;</span> (205,  92,  92) */
228   public static final HTMLColor INDIAN_RED        = new HTMLColor("INDIAN_RED", 205, 92, 92);
229   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(139,  69,  19)' >&nbsp;</span> (139,  69,  19) */
230   public static final HTMLColor SADDLE_BROWN      = new HTMLColor("SADDLE_BROWN", 139, 69, 19);
231   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(160,  82,  45)' >&nbsp;</span> (160,  82,  45) */
232   public static final HTMLColor SIENNA            = new HTMLColor("SIENNA", 160, 82, 45);
233   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(205, 133,  63)' >&nbsp;</span> (205, 133,  63) */
234   public static final HTMLColor PERU              = new HTMLColor("PERU", 205, 133, 63);
235   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(222, 184, 135)' >&nbsp;</span> (222, 184, 135) */
236   public static final HTMLColor BURLYWOOD         = new HTMLColor("BURLYWOOD", 222, 184, 135);
237   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(245, 245, 220)' >&nbsp;</span> (245, 245, 220) */
238   public static final HTMLColor BEIGE             = new HTMLColor("BEIGE", 245, 245, 220);
239   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(245, 222, 179)' >&nbsp;</span> (245, 222, 179) */
240   public static final HTMLColor WHEAT             = new HTMLColor("WHEAT", 245, 222, 179);
241   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(244, 164,  96)' >&nbsp;</span> (244, 164,  96) */
242   public static final HTMLColor SANDY_BROWN       = new HTMLColor("SANDY_BROWN", 244, 164, 96);
243   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(210, 180, 140)' >&nbsp;</span> (210, 180, 140) */
244   public static final HTMLColor TAN               = new HTMLColor("TAN", 210, 180, 140);
245   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(210, 105,  30)' >&nbsp;</span> (210, 105,  30) */
246   public static final HTMLColor CHOCOLATE         = new HTMLColor("CHOCOLATE", 210, 105, 30);
247   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(178,  34,  34)' >&nbsp;</span> (178,  34,  34) */
248   public static final HTMLColor FIREBRICK         = new HTMLColor("FIREBRICK", 178, 34, 34);
249   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(165,  42,  42)' >&nbsp;</span> (165,  42,  42) */
250   public static final HTMLColor BROWN             = new HTMLColor("BROWN", 165, 42, 42);
251   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(233, 150, 122)' >&nbsp;</span> (233, 150, 122) */
252   public static final HTMLColor DARK_SALMON       = new HTMLColor("DARK_SALMON", 233, 150, 122);
253   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(250, 128, 114)' >&nbsp;</span> (250, 128, 114) */
254   public static final HTMLColor SALMON            = new HTMLColor("SALMON", 250, 128, 114);
255   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 160, 122)' >&nbsp;</span> (255, 160, 122) */
256   public static final HTMLColor LIGHT_SALMON      = new HTMLColor("LIGHT_SALMON", 255, 160, 122);
257   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 165,   0)' >&nbsp;</span> (255, 165,   0) */
258   public static final HTMLColor ORANGE            = new HTMLColor("ORANGE", 255, 165, 0);
259   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 140,   0)' >&nbsp;</span> (255, 140,   0) */
260   public static final HTMLColor DARK_ORANGE       = new HTMLColor("DARK_ORANGE", 255, 140, 0);
261   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 127,  80)' >&nbsp;</span> (255, 127,  80) */
262   public static final HTMLColor CORAL             = new HTMLColor("CORAL", 255, 127, 80);
263   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(240, 128, 128)' >&nbsp;</span> (240, 128, 128) */
264   public static final HTMLColor LIGHT_CORAL       = new HTMLColor("LIGHT_CORAL", 240, 128, 128);
265   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255,  99,  71)' >&nbsp;</span> (255,  99,  71) */
266   public static final HTMLColor TOMATO            = new HTMLColor("TOMATO", 255, 99, 71);
267   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255,  69,   0)' >&nbsp;</span> (255,  69,   0) */
268   public static final HTMLColor ORANGE_RED        = new HTMLColor("ORANGE_RED", 255, 69, 0);
269   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255,   0,   0)' >&nbsp;</span> (255,   0,   0) */
270   public static final HTMLColor RED               = new HTMLColor("RED", 255, 0, 0);
271   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(139,   0,   0)' >&nbsp;</span> (139,   0,   0) */
272   public static final HTMLColor DARK_RED          = new HTMLColor("DARK_RED", 139, 0, 0);
273   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 105, 180)' >&nbsp;</span> (255, 105, 180) */
274   public static final HTMLColor HOT_PINK          = new HTMLColor("HOT_PINK", 255, 105, 180);
275   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255,  20, 147)' >&nbsp;</span> (255,  20, 147) */
276   public static final HTMLColor DEEP_PINK         = new HTMLColor("DEEP_PINK", 255, 20, 147);
277   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 192, 203)' >&nbsp;</span> (255, 192, 203) */
278   public static final HTMLColor PINK              = new HTMLColor("PINK", 255, 192, 203);
279   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 182, 193)' >&nbsp;</span> (255, 182, 193) */
280   public static final HTMLColor LIGHT_PINK        = new HTMLColor("LIGHT_PINK", 255, 182, 193);
281   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(219, 112, 147)' >&nbsp;</span> (219, 112, 147) */
282   public static final HTMLColor PALE_VIOLET_RED   = new HTMLColor("PALE_VIOLET_RED", 219, 112, 147);
283   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(176,  48,  96)' >&nbsp;</span> (176,  48,  96) */
284   public static final HTMLColor MAROON            = new HTMLColor("MAROON", 176, 48, 96);
285   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(199,  21, 133)' >&nbsp;</span> (199,  21, 133) */
286   public static final HTMLColor MEDIUM_VIOLET_RED = new HTMLColor("MEDIUM_VIOLET_RED", 199, 21, 133);
287   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(208,  32, 144)' >&nbsp;</span> (208,  32, 144) */
288   public static final HTMLColor VIOLET_RED        = new HTMLColor("VIOLET_RED", 208, 32, 144);
289   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255,   0, 255)' >&nbsp;</span> (255,   0, 255) */
290   public static final HTMLColor MAGENTA           = new HTMLColor("MAGENTA", 255, 0, 255);
291   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(139,   0, 139)' >&nbsp;</span> (139,   0, 139) */
292   public static final HTMLColor DARK_MAGENTA      = new HTMLColor("DARK_MAGENTA", 139, 0, 139);
293   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(238, 130, 238)' >&nbsp;</span> (238, 130, 238) */
294   public static final HTMLColor VIOLET            = new HTMLColor("VIOLET", 238, 130, 238);
295   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(221, 160, 221)' >&nbsp;</span> (221, 160, 221) */
296   public static final HTMLColor PLUM              = new HTMLColor("PLUM", 221, 160, 221);
297   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(218, 112, 214)' >&nbsp;</span> (218, 112, 214) */
298   public static final HTMLColor ORCHID            = new HTMLColor("ORCHID", 218, 112, 214);
299   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(186,  85, 211)' >&nbsp;</span> (186,  85, 211) */
300   public static final HTMLColor MEDIUM_ORCHID     = new HTMLColor("MEDIUM_ORCHID", 186, 85, 211);
301   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(153,  50, 204)' >&nbsp;</span> (153,  50, 204) */
302   public static final HTMLColor DARK_ORCHID       = new HTMLColor("DARK_ORCHID", 153, 50, 204);
303   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(148,   0, 211)' >&nbsp;</span> (148,   0, 211) */
304   public static final HTMLColor DARK_VIOLET       = new HTMLColor("DARK_VIOLET", 148, 0, 211);
305   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(138,  43, 226)' >&nbsp;</span> (138,  43, 226) */
306   public static final HTMLColor BLUE_VIOLET       = new HTMLColor("BLUE_VIOLET", 138, 43, 226);
307   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(160,  32, 240)' >&nbsp;</span> (160,  32, 240) */
308   public static final HTMLColor PURPLE            = new HTMLColor("PURPLE", 160, 32, 240);
309   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(147, 112, 219)' >&nbsp;</span> (147, 112, 219) */
310   public static final HTMLColor MEDIUM_PURPLE     = new HTMLColor("MEDIUM_PURPLE", 147, 112, 219);
311   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(216, 191, 216)' >&nbsp;</span> (216, 191, 216) */
312   public static final HTMLColor THISTLE           = new HTMLColor("THISTLE", 216, 191, 216);
313   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(0, 255, 255)' >&nbsp;</span> (0, 255, 255) */
314   public static final HTMLColor AQUA              = new HTMLColor("AQUA",      0, 255, 255);
315   /** <span style='width:100px; height:1em; display:inline-block; background-color:rgb(255, 0, 255)' >&nbsp;</span> (255, 0, 255) */
316   public static final HTMLColor FUCHSIA           = new HTMLColor("FUCHSIA", 255,   0, 255);
317
318
319   private static Pattern sRGB_Pattern = Pattern.compile("rgb\\(\\s*(\\d+)\\s*,?\\s*(\\d+)\\s*,?\\s*(\\d+)\\s*\\)");
320   private static Pattern sRGBA_Pattern = Pattern.compile("rgba\\(\\s*(\\d+)\\s*,?\\s*(\\d+)\\s*,?\\s*(\\d+)\\s*[,/]\\s*([\\.\\d]+)\\s*\\)");
321
322   private String mName;
323
324   //##########################################################################
325   // CONSTRUCTORS
326   //##########################################################################
327
328   //---------------------------------------------------------------------------
329   private HTMLColor(String inName, int inRed, int inGreen, int inBlue)
330   {
331      this(inName, inRed, inGreen, inBlue, 255);
332   }
333
334   //---------------------------------------------------------------------------
335   private HTMLColor(String inName, int inRed, int inGreen, int inBlue, int inAlpha)
336   {
337      super(inRed, inGreen, inBlue, inAlpha);
338      mName = inName;
339      sStandardColorMap.put(inName, this);
340      sStandardColorHexMap.put(toHex().substring(1), this);
341   }
342
343   //---------------------------------------------------------------------------
344   public HTMLColor(int inRed, int inGreen, int inBlue)
345   {
346      this(inRed, inGreen, inBlue, 255);
347   }
348
349   //---------------------------------------------------------------------------
350   public HTMLColor(int inRed, int inGreen, int inBlue, int inAlpha)
351   {
352      super(inRed, inGreen, inBlue, inAlpha);
353   }
354
355   //---------------------------------------------------------------------------
356   public HTMLColor(Color inColor)
357   {
358      super(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha());
359   }
360
361   //---------------------------------------------------------------------------
362   public HTMLColor(Color inColor, int inAlpha)
363   {
364      super(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inAlpha);
365
366      if (inAlpha < 0
367          || inAlpha > 255)
368      {
369         throw new RuntimeException("The alpha value must be specified as a value in the range of 0 - 255!");
370      }
371   }
372
373   //##########################################################################
374   // PUBLIC METHODS
375   //##########################################################################
376
377   //---------------------------------------------------------------------------
378   /**
379    Returns 134 standard named HTML colors.
380    * @return the set of standard HTML colors
381    */
382   public static Collection<HTMLColor> values()
383   {
384      return Collections.unmodifiableCollection(sStandardColorMap.values());
385   }
386
387   //---------------------------------------------------------------------------
388   /**
389    Turns a string value like 'blue' or a hexadecimal value into an HTMLColor object.
390    * @param inColorString color name or hex value
391    * @return HTMLColor object corresponding to the specified string
392    */
393   public static HTMLColor valueOf(String inColorString)
394   {
395      HTMLColor value = null;
396
397      if (StringUtil.isSet(inColorString)
398          && ! inColorString.equalsIgnoreCase("none")
399          && ! inColorString.equalsIgnoreCase("inherit"))
400      {
401         // See if it is the name of a standard color
402         value = sStandardColorMap.get(inColorString.trim().toUpperCase().replaceAll(" ", "_"));
403         if (null == value)
404         {
405            // Does it look like an RGB specification?
406            Matcher m = sRGB_Pattern.matcher(inColorString.trim());
407            if (m.matches())
408            {
409               int red = Integer.parseInt(m.group(1));
410               int green = Integer.parseInt(m.group(2));
411               int blue = Integer.parseInt(m.group(3));
412               value = new HTMLColor(red, green, blue);
413            }
414            else
415            {
416               // Does it look like an RGBA specification?
417               m = sRGBA_Pattern.matcher(inColorString.trim());
418               if (m.matches())
419               {
420                  int red = Integer.parseInt(m.group(1));
421                  int green = Integer.parseInt(m.group(2));
422                  int blue = Integer.parseInt(m.group(3));
423                  float alpha = Float.parseFloat(m.group(4));
424                  int intAlpha = (alpha == Math.round(alpha) ? (int) alpha : (int) (alpha * 255));
425                  value = new HTMLColor(red, green, blue, intAlpha);
426               }
427               else
428               {
429                  // Does it look like an hex specification?
430                  String potentialHexValue = inColorString.trim().toLowerCase();
431                  if (potentialHexValue.startsWith("#"))
432                  {
433                     potentialHexValue = potentialHexValue.substring(1);
434                  }
435                  else if (potentialHexValue.startsWith("0x"))
436                  {
437                     potentialHexValue = potentialHexValue.substring(2);
438                  }
439
440                  // Handle cases like '900' which expands to '990000'
441                  if (3 == potentialHexValue.length())
442                  {
443                     potentialHexValue = "" + potentialHexValue.charAt(0) + potentialHexValue.charAt(0)
444                                            + potentialHexValue.charAt(1) + potentialHexValue.charAt(1)
445                                            + potentialHexValue.charAt(2) + potentialHexValue.charAt(2);
446                  }
447                  else if (4 == potentialHexValue.length())
448                  {
449                     potentialHexValue = "" + potentialHexValue.charAt(0) + potentialHexValue.charAt(0)
450                                            + potentialHexValue.charAt(1) + potentialHexValue.charAt(1)
451                                            + potentialHexValue.charAt(2) + potentialHexValue.charAt(2)
452                                            + potentialHexValue.charAt(3) + potentialHexValue.charAt(3);
453                  }
454
455
456                  // Handle cases like 'fff00000' that includes alpha
457                  if (8 == potentialHexValue.length())
458                  {
459                     int red   = Integer.parseUnsignedInt(potentialHexValue.substring(0, 2), 16);
460                     int green = Integer.parseUnsignedInt(potentialHexValue.substring(2, 4), 16);
461                     int blue  = Integer.parseUnsignedInt(potentialHexValue.substring(4, 6), 16);
462                     int alpha = Integer.parseUnsignedInt(potentialHexValue.substring(6), 16);
463
464                     if (potentialHexValue.substring(6).equalsIgnoreCase("FF"))
465                     {
466                        // No alpha transparency
467                        potentialHexValue = potentialHexValue.substring(0, 6);
468                     }
469                     else
470                     {
471                        value = new HTMLColor(red, green, blue, alpha);
472                     }
473                  }
474
475                  if (null == value)
476                  {
477                     value = sStandardColorHexMap.get(potentialHexValue);
478                     if (null == value)
479                     {
480                        try
481                        {
482                           value = new HTMLColor(Color.decode("#" + potentialHexValue));
483                        }
484                        catch (Exception e)
485                        {
486                           // Ignore
487                        }
488                     }
489                  }
490               }
491            }
492         }
493      }
494
495      return value;
496   }
497
498   //---------------------------------------------------------------------------
499   /**
500    Turns a Color value into an HTMLColor object.
501    * @param inColor input Color object
502    * @return HTMLColor object corresponding to the specified color
503    */
504   public static HTMLColor valueOf(Color inColor)
505   {
506      HTMLColor value = null;
507
508      if (inColor != null)
509      {
510         String hexString = ColorUtil.colorToHex(inColor);
511         value = sStandardColorHexMap.get(hexString);
512         if (null == value)
513         {
514            try
515            {
516               value = new HTMLColor(Color.decode("#" + hexString));
517            }
518            catch (Exception e)
519            {
520               // Ignore
521            }
522         }
523      }
524
525      return value;
526   }
527
528   //---------------------------------------------------------------------------
529   /**
530    Returns the color's name if one is defined else null.
531    @return name of the HTMLColor
532    */
533   public String name()
534   {
535      return mName;
536   }
537
538   //---------------------------------------------------------------------------
539   /**
540    Returns the hexadecimal code for the color preceded by a '#'.
541    @return the color as a hexadecimal string
542    */
543   @Override
544   public String toString()
545   {
546      return (getAlpha() < 255 ? toRGBA() : toHex());
547   }
548
549   //---------------------------------------------------------------------------
550   /**
551    Returns the hexadecimal code for the color preceded by a '#'.
552    @return the color as a hexadecimal string
553    */
554   public String toHex()
555   {
556      return "#" + ColorUtil.colorToHex(this);
557   }
558
559   //---------------------------------------------------------------------------
560   /**
561    Returns the color as a string formatted like 'rgba(255, 0, 120, 0.5)'.
562    @return the color as an rgba string
563    */
564   public String toRGBA()
565   {
566      return "rgba(" + getRed() + ", " + getGreen() + ", " + getBlue() + ", " + String.format("%.1f", getAlpha()/255f) + ")";
567   }
568
569   //---------------------------------------------------------------------------
570   /**
571    Returns the color's brightness.
572    Color brightness is determined by the following formula:
573    <pre>
574    ((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
575    </pre>
576    @return brightness of the HTMLColor
577    */
578   public int getBrightness()
579   {
580      return getBrightness(this);
581   }
582
583   //---------------------------------------------------------------------------
584   /**
585    Returns the color's brightness.
586    Color brightness is determined by the following formula:
587    <pre>
588    ((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
589    </pre>
590    @param inColor for which to calculate the brightness
591    @return brightness of the specified color
592    */
593   public static int getBrightness(Color inColor)
594   {
595      return ((inColor.getRed() * 299) + (inColor.getGreen() * 587) + (inColor.getBlue() * 114)) / 1000;
596   }
597
598   //---------------------------------------------------------------------------
599   /**
600    Returns BLACK or WHITE depending on which has the higher contrast. Useful for
601    selecting the best foreground color for text.
602    @return best contrasting color for the HTMLColor
603    */
604   public HTMLColor getContrastingColor()
605   {
606      return getContrastingColor(this);
607   }
608
609   //---------------------------------------------------------------------------
610   /**
611    Returns BLACK or WHITE depending on which has the higher contrast.
612    @param inColor for which to calculate the best contrasting color
613    @return best contrasting color for the specified Color
614    */
615   public static HTMLColor getContrastingColor(Color inColor)
616   {
617      int brightness = getBrightness(inColor);
618      if (Math.abs(brightness - WHITE.getBrightness()) > Math.abs(brightness - BLACK.getBrightness()))
619      {
620         return WHITE;
621      }
622
623      return BLACK;
624   }
625
626   //---------------------------------------------------------------------------
627   @Override
628   public int compareTo(Object inObj2)
629   {
630      int result = -1;
631
632      if (inObj2 != null
633            && inObj2 instanceof Color)
634      {
635         Color color2 = (Color) inObj2;
636
637         result = CompareUtil.compare(getRed(), color2.getRed());
638         if(0 == result)
639         {
640            result = CompareUtil.compare(getGreen(), color2.getGreen());
641         }
642
643         if(0 == result)
644         {
645            result = CompareUtil.compare(getBlue(), color2.getBlue());
646         }
647
648         if(0 == result)
649         {
650            result = CompareUtil.compare(getAlpha(), color2.getAlpha());
651         }
652      }
653
654      return result;
655   }
656}