       1 /*
       2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
       3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4  *
       5  * This code is free software; you can redistribute it and/or modify it
       6  * under the terms of the GNU General Public License version 2 only, as
       7  * published by the Free Software Foundation.  Oracle designates this
       8  * particular file as subject to the "Classpath" exception as provided
       9  * by Oracle in the LICENSE file that accompanied this code.
      10  *
      11  * This code is distributed in the hope that it will be useful, but WITHOUT
      12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  * version 2 for more details (a copy is included in the LICENSE file that
      15  * accompanied this code).
      16  *
      17  * You should have received a copy of the GNU General Public License version
      18  * 2 along with this work; if not, write to the Free Software Foundation,
      19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      20  *
      21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      22  * or visit www.oracle.com if you need additional information or have any
      23  * questions.
      24  */
      25
      26 package javafx.scene.paint;
      27
      28 import javafx.animation.Interpolatable;
      29 import java.util.HashMap;
      30 import java.util.Locale;
      31 import java.util.Map;
      32 import com.sun.javafx.Utils;
      33 import com.sun.javafx.beans.annotations.Default;
      34 import com.sun.javafx.tk.Toolkit;
      35
      36 // NOTE: this definition, while correct, contains a lot of information which
      37 // is irrelevant to most developers. We should get to the basic definition and
      38 // usage patterns sooner.
      39
      40 /**
      41  * The Color class is used to encapsulate colors in the default sRGB color space.
      42  * Every color has an implicit alpha value of 1.0 or an explicit one provided
      43  * in the constructor. The alpha value defines the transparency of a color
      44  * and can be  represented by a double value in the range 0.0-1.0 or 0-255.
      45  * An alpha value of 1.0 or 255 means that the color is completely opaque
      46  * and an alpha value of 0 or 0.0 means that the color is completely transparent.
      47  * When constructing a {@code Color} with an explicit alpha or getting
      48  * the color/alpha components of a Color,
      49  * the color components are never premultiplied by the alpha component.
      50  * </p>
      51  *
      52  * <p>{@code Color}s can be created with the constructor or with one of several
      53  * utility methods.  The following lines of code all create the same
      54  * blue color:</p>
      55  *
      56  * <pre><code>
      57  * Color c = Color.BLUE;   //use the blue constant
      58  * Color c = new Color(0,0,1,1.0); // standard constructor, use 0->1.0 values, explicit alpha of 1.0
      59  *
      60  * Color c = Color.color(0,0,1.0); //use 0->1.0 values. implicit alpha of 1.0
      61  * Color c = Color.color(0,0,1.0,1.0); //use 0->1.0 values, explicit alpha of 1.0
      62  *
      63  * Color c = Color.rgb(0,0,255); //use 0->255 integers, implicit alpha of 1.0
      64  * Color c = Color.rgb(0,0,255,1.0); //use 0->255 integers, explicit alpha of 1.0
      65  *
      66  * Color c = Color.hsb(270,1.0,1.0); //hue = 270, saturation & value = 1.0. inplicit alpha of 1.0
      67  * Color c = Color.hsb(270,1.0,1.0,1.0); //hue = 270, saturation & value = 1.0, explicit alpha of 1.0
      68  *
      69  * Color c = Color.web("0x0000FF",1.0);// blue as a hex web value, explicit alpha
      70  * Color c = Color.web("0x0000FF");// blue as a hex web value, implicit alpha
      71  * Color c = Color.web("0x00F");// blue as a short hex web value, implicit alpha
      72  * Color c = Color.web("#0000FF",1.0);// blue as a hex web value, explicit alpha
      73  * Color c = Color.web("#0000FF");// blue as a hex web value, implicit alpha
      74  * Color c = Color.web("#00F");// blue as a short hex web value, implicit alpha
      75  * Color c = Color.web("0000FF",1.0);// blue as a hex web value, explicit alpha
      76  * Color c = Color.web("0000FF");// blue as a hex web value, implicit alpha
      77  * Color c = Color.web("00F");// blue as a short hex web value, implicit alpha
      78  * Color c = Color.web("rgba(0,0,255,1.0)");// blue as an rgb web value, explicit alpha
      79  * Color c = Color.web("rgb(0,0,255)");// blue as an rgb web value, implicit alpha
      80  * Color c = Color.web("rgba(0,0,100%,1.0)");// blue as an rgb percent web value, explicit alpha
      81  * Color c = Color.web("rgb(0,0,100%)");// blue as an rgb percent web value, implicit alpha
      82  * Color c = Color.web("hsla(270,100%,100%,1.0)");// blue as an hsl web value, explicit alpha
      83  * Color c = Color.web("hsl(270,100%,100%)");// blue as an hsl web value, implicit alpha
      84  * </code></pre>
      85  *
      86  * <p>
      87  * The creation of a {@code Color} will throw {@code IllegalArgumentException} if any
      88  * of the values are out of range.
      89  * </p>
      90  *
      91  * <p>
      92  * For example:
      93  * <pre><code>
      94  * Rectangle rec1 = new Rectangle(5, 5, 50, 40);
      95  * rec1.setFill(Color.RED);
      96  * rec1.setStroke(Color.GREEN);
      97  * rec1.setStrokeWidth(3);
      98  *
      99  * Rectangle rec2 = new Rectangle(65, 5, 50, 40);
     100  * rec2.setFill(Color.rgb(91, 127, 255));
     101  * rec2.setStroke(Color.hsb(40, 0.7, 0.8));
     102  * rec2.setStrokeWidth(3);
     103  * </code></pre>
     104  * </p>
     105  * @since JavaFX 2.0
     106  */
     107 public final class Color extends Paint implements Interpolatable<Color> {
     108
     109     /**
     110      * Brightness change factor for darker() and brighter() methods.
     111      */
     112     private static final double DARKER_BRIGHTER_FACTOR = 0.7;
     113
     114     /**
     115      * Saturation change factor for saturate() and desaturate() methods.
     116      */
     117     private static final double SATURATE_DESATURATE_FACTOR = 0.7;
     118
     119     /**
     120      * Creates an sRGB color with the specified red, green and blue values
     121      * in the range {@code 0.0-1.0}, and a given opacity.
     122      *
     123      * @param red the red component, in the range {@code 0.0-1.0}
     124      * @param green the green component, in the range {@code 0.0-1.0}
     125      * @param blue the blue component, in the range {@code 0.0-1.0}
     126      * @param opacity the opacity component, in the range {@code 0.0-1.0}
     127      * @return the {@code Color}
     128      * @throws IllegalArgumentException if any value is out of range
     129      */
     130     public static Color color(double red, double green, double blue, @Default("1") double opacity) {
     131         return new Color(red, green, blue, opacity);
     132     }
     133
     134     /**
     135      * Creates an opaque sRGB color with the specified red, green and blue values
     136      * in the range {@code 0.0-1.0}.
     137      *
     138      * @param red the red component, in the range {@code 0.0-1.0}
     139      * @param green the green component, in the range {@code 0.0-1.0}
     140      * @param blue the blue component, in the range {@code 0.0-1.0}
     141      * @return the {@code Color}
     142      * @throws IllegalArgumentException if any value is out of range
     143      */
     144     public static Color color(double red, double green, double blue) {
     145         return new Color(red, green, blue, 1);
     146     }
     147
     148     /**
     149      * Creates an sRGB color with the specified RGB values in the range {@code 0-255},
     150      * and a given opacity.
     151      *
     152      * @param red the red component, in the range {@code 0-255}
     153      * @param green the green component, in the range {@code 0-255}
     154      * @param blue the blue component, in the range {@code 0-255}
     155      * @param opacity the opacity component, in the range {@code 0.0-1.0}
     156      * @return the {@code Color}
     157      * @throws IllegalArgumentException if any value is out of range
     158      */
     159     public static Color rgb(int red, int green, int blue, double opacity) {
     160         checkRGB(red, green, blue);
     161         return new Color(
     162             red / 255.0,
     163             green / 255.0,
     164             blue / 255.0,
     165             opacity);
     166     }
     167
     168     /**
     169      * Creates an opaque sRGB color with the specified RGB values in the range {@code 0-255}.
     170      *
     171      * @param red the red component, in the range {@code 0-255}
     172      * @param green the green component, in the range {@code 0-255}
     173      * @param blue the blue component, in the range {@code 0-255}
     174      * @return the {@code Color}
     175      * @throws IllegalArgumentException if any value is out of range
     176      */
     177     public static Color rgb(int red, int green, int blue) {
     178         checkRGB(red, green, blue);
     179         return new Color(
     180             red / 255.0,
     181             green / 255.0,
     182             blue / 255.0,
     183             1.0);
     184     }
     185
     186
     187     /**
     188      * This is a shortcut for {@code rgb(gray, gray, gray)}.
     189      */
     190     public static Color grayRgb(int gray) {
     191         return rgb(gray, gray, gray);
     192     }
     193
     194     /**
     195      * This is a shortcut for {@code rgb(gray, gray, gray, opacity)}.
     196      */
     197     public static Color grayRgb(int gray, double opacity) {
     198         return rgb(gray, gray, gray, opacity);
     199     }
     200
     201     /**
     202      * Creates a grey color.
     203      * @param gray color on gray scale in the range
     204      *             {@code 0.0} (black) - {@code 1.0} (white).
     205      * @param opacity the opacity component, in the range {@code 0.0-1.0}
     206      * @return the {@code Color}
     207      * @throws IllegalArgumentException if any value is out of range
     208      */
     209     public static Color gray(double gray, double opacity) {
     210         return new Color(gray, gray, gray, opacity);
     211     }
     212
     213     /**
     214      * Creates an opaque grey color.
     215      * @param gray color on gray scale in the range
     216      *             {@code 0.0} (black) - {@code 1.0} (white).
     217      * @return the {@code Color}
     218      * @throws IllegalArgumentException if any value is out of range
     219      */
     220     public static Color gray(double gray) {
     221         return gray(gray, 1.0);
     222     }
     223
     224     private static void checkRGB(int red, int green, int blue) {
     225         if (red < 0 || red > 255) {
     226             throw new IllegalArgumentException("Color.rgb's red parameter (" + red + ") expects color values 0-255");
     227         }
     228         if (green < 0 || green > 255) {
     229             throw new IllegalArgumentException("Color.rgb's green parameter (" + green + ") expects color values 0-255");
     230         }
     231         if (blue < 0 || blue > 255) {
     232             throw new IllegalArgumentException("Color.rgb's blue parameter (" + blue + ") expects color values 0-255");
     233         }
     234     }
     235
     236     /**
     237      * Creates a {@code Color} based on the specified values in the HSB color model,
     238      * and a given opacity.
     239      *
     240      * @param hue the hue, in degrees
     241      * @param saturation the saturation, {@code 0.0 to 1.0}
     242      * @param brightness the brightness, {@code 0.0 to 1.0}
     243      * @param opacity the opacity, {@code 0.0 to 1.0}
     244      * @return the {@code Color}
     245      * @throws IllegalArgumentException if {@code saturation}, {@code brightness} or
     246      *         {@code opacity} are out of range
     247      */
     248     public static Color hsb(double hue, double saturation, double brightness, double opacity) {
     249         checkSB(saturation, brightness);
     250         double[] rgb = Utils.HSBtoRGB(hue, saturation, brightness);
     251         Color result = new Color(rgb[0], rgb[1], rgb[2], opacity);
     252         return result;
     253     }
     254
     255     /**
     256      * Creates an opaque {@code Color} based on the specified values in the HSB color model.
     257      *
     258      * @param hue the hue, in degrees
     259      * @param saturation the saturation, {@code 0.0 to 1.0}
     260      * @param brightness the brightness, {@code 0.0 to 1.0}
     261      * @return the {@code Color}
     262      * @throws IllegalArgumentException if {@code saturation} or {@code brightness} are
     263      *         out of range
     264      */
     265     public static Color hsb(double hue, double saturation, double brightness) {
     266         return hsb(hue, saturation, brightness, 1.0);
     267     }
     268
     269     private static void checkSB(double saturation, double brightness) {
     270         if (saturation < 0.0 || saturation > 1.0) {
     271             throw new IllegalArgumentException("Color.hsb's saturation parameter (" + saturation + ") expects values 0.0-1.0");
     272         }
     273         if (brightness < 0.0 || brightness > 1.0) {
     274             throw new IllegalArgumentException("Color.hsb's brightness parameter (" + brightness + ") expects values 0.0-1.0");
     275         }
     276     }
     277
     278     /**
     279      * Creates an RGB color specified with an HTML or CSS attribute string.
     280      *
     281      * <p>
     282      * This method supports the following formats:
     283      * <ul>
     284      * <li>Any standard HTML color name
     285      * <li>An HTML long or short format hex string with an optional hex alpha
     286      * channel.
     287      * Hexadecimal values may be preceded by either {@code "0x"} or {@code "#"}
     288      * and can either be 2 digits in the range {@code 00} to {@code 0xFF} or a
     289      * single digit in the range {@code 0} to {@code F}.
     290      * <li>An {@code rgb(r,g,b)} or {@code rgba(r,g,b,a)} format string.
     291      * Each of the {@code r}, {@code g}, or {@code b} values can be an integer
     292      * from 0 to 255 or a floating point percentage value from 0.0 to 100.0
     293      * followed by the percent ({@code %}) character.
     294      * The alpha component, if present, is a
     295      * floating point value from 0.0 to 1.0.  Spaces are allowed before or
     296      * after the numbers and between the percentage number and its percent
     297      * sign ({@code %}).
     298      * <li>An {@code hsl(h,s,l)} or {@code hsla(h,s,l,a)} format string.
     299      * The {@code h} value is a floating point number from 0.0 to 360.0
     300      * representing the hue angle on a color wheel in degrees with
     301      * {@code 0.0} or {@code 360.0} representing red, {@code 120.0}
     302      * representing green, and {@code 240.0} representing blue.  The
     303      * {@code s} value is the saturation of the desired color represented
     304      * as a floating point percentage from gray ({@code 0.0}) to
     305      * the fully saturated color ({@code 100.0}) and the {@code l} value
     306      * is the desired lightness or brightness of the desired color represented
     307      * as a floating point percentage from black ({@code 0.0}) to the full
     308      * brightness of the color ({@code 100.0}).
     309      * The alpha component, if present, is a floating
     310      * point value from 0.0 to 1.0.  Spaces are allowed before or
     311      * after the numbers and between the percentage number and its percent
     312      * sign ({@code %}).
     313      * </ul>
     314      *
     315      * <p>For formats without an alpha component and for named colors, opacity
     316      * is set according to the {@code opacity} argument. For colors specified
     317      * with an alpha component, the resulting opacity is a combination of the
     318      * parsed alpha component and the {@code opacity} argument, so a
     319      * transparent color becomes more transparent by specifying opacity.</p>
     320      *
     321      * <p>Examples:</p>
     322      * <div class="classUseContainer">
     323      * <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0">
     324      * <tr>
     325      * <th class="colFirst">Web Format String</th>
     326      * <th class="colLast">Equivalent constructor or factory call</th>
     327      * </tr>
     328      * <tr class="rowColor">
     329      * <td class="colFirst"><code>Color.web("orange", 0.5);</code></td>
     330      * <td class="colLast"><code>new Color(1.0, 0xA5/255.0, 0.0, 0.5)</code></td>
     331      * </tr>
     332      * <tr class="altColor">
     333      * <td class="colFirst"><code>Color.web("0xff66cc33", 0.5);</code></td>
     334      * <td class="colLast"><code>new Color(1.0, 0.4, 0.8, 0.1)</code></td>
     335      * </tr>
     336      * <tr class="rowColor">
     337      * <td class="colFirst"><code>Color.web("0xff66cc", 0.5);</code></td>
     338      * <td class="colLast"><code>new Color(1.0, 0.4, 0.8, 0.5)</code></td>
     339      * </tr>
     340      * <tr class="altColor">
     341      * <td class="colFirst"><code>Color.web("#ff66cc", 0.5);</code></td>
     342      * <td class="colLast"><code>new Color(1.0, 0.4, 0.8, 0.5)</code></td>
     343      * </tr>
     344      * <tr class="rowColor">
     345      * <td class="colFirst"><code>Color.web("#f68", 0.5);</code></td>
     346      * <td class="colLast"><code>new Color(1.0, 0.4, 0.8, 0.5)</code></td>
     347      * </tr>
     348      * <tr class="altColor">
     349      * <td class="colFirst"><code>Color.web("rgb(255,102,204)", 0.5);</code></td>
     350      * <td class="colLast"><code>new Color(1.0, 0.4, 0.8, 0.5)</code></td>
     351      * </tr>
     352      * <tr class="rowColor">
     353      * <td class="colFirst"><code>Color.web("rgb(100%,50%,50%)", 0.5);</code></td>
     354      * <td class="colLast"><code>new Color(1.0, 0.5, 0.5, 0.5)</code></td>
     355      * </tr>
     356      * <tr class="altColor">
     357      * <td class="colFirst"><code>Color.web("rgb(255,50%,50%,0.25)", 0.5);</code></td>
     358      * <td class="colLast"><code>new Color(1.0, 0.5, 0.5, 0.125)</code></td>
     359      * </tr>
     360      * <tr class="rowColor">
     361      * <td class="colFirst"><code>Color.web("hsl(240,100%,100%)", 0.5);</code></td>
     362      * <td class="colLast"><code>Color.hsb(240.0, 1.0, 1.0, 0.5)</code></td>
     363      * </tr>
     364      * <tr class="altColor">
     365      * <td style="border-bottom:1px solid" class="colFirst">
     366      *     <code>Color.web("hsla(120,0%,0%,0.25)", 0.5);</code>
     367      * </td>
     368      * <td style="border-bottom:1px solid" class="colLast">
     369      *     <code>Color.hsb(120.0, 0.0, 0.0, 0.125)</code>
     370      * </td>
     371      * </tr>
     372      * </table>
     373      * </div>
     374      *
     375      * @param colorString the name or numeric representation of the color
     376      *                    in one of the supported formats
     377      * @param opacity the opacity component in range from 0.0 (transparent)
     378      *                to 1.0 (opaque)
     379      * @throws NullPointerException if {@code colorString} is {@code null}
     380      * @throws IllegalArgumentException if {@code colorString} specifies
     381      *      an unsupported color name or contains an illegal numeric value
     382      */
     383     public static Color web(String colorString, double opacity) {
     384         if (colorString == null) {
     385             throw new NullPointerException(
     386                     "The color components or name must be specified");
     387         }
     388         if (colorString.isEmpty()) {
     389             throw new IllegalArgumentException("Invalid color specification");
     390         }
     391
     392         String color = colorString.toLowerCase(Locale.ROOT);
     393
     394         if (color.startsWith("#")) {
     395             color = color.substring(1);
     396         } else if (color.startsWith("0x")) {
     397             color = color.substring(2);
     398         } else if (color.startsWith("rgb")) {
     399             if (color.startsWith("(", 3)) {
     400                 return parseRGBColor(color, 4, false, opacity);
     401             } else if (color.startsWith("a(", 3)) {
     402                 return parseRGBColor(color, 5, true, opacity);
     403             }
     404         } else if (color.startsWith("hsl")) {
     405             if (color.startsWith("(", 3)) {
     406                 return parseHSLColor(color, 4, false, opacity);
     407             } else if (color.startsWith("a(", 3)) {
     408                 return parseHSLColor(color, 5, true, opacity);
     409             }
     410         } else {
     411             Color col = NamedColors.get(color);
     412             if (col != null) {
     413                 if (opacity == 1.0) {
     414                     return col;
     415                 } else {
     416                     return Color.color(col.red, col.green, col.blue, opacity);
     417                 }
     418             }
     419         }
     420
     421         int len = color.length();
     422
     423         try {
     424             int r;
     425             int g;
     426             int b;
     427             int a;
     428
     429             if (len == 3) {
     430                 r = Integer.parseInt(color.substring(0, 1), 16);
     431                 g = Integer.parseInt(color.substring(1, 2), 16);
     432                 b = Integer.parseInt(color.substring(2, 3), 16);
     433                 return Color.color(r / 15.0, g / 15.0, b / 15.0, opacity);
     434             } else if (len == 4) {
     435                 r = Integer.parseInt(color.substring(0, 1), 16);
     436                 g = Integer.parseInt(color.substring(1, 2), 16);
     437                 b = Integer.parseInt(color.substring(2, 3), 16);
     438                 a = Integer.parseInt(color.substring(3, 4), 16);
     439                 return Color.color(r / 15.0, g / 15.0, b / 15.0,
     440                         opacity * a / 15.0);
     441             } else if (len == 6) {
     442                 r = Integer.parseInt(color.substring(0, 2), 16);
     443                 g = Integer.parseInt(color.substring(2, 4), 16);
     444                 b = Integer.parseInt(color.substring(4, 6), 16);
     445                 return Color.rgb(r, g, b, opacity);
     446             } else if (len == 8) {
     447                 r = Integer.parseInt(color.substring(0, 2), 16);
     448                 g = Integer.parseInt(color.substring(2, 4), 16);
     449                 b = Integer.parseInt(color.substring(4, 6), 16);
     450                 a = Integer.parseInt(color.substring(6, 8), 16);
     451                 return Color.rgb(r, g, b, opacity * a / 255.0);
     452             }
     453         } catch (NumberFormatException nfe) {}
     454
     455         throw new IllegalArgumentException("Invalid color specification");
     456     }
     457
     458     private static Color parseRGBColor(String color, int roff,
     459                                        boolean hasAlpha, double a)
     460     {
     461         try {
     462             int rend = color.indexOf(',', roff);
     463             int gend = rend < 0 ? -1 : color.indexOf(',', rend+1);
     464             int bend = gend < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', gend+1);
     465             int aend = hasAlpha ? (bend < 0 ? -1 : color.indexOf(')', bend+1)) : bend;
     466             if (aend >= 0) {
     467                 double r = parseComponent(color, roff, rend, PARSE_COMPONENT);
     468                 double g = parseComponent(color, rend+1, gend, PARSE_COMPONENT);
     469                 double b = parseComponent(color, gend+1, bend, PARSE_COMPONENT);
     470                 if (hasAlpha) {
     471                     a *= parseComponent(color, bend+1, aend, PARSE_ALPHA);
     472                 }
     473                 return new Color(r, g, b, a);
     474             }
     475         } catch (NumberFormatException nfe) {}
     476
     477         throw new IllegalArgumentException("Invalid color specification");
     478     }
     479
     480     private static Color parseHSLColor(String color, int hoff,
     481                                        boolean hasAlpha, double a)
     482     {
     483         try {
     484             int hend = color.indexOf(',', hoff);
     485             int send = hend < 0 ? -1 : color.indexOf(',', hend+1);
     486             int lend = send < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', send+1);
     487             int aend = hasAlpha ? (lend < 0 ? -1 : color.indexOf(')', lend+1)) : lend;
     488             if (aend >= 0) {
     489                 double h = parseComponent(color, hoff, hend, PARSE_ANGLE);
     490                 double s = parseComponent(color, hend+1, send, PARSE_PERCENT);
     491                 double l = parseComponent(color, send+1, lend, PARSE_PERCENT);
     492                 if (hasAlpha) {
     493                     a *= parseComponent(color, lend+1, aend, PARSE_ALPHA);
     494                 }
     495                 return Color.hsb(h, s, l, a);
     496             }
     497         } catch (NumberFormatException nfe) {}
     498
     499         throw new IllegalArgumentException("Invalid color specification");
     500     }
     501
     502     private static final int PARSE_COMPONENT = 0; // percent, or clamped to [0,255] => [0,1]
     503     private static final int PARSE_PERCENT = 1; // clamped to [0,100]% => [0,1]
     504     private static final int PARSE_ANGLE = 2; // clamped to [0,360]
     505     private static final int PARSE_ALPHA = 3; // clamped to [0.0,1.0]
     506     private static double parseComponent(String color, int off, int end, int type) {
     507         color = color.substring(off, end).trim();
     508         if (color.endsWith("%")) {
     509             if (type > PARSE_PERCENT) {
     510                 throw new IllegalArgumentException("Invalid color specification");
     511             }
     512             type = PARSE_PERCENT;
     513             color = color.substring(0, color.length()-1).trim();
     514         } else if (type == PARSE_PERCENT) {
     515             throw new IllegalArgumentException("Invalid color specification");
     516         }
     517         double c = ((type == PARSE_COMPONENT)
     518                     ? Integer.parseInt(color)
     519                     : Double.parseDouble(color));
     520         switch (type) {
     521             case PARSE_ALPHA:
     522                 return (c < 0.0) ? 0.0 : ((c > 1.0) ? 1.0 : c);
     523             case PARSE_PERCENT:
     524                 return (c <= 0.0) ? 0.0 : ((c >= 100.0) ? 1.0 : (c / 100.0));
     525             case PARSE_COMPONENT:
     526                 return (c <= 0.0) ? 0.0 : ((c >= 255.0) ? 1.0 : (c / 255.0));
     527             case PARSE_ANGLE:
     528                 return ((c < 0.0)
     529                         ? ((c % 360.0) + 360.0)
     530                         : ((c > 360.0)
     531                             ? (c % 360.0)
     532                             : c));
     533         }
     534
     535         throw new IllegalArgumentException("Invalid color specification");
     536     }
     537
     538     /**
     539      * Creates an RGB color specified with an HTML or CSS attribute string.
     540      *
     541      * <p>
     542      * This method supports the following formats:
     543      * <ul>
     544      * <li>Any standard HTML color name
     545      * <li>An HTML long or short format hex string with an optional hex alpha
     546      * channel.
     547      * Hexadecimal values may be preceded by either {@code "0x"} or {@code "#"}
     548      * and can either be 2 digits in the range {@code 00} to {@code 0xFF} or a
     549      * single digit in the range {@code 0} to {@code F}.
     550      * <li>An {@code rgb(r,g,b)} or {@code rgba(r,g,b,a)} format string.
     551      * Each of the {@code r}, {@code g}, or {@code b} values can be an integer
     552      * from 0 to 255 or a floating point percentage value from 0.0 to 100.0
     553      * followed by the percent ({@code %}) character.
     554      * The alpha component, if present, is a
     555      * floating point value from 0.0 to 1.0.  Spaces are allowed before or
     556      * after the numbers and between the percentage number and its percent
     557      * sign ({@code %}).
     558      * <li>An {@code hsl(h,s,l)} or {@code hsla(h,s,l,a)} format string.
     559      * The {@code h} value is a floating point number from 0.0 to 360.0
     560      * representing the hue angle on a color wheel in degrees with
     561      * {@code 0.0} or {@code 360.0} representing red, {@code 120.0}
     562      * representing green, and {@code 240.0} representing blue.  The
     563      * {@code s} value is the saturation of the desired color represented
     564      * as a floating point percentage from gray ({@code 0.0}) to
     565      * the fully saturated color ({@code 100.0}) and the {@code l} value
     566      * is the desired lightness or brightness of the desired color represented
     567      * as a floating point percentage from black ({@code 0.0}) to the full
     568      * brightness of the color ({@code 100.0}).
     569      * The alpha component, if present, is a floating
     570      * point value from 0.0 to 1.0.  Spaces are allowed before or
     571      * after the numbers and between the percentage number and its percent
     572      * sign ({@code %}).
     573      * </ul>
     574      *
     575      * <p>Examples:</p>
     576      * <div class="classUseContainer">
     577      * <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0">
     578      * <tr>
     579      * <th class="colFirst">Web Format String</th>
     580      * <th class="colLast">Equivalent constant or factory call</th>
     581      * </tr>
     582      * <tr class="rowColor">
     583      * <td class="colFirst"><code>Color.web("orange");</code></td>
     584      * <td class="colLast"><code>Color.ORANGE</code></td>
     585      * </tr>
     586      * <tr class="altColor">
     587      * <td class="colFirst"><code>Color.web("0xff668840");</code></td>
     588      * <td class="colLast"><code>Color.rgb(255, 102, 136, 0.25)</code></td>
     589      * </tr>
     590      * <tr class="rowColor">
     591      * <td class="colFirst"><code>Color.web("0xff6688");</code></td>
     592      * <td class="colLast"><code>Color.rgb(255, 102, 136, 1.0)</code></td>
     593      * </tr>
     594      * <tr class="altColor">
     595      * <td class="colFirst"><code>Color.web("#ff6688");</code></td>
     596      * <td class="colLast"><code>Color.rgb(255, 102, 136, 1.0)</code></td>
     597      * </tr>
     598      * <tr class="rowColor">
     599      * <td class="colFirst"><code>Color.web("#f68");</code></td>
     600      * <td class="colLast"><code>Color.rgb(255, 102, 136, 1.0)</code></td>
     601      * </tr>
     602      * <tr class="altColor">
     603      * <td class="colFirst"><code>Color.web("rgb(255,102,136)");</code></td>
     604      * <td class="colLast"><code>Color.rgb(255, 102, 136, 1.0)</code></td>
     605      * </tr>
     606      * <tr class="rowColor">
     607      * <td class="colFirst"><code>Color.web("rgb(100%,50%,50%)");</code></td>
     608      * <td class="colLast"><code>Color.rgb(255, 128, 128, 1.0)</code></td>
     609      * </tr>
     610      * <tr class="altColor">
     611      * <td class="colFirst"><code>Color.web("rgb(255,50%,50%,0.25)");</code></td>
     612      * <td class="colLast"><code>Color.rgb(255, 128, 128, 0.25)</code></td>
     613      * </tr>
     614      * <tr class="rowColor">
     615      * <td class="colFirst"><code>Color.web("hsl(240,100%,100%)");</code></td>
     616      * <td class="colLast"><code>Color.hsb(240.0, 1.0, 1.0, 1.0)</code></td>
     617      * </tr>
     618      * <tr class="altColor">
     619      * <td style="border-bottom:1px solid" class="colFirst">
     620      *     <code>Color.web("hsla(120,0%,0%,0.25)");</code>
     621      * </td>
     622      * <td style="border-bottom:1px solid" class="colLast">
     623      *     <code>Color.hsb(120.0, 0.0, 0.0, 0.25)</code>
     624      * </td>
     625      * </tr>
     626      * </table>
     627      * </div>
     628      *
     629      * @param colorString the name or numeric representation of the color
     630      *                    in one of the supported formats
     631      * @throws NullPointerException if {@code colorString} is {@code null}
     632      * @throws IllegalArgumentException if {@code colorString} specifies
     633      *      an unsupported color name or contains an illegal numeric value
     634      */
     635     public static Color web(String colorString) {
     636         return web(colorString, 1.0);
     637     }
     638
     639     /**
     640      * Creates a color value from a string representation. The format
     641      * of the string representation is the same as in {@link #web(String)}.
     642      *
     643      * @param value the string to convert
     644      * @throws NullPointerException if the {@code value} is {@code null}
     645      * @throws IllegalArgumentException if the {@code value} specifies
     646      *      an unsupported color name or illegal hexadecimal value
     647      * @return a {@code Color} object holding the value represented
     648      * by the string argument
     649      * @see #web(String)
     650      * @since JavaFX 2.1
     651      */
     652     public static Color valueOf(String value) {
     653         if (value == null) {
     654             throw new NullPointerException("color must be specified");
     655         }
     656
     657         return web(value);
     658     }
     659
     660     private static int to32BitInteger(int red, int green, int blue, int alpha) {
     661         int i = red;
     662         i = i << 8;
     663         i = i | green;
     664         i = i << 8;
     665         i = i | blue;
     666         i = i << 8;
     667         i = i | alpha;
     668         return i;
     669     }
     670
     671     /**
     672      * Gets the hue component of this {@code Color}.
     673      * @return Hue value in the range in the range {@code 0.0-360.0}.
     674      */
     675     public double getHue() {
     676         return Utils.RGBtoHSB(red, green, blue)[0];
     677     }
     678
     679     /**
     680      * Gets the saturation component of this {@code Color}.
     681      * @return Saturation value in the range in the range {@code 0.0-1.0}.
     682      */
     683     public double getSaturation() {
     684         return Utils.RGBtoHSB(red, green, blue)[1];
     685     }
     686
     687     /**
     688      * Gets the brightness component of this {@code Color}.
     689      * @return Brightness value in the range in the range {@code 0.0-1.0}.
     690      */
     691     public double getBrightness() {
     692         return Utils.RGBtoHSB(red, green, blue)[2];
     693     }
     694
     695     /**
     696      * Creates a new {@code Color} based on this {@code Color} with hue,
     697      * saturation, brightness and opacity values altered. Hue is shifted
     698      * about the given value and normalized into its natural range, the
     699      * other components' values are multiplied by the given factors and
     700      * clipped into their ranges.
     701      *
     702      * Increasing brightness of black color is allowed by using an arbitrary,
     703      * very small source brightness instead of zero.
     704      */
     705     public Color deriveColor(double hueShift, double saturationFactor,
     706                              double brightnessFactor, double opacityFactor) {
     707
     708         double[] hsb = Utils.RGBtoHSB(red, green, blue);
     709
     710         /* Allow brightness increase of black color */
     711         double b = hsb[2];
     712         if (b == 0 && brightnessFactor > 1.0) {
     713             b = 0.05;
     714         }
     715
     716         /* the tail "+ 360) % 360" solves shifts into negative numbers */
     717         double h = (((hsb[0] + hueShift) % 360) + 360) % 360;
     718         double s = Math.max(Math.min(hsb[1] * saturationFactor, 1.0), 0.0);
     719         b = Math.max(Math.min(b * brightnessFactor, 1.0), 0.0);
     720         double a = Math.max(Math.min(opacity * opacityFactor, 1.0), 0.0);
     721         return hsb(h, s, b, a);
     722     }
     723
     724     /**
     725      * Creates a new Color that is a brighter version of this Color.
     726      */
     727     public Color brighter() {
     728         return deriveColor(0, 1.0, 1.0 / DARKER_BRIGHTER_FACTOR, 1.0);
     729     }
     730
     731     /**
     732      * Creates a new Color that is a darker version of this Color.
     733      */
     734     public Color darker() {
     735         return deriveColor(0, 1.0, DARKER_BRIGHTER_FACTOR, 1.0);
     736     }
     737
     738     /**
     739      * Creates a new Color that is a more saturated version of this Color.
     740      */
     741     public Color saturate() {
     742         return deriveColor(0, 1.0 / SATURATE_DESATURATE_FACTOR, 1.0, 1.0);
     743     }
     744
     745     /**
     746      * Creates a new Color that is a less saturated version of this Color.
     747      */
     748     public Color desaturate() {
     749         return deriveColor(0, SATURATE_DESATURATE_FACTOR, 1.0, 1.0);
     750     }
     751
     752     /**
     753      * Creates a new Color that is grayscale equivalent of this Color.
     754      * Opacity is preserved.
     755      */
     756     public Color grayscale() {
     757         double gray = 0.21 * red + 0.71 * green + 0.07 * blue;
     758         return Color.color(gray, gray, gray, opacity);
     759     }
     760
     761     /**
     762      * Creates a new Color that is inversion of this Color.
     763      * Opacity is preserved.
     764      */
     765     public Color invert() {
     766         return Color.color(1.0 - red, 1.0 - green, 1.0 - blue, opacity);
     767     }
     768
     769     /**
     770      * A fully transparent color with an ARGB value of #00000000.
     771      */
     772     public static final Color TRANSPARENT          = new Color(0f, 0f, 0f, 0f);
     773
     774     /**
     775      * The color alice blue with an RGB value of #F0F8FF.
     776      */
     777     public static final Color ALICEBLUE = new Color(0.9411765f, 0.972549f, 1.0f);
     778
     779     /**
     780      * The color antique white with an RGB value of #FAEBD7.
     781      */
     782     public static final Color ANTIQUEWHITE = new Color(0.98039216f, 0.92156863f, 0.84313726f);
     783
     784     /**
     785      * The color aqua with an RGB value of #00FFFF.
     786      */
     787     public static final Color AQUA = new Color(0.0f, 1.0f, 1.0f);
     788
     789     /**
     790      * The color aquamarine with an RGB value of #7FFFD4.
     791      */
     792     public static final Color AQUAMARINE = new Color(0.49803922f, 1.0f, 0.83137256f);
     793
     794     /**
     795      * The color azure with an RGB value of #F0FFFF.
     796      */
     797     public static final Color AZURE = new Color(0.9411765f, 1.0f, 1.0f);
     798
     799     /**
     800      * The color beige with an RGB value of #F5F5DC.
     801      */
     802     public static final Color BEIGE = new Color(0.9607843f, 0.9607843f, 0.8627451f);
     803
     804     /**
     805      * The color bisque with an RGB value of #FFE4C4.
     806      */
     807     public static final Color BISQUE = new Color(1.0f, 0.89411765f, 0.76862746f);
     808
     809     /**
     810      * The color black with an RGB value of #000000.
     811      */
     812     public static final Color BLACK = new Color(0.0f, 0.0f, 0.0f);
     813
     814     /**
     815      * The color blanched almond with an RGB value of #FFEBCD.
     816      */
     817     public static final Color BLANCHEDALMOND = new Color(1.0f, 0.92156863f, 0.8039216f);
     818
     819     /**
     820      * The color blue with an RGB value of #0000FF.
     821      */
     822     public static final Color BLUE = new Color(0.0f, 0.0f, 1.0f);
     823
     824     /**
     825      * The color blue violet with an RGB value of #8A2BE2.
     826      */
     827     public static final Color BLUEVIOLET = new Color(0.5411765f, 0.16862746f, 0.8862745f);
     828
     829     /**
     830      * The color brown with an RGB value of #A52A2A.
     831      */
     832     public static final Color BROWN = new Color(0.64705884f, 0.16470589f, 0.16470589f);
     833
     834     /**
     835      * The color burly wood with an RGB value of #DEB887.
     836      */
     837     public static final Color BURLYWOOD = new Color(0.87058824f, 0.72156864f, 0.5294118f);
     838
     839     /**
     840      * The color cadet blue with an RGB value of #5F9EA0.
     841      */
     842     public static final Color CADETBLUE = new Color(0.37254903f, 0.61960787f, 0.627451f);
     843
     844     /**
     845      * The color chartreuse with an RGB value of #7FFF00.
     846      */
     847     public static final Color CHARTREUSE = new Color(0.49803922f, 1.0f, 0.0f);
     848
     849     /**
     850      * The color chocolate with an RGB value of #D2691E.
     851      */
     852     public static final Color CHOCOLATE = new Color(0.8235294f, 0.4117647f, 0.11764706f);
     853
     854     /**
     855      * The color coral with an RGB value of #FF7F50.
     856      */
     857     public static final Color CORAL = new Color(1.0f, 0.49803922f, 0.3137255f);
     858
     859     /**
     860      * The color cornflower blue with an RGB value of #6495ED.
     861      */
     862     public static final Color CORNFLOWERBLUE = new Color(0.39215687f, 0.58431375f, 0.92941177f);
     863
     864     /**
     865      * The color cornsilk with an RGB value of #FFF8DC.
     866      */
     867     public static final Color CORNSILK = new Color(1.0f, 0.972549f, 0.8627451f);
     868
     869     /**
     870      * The color crimson with an RGB value of #DC143C.
     871      */
     872     public static final Color CRIMSON = new Color(0.8627451f, 0.078431375f, 0.23529412f);
     873
     874     /**
     875      * The color cyan with an RGB value of #00FFFF.
     876      */
     877     public static final Color CYAN = new Color(0.0f, 1.0f, 1.0f);
     878
     879     /**
     880      * The color dark blue with an RGB value of #00008B.
     881      */
     882     public static final Color DARKBLUE = new Color(0.0f, 0.0f, 0.54509807f);
     883
     884     /**
     885      * The color dark cyan with an RGB value of #008B8B.
     886      */
     887     public static final Color DARKCYAN = new Color(0.0f, 0.54509807f, 0.54509807f);
     888
     889     /**
     890      * The color dark goldenrod with an RGB value of #B8860B.
     891      */
     892     public static final Color DARKGOLDENROD = new Color(0.72156864f, 0.5254902f, 0.043137256f);
     893
     894     /**
     895      * The color dark gray with an RGB value of #A9A9A9.
     896      */
     897     public static final Color DARKGRAY = new Color(0.6627451f, 0.6627451f, 0.6627451f);
     898
     899     /**
     900      * The color dark green with an RGB value of #006400.
     901      */
     902     public static final Color DARKGREEN = new Color(0.0f, 0.39215687f, 0.0f);
     903
     904     /**
     905      * The color dark grey with an RGB value of #A9A9A9.
     906      */
     907     public static final Color DARKGREY             = DARKGRAY;
     908
     909     /**
     910      * The color dark khaki with an RGB value of #BDB76B.
     911      */
     912     public static final Color DARKKHAKI = new Color(0.7411765f, 0.7176471f, 0.41960785f);
     913
     914     /**
     915      * The color dark magenta with an RGB value of #8B008B.
     916      */
     917     public static final Color DARKMAGENTA = new Color(0.54509807f, 0.0f, 0.54509807f);
     918
     919     /**
     920      * The color dark olive green with an RGB value of #556B2F.
     921      */
     922     public static final Color DARKOLIVEGREEN = new Color(0.33333334f, 0.41960785f, 0.18431373f);
     923
     924     /**
     925      * The color dark orange with an RGB value of #FF8C00.
     926      */
     927     public static final Color DARKORANGE = new Color(1.0f, 0.54901963f, 0.0f);
     928
     929     /**
     930      * The color dark orchid with an RGB value of #9932CC.
     931      */
     932     public static final Color DARKORCHID = new Color(0.6f, 0.19607843f, 0.8f);
     933
     934     /**
     935      * The color dark red with an RGB value of #8B0000.
     936      */
     937     public static final Color DARKRED = new Color(0.54509807f, 0.0f, 0.0f);
     938
     939     /**
     940      * The color dark salmon with an RGB value of #E9967A.
     941      */
     942     public static final Color DARKSALMON = new Color(0.9137255f, 0.5882353f, 0.47843137f);
     943
     944     /**
     945      * The color dark sea green with an RGB value of #8FBC8F.
     946      */
     947     public static final Color DARKSEAGREEN = new Color(0.56078434f, 0.7372549f, 0.56078434f);
     948
     949     /**
     950      * The color dark slate blue with an RGB value of #483D8B.
     951      */
     952     public static final Color DARKSLATEBLUE = new Color(0.28235295f, 0.23921569f, 0.54509807f);
     953
     954     /**
     955      * The color dark slate gray with an RGB value of #2F4F4F.
     956      */
     957     public static final Color DARKSLATEGRAY = new Color(0.18431373f, 0.30980393f, 0.30980393f);
     958
     959     /**
     960      * The color dark slate grey with an RGB value of #2F4F4F.
     961      */
     962     public static final Color DARKSLATEGREY        = DARKSLATEGRAY;
     963
     964     /**
     965      * The color dark turquoise with an RGB value of #00CED1.
     966      */
     967     public static final Color DARKTURQUOISE = new Color(0.0f, 0.80784315f, 0.81960785f);
     968
     969     /**
     970      * The color dark violet with an RGB value of #9400D3.
     971      */
     972     public static final Color DARKVIOLET = new Color(0.5803922f, 0.0f, 0.827451f);
     973
     974     /**
     975      * The color deep pink with an RGB value of #FF1493.
     976      */
     977     public static final Color DEEPPINK = new Color(1.0f, 0.078431375f, 0.5764706f);
     978
     979     /**
     980      * The color deep sky blue with an RGB value of #00BFFF.
     981      */
     982     public static final Color DEEPSKYBLUE = new Color(0.0f, 0.7490196f, 1.0f);
     983
     984     /**
     985      * The color dim gray with an RGB value of #696969.
     986      */
     987     public static final Color DIMGRAY = new Color(0.4117647f, 0.4117647f, 0.4117647f);
     988
     989     /**
     990      * The color dim grey with an RGB value of #696969.
     991      */
     992     public static final Color DIMGREY              = DIMGRAY;
     993
     994     /**
     995      * The color dodger blue with an RGB value of #1E90FF.
     996      */
     997     public static final Color DODGERBLUE = new Color(0.11764706f, 0.5647059f, 1.0f);
     998
     999     /**
    1000      * The color firebrick with an RGB value of #B22222.
    1001      */
    1002     public static final Color FIREBRICK = new Color(0.69803923f, 0.13333334f, 0.13333334f);
    1003
    1004     /**
    1005      * The color floral white with an RGB value of #FFFAF0.
    1006      */
    1007     public static final Color FLORALWHITE = new Color(1.0f, 0.98039216f, 0.9411765f);
    1008
    1009     /**
    1010      * The color forest green with an RGB value of #228B22.
    1011      */
    1012     public static final Color FORESTGREEN = new Color(0.13333334f, 0.54509807f, 0.13333334f);
    1013
    1014     /**
    1015      * The color fuchsia with an RGB value of #FF00FF.
    1016      */
    1017     public static final Color FUCHSIA = new Color(1.0f, 0.0f, 1.0f);
    1018
    1019     /**
    1020      * The color gainsboro with an RGB value of #DCDCDC.
    1021      */
    1022     public static final Color GAINSBORO = new Color(0.8627451f, 0.8627451f, 0.8627451f);
    1023
    1024     /**
    1025      * The color ghost white with an RGB value of #F8F8FF.
    1026      */
    1027     public static final Color GHOSTWHITE = new Color(0.972549f, 0.972549f, 1.0f);
    1028
    1029     /**
    1030      * The color gold with an RGB value of #FFD700.
    1031      */
    1032     public static final Color GOLD = new Color(1.0f, 0.84313726f, 0.0f);
    1033
    1034     /**
    1035      * The color goldenrod with an RGB value of #DAA520.
    1036      */
    1037     public static final Color GOLDENROD = new Color(0.85490197f, 0.64705884f, 0.1254902f);
    1038
    1039     /**
    1040      * The color gray with an RGB value of #808080.
    1041      */
    1042     public static final Color GRAY = new Color(0.5019608f, 0.5019608f, 0.5019608f);
    1043
    1044     /**
    1045      * The color green with an RGB value of #008000.
    1046      */
    1047     public static final Color GREEN = new Color(0.0f, 0.5019608f, 0.0f);
    1048
    1049     /**
    1050      * The color green yellow with an RGB value of #ADFF2F.
    1051      */
    1052     public static final Color GREENYELLOW = new Color(0.6784314f, 1.0f, 0.18431373f);
    1053
    1054     /**
    1055      * The color grey with an RGB value of #808080.
    1056      */
    1057     public static final Color GREY                 = GRAY;
    1058
    1059     /**
    1060      * The color honeydew with an RGB value of #F0FFF0.
    1061      */
    1062     public static final Color HONEYDEW = new Color(0.9411765f, 1.0f, 0.9411765f);
    1063
    1064     /**
    1065      * The color hot pink with an RGB value of #FF69B4.
    1066      */
    1067     public static final Color HOTPINK = new Color(1.0f, 0.4117647f, 0.7058824f);
    1068
    1069     /**
    1070      * The color indian red with an RGB value of #CD5C5C.
    1071      */
    1072     public static final Color INDIANRED = new Color(0.8039216f, 0.36078432f, 0.36078432f);
    1073
    1074     /**
    1075      * The color indigo with an RGB value of #4B0082.
    1076      */
    1077     public static final Color INDIGO = new Color(0.29411766f, 0.0f, 0.50980395f);
    1078
    1079     /**
    1080      * The color ivory with an RGB value of #FFFFF0.
    1081      */
    1082     public static final Color IVORY = new Color(1.0f, 1.0f, 0.9411765f);
    1083
    1084     /**
    1085      * The color khaki with an RGB value of #F0E68C.
    1086      */
    1087     public static final Color KHAKI = new Color(0.9411765f, 0.9019608f, 0.54901963f);
    1088
    1089     /**
    1090      * The color lavender with an RGB value of #E6E6FA.
    1091      */
    1092     public static final Color LAVENDER = new Color(0.9019608f, 0.9019608f, 0.98039216f);
    1093
    1094     /**
    1095      * The color lavender blush with an RGB value of #FFF0F5.
    1096      */
    1097     public static final Color LAVENDERBLUSH = new Color(1.0f, 0.9411765f, 0.9607843f);
    1098
    1099     /**
    1100      * The color lawn green with an RGB value of #7CFC00.
    1101      */
    1102     public static final Color LAWNGREEN = new Color(0.4862745f, 0.9882353f, 0.0f);
    1103
    1104     /**
    1105      * The color lemon chiffon with an RGB value of #FFFACD.
    1106      */
    1107     public static final Color LEMONCHIFFON = new Color(1.0f, 0.98039216f, 0.8039216f);
    1108
    1109     /**
    1110      * The color light blue with an RGB value of #ADD8E6.
    1111      */
    1112     public static final Color LIGHTBLUE = new Color(0.6784314f, 0.84705883f, 0.9019608f);
    1113
    1114     /**
    1115      * The color light coral with an RGB value of #F08080.
    1116      */
    1117     public static final Color LIGHTCORAL = new Color(0.9411765f, 0.5019608f, 0.5019608f);
    1118
    1119     /**
    1120      * The color light cyan with an RGB value of #E0FFFF.
    1121      */
    1122     public static final Color LIGHTCYAN = new Color(0.8784314f, 1.0f, 1.0f);
    1123
    1124     /**
    1125      * The color light goldenrod yellow with an RGB value of #FAFAD2.
    1126      */
    1127     public static final Color LIGHTGOLDENRODYELLOW = new Color(0.98039216f, 0.98039216f, 0.8235294f);
    1128
    1129     /**
    1130      * The color light gray with an RGB value of #D3D3D3.
    1131      */
    1132     public static final Color LIGHTGRAY = new Color(0.827451f, 0.827451f, 0.827451f);
    1133
    1134     /**
    1135      * The color light green with an RGB value of #90EE90.
    1136      */
    1137     public static final Color LIGHTGREEN = new Color(0.5647059f, 0.93333334f, 0.5647059f);
    1138
    1139     /**
    1140      * The color light grey with an RGB value of #D3D3D3.
    1141      */
    1142     public static final Color LIGHTGREY            = LIGHTGRAY;
    1143
    1144     /**
    1145      * The color light pink with an RGB value of #FFB6C1.
    1146      */
    1147     public static final Color LIGHTPINK = new Color(1.0f, 0.7137255f, 0.75686276f);
    1148
    1149     /**
    1150      * The color light salmon with an RGB value of #FFA07A.
    1151      */
    1152     public static final Color LIGHTSALMON = new Color(1.0f, 0.627451f, 0.47843137f);
    1153
    1154     /**
    1155      * The color light sea green with an RGB value of #20B2AA.
    1156      */
    1157     public static final Color LIGHTSEAGREEN = new Color(0.1254902f, 0.69803923f, 0.6666667f);
    1158
    1159     /**
    1160      * The color light sky blue with an RGB value of #87CEFA.
    1161      */
    1162     public static final Color LIGHTSKYBLUE = new Color(0.5294118f, 0.80784315f, 0.98039216f);
    1163
    1164     /**
    1165      * The color light slate gray with an RGB value of #778899.
    1166      */
    1167     public static final Color LIGHTSLATEGRAY = new Color(0.46666667f, 0.53333336f, 0.6f);
    1168
    1169     /**
    1170      * The color light slate grey with an RGB value of #778899.
    1171      */
    1172     public static final Color LIGHTSLATEGREY       = LIGHTSLATEGRAY;
    1173
    1174     /**
    1175      * The color light steel blue with an RGB value of #B0C4DE.
    1176      */
    1177     public static final Color LIGHTSTEELBLUE = new Color(0.6901961f, 0.76862746f, 0.87058824f);
    1178
    1179     /**
    1180      * The color light yellow with an RGB value of #FFFFE0.
    1181      */
    1182     public static final Color LIGHTYELLOW = new Color(1.0f, 1.0f, 0.8784314f);
    1183
    1184     /**
    1185      * The color lime with an RGB value of #00FF00.
    1186      */
    1187     public static final Color LIME = new Color(0.0f, 1.0f, 0.0f);
    1188
    1189     /**
    1190      * The color lime green with an RGB value of #32CD32.
    1191      */
    1192     public static final Color LIMEGREEN = new Color(0.19607843f, 0.8039216f, 0.19607843f);
    1193
    1194     /**
    1195      * The color linen with an RGB value of #FAF0E6.
    1196      */
    1197     public static final Color LINEN = new Color(0.98039216f, 0.9411765f, 0.9019608f);
    1198
    1199     /**
    1200      * The color magenta with an RGB value of #FF00FF.
    1201      */
    1202     public static final Color MAGENTA = new Color(1.0f, 0.0f, 1.0f);
    1203
    1204     /**
    1205      * The color maroon with an RGB value of #800000.
    1206      */
    1207     public static final Color MAROON = new Color(0.5019608f, 0.0f, 0.0f);
    1208
    1209     /**
    1210      * The color medium aquamarine with an RGB value of #66CDAA.
    1211      */
    1212     public static final Color MEDIUMAQUAMARINE = new Color(0.4f, 0.8039216f, 0.6666667f);
    1213
    1214     /**
    1215      * The color medium blue with an RGB value of #0000CD.
    1216      */
    1217     public static final Color MEDIUMBLUE = new Color(0.0f, 0.0f, 0.8039216f);
    1218
    1219     /**
    1220      * The color medium orchid with an RGB value of #BA55D3.
    1221      */
    1222     public static final Color MEDIUMORCHID = new Color(0.7294118f, 0.33333334f, 0.827451f);
    1223
    1224     /**
    1225      * The color medium purple with an RGB value of #9370DB.
    1226      */
    1227     public static final Color MEDIUMPURPLE = new Color(0.5764706f, 0.4392157f, 0.85882354f);
    1228
    1229     /**
    1230      * The color medium sea green with an RGB value of #3CB371.
    1231      */
    1232     public static final Color MEDIUMSEAGREEN = new Color(0.23529412f, 0.7019608f, 0.44313726f);
    1233
    1234     /**
    1235      * The color medium slate blue with an RGB value of #7B68EE.
    1236      */
    1237     public static final Color MEDIUMSLATEBLUE = new Color(0.48235294f, 0.40784314f, 0.93333334f);
    1238
    1239     /**
    1240      * The color medium spring green with an RGB value of #00FA9A.
    1241      */
    1242     public static final Color MEDIUMSPRINGGREEN = new Color(0.0f, 0.98039216f, 0.6039216f);
    1243
    1244     /**
    1245      * The color medium turquoise with an RGB value of #48D1CC.
    1246      */
    1247     public static final Color MEDIUMTURQUOISE = new Color(0.28235295f, 0.81960785f, 0.8f);
    1248
    1249     /**
    1250      * The color medium violet red with an RGB value of #C71585.
    1251      */
    1252     public static final Color MEDIUMVIOLETRED = new Color(0.78039217f, 0.08235294f, 0.52156866f);
    1253
    1254     /**
    1255      * The color midnight blue with an RGB value of #191970.
    1256      */
    1257     public static final Color MIDNIGHTBLUE = new Color(0.09803922f, 0.09803922f, 0.4392157f);
    1258
    1259     /**
    1260      * The color mint cream with an RGB value of #F5FFFA.
    1261      */
    1262     public static final Color MINTCREAM = new Color(0.9607843f, 1.0f, 0.98039216f);
    1263
    1264     /**
    1265      * The color misty rose with an RGB value of #FFE4E1.
    1266      */
    1267     public static final Color MISTYROSE = new Color(1.0f, 0.89411765f, 0.88235295f);
    1268
    1269     /**
    1270      * The color moccasin with an RGB value of #FFE4B5.
    1271      */
    1272     public static final Color MOCCASIN = new Color(1.0f, 0.89411765f, 0.70980394f);
    1273
    1274     /**
    1275      * The color navajo white with an RGB value of #FFDEAD.
    1276      */
    1277     public static final Color NAVAJOWHITE = new Color(1.0f, 0.87058824f, 0.6784314f);
    1278
    1279     /**
    1280      * The color navy with an RGB value of #000080.
    1281      */
    1282     public static final Color NAVY = new Color(0.0f, 0.0f, 0.5019608f);
    1283
    1284     /**
    1285      * The color old lace with an RGB value of #FDF5E6.
    1286      */
    1287     public static final Color OLDLACE = new Color(0.99215686f, 0.9607843f, 0.9019608f);
    1288
    1289     /**
    1290      * The color olive with an RGB value of #808000.
    1291      */
    1292     public static final Color OLIVE = new Color(0.5019608f, 0.5019608f, 0.0f);
    1293
    1294     /**
    1295      * The color olive drab with an RGB value of #6B8E23.
    1296      */
    1297     public static final Color OLIVEDRAB = new Color(0.41960785f, 0.5568628f, 0.13725491f);
    1298
    1299     /**
    1300      * The color orange with an RGB value of #FFA500.
    1301      */
    1302     public static final Color ORANGE = new Color(1.0f, 0.64705884f, 0.0f);
    1303
    1304     /**
    1305      * The color orange red with an RGB value of #FF4500.
    1306      */
    1307     public static final Color ORANGERED = new Color(1.0f, 0.27058825f, 0.0f);
    1308
    1309     /**
    1310      * The color orchid with an RGB value of #DA70D6.
    1311      */
    1312     public static final Color ORCHID = new Color(0.85490197f, 0.4392157f, 0.8392157f);
    1313
    1314     /**
    1315      * The color pale goldenrod with an RGB value of #EEE8AA.
    1316      */
    1317     public static final Color PALEGOLDENROD = new Color(0.93333334f, 0.9098039f, 0.6666667f);
    1318
    1319     /**
    1320      * The color pale green with an RGB value of #98FB98.
    1321      */
    1322     public static final Color PALEGREEN = new Color(0.59607846f, 0.9843137f, 0.59607846f);
    1323
    1324     /**
    1325      * The color pale turquoise with an RGB value of #AFEEEE.
    1326      */
    1327     public static final Color PALETURQUOISE = new Color(0.6862745f, 0.93333334f, 0.93333334f);
    1328
    1329     /**
    1330      * The color pale violet red with an RGB value of #DB7093.
    1331      */
    1332     public static final Color PALEVIOLETRED = new Color(0.85882354f, 0.4392157f, 0.5764706f);
    1333
    1334     /**
    1335      * The color papaya whip with an RGB value of #FFEFD5.
    1336      */
    1337     public static final Color PAPAYAWHIP = new Color(1.0f, 0.9372549f, 0.8352941f);
    1338
    1339     /**
    1340      * The color peach puff with an RGB value of #FFDAB9.
    1341      */
    1342     public static final Color PEACHPUFF = new Color(1.0f, 0.85490197f, 0.7254902f);
    1343
    1344     /**
    1345      * The color peru with an RGB value of #CD853F.
    1346      */
    1347     public static final Color PERU = new Color(0.8039216f, 0.52156866f, 0.24705882f);
    1348
    1349     /**
    1350      * The color pink with an RGB value of #FFC0CB.
    1351      */
    1352     public static final Color PINK = new Color(1.0f, 0.7529412f, 0.79607844f);
    1353
    1354     /**
    1355      * The color plum with an RGB value of #DDA0DD.
    1356      */
    1357     public static final Color PLUM = new Color(0.8666667f, 0.627451f, 0.8666667f);
    1358
    1359     /**
    1360      * The color powder blue with an RGB value of #B0E0E6.
    1361      */
    1362     public static final Color POWDERBLUE = new Color(0.6901961f, 0.8784314f, 0.9019608f);
    1363
    1364     /**
    1365      * The color purple with an RGB value of #800080.
    1366      */
    1367     public static final Color PURPLE = new Color(0.5019608f, 0.0f, 0.5019608f);
    1368
    1369     /**
    1370      * The color red with an RGB value of #FF0000.
    1371      */
    1372     public static final Color RED = new Color(1.0f, 0.0f, 0.0f);
    1373
    1374     /**
    1375      * The color rosy brown with an RGB value of #BC8F8F.
    1376      */
    1377     public static final Color ROSYBROWN = new Color(0.7372549f, 0.56078434f, 0.56078434f);
    1378
    1379     /**
    1380      * The color royal blue with an RGB value of #4169E1.
    1381      */
    1382     public static final Color ROYALBLUE = new Color(0.25490198f, 0.4117647f, 0.88235295f);
    1383
    1384     /**
    1385      * The color saddle brown with an RGB value of #8B4513.
    1386      */
    1387     public static final Color SADDLEBROWN = new Color(0.54509807f, 0.27058825f, 0.07450981f);
    1388
    1389     /**
    1390      * The color salmon with an RGB value of #FA8072.
    1391      */
    1392     public static final Color SALMON = new Color(0.98039216f, 0.5019608f, 0.44705883f);
    1393
    1394     /**
    1395      * The color sandy brown with an RGB value of #F4A460.
    1396      */
    1397     public static final Color SANDYBROWN = new Color(0.95686275f, 0.6431373f, 0.3764706f);
    1398
    1399     /**
    1400      * The color sea green with an RGB value of #2E8B57.
    1401      */
    1402     public static final Color SEAGREEN = new Color(0.18039216f, 0.54509807f, 0.34117648f);
    1403
    1404     /**
    1405      * The color sea shell with an RGB value of #FFF5EE.
    1406      */
    1407     public static final Color SEASHELL = new Color(1.0f, 0.9607843f, 0.93333334f);
    1408
    1409     /**
    1410      * The color sienna with an RGB value of #A0522D.
    1411      */
    1412     public static final Color SIENNA = new Color(0.627451f, 0.32156864f, 0.1764706f);
    1413
    1414     /**
    1415      * The color silver with an RGB value of #C0C0C0.
    1416      */
    1417     public static final Color SILVER = new Color(0.7529412f, 0.7529412f, 0.7529412f);
    1418
    1419     /**
    1420      * The color sky blue with an RGB value of #87CEEB.
    1421      */
    1422     public static final Color SKYBLUE = new Color(0.5294118f, 0.80784315f, 0.92156863f);
    1423
    1424     /**
    1425      * The color slate blue with an RGB value of #6A5ACD.
    1426      */
    1427     public static final Color SLATEBLUE = new Color(0.41568628f, 0.3529412f, 0.8039216f);
    1428
    1429     /**
    1430      * The color slate gray with an RGB value of #708090.
    1431      */
    1432     public static final Color SLATEGRAY = new Color(0.4392157f, 0.5019608f, 0.5647059f);
    1433
    1434     /**
    1435      * The color slate grey with an RGB value of #708090.
    1436      */
    1437     public static final Color SLATEGREY            = SLATEGRAY;
    1438
    1439     /**
    1440      * The color snow with an RGB value of #FFFAFA.
    1441      */
    1442     public static final Color SNOW = new Color(1.0f, 0.98039216f, 0.98039216f);
    1443
    1444     /**
    1445      * The color spring green with an RGB value of #00FF7F.
    1446      */
    1447     public static final Color SPRINGGREEN = new Color(0.0f, 1.0f, 0.49803922f);
    1448
    1449     /**
    1450      * The color steel blue with an RGB value of #4682B4.
    1451      */
    1452     public static final Color STEELBLUE = new Color(0.27450982f, 0.50980395f, 0.7058824f);
    1453
    1454     /**
    1455      * The color tan with an RGB value of #D2B48C.
    1456      */
    1457     public static final Color TAN = new Color(0.8235294f, 0.7058824f, 0.54901963f);
    1458
    1459     /**
    1460      * The color teal with an RGB value of #008080.
    1461      */
    1462     public static final Color TEAL = new Color(0.0f, 0.5019608f, 0.5019608f);
    1463
    1464     /**
    1465      * The color thistle with an RGB value of #D8BFD8.
    1466      */
    1467     public static final Color THISTLE = new Color(0.84705883f, 0.7490196f, 0.84705883f);
    1468
    1469     /**
    1470      * The color tomato with an RGB value of #FF6347.
    1471      */
    1472     public static final Color TOMATO = new Color(1.0f, 0.3882353f, 0.2784314f);
    1473
    1474     /**
    1475      * The color turquoise with an RGB value of #40E0D0.
    1476      */
    1477     public static final Color TURQUOISE = new Color(0.2509804f, 0.8784314f, 0.8156863f);
    1478
    1479     /**
    1480      * The color violet with an RGB value of #EE82EE.
    1481      */
    1482     public static final Color VIOLET = new Color(0.93333334f, 0.50980395f, 0.93333334f);
    1483
    1484     /**
    1485      * The color wheat with an RGB value of #F5DEB3.
    1486      */
    1487     public static final Color WHEAT = new Color(0.9607843f, 0.87058824f, 0.7019608f);
    1488
    1489     /**
    1490      * The color white with an RGB value of #FFFFFF.
    1491      */
    1492     public static final Color WHITE = new Color(1.0f, 1.0f, 1.0f);
    1493
    1494     /**
    1495      * The color white smoke with an RGB value of #F5F5F5.
    1496      */
    1497     public static final Color WHITESMOKE = new Color(0.9607843f, 0.9607843f, 0.9607843f);
    1498
    1499     /**
    1500      * The color yellow with an RGB value of #FFFF00.
    1501      */
    1502     public static final Color YELLOW = new Color(1.0f, 1.0f, 0.0f);
    1503
    1504     /**
    1505      * The color yellow green with an RGB value of #9ACD32.
    1506      */
    1507     public static final Color YELLOWGREEN = new Color(0.6039216f, 0.8039216f, 0.19607843f);
    1508
    1509     /*
    1510      * Named colors moved to nested class to initialize them only when they
    1511      * are needed.
    1512      */
    1513     private static final class NamedColors {
    1514         private static final Map<String, Color> namedColors =
    1515                 createNamedColors();
    1516
    1517         private NamedColors() {
    1518         }
    1519
    1520         private static Color get(String name) {
    1521             return namedColors.get(name);
    1522         }
    1523
    1524         private static Map<String, Color> createNamedColors() {
    1525             Map<String, Color> colors = new HashMap<String,Color>(256);
    1526
    1527             colors.put("aliceblue",            ALICEBLUE);
    1528             colors.put("antiquewhite",         ANTIQUEWHITE);
    1529             colors.put("aqua",                 AQUA);
    1530             colors.put("aquamarine",           AQUAMARINE);
    1531             colors.put("azure",                AZURE);
    1532             colors.put("beige",                BEIGE);
    1533             colors.put("bisque",               BISQUE);
    1534             colors.put("black",                BLACK);
    1535             colors.put("blanchedalmond",       BLANCHEDALMOND);
    1536             colors.put("blue",                 BLUE);
    1537             colors.put("blueviolet",           BLUEVIOLET);
    1538             colors.put("brown",                BROWN);
    1539             colors.put("burlywood",            BURLYWOOD);
    1540             colors.put("cadetblue",            CADETBLUE);
    1541             colors.put("chartreuse",           CHARTREUSE);
    1542             colors.put("chocolate",            CHOCOLATE);
    1543             colors.put("coral",                CORAL);
    1544             colors.put("cornflowerblue",       CORNFLOWERBLUE);
    1545             colors.put("cornsilk",             CORNSILK);
    1546             colors.put("crimson",              CRIMSON);
    1547             colors.put("cyan",                 CYAN);
    1548             colors.put("darkblue",             DARKBLUE);
    1549             colors.put("darkcyan",             DARKCYAN);
    1550             colors.put("darkgoldenrod",        DARKGOLDENROD);
    1551             colors.put("darkgray",             DARKGRAY);
    1552             colors.put("darkgreen",            DARKGREEN);
    1553             colors.put("darkgrey",             DARKGREY);
    1554             colors.put("darkkhaki",            DARKKHAKI);
    1555             colors.put("darkmagenta",          DARKMAGENTA);
    1556             colors.put("darkolivegreen",       DARKOLIVEGREEN);
    1557             colors.put("darkorange",           DARKORANGE);
    1558             colors.put("darkorchid",           DARKORCHID);
    1559             colors.put("darkred",              DARKRED);
    1560             colors.put("darksalmon",           DARKSALMON);
    1561             colors.put("darkseagreen",         DARKSEAGREEN);
    1562             colors.put("darkslateblue",        DARKSLATEBLUE);
    1563             colors.put("darkslategray",        DARKSLATEGRAY);
    1564             colors.put("darkslategrey",        DARKSLATEGREY);
    1565             colors.put("darkturquoise",        DARKTURQUOISE);
    1566             colors.put("darkviolet",           DARKVIOLET);
    1567             colors.put("deeppink",             DEEPPINK);
    1568             colors.put("deepskyblue",          DEEPSKYBLUE);
    1569             colors.put("dimgray",              DIMGRAY);
    1570             colors.put("dimgrey",              DIMGREY);
    1571             colors.put("dodgerblue",           DODGERBLUE);
    1572             colors.put("firebrick",            FIREBRICK);
    1573             colors.put("floralwhite",          FLORALWHITE);
    1574             colors.put("forestgreen",          FORESTGREEN);
    1575             colors.put("fuchsia",              FUCHSIA);
    1576             colors.put("gainsboro",            GAINSBORO);
    1577             colors.put("ghostwhite",           GHOSTWHITE);
    1578             colors.put("gold",                 GOLD);
    1579             colors.put("goldenrod",            GOLDENROD);
    1580             colors.put("gray",                 GRAY);
    1581             colors.put("green",                GREEN);
    1582             colors.put("greenyellow",          GREENYELLOW);
    1583             colors.put("grey",                 GREY);
    1584             colors.put("honeydew",             HONEYDEW);
    1585             colors.put("hotpink",              HOTPINK);
    1586             colors.put("indianred",            INDIANRED);
    1587             colors.put("indigo",               INDIGO);
    1588             colors.put("ivory",                IVORY);
    1589             colors.put("khaki",                KHAKI);
    1590             colors.put("lavender",             LAVENDER);
    1591             colors.put("lavenderblush",        LAVENDERBLUSH);
    1592             colors.put("lawngreen",            LAWNGREEN);
    1593             colors.put("lemonchiffon",         LEMONCHIFFON);
    1594             colors.put("lightblue",            LIGHTBLUE);
    1595             colors.put("lightcoral",           LIGHTCORAL);
    1596             colors.put("lightcyan",            LIGHTCYAN);
    1597             colors.put("lightgoldenrodyellow", LIGHTGOLDENRODYELLOW);
    1598             colors.put("lightgray",            LIGHTGRAY);
    1599             colors.put("lightgreen",           LIGHTGREEN);
    1600             colors.put("lightgrey",            LIGHTGREY);
    1601             colors.put("lightpink",            LIGHTPINK);
    1602             colors.put("lightsalmon",          LIGHTSALMON);
    1603             colors.put("lightseagreen",        LIGHTSEAGREEN);
    1604             colors.put("lightskyblue",         LIGHTSKYBLUE);
    1605             colors.put("lightslategray",       LIGHTSLATEGRAY);
    1606             colors.put("lightslategrey",       LIGHTSLATEGREY);
    1607             colors.put("lightsteelblue",       LIGHTSTEELBLUE);
    1608             colors.put("lightyellow",          LIGHTYELLOW);
    1609             colors.put("lime",                 LIME);
    1610             colors.put("limegreen",            LIMEGREEN);
    1611             colors.put("linen",                LINEN);
    1612             colors.put("magenta",              MAGENTA);
    1613             colors.put("maroon",               MAROON);
    1614             colors.put("mediumaquamarine",     MEDIUMAQUAMARINE);
    1615             colors.put("mediumblue",           MEDIUMBLUE);
    1616             colors.put("mediumorchid",         MEDIUMORCHID);
    1617             colors.put("mediumpurple",         MEDIUMPURPLE);
    1618             colors.put("mediumseagreen",       MEDIUMSEAGREEN);
    1619             colors.put("mediumslateblue",      MEDIUMSLATEBLUE);
    1620             colors.put("mediumspringgreen",    MEDIUMSPRINGGREEN);
    1621             colors.put("mediumturquoise",      MEDIUMTURQUOISE);
    1622             colors.put("mediumvioletred",      MEDIUMVIOLETRED);
    1623             colors.put("midnightblue",         MIDNIGHTBLUE);
    1624             colors.put("mintcream",            MINTCREAM);
    1625             colors.put("mistyrose",            MISTYROSE);
    1626             colors.put("moccasin",             MOCCASIN);
    1627             colors.put("navajowhite",          NAVAJOWHITE);
    1628             colors.put("navy",                 NAVY);
    1629             colors.put("oldlace",              OLDLACE);
    1630             colors.put("olive",                OLIVE);
    1631             colors.put("olivedrab",            OLIVEDRAB);
    1632             colors.put("orange",               ORANGE);
    1633             colors.put("orangered",            ORANGERED);
    1634             colors.put("orchid",               ORCHID);
    1635             colors.put("palegoldenrod",        PALEGOLDENROD);
    1636             colors.put("palegreen",            PALEGREEN);
    1637             colors.put("paleturquoise",        PALETURQUOISE);
    1638             colors.put("palevioletred",        PALEVIOLETRED);
    1639             colors.put("papayawhip",           PAPAYAWHIP);
    1640             colors.put("peachpuff",            PEACHPUFF);
    1641             colors.put("peru",                 PERU);
    1642             colors.put("pink",                 PINK);
    1643             colors.put("plum",                 PLUM);
    1644             colors.put("powderblue",           POWDERBLUE);
    1645             colors.put("purple",               PURPLE);
    1646             colors.put("red",                  RED);
    1647             colors.put("rosybrown",            ROSYBROWN);
    1648             colors.put("royalblue",            ROYALBLUE);
    1649             colors.put("saddlebrown",          SADDLEBROWN);
    1650             colors.put("salmon",               SALMON);
    1651             colors.put("sandybrown",           SANDYBROWN);
    1652             colors.put("seagreen",             SEAGREEN);
    1653             colors.put("seashell",             SEASHELL);
    1654             colors.put("sienna",               SIENNA);
    1655             colors.put("silver",               SILVER);
    1656             colors.put("skyblue",              SKYBLUE);
    1657             colors.put("slateblue",            SLATEBLUE);
    1658             colors.put("slategray",            SLATEGRAY);
    1659             colors.put("slategrey",            SLATEGREY);
    1660             colors.put("snow",                 SNOW);
    1661             colors.put("springgreen",          SPRINGGREEN);
    1662             colors.put("steelblue",            STEELBLUE);
    1663             colors.put("tan",                  TAN);
    1664             colors.put("teal",                 TEAL);
    1665             colors.put("thistle",              THISTLE);
    1666             colors.put("tomato",               TOMATO);
    1667             colors.put("transparent",          TRANSPARENT);
    1668             colors.put("turquoise",            TURQUOISE);
    1669             colors.put("violet",               VIOLET);
    1670             colors.put("wheat",                WHEAT);
    1671             colors.put("white",                WHITE);
    1672             colors.put("whitesmoke",           WHITESMOKE);
    1673             colors.put("yellow",               YELLOW);
    1674             colors.put("yellowgreen",          YELLOWGREEN);
    1675
    1676             return colors;
    1677         }
    1678     }
    1679
    1680     /**
    1681      * The red component of the {@code Color}, in the range {@code 0.0-1.0}.
    1682      *
    1683      * @defaultValue 0.0
    1684      */
    1685     public final double getRed() { return red; }
    1686     private float red;
    1687
    1688     /**
    1689      * The green component of the {@code Color}, in the range {@code 0.0-1.0}.
    1690      *
    1691      * @defaultValue 0.0
    1692      */
    1693     public final double getGreen() { return green; }
    1694     private float green;
    1695
    1696     /**
    1697      * The blue component of the {@code Color}, in the range {@code 0.0-1.0}.
    1698      *
    1699      * @defaultValue 0.0
    1700      */
    1701     public final double getBlue() { return blue; }
    1702     private float blue;
    1703
    1704     /**
    1705      * The opacity of the {@code Color}, in the range {@code 0.0-1.0}.
    1706      *
    1707      * @defaultValue 1.0
    1708      */
    1709     public final double getOpacity() { return opacity; }
    1710     private float opacity = 1;
    1711
    1712     /**
    1713      * @inheritDoc
    1714      * @since JavaFX 8.0
    1715      */
    1716     @Override public final boolean isOpaque() {
    1717         return opacity >= 1f;
    1718     }
    1719
    1720     private Object platformPaint;
    1721
    1722     /**
    1723      * Creates a new instance of color
    1724      * @param red red component ranging from {@code 0} to {@code 1}
    1725      * @param green green component ranging from {@code 0} to {@code 1}
    1726      * @param blue blue component ranging from {@code 0} to {@code 1}
    1727      * @param opacity opacity ranging from {@code 0} to {@code 1}
    1728      */
    1729     public Color(double red, double green, double blue, @Default("1") double opacity) {
    1730         if (red < 0 || red > 1) {
    1731             throw new IllegalArgumentException("Color's red value (" + red + ") must be in the range 0.0-1.0");
    1732         }
    1733         if (green < 0 || green > 1) {
    1734             throw new IllegalArgumentException("Color's green value (" + green + ") must be in the range 0.0-1.0");
    1735         }
    1736         if (blue < 0 || blue > 1) {
    1737             throw new IllegalArgumentException("Color's blue value (" + blue + ") must be in the range 0.0-1.0");
    1738         }
    1739         if (opacity < 0 || opacity > 1) {
    1740             throw new IllegalArgumentException("Color's opacity value (" + opacity + ") must be in the range 0.0-1.0");
    1741         }
    1742
    1743         this.red = (float) red;
    1744         this.green = (float) green;
    1745         this.blue = (float) blue;
    1746         this.opacity = (float) opacity;
    1747     }
    1748
    1749     /**
    1750      * Creates a new instance of color. This constructor performs no integrity
    1751      * checks, and thus should ONLY be used by internal code in Color which
    1752      * knows that the hard-coded values are correct.
    1753      *
    1754      * @param red red component ranging from {@code 0} to {@code 1}
    1755      * @param green green component ranging from {@code 0} to {@code 1}
    1756      * @param blue blue component ranging from {@code 0} to {@code 1}
    1757      * @param opacity opacity ranging from {@code 0} to {@code 1}
    1758      */
    1759     private Color(float red, float green, float blue) {
    1760         this.red = red;
    1761         this.green = green;
    1762         this.blue = blue;
    1763     }
    1764
    1765     @Override
    1766     Object acc_getPlatformPaint() {
    1767         if (platformPaint == null) {
    1768             platformPaint = Toolkit.getToolkit().getPaint(this);
    1769         }
    1770         return platformPaint;
    1771     }
    1772
    1773     /**
    1774      * @inheritDoc
    1775      */
    1776     @Override public Color interpolate(Color endValue, double t) {
    1777         if (t <= 0.0) return this;
    1778         if (t >= 1.0) return endValue;
    1779         float ft = (float) t;
    1780         return new Color(
    1781             red     + (endValue.red     - red)     * ft,
    1782             green   + (endValue.green   - green)   * ft,
    1783             blue    + (endValue.blue    - blue)    * ft,
    1784             opacity + (endValue.opacity - opacity) * ft
    1785         );
    1786     }
    1787
    1788     /**
    1789      * Indicates whether some other object is "equal to" this one.
    1790      * @param obj the reference object with which to compare.
    1791      * @return {@code true} if this object is equal to the {@code obj} argument; {@code false} otherwise.
    1792      */
    1793     @Override public boolean equals(Object obj) {
    1794         if (obj == this) return true;
    1795         if (obj instanceof Color) {
    1796             Color other = (Color) obj;
    1797             return red == other.red
    1798                 && green == other.green
    1799                 && blue == other.blue
    1800                 && opacity == other.opacity;
    1801         } else return false;
    1802     }
    1803
    1804     /**
    1805      * Returns a hash code for this {@code Color} object.
    1806      * @return a hash code for this {@code Color} object.
    1807      */
    1808     @Override public int hashCode() {
    1809         // construct the 32bit integer representation of this color
    1810         int r = (int)Math.round(red * 255.0);
    1811         int g = (int)Math.round(green * 255.0);
    1812         int b = (int)Math.round(blue * 255.0);
    1813         int a = (int)Math.round(opacity * 255.0);
    1814         return to32BitInteger(r, g, b, a);
    1815     }
    1816
    1817     /**
    1818      * Returns a string representation of this {@code Color}.
    1819      * This method is intended to be used only for informational purposes.
    1820      * The content and format of the returned string might vary between implementations.
    1821      * The returned string might be empty but cannot be {@code null}.
    1822      *
    1823      * @return the string representation
    1824      */
    1825     @Override public String toString() {
    1826         int r = (int)Math.round(red * 255.0);
    1827         int g = (int)Math.round(green * 255.0);
    1828         int b = (int)Math.round(blue * 255.0);
    1829         int o = (int)Math.round(opacity * 255.0);
    1830         return String.format("0x%02x%02x%02x%02x" , r, g, b, o);
    1831     }
    1832 }