Open scientificware opened 2 years ago
Note that the switch
expression needs to use str.toLowerCase(Locale.ROOT)
, otherwise any color containing the letter i
will break when the current locale is Turkish (because "I".toLowerCase(Locale.forLanguageTag("tr"))
returns "ı"
and "i".toUpperCase(Locale.forLanguageTag("tr"))
returns "İ"
)
@ExE-Boss Done. Thanks. What is your preference ?
named
Color method.Color.java name declarations.
Color.java named
method :construction: Rewrite this using TreeMap or Map.
TreeMap
unused import .str.length() == 0
with str.isEmpty()
.rgb
and rgba
. Consider this : 8286270: [java.desktop] Replace color search in XColors with a switch statement #7096.
Add this subset hexadecimal color test to MissingColorNames.listNAMEetRGBA method :
Value | Ret. Val. Before PR | Ret. Val. after PR | Expect. Val. | ||
---|---|---|---|---|---|
null | null | :green_circle: | |||
# | null | null | :green_circle: | ||
#f | java.awt.Color[r=0,g=0,b=15] + a=255 | null | :white_circle: | ||
#f0 | java.awt.Color[r=0,g=0,b=240] + a=255 | null | :white_circle: | ||
#f0f | java.awt.Color[r=255,g=0,b=255] + a=255 | java.awt.Color[r=255,g=0,b=255] + a=255 | :green_circle: | ||
#f0f1 | java.awt.Color[r=0,g=240,b=241] + a=255 | java.awt.Color[r=255,g=0,b=255] + a=17 | :white_circle: | ||
#f0f10 | java.awt.Color[r=15,g=15,b=16] + a=255 | null | :white_circle: | ||
#f0f109 | java.awt.Color[r=240,g=241,b=9] + a=255 | java.awt.Color[r=240,g=241,b=9] + a=255 | :green_circle: | ||
#f0f1092 | java.awt.Color[r=240,g=241,b=9] + a=255 | null | :white_circle: | ||
#f0f10928 | java.awt.Color[r=240,g=241,b=9] + a=255 | java.awt.Color[r=240,g=241,b=153] + a=40 | :white_circle: | ||
f0f10928 | null | java.awt.Color[r=240,g=241,b=9] + a=40 | :white_circle: | ||
#f0f109289 | java.awt.Color[r=240,g=241,b=9] + a=255 | null | :white_circle: | ||
f0f109289 | null | null | :green_circle: | ||
ppabcdef | null | null | :green_circle: | ||
b52k | null | null | :green_circle: | ||
#ppabcdef | null | null | :green_circle: | ||
#b52k | null | null | :green_circle: | ||
#ffffffff | java.awt.Color[r=255,g=255,b=255] + a=255 | java.awt.Color[r=255,g=255,b=255] + a=255 | :green_circle: | ||
ffffffff | null | java.awt.Color[r=255,g=255,b=255] + a=255 | :white_circle: | ||
#ffffff | java.awt.Color[r=255,g=255,b=255] + a=255 | java.awt.Color[r=255,g=255,b=255] + a=255 | :green_circle: | ||
ffffff | java.awt.Color[r=255,g=255,b=255] + a=255 | java.awt.Color[r=255,g=255,b=255] + a=255 | :green_circle: |
Exception
.Exception in thread "main" java.lang.RuntimeException: Failed.
[aliceblue is not supported]
[antiquewhite is not supported]
[aquamarine is not supported]
[azure is not supported]
[beige is not supported]
[bisque is not supported]
[blanchedalmond is not supported]
[blueviolet is not supported]
[brown is not supported]
[burlywood is not supported]
[cadetblue is not supported]
[chartreuse is not supported]
[chocolate is not supported]
[coral is not supported]
[cornflowerblue is not supported]
[cornsilk is not supported]
[crimson is not supported]
[cyan is not supported]
[darkblue is not supported]
[darkcyan is not supported]
[darkgoldenrod is not supported]
[darkgray is not supported]
[darkgreen is not supported]
[darkgrey is not supported]
[darkkhaki is not supported]
[darkmagenta is not supported]
[darkolivegreen is not supported]
[darkorange is not supported]
[darkorchid is not supported]
[darkred is not supported]
[darksalmon is not supported]
[darkseagreen is not supported]
[darkslateblue is not supported]
[darkslategray is not supported]
[darkslategrey is not supported]
[darkturquoise is not supported]
[darkviolet is not supported]
[deeppink is not supported]
[deepskyblue is not supported]
[dimgray is not supported]
[dimgrey is not supported]
[dodgerblue is not supported]
[firebrick is not supported]
[floralwhite is not supported]
[forestgreen is not supported]
[gainsboro is not supported]
[ghostwhite is not supported]
[gold is not supported]
[goldenrod is not supported]
[greenyellow is not supported]
[grey is not supported]
[honeydew is not supported]
[hotpink is not supported]
[indianred is not supported]
[indigo is not supported]
[ivory is not supported]
[khaki is not supported]
[lavender is not supported]
[lavenderblush is not supported]
[lawngreen is not supported]
[lemonchiffon is not supported]
[lightblue is not supported]
[lightcoral is not supported]
[lightcyan is not supported]
[lightgoldenrodyellow is not supported]
[lightgray is not supported]
[lightgreen is not supported]
[lightgrey is not supported]
[lightpink is not supported]
[lightsalmon is not supported]
[lightseagreen is not supported]
[lightskyblue is not supported]
[lightslategray is not supported]
[lightslategrey is not supported]
[lightsteelblue is not supported]
[lightyellow is not supported]
[limegreen is not supported]
[linen is not supported]
[magenta is not supported]
[mediumaquamarine is not supported]
[mediumblue is not supported]
[mediumorchid is not supported]
[mediumpurple is not supported]
[mediumseagreen is not supported]
[mediumslateblue is not supported]
[mediumspringgreen is not supported]
[mediumturquoise is not supported]
[mediumvioletred is not supported]
[midnightblue is not supported]
[mintcream is not supported]
[mistyrose is not supported]
[moccasin is not supported]
[navajowhite is not supported]
[oldlace is not supported]
[olivedrab is not supported]
-> [ orange wrong RGB code ] expected ffffa500, returned ffff8000
[orangered is not supported]
[orchid is not supported]
[palegoldenrod is not supported]
[palegreen is not supported]
[paleturquoise is not supported]
[palevioletred is not supported]
[papayawhip is not supported]
[peachpuff is not supported]
[peru is not supported]
[pink is not supported]
[plum is not supported]
[powderblue is not supported]
[rebeccapurple is not supported]
[rosybrown is not supported]
[royalblue is not supported]
[saddlebrown is not supported]
[salmon is not supported]
[sandybrown is not supported]
[seagreen is not supported]
[seashell is not supported]
[sienna is not supported]
[skyblue is not supported]
[slateblue is not supported]
[slategray is not supported]
[slategrey is not supported]
[snow is not supported]
[springgreen is not supported]
[steelblue is not supported]
[tan is not supported]
[thistle is not supported]
[tomato is not supported]
[transparent is not supported]
[turquoise is not supported]
[violet is not supported]
[wheat is not supported]
[whitesmoke is not supported]
[yellowgreen is not supported]
[#f should return null]
[#f0 should return null]
-> [ #f12a wrong RGB code ] expected aaff1122, returned ff00f12a
[#f0f10 should return null]
[#f0f1092 should return null]
-> [ #ff1122aa wrong RGB code ] expected aaff1122, returned ffff1122
-> [ #f0f10928 wrong RGB code ] expected 28f0f109, returned fff0f109
[f0f10928 is not supported]
[#f0f109289 should return null]
[ffffffff is not supported]
-> [ rgb(12 24 200 / 82%) wrong RGB code ] expected d10c18c8, returned ff0c18c8
-> [ rgb(12 24 200 / 0.82) wrong RGB code ] expected d10c18c8, returned ff0c18c8
-> [ rgb(12 24 200 / -210) wrong RGB code ] expected 000c18c8, returned ff0c18c8
-> [ rgb(15% 60% 49%) wrong RGB code ] expected ff26997d, returned ff26997c
-> [ rgb(15% 60% 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
-> [ rgb(15%, 60%, 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
-> [ rgb(0.14 60% 52.3 / 0.98) wrong RGB code ] expected fa009934, returned ff009934
-> [ rgb(none none none / none) wrong RGB code ] expected 00000000, returned ff000000
-> [ rgb(none none none/none) wrong RGB code ] expected 00000000, returned ff000000
-> [ rgb(none none 30) wrong RGB code ] expected ff00001e, returned ff1e0000
-> [ rgb(none 20 none) wrong RGB code ] expected ff001400, returned ff140000
-> [ rgb(10 50 13% / 50%) wrong RGB code ] expected 800a3221, returned ff0a3221
-> [ rgb(10 50 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(10 50,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(10 50 ,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(1.2e1 0.24e2 2e2) wrong RGB code ] expected ff0c18c8, returned ff010100
-> [ rgb(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgb(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgb(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgba(12 24 200) wrong RGB code ] expected ff0c18c8, returned c18c8
-> [ rgba(12 24 200%) wrong RGB code ] expected ff0c18ff, returned c18ff
-> [ rgba(-1 24 200%) wrong RGB code ] expected ff0018ff, returned 18ff
-> [ rgba(300 24 28) wrong RGB code ] expected ffff181c, returned ff181c
+> [ rgba(12 24 200 / 82%) illegal argument ] d10c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(12, 24, 200) wrong RGB code ] expected ff0c18c8, returned c18c8
+> [ rgba(12, 24, 200, 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12, 24, 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12 , 24 , 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba( 12 , 24 , 200 , 210 ) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12 ,24, 200 ,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12,24,200,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(15% 60% 49%) wrong RGB code ] expected ff26997d, returned 26997d
+> [ rgba(15% 60% 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
+> [ rgba(15%, 60%, 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
-> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
-> [ rgba(none none 30) wrong RGB code ] expected ff00001e, returned 1e0000
-> [ rgba(none 20 none) wrong RGB code ] expected ff001400, returned 140000
-> [ rgba(10 none none) wrong RGB code ] expected ff0a0000, returned a0000
-> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
+> [ rgba(10 50 13% / 50%) illegal argument ] 800a3221 Color parameter outside of expected range: Alpha
+> [ rgba(10 50 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(10 50,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(10 50 ,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(1.2e1 0.24e2 2e2) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
-> [ rgba(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
-> [ rgba(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
at MissingColorNames.main(MissingColorNames.java:67)
The purpose of this issue is to add the missing color names, keyword
transparent
and allow non lowercase<rgb()>
or<rgba()>
values in CSS.java.This is referenced in Java Bug Database as
This is tracked in JBS as
Related Pull Request
<rgb()>
and<rgba()>
function behavioursLime
colorCSS color names are defined by :
CSS Color Module Level 4
W3C Candidate Recommendation Snapshot, 5 July 2022
4.1 The
<Color>
syntax5.1. The
<color>
syntax5.7.1. Resolving sRGB values
6.1. The RGB functions:
rgb()
andrgba()
6.2. The RGB Hexadecimal Notations: #RRGGBB
7.1. Named Colors
7.3. The
transparent
keywordRunning with Java before the patch
Running with Java after the patch
Impacts of these modifications.
stringToColor
methodorange
definition,transparent
keywordcurrentcolor
keyword.This PR modifies
stringToColor
method which has no modifier, so only usages are limited to :ColorValue
also without modifier uses it through the method to return theColor
Object
stringToColor
is also used byjavax.swing.text.html.StyleSheet
stringToColor
method to publicly return theColor
Object
.Color
Object
is publicly exposed, one can't change method behavior. This preventing to return a constantColor
excepted for the existingString.isEmpty
argument.Details
()
multiple white-space (according to Java) occurences are replaced by only one space character.rgb
orrgba
and(
are removed., like color names but I don't know where occurs this transformation!Update Javadoc
Alternatives to the first PR : Performances are tested below.
All implementations are build with
CSS_Java_Color_Generator_4_JDK.java
application from/home/scientificwaredev/Documents/openjfx-compile-tests
. Double clickcssb
.Switch ... case statement.
Clic to see the code
/** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { Color color; if (str == null) return null; if (str.length() == 0) color = Color.black; else if (str.startsWith("rgb(")) color = parseRGB(str); else if (str.startsWith("rgba(")) color = parseRGBA(str); else if (str.charAt(0) == '#') color = hexToColor(str); else color = switch(str.toLowerCase(Locale.ROOT)) { case "aliceblue" -> new Color(240, 248, 255); case "antiquewhite" -> new Color(250, 235, 215); case "aqua" -> new Color(0, 255, 255); case "aquamarine" -> new Color(127, 255, 212); case "azure" -> new Color(240, 255, 255); case "beige" -> new Color(245, 245, 220); case "bisque" -> new Color(255, 228, 196); case "black" -> new Color(0, 0, 0); case "blanchedalmond" -> new Color(255, 235, 205); case "blue" -> new Color(0, 0, 255); case "blueviolet" -> new Color(138, 43, 226); case "brown" -> new Color(165, 42, 42); case "burlywood" -> new Color(222, 184, 135); case "cadetblue" -> new Color(95, 158, 160); case "chartreuse" -> new Color(127, 255, 0); case "chocolate" -> new Color(210, 105, 30); case "coral" -> new Color(255, 127, 80); case "cornflowerblue" -> new Color(100, 149, 237); case "cornsilk" -> new Color(255, 248, 220); case "crimson" -> new Color(220, 20, 60); case "cyan" -> new Color(0, 255, 255); case "darkblue" -> new Color(0, 0, 139); case "darkcyan" -> new Color(0, 139, 139); case "darkgoldenrod" -> new Color(184, 134, 11); case "darkgray" -> new Color(169, 169, 169); case "darkgreen" -> new Color(0, 100, 0); case "darkgrey" -> new Color(169, 169, 169); case "darkkhaki" -> new Color(189, 183, 107); case "darkmagenta" -> new Color(139, 0, 139); case "darkolivegreen" -> new Color(85, 107, 47); case "darkorange" -> new Color(255, 140, 0); case "darkorchid" -> new Color(153, 50, 204); case "darkred" -> new Color(139, 0, 0); case "darksalmon" -> new Color(233, 150, 122); case "darkseagreen" -> new Color(143, 188, 143); case "darkslateblue" -> new Color(72, 61, 139); case "darkslategray" -> new Color(47, 79, 79); case "darkslategrey" -> new Color(47, 79, 79); case "darkturquoise" -> new Color(0, 206, 209); case "darkviolet" -> new Color(148, 0, 211); case "deeppink" -> new Color(255, 20, 147); case "deepskyblue" -> new Color(0, 191, 255); case "dimgray" -> new Color(105, 105, 105); case "dimgrey" -> new Color(105, 105, 105); case "dodgerblue" -> new Color(30, 144, 255); case "firebrick" -> new Color(178, 34, 34); case "floralwhite" -> new Color(255, 250, 240); case "forestgreen" -> new Color(34, 139, 34); case "fuchsia" -> new Color(255, 0, 255); case "gainsboro" -> new Color(220, 220, 220); case "ghostwhite" -> new Color(248, 248, 255); case "gold" -> new Color(255, 215, 0); case "goldenrod" -> new Color(218, 165, 32); case "gray" -> new Color(128, 128, 128); case "green" -> new Color(0, 128, 0); case "greenyellow" -> new Color(173, 255, 47); case "grey" -> new Color(128, 128, 128); case "honeydew" -> new Color(240, 255, 240); case "hotpink" -> new Color(255, 105, 180); case "indianred" -> new Color(205, 92, 92); case "indigo" -> new Color(75, 0, 130); case "ivory" -> new Color(255, 255, 240); case "khaki" -> new Color(240, 230, 140); case "lavender" -> new Color(230, 230, 250); case "lavenderblush" -> new Color(255, 240, 245); case "lawngreen" -> new Color(124, 252, 0); case "lemonchiffon" -> new Color(255, 250, 205); case "lightblue" -> new Color(173, 216, 230); case "lightcoral" -> new Color(240, 128, 128); case "lightcyan" -> new Color(224, 255, 255); case "lightgoldenrodyellow" -> new Color(250, 250, 210); case "lightgray" -> new Color(211, 211, 211); case "lightgreen" -> new Color(144, 238, 144); case "lightgrey" -> new Color(211, 211, 211); case "lightpink" -> new Color(255, 182, 193); case "lightsalmon" -> new Color(255, 160, 122); case "lightseagreen" -> new Color(32, 178, 170); case "lightskyblue" -> new Color(135, 206, 250); case "lightslategray" -> new Color(119, 136, 153); case "lightslategrey" -> new Color(119, 136, 153); case "lightsteelblue" -> new Color(176, 196, 222); case "lightyellow" -> new Color(255, 255, 224); case "lime" -> new Color(0, 255, 0); case "limegreen" -> new Color(50, 205, 50); case "linen" -> new Color(250, 240, 230); case "magenta" -> new Color(255, 0, 255); case "maroon" -> new Color(128, 0, 0); case "mediumaquamarine" -> new Color(102, 205, 170); case "mediumblue" -> new Color(0, 0, 205); case "mediumorchid" -> new Color(186, 85, 211); case "mediumpurple" -> new Color(147, 112, 219); case "mediumseagreen" -> new Color(60, 179, 113); case "mediumslateblue" -> new Color(123, 104, 238); case "mediumspringgreen" -> new Color(0, 250, 154); case "mediumturquoise" -> new Color(72, 209, 204); case "mediumvioletred" -> new Color(199, 21, 133); case "midnightblue" -> new Color(25, 25, 112); case "mintcream" -> new Color(245, 255, 250); case "mistyrose" -> new Color(255, 228, 225); case "moccasin" -> new Color(255, 228, 181); case "navajowhite" -> new Color(255, 222, 173); case "navy" -> new Color(0, 0, 128); case "oldlace" -> new Color(253, 245, 230); case "olive" -> new Color(128, 128, 0); case "olivedrab" -> new Color(107, 142, 35); case "orange" -> new Color(255, 165, 0); case "orangered" -> new Color(255, 69, 0); case "orchid" -> new Color(218, 112, 214); case "palegoldenrod" -> new Color(238, 232, 170); case "palegreen" -> new Color(152, 251, 152); case "paleturquoise" -> new Color(175, 238, 238); case "palevioletred" -> new Color(219, 112, 147); case "papayawhip" -> new Color(255, 239, 213); case "peachpuff" -> new Color(255, 218, 185); case "peru" -> new Color(205, 133, 63); case "pink" -> new Color(255, 192, 203); case "plum" -> new Color(221, 160, 221); case "powderblue" -> new Color(176, 224, 230); case "purple" -> new Color(128, 0, 128); case "rebeccapurple" -> new Color(102, 51, 153); case "red" -> new Color(255, 0, 0); case "rosybrown" -> new Color(188, 143, 143); case "royalblue" -> new Color(65, 105, 225); case "saddlebrown" -> new Color(139, 69, 19); case "salmon" -> new Color(250, 128, 114); case "sandybrown" -> new Color(244, 164, 96); case "seagreen" -> new Color(46, 139, 87); case "seashell" -> new Color(255, 245, 238); case "sienna" -> new Color(160, 82, 45); case "silver" -> new Color(192, 192, 192); case "skyblue" -> new Color(135, 206, 235); case "slateblue" -> new Color(106, 90, 205); case "slategray" -> new Color(112, 128, 144); case "slategrey" -> new Color(112, 128, 144); case "snow" -> new Color(255, 250, 250); case "springgreen" -> new Color(0, 255, 127); case "steelblue" -> new Color(70, 130, 180); case "tan" -> new Color(210, 180, 140); case "teal" -> new Color(0, 128, 128); case "thistle" -> new Color(216, 191, 216); case "tomato" -> new Color(255, 99, 71); case "turquoise" -> new Color(64, 224, 208); case "violet" -> new Color(238, 130, 238); case "wheat" -> new Color(245, 222, 179); case "white" -> new Color(255, 255, 255); case "whitesmoke" -> new Color(245, 245, 245); case "yellow" -> new Color(255, 255, 0); case "yellowgreen" -> new Color(154, 205, 50); default -> hexToColor(str); }; return color; }Or if ... else statement but with direct RGB generation.
Clic to see the code
/** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { Color color; if (str == null) return null; if (str.length() == 0) color = Color.black; else if (str.startsWith("rgb(")) color = parseRGB(str); else if (str.startsWith("rgba(")) color = parseRGBA(str); else if (str.charAt(0) == '#') color = hexToColor(str); else if (str.equalsIgnoreCase("Aliceblue")) color = new Color(240, 248, 255); else if (str.equalsIgnoreCase("Antiquewhite")) color = new Color(250, 235, 215); else if (str.equalsIgnoreCase("Aqua")) color = new Color(0, 255, 255); else if (str.equalsIgnoreCase("Aquamarine")) color = new Color(127, 255, 212); else if (str.equalsIgnoreCase("Azure")) color = new Color(240, 255, 255); else if (str.equalsIgnoreCase("Beige")) color = new Color(245, 245, 220); else if (str.equalsIgnoreCase("Bisque")) color = new Color(255, 228, 196); else if (str.equalsIgnoreCase("Black")) color = new Color(0, 0, 0); else if (str.equalsIgnoreCase("Blanchedalmond")) color = new Color(255, 235, 205); else if (str.equalsIgnoreCase("Blue")) color = new Color(0, 0, 255); else if (str.equalsIgnoreCase("Blueviolet")) color = new Color(138, 43, 226); else if (str.equalsIgnoreCase("Brown")) color = new Color(165, 42, 42); else if (str.equalsIgnoreCase("Burlywood")) color = new Color(222, 184, 135); else if (str.equalsIgnoreCase("Cadetblue")) color = new Color(95, 158, 160); else if (str.equalsIgnoreCase("Chartreuse")) color = new Color(127, 255, 0); else if (str.equalsIgnoreCase("Chocolate")) color = new Color(210, 105, 30); else if (str.equalsIgnoreCase("Coral")) color = new Color(255, 127, 80); else if (str.equalsIgnoreCase("Cornflowerblue")) color = new Color(100, 149, 237); else if (str.equalsIgnoreCase("Cornsilk")) color = new Color(255, 248, 220); else if (str.equalsIgnoreCase("Crimson")) color = new Color(220, 20, 60); else if (str.equalsIgnoreCase("Cyan")) color = new Color(0, 255, 255); else if (str.equalsIgnoreCase("Darkblue")) color = new Color(0, 0, 139); else if (str.equalsIgnoreCase("Darkcyan")) color = new Color(0, 139, 139); else if (str.equalsIgnoreCase("Darkgoldenrod")) color = new Color(184, 134, 11); else if (str.equalsIgnoreCase("Darkgray")) color = new Color(169, 169, 169); else if (str.equalsIgnoreCase("Darkgreen")) color = new Color(0, 100, 0); else if (str.equalsIgnoreCase("Darkgrey")) color = new Color(169, 169, 169); else if (str.equalsIgnoreCase("Darkkhaki")) color = new Color(189, 183, 107); else if (str.equalsIgnoreCase("Darkmagenta")) color = new Color(139, 0, 139); else if (str.equalsIgnoreCase("Darkolivegreen")) color = new Color(85, 107, 47); else if (str.equalsIgnoreCase("Darkorange")) color = new Color(255, 140, 0); else if (str.equalsIgnoreCase("Darkorchid")) color = new Color(153, 50, 204); else if (str.equalsIgnoreCase("Darkred")) color = new Color(139, 0, 0); else if (str.equalsIgnoreCase("Darksalmon")) color = new Color(233, 150, 122); else if (str.equalsIgnoreCase("Darkseagreen")) color = new Color(143, 188, 143); else if (str.equalsIgnoreCase("Darkslateblue")) color = new Color(72, 61, 139); else if (str.equalsIgnoreCase("Darkslategray")) color = new Color(47, 79, 79); else if (str.equalsIgnoreCase("Darkslategrey")) color = new Color(47, 79, 79); else if (str.equalsIgnoreCase("Darkturquoise")) color = new Color(0, 206, 209); else if (str.equalsIgnoreCase("Darkviolet")) color = new Color(148, 0, 211); else if (str.equalsIgnoreCase("Deeppink")) color = new Color(255, 20, 147); else if (str.equalsIgnoreCase("Deepskyblue")) color = new Color(0, 191, 255); else if (str.equalsIgnoreCase("Dimgray")) color = new Color(105, 105, 105); else if (str.equalsIgnoreCase("Dimgrey")) color = new Color(105, 105, 105); else if (str.equalsIgnoreCase("Dodgerblue")) color = new Color(30, 144, 255); else if (str.equalsIgnoreCase("Firebrick")) color = new Color(178, 34, 34); else if (str.equalsIgnoreCase("Floralwhite")) color = new Color(255, 250, 240); else if (str.equalsIgnoreCase("Forestgreen")) color = new Color(34, 139, 34); else if (str.equalsIgnoreCase("Fuchsia")) color = new Color(255, 0, 255); else if (str.equalsIgnoreCase("Gainsboro")) color = new Color(220, 220, 220); else if (str.equalsIgnoreCase("Ghostwhite")) color = new Color(248, 248, 255); else if (str.equalsIgnoreCase("Gold")) color = new Color(255, 215, 0); else if (str.equalsIgnoreCase("Goldenrod")) color = new Color(218, 165, 32); else if (str.equalsIgnoreCase("Gray")) color = new Color(128, 128, 128); else if (str.equalsIgnoreCase("Green")) color = new Color(0, 128, 0); else if (str.equalsIgnoreCase("Greenyellow")) color = new Color(173, 255, 47); else if (str.equalsIgnoreCase("Grey")) color = new Color(128, 128, 128); else if (str.equalsIgnoreCase("Honeydew")) color = new Color(240, 255, 240); else if (str.equalsIgnoreCase("Hotpink")) color = new Color(255, 105, 180); else if (str.equalsIgnoreCase("Indianred")) color = new Color(205, 92, 92); else if (str.equalsIgnoreCase("Indigo")) color = new Color(75, 0, 130); else if (str.equalsIgnoreCase("Ivory")) color = new Color(255, 255, 240); else if (str.equalsIgnoreCase("Khaki")) color = new Color(240, 230, 140); else if (str.equalsIgnoreCase("Lavender")) color = new Color(230, 230, 250); else if (str.equalsIgnoreCase("Lavenderblush")) color = new Color(255, 240, 245); else if (str.equalsIgnoreCase("Lawngreen")) color = new Color(124, 252, 0); else if (str.equalsIgnoreCase("Lemonchiffon")) color = new Color(255, 250, 205); else if (str.equalsIgnoreCase("Lightblue")) color = new Color(173, 216, 230); else if (str.equalsIgnoreCase("Lightcoral")) color = new Color(240, 128, 128); else if (str.equalsIgnoreCase("Lightcyan")) color = new Color(224, 255, 255); else if (str.equalsIgnoreCase("Lightgoldenrodyellow")) color = new Color(250, 250, 210); else if (str.equalsIgnoreCase("Lightgray")) color = new Color(211, 211, 211); else if (str.equalsIgnoreCase("Lightgreen")) color = new Color(144, 238, 144); else if (str.equalsIgnoreCase("Lightgrey")) color = new Color(211, 211, 211); else if (str.equalsIgnoreCase("Lightpink")) color = new Color(255, 182, 193); else if (str.equalsIgnoreCase("Lightsalmon")) color = new Color(255, 160, 122); else if (str.equalsIgnoreCase("Lightseagreen")) color = new Color(32, 178, 170); else if (str.equalsIgnoreCase("Lightskyblue")) color = new Color(135, 206, 250); else if (str.equalsIgnoreCase("Lightslategray")) color = new Color(119, 136, 153); else if (str.equalsIgnoreCase("Lightslategrey")) color = new Color(119, 136, 153); else if (str.equalsIgnoreCase("Lightsteelblue")) color = new Color(176, 196, 222); else if (str.equalsIgnoreCase("Lightyellow")) color = new Color(255, 255, 224); else if (str.equalsIgnoreCase("Lime")) color = new Color(0, 255, 0); else if (str.equalsIgnoreCase("Limegreen")) color = new Color(50, 205, 50); else if (str.equalsIgnoreCase("Linen")) color = new Color(250, 240, 230); else if (str.equalsIgnoreCase("Magenta")) color = new Color(255, 0, 255); else if (str.equalsIgnoreCase("Maroon")) color = new Color(128, 0, 0); else if (str.equalsIgnoreCase("Mediumaquamarine")) color = new Color(102, 205, 170); else if (str.equalsIgnoreCase("Mediumblue")) color = new Color(0, 0, 205); else if (str.equalsIgnoreCase("Mediumorchid")) color = new Color(186, 85, 211); else if (str.equalsIgnoreCase("Mediumpurple")) color = new Color(147, 112, 219); else if (str.equalsIgnoreCase("Mediumseagreen")) color = new Color(60, 179, 113); else if (str.equalsIgnoreCase("Mediumslateblue")) color = new Color(123, 104, 238); else if (str.equalsIgnoreCase("Mediumspringgreen")) color = new Color(0, 250, 154); else if (str.equalsIgnoreCase("Mediumturquoise")) color = new Color(72, 209, 204); else if (str.equalsIgnoreCase("Mediumvioletred")) color = new Color(199, 21, 133); else if (str.equalsIgnoreCase("Midnightblue")) color = new Color(25, 25, 112); else if (str.equalsIgnoreCase("Mintcream")) color = new Color(245, 255, 250); else if (str.equalsIgnoreCase("Mistyrose")) color = new Color(255, 228, 225); else if (str.equalsIgnoreCase("Moccasin")) color = new Color(255, 228, 181); else if (str.equalsIgnoreCase("Navajowhite")) color = new Color(255, 222, 173); else if (str.equalsIgnoreCase("Navy")) color = new Color(0, 0, 128); else if (str.equalsIgnoreCase("Oldlace")) color = new Color(253, 245, 230); else if (str.equalsIgnoreCase("Olive")) color = new Color(128, 128, 0); else if (str.equalsIgnoreCase("Olivedrab")) color = new Color(107, 142, 35); else if (str.equalsIgnoreCase("Orange")) color = new Color(255, 165, 0); else if (str.equalsIgnoreCase("Orangered")) color = new Color(255, 69, 0); else if (str.equalsIgnoreCase("Orchid")) color = new Color(218, 112, 214); else if (str.equalsIgnoreCase("Palegoldenrod")) color = new Color(238, 232, 170); else if (str.equalsIgnoreCase("Palegreen")) color = new Color(152, 251, 152); else if (str.equalsIgnoreCase("Paleturquoise")) color = new Color(175, 238, 238); else if (str.equalsIgnoreCase("Palevioletred")) color = new Color(219, 112, 147); else if (str.equalsIgnoreCase("Papayawhip")) color = new Color(255, 239, 213); else if (str.equalsIgnoreCase("Peachpuff")) color = new Color(255, 218, 185); else if (str.equalsIgnoreCase("Peru")) color = new Color(205, 133, 63); else if (str.equalsIgnoreCase("Pink")) color = new Color(255, 192, 203); else if (str.equalsIgnoreCase("Plum")) color = new Color(221, 160, 221); else if (str.equalsIgnoreCase("Powderblue")) color = new Color(176, 224, 230); else if (str.equalsIgnoreCase("Purple")) color = new Color(128, 0, 128); else if (str.equalsIgnoreCase("Rebeccapurple")) color = new Color(102, 51, 153); else if (str.equalsIgnoreCase("Red")) color = new Color(255, 0, 0); else if (str.equalsIgnoreCase("Rosybrown")) color = new Color(188, 143, 143); else if (str.equalsIgnoreCase("Royalblue")) color = new Color(65, 105, 225); else if (str.equalsIgnoreCase("Saddlebrown")) color = new Color(139, 69, 19); else if (str.equalsIgnoreCase("Salmon")) color = new Color(250, 128, 114); else if (str.equalsIgnoreCase("Sandybrown")) color = new Color(244, 164, 96); else if (str.equalsIgnoreCase("Seagreen")) color = new Color(46, 139, 87); else if (str.equalsIgnoreCase("Seashell")) color = new Color(255, 245, 238); else if (str.equalsIgnoreCase("Sienna")) color = new Color(160, 82, 45); else if (str.equalsIgnoreCase("Silver")) color = new Color(192, 192, 192); else if (str.equalsIgnoreCase("Skyblue")) color = new Color(135, 206, 235); else if (str.equalsIgnoreCase("Slateblue")) color = new Color(106, 90, 205); else if (str.equalsIgnoreCase("Slategray")) color = new Color(112, 128, 144); else if (str.equalsIgnoreCase("Slategrey")) color = new Color(112, 128, 144); else if (str.equalsIgnoreCase("Snow")) color = new Color(255, 250, 250); else if (str.equalsIgnoreCase("Springgreen")) color = new Color(0, 255, 127); else if (str.equalsIgnoreCase("Steelblue")) color = new Color(70, 130, 180); else if (str.equalsIgnoreCase("Tan")) color = new Color(210, 180, 140); else if (str.equalsIgnoreCase("Teal")) color = new Color(0, 128, 128); else if (str.equalsIgnoreCase("Thistle")) color = new Color(216, 191, 216); else if (str.equalsIgnoreCase("Tomato")) color = new Color(255, 99, 71); else if (str.equalsIgnoreCase("Turquoise")) color = new Color(64, 224, 208); else if (str.equalsIgnoreCase("Violet")) color = new Color(238, 130, 238); else if (str.equalsIgnoreCase("Wheat")) color = new Color(245, 222, 179); else if (str.equalsIgnoreCase("White")) color = new Color(255, 255, 255); else if (str.equalsIgnoreCase("Whitesmoke")) color = new Color(245, 245, 245); else if (str.equalsIgnoreCase("Yellow")) color = new Color(255, 255, 0); else if (str.equalsIgnoreCase("Yellowgreen")) color = new Color(154, 205, 50); else color = hexToColor(str); // sometimes get specified without leading # return color; }Or TreeMap approach
Clic to see the code
/** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { Color color; if (str == null) return null; if (str.length() == 0) color = Color.black; else if (str.startsWith("rgb(")) color = parseRGB(str); else if (str.startsWith("rgba(")) color = parseRGBA(str); else if (str.charAt(0) == '#') color = hexToColor(str); else if ((color = colorNamed.get(str.toLowerCase(Locale.ROOT))) == null) color = hexToColor(str); // sometimes get specified without leading # return color; } static TreeMapOr a Simple Map
Clic to see the code
/** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { Color color; if (str == null) return null; if (str.length() == 0) color = Color.black; else if (str.startsWith("rgb(")) color = parseRGB(str); else if (str.startsWith("rgba(")) color = parseRGBA(str); else if (str.charAt(0) == '#') color = hexToColor(str); else if ((color = colorNamed.get(str.toLowerCase(Locale.ROOT))) == null) color = hexToColor(str); // sometimes get specified without leading # return color; } static MapOr simple Map + new Color instance returned
Clic to see the code
/** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { if (str == null) { return null; } else if (str.isEmpty()) { return Color.black; } String strlc = str.toLowerCase(Locale.ROOT); if (strlc.startsWith("rgb(")) { return parseRGB(str); } else if (strlc.startsWith("rgba(")) { return parseRGBA(str); } else if (str.charAt(0) == '#') { return hexToColor(str); } else { Color color = colorNamed.get(strlc); if (color != null) { return new Color(color.getRGB(), true); } // sometimes get specified without leading # return hexToColor(str); } } private static MapOr an handmade binary tree.
Clic to see the code
/** * The color yellowGreen. In the default sRGB space. * @since 19 */ public static final Color YELLOW_GREEN = yellowGreen; /** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { if (str == null) { return null; } else if (str.length() == 0) { return Color.black; } else if (str.startsWith("rgb(")) { return parseRGB(str); } else if (str.startsWith("rgba(")) { return parseRGBA(str); } else if (str.charAt(0) == '#') { return hexToColor(str); } else { Color color = colorNamed(str.toLowerCase(Locale.ROOT)); if (color != null){ return color; } return hexToColor(str); // sometimes get specified without leading # } } private static Color colorNamed(String str) { if (str.compareTo("lightpink") < 0){ if (str.compareTo("darkslategrey") < 0){ if (str.compareTo("crimson") < 0){ if (str.compareTo("blueviolet") < 0){ if (str.compareTo("beige") < 0){ if (str.compareTo("aquamarine") < 0){ if (str.equals("aliceblue")) return new Color(240, 248, 255); if (str.equals("antiquewhite")) return new Color(250, 235, 215); if (str.equals("aqua")) return new Color(0, 255, 255); } else { if (str.equals("aquamarine")) return new Color(127, 255, 212); if (str.equals("azure")) return new Color(240, 255, 255); } } else if (str.compareTo("blanchedalmond") < 0){ if (str.equals("beige")) return new Color(245, 245, 220); if (str.equals("bisque")) return new Color(255, 228, 196); if (str.equals("black")) return new Color(0, 0, 0); } else { if (str.equals("blanchedalmond")) return new Color(255, 235, 205); if (str.equals("blue")) return new Color(0, 0, 255); } } else if (str.compareTo("chocolate") < 0){ if (str.compareTo("cadetblue") < 0){ if (str.equals("blueviolet")) return new Color(138, 43, 226); if (str.equals("brown")) return new Color(165, 42, 42); if (str.equals("burlywood")) return new Color(222, 184, 135); } else { if (str.equals("cadetblue")) return new Color(95, 158, 160); if (str.equals("chartreuse")) return new Color(127, 255, 0); } } else if (str.compareTo("cornflowerblue") < 0){ if (str.equals("chocolate")) return new Color(210, 105, 30); if (str.equals("coral")) return new Color(255, 127, 80); } else { if (str.equals("cornflowerblue")) return new Color(100, 149, 237); if (str.equals("cornsilk")) return new Color(255, 248, 220); } } else if (str.compareTo("darkmagenta") < 0){ if (str.compareTo("darkgray") < 0){ if (str.compareTo("darkcyan") < 0){ if (str.equals("crimson")) return new Color(220, 20, 60); if (str.equals("cyan")) return new Color(0, 255, 255); if (str.equals("darkblue")) return new Color(0, 0, 139); } else { if (str.equals("darkcyan")) return new Color(0, 139, 139); if (str.equals("darkgoldenrod")) return new Color(184, 134, 11); } } else if (str.compareTo("darkgrey") < 0){ if (str.equals("darkgray")) return new Color(169, 169, 169); if (str.equals("darkgreen")) return new Color(0, 100, 0); } else { if (str.equals("darkgrey")) return new Color(169, 169, 169); if (str.equals("darkkhaki")) return new Color(189, 183, 107); } } else if (str.compareTo("darksalmon") < 0){ if (str.compareTo("darkorchid") < 0){ if (str.equals("darkmagenta")) return new Color(139, 0, 139); if (str.equals("darkolivegreen")) return new Color(85, 107, 47); if (str.equals("darkorange")) return new Color(255, 140, 0); } else { if (str.equals("darkorchid")) return new Color(153, 50, 204); if (str.equals("darkred")) return new Color(139, 0, 0); } } else if (str.compareTo("darkslateblue") < 0){ if (str.equals("darksalmon")) return new Color(233, 150, 122); if (str.equals("darkseagreen")) return new Color(143, 188, 143); } else { if (str.equals("darkslateblue")) return new Color(72, 61, 139); if (str.equals("darkslategray")) return new Color(47, 79, 79); } } else if (str.compareTo("grey") < 0){ if (str.compareTo("forestgreen") < 0){ if (str.compareTo("dimgray") < 0){ if (str.compareTo("deeppink") < 0){ if (str.equals("darkslategrey")) return new Color(47, 79, 79); if (str.equals("darkturquoise")) return new Color(0, 206, 209); if (str.equals("darkviolet")) return new Color(148, 0, 211); } else { if (str.equals("deeppink")) return new Color(255, 20, 147); if (str.equals("deepskyblue")) return new Color(0, 191, 255); } } else if (str.compareTo("firebrick") < 0){ if (str.equals("dimgray")) return new Color(105, 105, 105); if (str.equals("dimgrey")) return new Color(105, 105, 105); if (str.equals("dodgerblue")) return new Color(30, 144, 255); } else { if (str.equals("firebrick")) return new Color(178, 34, 34); if (str.equals("floralwhite")) return new Color(255, 250, 240); } } else if (str.compareTo("goldenrod") < 0){ if (str.compareTo("ghostwhite") < 0){ if (str.equals("forestgreen")) return new Color(34, 139, 34); if (str.equals("fuchsia")) return new Color(255, 0, 255); if (str.equals("gainsboro")) return new Color(220, 220, 220); } else { if (str.equals("ghostwhite")) return new Color(248, 248, 255); if (str.equals("gold")) return new Color(255, 215, 0); } } else if (str.compareTo("green") < 0){ if (str.equals("goldenrod")) return new Color(218, 165, 32); if (str.equals("gray")) return new Color(128, 128, 128); } else { if (str.equals("green")) return new Color(0, 128, 0); if (str.equals("greenyellow")) return new Color(173, 255, 47); } } else if (str.compareTo("lawngreen") < 0){ if (str.compareTo("ivory") < 0){ if (str.compareTo("indianred") < 0){ if (str.equals("grey")) return new Color(128, 128, 128); if (str.equals("honeydew")) return new Color(240, 255, 240); if (str.equals("hotpink")) return new Color(255, 105, 180); } else { if (str.equals("indianred")) return new Color(205, 92, 92); if (str.equals("indigo")) return new Color(75, 0, 130); } } else if (str.compareTo("lavender") < 0){ if (str.equals("ivory")) return new Color(255, 255, 240); if (str.equals("khaki")) return new Color(240, 230, 140); } else { if (str.equals("lavender")) return new Color(230, 230, 250); if (str.equals("lavenderblush")) return new Color(255, 240, 245); } } else if (str.compareTo("lightgoldenrodyellow") < 0){ if (str.compareTo("lightcoral") < 0){ if (str.equals("lawngreen")) return new Color(124, 252, 0); if (str.equals("lemonchiffon")) return new Color(255, 250, 205); if (str.equals("lightblue")) return new Color(173, 216, 230); } else { if (str.equals("lightcoral")) return new Color(240, 128, 128); if (str.equals("lightcyan")) return new Color(224, 255, 255); } } else if (str.compareTo("lightgreen") < 0){ if (str.equals("lightgoldenrodyellow")) return new Color(250, 250, 210); if (str.equals("lightgray")) return new Color(211, 211, 211); } else { if (str.equals("lightgreen")) return new Color(144, 238, 144); if (str.equals("lightgrey")) return new Color(211, 211, 211); } } else if (str.compareTo("palevioletred") < 0){ if (str.compareTo("mediumspringgreen") < 0){ if (str.compareTo("linen") < 0){ if (str.compareTo("lightslategrey") < 0){ if (str.compareTo("lightskyblue") < 0){ if (str.equals("lightpink")) return new Color(255, 182, 193); if (str.equals("lightsalmon")) return new Color(255, 160, 122); if (str.equals("lightseagreen")) return new Color(32, 178, 170); } else { if (str.equals("lightskyblue")) return new Color(135, 206, 250); if (str.equals("lightslategray")) return new Color(119, 136, 153); } } else if (str.compareTo("lime") < 0){ if (str.equals("lightslategrey")) return new Color(119, 136, 153); if (str.equals("lightsteelblue")) return new Color(176, 196, 222); if (str.equals("lightyellow")) return new Color(255, 255, 224); } else { if (str.equals("lime")) return new Color(0, 255, 0); if (str.equals("limegreen")) return new Color(50, 205, 50); } } else if (str.compareTo("mediumorchid") < 0){ if (str.compareTo("mediumaquamarine") < 0){ if (str.equals("linen")) return new Color(250, 240, 230); if (str.equals("magenta")) return new Color(255, 0, 255); if (str.equals("maroon")) return new Color(128, 0, 0); } else { if (str.equals("mediumaquamarine")) return new Color(102, 205, 170); if (str.equals("mediumblue")) return new Color(0, 0, 205); } } else if (str.compareTo("mediumseagreen") < 0){ if (str.equals("mediumorchid")) return new Color(186, 85, 211); if (str.equals("mediumpurple")) return new Color(147, 112, 219); } else { if (str.equals("mediumseagreen")) return new Color(60, 179, 113); if (str.equals("mediumslateblue")) return new Color(123, 104, 238); } } else if (str.compareTo("oldlace") < 0){ if (str.compareTo("mistyrose") < 0){ if (str.compareTo("midnightblue") < 0){ if (str.equals("mediumspringgreen")) return new Color(0, 250, 154); if (str.equals("mediumturquoise")) return new Color(72, 209, 204); if (str.equals("mediumvioletred")) return new Color(199, 21, 133); } else { if (str.equals("midnightblue")) return new Color(25, 25, 112); if (str.equals("mintcream")) return new Color(245, 255, 250); } } else if (str.compareTo("navajowhite") < 0){ if (str.equals("mistyrose")) return new Color(255, 228, 225); if (str.equals("moccasin")) return new Color(255, 228, 181); } else { if (str.equals("navajowhite")) return new Color(255, 222, 173); if (str.equals("navy")) return new Color(0, 0, 128); } } else if (str.compareTo("orchid") < 0){ if (str.compareTo("orange") < 0){ if (str.equals("oldlace")) return new Color(253, 245, 230); if (str.equals("olive")) return new Color(128, 128, 0); if (str.equals("olivedrab")) return new Color(107, 142, 35); } else { if (str.equals("orange")) return new Color(255, 165, 0); if (str.equals("orangered")) return new Color(255, 69, 0); } } else if (str.compareTo("palegreen") < 0){ if (str.equals("orchid")) return new Color(218, 112, 214); if (str.equals("palegoldenrod")) return new Color(238, 232, 170); } else { if (str.equals("palegreen")) return new Color(152, 251, 152); if (str.equals("paleturquoise")) return new Color(175, 238, 238); } } else if (str.compareTo("skyblue") < 0){ if (str.compareTo("rosybrown") < 0){ if (str.compareTo("plum") < 0){ if (str.compareTo("peru") < 0){ if (str.equals("palevioletred")) return new Color(219, 112, 147); if (str.equals("papayawhip")) return new Color(255, 239, 213); if (str.equals("peachpuff")) return new Color(255, 218, 185); } else { if (str.equals("peru")) return new Color(205, 133, 63); if (str.equals("pink")) return new Color(255, 192, 203); } } else if (str.compareTo("rebeccapurple") < 0){ if (str.equals("plum")) return new Color(221, 160, 221); if (str.equals("powderblue")) return new Color(176, 224, 230); if (str.equals("purple")) return new Color(128, 0, 128); } else { if (str.equals("rebeccapurple")) return new Color(102, 51, 153); if (str.equals("red")) return new Color(255, 0, 0); } } else if (str.compareTo("seagreen") < 0){ if (str.compareTo("salmon") < 0){ if (str.equals("rosybrown")) return new Color(188, 143, 143); if (str.equals("royalblue")) return new Color(65, 105, 225); if (str.equals("saddlebrown")) return new Color(139, 69, 19); } else { if (str.equals("salmon")) return new Color(250, 128, 114); if (str.equals("sandybrown")) return new Color(244, 164, 96); } } else if (str.compareTo("sienna") < 0){ if (str.equals("seagreen")) return new Color(46, 139, 87); if (str.equals("seashell")) return new Color(255, 245, 238); } else { if (str.equals("sienna")) return new Color(160, 82, 45); if (str.equals("silver")) return new Color(192, 192, 192); } } else if (str.compareTo("thistle") < 0){ if (str.compareTo("springgreen") < 0){ if (str.compareTo("slategrey") < 0){ if (str.equals("skyblue")) return new Color(135, 206, 235); if (str.equals("slateblue")) return new Color(106, 90, 205); if (str.equals("slategray")) return new Color(112, 128, 144); } else { if (str.equals("slategrey")) return new Color(112, 128, 144); if (str.equals("snow")) return new Color(255, 250, 250); } } else if (str.compareTo("tan") < 0){ if (str.equals("springgreen")) return new Color(0, 255, 127); if (str.equals("steelblue")) return new Color(70, 130, 180); } else { if (str.equals("tan")) return new Color(210, 180, 140); if (str.equals("teal")) return new Color(0, 128, 128); } } else if (str.compareTo("white") < 0){ if (str.compareTo("violet") < 0){ if (str.equals("thistle")) return new Color(216, 191, 216); if (str.equals("tomato")) return new Color(255, 99, 71); if (str.equals("turquoise")) return new Color(64, 224, 208); } else { if (str.equals("violet")) return new Color(238, 130, 238); if (str.equals("wheat")) return new Color(245, 222, 179); } } else if (str.compareTo("yellow") < 0){ if (str.equals("white")) return new Color(255, 255, 255); if (str.equals("whitesmoke")) return new Color(245, 245, 245); } else { if (str.equals("yellow")) return new Color(255, 255, 0); if (str.equals("yellowgreen")) return new Color(154, 205, 50); } return null; }Push code to java.awt.Color ?
Finaly I think, this should be transfered to java.awt.Color with the creation of the named(String name) method. Making the code simplier :
Such proposition already rejected few years ago JDK-6921655 Additional java.awt.Color constants requested ...
Clic to see the code
``` /** * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" * or "rgba(r, g, b, a)" to a Color. */ static Color stringToColor(String str) { Color color; if (str == null) return null; if (str.length() == 0) color = Color.black; else if (str.startsWith("rgb(")) color = parseRGB(str); else if (str.startsWith("rgba(")) color = parseRGBA(str); else if (str.charAt(0) == '#') color = hexToColor(str); else if ((color = Color.named(str)) == null) color = hexToColor(str); // return color; } ```Color.java name declarations.
Fields
Clic to see the code
``` /** * The color aliceBlue. In the default sRGB space. * @since 19 */ public static final Color aliceBlue = new Color(240, 248, 255); /** * The color aliceBlue. In the default sRGB space. * @since 19 */ public static final Color ALICE_BLUE = aliceBlue; /** * The color antiqueWhite. In the default sRGB space. * @since 19 */ public static final Color antiqueWhite = new Color(250, 235, 215); /** * The color antiqueWhite. In the default sRGB space. * @since 19 */ public static final Color ANTIQUE_WHITE = antiqueWhite; /** * The color aqua. In the default sRGB space. * @since 19 */ public static final Color aqua = new Color(0, 255, 255); /** * The color aqua. In the default sRGB space. * @since 19 */ public static final Color AQUA = aqua; /** * The color aquaMarine. In the default sRGB space. * @since 19 */ public static final Color aquaMarine = new Color(127, 255, 212); /** * The color aquaMarine. In the default sRGB space. * @since 19 */ public static final Color AQUA_MARINE = aquaMarine; /** * The color azure. In the default sRGB space. * @since 19 */ public static final Color azure = new Color(240, 255, 255); /** * The color azure. In the default sRGB space. * @since 19 */ public static final Color AZURE = azure; /** * The color beige. In the default sRGB space. * @since 19 */ public static final Color beige = new Color(245, 245, 220); /** * The color beige. In the default sRGB space. * @since 19 */ public static final Color BEIGE = beige; /** * The color bisque. In the default sRGB space. * @since 19 */ public static final Color bisque = new Color(255, 228, 196); /** * The color bisque. In the default sRGB space. * @since 19 */ public static final Color BISQUE = bisque; /** * The color black. In the default sRGB space. */ public static final Color black = new Color(0, 0, 0); /** * The color black. In the default sRGB space. * @since 1.4 */ public static final Color BLACK = black; /** * The color blanchedAlmond. In the default sRGB space. * @since 19 */ public static final Color blanchedAlmond = new Color(255, 235, 205); /** * The color blanchedAlmond. In the default sRGB space. * @since 19 */ public static final Color BLANCHED_ALMOND = blanchedAlmond; /** * The color blue. In the default sRGB space. */ public static final Color blue = new Color(0, 0, 255); /** * The color blue. In the default sRGB space. * @since 1.4 */ public static final Color BLUE = blue; /** * The color blueViolet. In the default sRGB space. * @since 19 */ public static final Color blueViolet = new Color(138, 43, 226); /** * The color blueViolet. In the default sRGB space. * @since 19 */ public static final Color BLUE_VIOLET = blueViolet; /** * The color brown. In the default sRGB space. * @since 19 */ public static final Color brown = new Color(165, 42, 42); /** * The color brown. In the default sRGB space. * @since 19 */ public static final Color BROWN = brown; /** * The color burlywood. In the default sRGB space. * @since 19 */ public static final Color burlywood = new Color(222, 184, 135); /** * The color burlywood. In the default sRGB space. * @since 19 */ public static final Color BURLYWOOD = burlywood; /** * The color cadetBlue. In the default sRGB space. * @since 19 */ public static final Color cadetBlue = new Color(95, 158, 160); /** * The color cadetBlue. In the default sRGB space. * @since 19 */ public static final Color CADET_BLUE = cadetBlue; /** * The color chartreuse. In the default sRGB space. * @since 19 */ public static final Color chartreuse = new Color(127, 255, 0); /** * The color chartreuse. In the default sRGB space. * @since 19 */ public static final Color CHARTREUSE = chartreuse; /** * The color chocolate. In the default sRGB space. * @since 19 */ public static final Color chocolate = new Color(210, 105, 30); /** * The color chocolate. In the default sRGB space. * @since 19 */ public static final Color CHOCOLATE = chocolate; /** * The color coral. In the default sRGB space. * @since 19 */ public static final Color coral = new Color(255, 127, 80); /** * The color coral. In the default sRGB space. * @since 19 */ public static final Color CORAL = coral; /** * The color cornflowerBlue. In the default sRGB space. * @since 19 */ public static final Color cornflowerBlue = new Color(100, 149, 237); /** * The color cornflowerBlue. In the default sRGB space. * @since 19 */ public static final Color CORNFLOWER_BLUE = cornflowerBlue; /** * The color cornsilk. In the default sRGB space. * @since 19 */ public static final Color cornsilk = new Color(255, 248, 220); /** * The color cornsilk. In the default sRGB space. * @since 19 */ public static final Color CORNSILK = cornsilk; /** * The color crimson. In the default sRGB space. * @since 19 */ public static final Color crimson = new Color(220, 20, 60); /** * The color crimson. In the default sRGB space. * @since 19 */ public static final Color CRIMSON = crimson; /** * The color cyan. In the default sRGB space. */ public static final Color cyan = new Color(0, 255, 255); /** * The color cyan. In the default sRGB space. * @since 1.4 */ public static final Color CYAN = cyan; /** * The color darkBlue. In the default sRGB space. * @since 19 */ public static final Color darkBlue = new Color(0, 0, 139); /** * The color darkBlue. In the default sRGB space. * @since 19 */ public static final Color DARK_BLUE = darkBlue; /** * The color darkCyan. In the default sRGB space. * @since 19 */ public static final Color darkCyan = new Color(0, 139, 139); /** * The color darkCyan. In the default sRGB space. * @since 19 */ public static final Color DARK_CYAN = darkCyan; /** * The color darkGoldenrod. In the default sRGB space. * @since 19 */ public static final Color darkGoldenrod = new Color(184, 134, 11); /** * The color darkGoldenrod. In the default sRGB space. * @since 19 */ public static final Color DARK_GOLDENROD = darkGoldenrod; /** * The color darkGray. In the default sRGB space. * @since 19 */ public static final Color darkGray = new Color(169, 169, 169); /** * The color darkGray. In the default sRGB space. * @since 19 */ public static final Color DARK_GRAY = darkGray; /** * The color darkGreen. In the default sRGB space. * @since 19 */ public static final Color darkGreen = new Color(0, 100, 0); /** * The color darkGreen. In the default sRGB space. * @since 19 */ public static final Color DARK_GREEN = darkGreen; /** * The color darkGrey. In the default sRGB space. * @since 19 */ public static final Color darkGrey = new Color(169, 169, 169); /** * The color darkGrey. In the default sRGB space. * @since 19 */ public static final Color DARK_GREY = darkGrey; /** * The color darkKhaki. In the default sRGB space. * @since 19 */ public static final Color darkKhaki = new Color(189, 183, 107); /** * The color darkKhaki. In the default sRGB space. * @since 19 */ public static final Color DARK_KHAKI = darkKhaki; /** * The color darkMagenta. In the default sRGB space. * @since 19 */ public static final Color darkMagenta = new Color(139, 0, 139); /** * The color darkMagenta. In the default sRGB space. * @since 19 */ public static final Color DARK_MAGENTA = darkMagenta; /** * The color darkOliveGreen. In the default sRGB space. * @since 19 */ public static final Color darkOliveGreen = new Color(85, 107, 47); /** * The color darkOliveGreen. In the default sRGB space. * @since 19 */ public static final Color DARK_OLIVE_GREEN = darkOliveGreen; /** * The color darkOrange. In the default sRGB space. * @since 19 */ public static final Color darkOrange = new Color(255, 140, 0); /** * The color darkOrange. In the default sRGB space. * @since 19 */ public static final Color DARK_ORANGE = darkOrange; /** * The color darkOrchid. In the default sRGB space. * @since 19 */ public static final Color darkOrchid = new Color(153, 50, 204); /** * The color darkOrchid. In the default sRGB space. * @since 19 */ public static final Color DARK_ORCHID = darkOrchid; /** * The color darkRed. In the default sRGB space. * @since 19 */ public static final Color darkRed = new Color(139, 0, 0); /** * The color darkRed. In the default sRGB space. * @since 19 */ public static final Color DARK_RED = darkRed; /** * The color darkSalmon. In the default sRGB space. * @since 19 */ public static final Color darkSalmon = new Color(233, 150, 122); /** * The color darkSalmon. In the default sRGB space. * @since 19 */ public static final Color DARK_SALMON = darkSalmon; /** * The color darkSeaGreen. In the default sRGB space. * @since 19 */ public static final Color darkSeaGreen = new Color(143, 188, 143); /** * The color darkSeaGreen. In the default sRGB space. * @since 19 */ public static final Color DARK_SEA_GREEN = darkSeaGreen; /** * The color darkSlateBlue. In the default sRGB space. * @since 19 */ public static final Color darkSlateBlue = new Color(72, 61, 139); /** * The color darkSlateBlue. In the default sRGB space. * @since 19 */ public static final Color DARK_SLATE_BLUE = darkSlateBlue; /** * The color darkSlateGray. In the default sRGB space. * @since 19 */ public static final Color darkSlateGray = new Color(47, 79, 79); /** * The color darkSlateGray. In the default sRGB space. * @since 19 */ public static final Color DARK_SLATE_GRAY = darkSlateGray; /** * The color darkSlateGrey. In the default sRGB space. * @since 19 */ public static final Color darkSlateGrey = new Color(47, 79, 79); /** * The color darkSlateGrey. In the default sRGB space. * @since 19 */ public static final Color DARK_SLATE_GREY = darkSlateGrey; /** * The color darkTurquoise. In the default sRGB space. * @since 19 */ public static final Color darkTurquoise = new Color(0, 206, 209); /** * The color darkTurquoise. In the default sRGB space. * @since 19 */ public static final Color DARK_TURQUOISE = darkTurquoise; /** * The color darkViolet. In the default sRGB space. * @since 19 */ public static final Color darkViolet = new Color(148, 0, 211); /** * The color darkViolet. In the default sRGB space. * @since 19 */ public static final Color DARK_VIOLET = darkViolet; /** * The color deepPink. In the default sRGB space. * @since 19 */ public static final Color deepPink = new Color(255, 20, 147); /** * The color deepPink. In the default sRGB space. * @since 19 */ public static final Color DEEP_PINK = deepPink; /** * The color deepSkyBlue. In the default sRGB space. * @since 19 */ public static final Color deepSkyBlue = new Color(0, 191, 255); /** * The color deepSkyBlue. In the default sRGB space. * @since 19 */ public static final Color DEEP_SKY_BLUE = deepSkyBlue; /** * The color dimGray. In the default sRGB space. * @since 19 */ public static final Color dimGray = new Color(105, 105, 105); /** * The color dimGray. In the default sRGB space. * @since 19 */ public static final Color DIM_GRAY = dimGray; /** * The color dimGrey. In the default sRGB space. * @since 19 */ public static final Color dimGrey = new Color(105, 105, 105); /** * The color dimGrey. In the default sRGB space. * @since 19 */ public static final Color DIM_GREY = dimGrey; /** * The color dodgerBlue. In the default sRGB space. * @since 19 */ public static final Color dodgerBlue = new Color(30, 144, 255); /** * The color dodgerBlue. In the default sRGB space. * @since 19 */ public static final Color DODGER_BLUE = dodgerBlue; /** * The color firebrick. In the default sRGB space. * @since 19 */ public static final Color firebrick = new Color(178, 34, 34); /** * The color firebrick. In the default sRGB space. * @since 19 */ public static final Color FIREBRICK = firebrick; /** * The color floralWhite. In the default sRGB space. * @since 19 */ public static final Color floralWhite = new Color(255, 250, 240); /** * The color floralWhite. In the default sRGB space. * @since 19 */ public static final Color FLORAL_WHITE = floralWhite; /** * The color forestGreen. In the default sRGB space. * @since 19 */ public static final Color forestGreen = new Color(34, 139, 34); /** * The color forestGreen. In the default sRGB space. * @since 19 */ public static final Color FOREST_GREEN = forestGreen; /** * The color fuchsia. In the default sRGB space. * @since 19 */ public static final Color fuchsia = new Color(255, 0, 255); /** * The color fuchsia. In the default sRGB space. * @since 19 */ public static final Color FUCHSIA = fuchsia; /** * The color gainsboro. In the default sRGB space. * @since 19 */ public static final Color gainsboro = new Color(220, 220, 220); /** * The color gainsboro. In the default sRGB space. * @since 19 */ public static final Color GAINSBORO = gainsboro; /** * The color ghostWhite. In the default sRGB space. * @since 19 */ public static final Color ghostWhite = new Color(248, 248, 255); /** * The color ghostWhite. In the default sRGB space. * @since 19 */ public static final Color GHOST_WHITE = ghostWhite; /** * The color gold. In the default sRGB space. * @since 19 */ public static final Color gold = new Color(255, 215, 0); /** * The color gold. In the default sRGB space. * @since 19 */ public static final Color GOLD = gold; /** * The color goldenrod. In the default sRGB space. * @since 19 */ public static final Color goldenrod = new Color(218, 165, 32); /** * The color goldenrod. In the default sRGB space. * @since 19 */ public static final Color GOLDENROD = goldenrod; /** * The color gray. In the default sRGB space. */ public static final Color gray = new Color(128, 128, 128); /** * The color gray. In the default sRGB space. * @since 1.4 */ public static final Color GRAY = gray; /** * The color green. In the default sRGB space. */ public static final Color green = new Color(0, 128, 0); /** * The color green. In the default sRGB space. * @since 1.4 */ public static final Color GREEN = green; /** * The color greenYellow. In the default sRGB space. * @since 19 */ public static final Color greenYellow = new Color(173, 255, 47); /** * The color greenYellow. In the default sRGB space. * @since 19 */ public static final Color GREEN_YELLOW = greenYellow; /** * The color grey. In the default sRGB space. * @since 19 */ public static final Color grey = new Color(128, 128, 128); /** * The color grey. In the default sRGB space. * @since 19 */ public static final Color GREY = grey; /** * The color honeydew. In the default sRGB space. * @since 19 */ public static final Color honeydew = new Color(240, 255, 240); /** * The color honeydew. In the default sRGB space. * @since 19 */ public static final Color HONEYDEW = honeydew; /** * The color hotPink. In the default sRGB space. * @since 19 */ public static final Color hotPink = new Color(255, 105, 180); /** * The color hotPink. In the default sRGB space. * @since 19 */ public static final Color HOT_PINK = hotPink; /** * The color indianRed. In the default sRGB space. * @since 19 */ public static final Color indianRed = new Color(205, 92, 92); /** * The color indianRed. In the default sRGB space. * @since 19 */ public static final Color INDIAN_RED = indianRed; /** * The color indigo. In the default sRGB space. * @since 19 */ public static final Color indigo = new Color(75, 0, 130); /** * The color indigo. In the default sRGB space. * @since 19 */ public static final Color INDIGO = indigo; /** * The color ivory. In the default sRGB space. * @since 19 */ public static final Color ivory = new Color(255, 255, 240); /** * The color ivory. In the default sRGB space. * @since 19 */ public static final Color IVORY = ivory; /** * The color khaki. In the default sRGB space. * @since 19 */ public static final Color khaki = new Color(240, 230, 140); /** * The color khaki. In the default sRGB space. * @since 19 */ public static final Color KHAKI = khaki; /** * The color lavender. In the default sRGB space. * @since 19 */ public static final Color lavender = new Color(230, 230, 250); /** * The color lavender. In the default sRGB space. * @since 19 */ public static final Color LAVENDER = lavender; /** * The color lavenderBlush. In the default sRGB space. * @since 19 */ public static final Color lavenderBlush = new Color(255, 240, 245); /** * The color lavenderBlush. In the default sRGB space. * @since 19 */ public static final Color LAVENDER_BLUSH = lavenderBlush; /** * The color lawnGreen. In the default sRGB space. * @since 19 */ public static final Color lawnGreen = new Color(124, 252, 0); /** * The color lawnGreen. In the default sRGB space. * @since 19 */ public static final Color LAWN_GREEN = lawnGreen; /** * The color lemonChiffon. In the default sRGB space. * @since 19 */ public static final Color lemonChiffon = new Color(255, 250, 205); /** * The color lemonChiffon. In the default sRGB space. * @since 19 */ public static final Color LEMON_CHIFFON = lemonChiffon; /** * The color lightBlue. In the default sRGB space. * @since 19 */ public static final Color lightBlue = new Color(173, 216, 230); /** * The color lightBlue. In the default sRGB space. * @since 19 */ public static final Color LIGHT_BLUE = lightBlue; /** * The color lightCoral. In the default sRGB space. * @since 19 */ public static final Color lightCoral = new Color(240, 128, 128); /** * The color lightCoral. In the default sRGB space. * @since 19 */ public static final Color LIGHT_CORAL = lightCoral; /** * The color lightCyan. In the default sRGB space. * @since 19 */ public static final Color lightCyan = new Color(224, 255, 255); /** * The color lightCyan. In the default sRGB space. * @since 19 */ public static final Color LIGHT_CYAN = lightCyan; /** * The color lightGoldenrodYellow. In the default sRGB space. * @since 19 */ public static final Color lightGoldenrodYellow = new Color(250, 250, 210); /** * The color lightGoldenrodYellow. In the default sRGB space. * @since 19 */ public static final Color LIGHT_GOLDENROD_YELLOW = lightGoldenrodYellow; /** * The color lightGray. In the default sRGB space. * @since 19 */ public static final Color lightGray = new Color(211, 211, 211); /** * The color lightGray. In the default sRGB space. * @since 19 */ public static final Color LIGHT_GRAY = lightGray; /** * The color lightGreen. In the default sRGB space. * @since 19 */ public static final Color lightGreen = new Color(144, 238, 144); /** * The color lightGreen. In the default sRGB space. * @since 19 */ public static final Color LIGHT_GREEN = lightGreen; /** * The color lightGrey. In the default sRGB space. * @since 19 */ public static final Color lightGrey = new Color(211, 211, 211); /** * The color lightGrey. In the default sRGB space. * @since 19 */ public static final Color LIGHT_GREY = lightGrey; /** * The color lightPink. In the default sRGB space. * @since 19 */ public static final Color lightPink = new Color(255, 182, 193); /** * The color lightPink. In the default sRGB space. * @since 19 */ public static final Color LIGHT_PINK = lightPink; /** * The color lightSalmon. In the default sRGB space. * @since 19 */ public static final Color lightSalmon = new Color(255, 160, 122); /** * The color lightSalmon. In the default sRGB space. * @since 19 */ public static final Color LIGHT_SALMON = lightSalmon; /** * The color lightSeaGreen. In the default sRGB space. * @since 19 */ public static final Color lightSeaGreen = new Color(32, 178, 170); /** * The color lightSeaGreen. In the default sRGB space. * @since 19 */ public static final Color LIGHT_SEA_GREEN = lightSeaGreen; /** * The color lightSkyBlue. In the default sRGB space. * @since 19 */ public static final Color lightSkyBlue = new Color(135, 206, 250); /** * The color lightSkyBlue. In the default sRGB space. * @since 19 */ public static final Color LIGHT_SKY_BLUE = lightSkyBlue; /** * The color lightSlateGray. In the default sRGB space. * @since 19 */ public static final Color lightSlateGray = new Color(119, 136, 153); /** * The color lightSlateGray. In the default sRGB space. * @since 19 */ public static final Color LIGHT_SLATE_GRAY = lightSlateGray; /** * The color lightSlateGrey. In the default sRGB space. * @since 19 */ public static final Color lightSlateGrey = new Color(119, 136, 153); /** * The color lightSlateGrey. In the default sRGB space. * @since 19 */ public static final Color LIGHT_SLATE_GREY = lightSlateGrey; /** * The color lightSteelBlue. In the default sRGB space. * @since 19 */ public static final Color lightSteelBlue = new Color(176, 196, 222); /** * The color lightSteelBlue. In the default sRGB space. * @since 19 */ public static final Color LIGHT_STEEL_BLUE = lightSteelBlue; /** * The color lightYellow. In the default sRGB space. * @since 19 */ public static final Color lightYellow = new Color(255, 255, 224); /** * The color lightYellow. In the default sRGB space. * @since 19 */ public static final Color LIGHT_YELLOW = lightYellow; /** * The color lime. In the default sRGB space. * @since 19 */ public static final Color lime = new Color(0, 255, 0); /** * The color lime. In the default sRGB space. * @since 19 */ public static final Color LIME = lime; /** * The color limeGreen. In the default sRGB space. * @since 19 */ public static final Color limeGreen = new Color(50, 205, 50); /** * The color limeGreen. In the default sRGB space. * @since 19 */ public static final Color LIME_GREEN = limeGreen; /** * The color linen. In the default sRGB space. * @since 19 */ public static final Color linen = new Color(250, 240, 230); /** * The color linen. In the default sRGB space. * @since 19 */ public static final Color LINEN = linen; /** * The color magenta. In the default sRGB space. */ public static final Color magenta = new Color(255, 0, 255); /** * The color magenta. In the default sRGB space. * @since 1.4 */ public static final Color MAGENTA = magenta; /** * The color maroon. In the default sRGB space. * @since 19 */ public static final Color maroon = new Color(128, 0, 0); /** * The color maroon. In the default sRGB space. * @since 19 */ public static final Color MAROON = maroon; /** * The color mediumAquamarine. In the default sRGB space. * @since 19 */ public static final Color mediumAquamarine = new Color(102, 205, 170); /** * The color mediumAquamarine. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_AQUAMARINE = mediumAquamarine; /** * The color mediumBlue. In the default sRGB space. * @since 19 */ public static final Color mediumBlue = new Color(0, 0, 205); /** * The color mediumBlue. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_BLUE = mediumBlue; /** * The color mediumOrchid. In the default sRGB space. * @since 19 */ public static final Color mediumOrchid = new Color(186, 85, 211); /** * The color mediumOrchid. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_ORCHID = mediumOrchid; /** * The color mediumPurple. In the default sRGB space. * @since 19 */ public static final Color mediumPurple = new Color(147, 112, 219); /** * The color mediumPurple. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_PURPLE = mediumPurple; /** * The color mediumSeaGreen. In the default sRGB space. * @since 19 */ public static final Color mediumSeaGreen = new Color(60, 179, 113); /** * The color mediumSeaGreen. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_SEA_GREEN = mediumSeaGreen; /** * The color mediumSlateBlue. In the default sRGB space. * @since 19 */ public static final Color mediumSlateBlue = new Color(123, 104, 238); /** * The color mediumSlateBlue. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_SLATE_BLUE = mediumSlateBlue; /** * The color mediumSpringGreen. In the default sRGB space. * @since 19 */ public static final Color mediumSpringGreen = new Color(0, 250, 154); /** * The color mediumSpringGreen. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_SPRING_GREEN = mediumSpringGreen; /** * The color mediumTurquoise. In the default sRGB space. * @since 19 */ public static final Color mediumTurquoise = new Color(72, 209, 204); /** * The color mediumTurquoise. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_TURQUOISE = mediumTurquoise; /** * The color mediumVioletRed. In the default sRGB space. * @since 19 */ public static final Color mediumVioletRed = new Color(199, 21, 133); /** * The color mediumVioletRed. In the default sRGB space. * @since 19 */ public static final Color MEDIUM_VIOLET_RED = mediumVioletRed; /** * The color midnightblue. In the default sRGB space. * @since 19 */ public static final Color midnightblue = new Color(25, 25, 112); /** * The color midnightblue. In the default sRGB space. * @since 19 */ public static final Color MIDNIGHTBLUE = midnightblue; /** * The color mintCream. In the default sRGB space. * @since 19 */ public static final Color mintCream = new Color(245, 255, 250); /** * The color mintCream. In the default sRGB space. * @since 19 */ public static final Color MINT_CREAM = mintCream; /** * The color mistyRose. In the default sRGB space. * @since 19 */ public static final Color mistyRose = new Color(255, 228, 225); /** * The color mistyRose. In the default sRGB space. * @since 19 */ public static final Color MISTY_ROSE = mistyRose; /** * The color moccasin. In the default sRGB space. * @since 19 */ public static final Color moccasin = new Color(255, 228, 181); /** * The color moccasin. In the default sRGB space. * @since 19 */ public static final Color MOCCASIN = moccasin; /** * The color navajoWhite. In the default sRGB space. * @since 19 */ public static final Color navajoWhite = new Color(255, 222, 173); /** * The color navajoWhite. In the default sRGB space. * @since 19 */ public static final Color NAVAJO_WHITE = navajoWhite; /** * The color navy. In the default sRGB space. * @since 19 */ public static final Color navy = new Color(0, 0, 128); /** * The color navy. In the default sRGB space. * @since 19 */ public static final Color NAVY = navy; /** * The color oldLace. In the default sRGB space. * @since 19 */ public static final Color oldLace = new Color(253, 245, 230); /** * The color oldLace. In the default sRGB space. * @since 19 */ public static final Color OLD_LACE = oldLace; /** * The color olive. In the default sRGB space. * @since 19 */ public static final Color olive = new Color(128, 128, 0); /** * The color olive. In the default sRGB space. * @since 19 */ public static final Color OLIVE = olive; /** * The color oliveDrab. In the default sRGB space. * @since 19 */ public static final Color oliveDrab = new Color(107, 142, 35); /** * The color oliveDrab. In the default sRGB space. * @since 19 */ public static final Color OLIVE_DRAB = oliveDrab; /** * The color orange. In the default sRGB space. */ public static final Color orange = new Color(255, 165, 0); /** * The color orange. In the default sRGB space. * @since 1.4 */ public static final Color ORANGE = orange; /** * The color orangeRed. In the default sRGB space. * @since 19 */ public static final Color orangeRed = new Color(255, 69, 0); /** * The color orangeRed. In the default sRGB space. * @since 19 */ public static final Color ORANGE_RED = orangeRed; /** * The color orchid. In the default sRGB space. * @since 19 */ public static final Color orchid = new Color(218, 112, 214); /** * The color orchid. In the default sRGB space. * @since 19 */ public static final Color ORCHID = orchid; /** * The color paleGoldenrod. In the default sRGB space. * @since 19 */ public static final Color paleGoldenrod = new Color(238, 232, 170); /** * The color paleGoldenrod. In the default sRGB space. * @since 19 */ public static final Color PALE_GOLDENROD = paleGoldenrod; /** * The color paleGreen. In the default sRGB space. * @since 19 */ public static final Color paleGreen = new Color(152, 251, 152); /** * The color paleGreen. In the default sRGB space. * @since 19 */ public static final Color PALE_GREEN = paleGreen; /** * The color paleTurquoise. In the default sRGB space. * @since 19 */ public static final Color paleTurquoise = new Color(175, 238, 238); /** * The color paleTurquoise. In the default sRGB space. * @since 19 */ public static final Color PALE_TURQUOISE = paleTurquoise; /** * The color paleVioletRed. In the default sRGB space. * @since 19 */ public static final Color paleVioletRed = new Color(219, 112, 147); /** * The color paleVioletRed. In the default sRGB space. * @since 19 */ public static final Color PALE_VIOLET_RED = paleVioletRed; /** * The color papayaWhip. In the default sRGB space. * @since 19 */ public static final Color papayaWhip = new Color(255, 239, 213); /** * The color papayaWhip. In the default sRGB space. * @since 19 */ public static final Color PAPAYA_WHIP = papayaWhip; /** * The color peachPuff. In the default sRGB space. * @since 19 */ public static final Color peachPuff = new Color(255, 218, 185); /** * The color peachPuff. In the default sRGB space. * @since 19 */ public static final Color PEACH_PUFF = peachPuff; /** * The color peru. In the default sRGB space. * @since 19 */ public static final Color peru = new Color(205, 133, 63); /** * The color peru. In the default sRGB space. * @since 19 */ public static final Color PERU = peru; /** * The color pink. In the default sRGB space. */ public static final Color pink = new Color(255, 192, 203); /** * The color pink. In the default sRGB space. * @since 1.4 */ public static final Color PINK = pink; /** * The color plum. In the default sRGB space. * @since 19 */ public static final Color plum = new Color(221, 160, 221); /** * The color plum. In the default sRGB space. * @since 19 */ public static final Color PLUM = plum; /** * The color powderBlue. In the default sRGB space. * @since 19 */ public static final Color powderBlue = new Color(176, 224, 230); /** * The color powderBlue. In the default sRGB space. * @since 19 */ public static final Color POWDER_BLUE = powderBlue; /** * The color purple. In the default sRGB space. * @since 19 */ public static final Color purple = new Color(128, 0, 128); /** * The color purple. In the default sRGB space. * @since 19 */ public static final Color PURPLE = purple; /** * The color rebeccaPurple. In the default sRGB space. * @since 19 */ public static final Color rebeccaPurple = new Color(102, 51, 153); /** * The color rebeccaPurple. In the default sRGB space. * @since 19 */ public static final Color REBECCA_PURPLE = rebeccaPurple; /** * The color red. In the default sRGB space. */ public static final Color red = new Color(255, 0, 0); /** * The color red. In the default sRGB space. * @since 1.4 */ public static final Color RED = red; /** * The color rosyBrown. In the default sRGB space. * @since 19 */ public static final Color rosyBrown = new Color(188, 143, 143); /** * The color rosyBrown. In the default sRGB space. * @since 19 */ public static final Color ROSY_BROWN = rosyBrown; /** * The color royalBlue. In the default sRGB space. * @since 19 */ public static final Color royalBlue = new Color(65, 105, 225); /** * The color royalBlue. In the default sRGB space. * @since 19 */ public static final Color ROYAL_BLUE = royalBlue; /** * The color saddleBrown. In the default sRGB space. * @since 19 */ public static final Color saddleBrown = new Color(139, 69, 19); /** * The color saddleBrown. In the default sRGB space. * @since 19 */ public static final Color SADDLE_BROWN = saddleBrown; /** * The color salmon. In the default sRGB space. * @since 19 */ public static final Color salmon = new Color(250, 128, 114); /** * The color salmon. In the default sRGB space. * @since 19 */ public static final Color SALMON = salmon; /** * The color sandyBrown. In the default sRGB space. * @since 19 */ public static final Color sandyBrown = new Color(244, 164, 96); /** * The color sandyBrown. In the default sRGB space. * @since 19 */ public static final Color SANDY_BROWN = sandyBrown; /** * The color seaGreen. In the default sRGB space. * @since 19 */ public static final Color seaGreen = new Color(46, 139, 87); /** * The color seaGreen. In the default sRGB space. * @since 19 */ public static final Color SEA_GREEN = seaGreen; /** * The color seashell. In the default sRGB space. * @since 19 */ public static final Color seashell = new Color(255, 245, 238); /** * The color seashell. In the default sRGB space. * @since 19 */ public static final Color SEASHELL = seashell; /** * The color sienna. In the default sRGB space. * @since 19 */ public static final Color sienna = new Color(160, 82, 45); /** * The color sienna. In the default sRGB space. * @since 19 */ public static final Color SIENNA = sienna; /** * The color silver. In the default sRGB space. * @since 19 */ public static final Color silver = new Color(192, 192, 192); /** * The color silver. In the default sRGB space. * @since 19 */ public static final Color SILVER = silver; /** * The color skyBlue. In the default sRGB space. * @since 19 */ public static final Color skyBlue = new Color(135, 206, 235); /** * The color skyBlue. In the default sRGB space. * @since 19 */ public static final Color SKY_BLUE = skyBlue; /** * The color slateBlue. In the default sRGB space. * @since 19 */ public static final Color slateBlue = new Color(106, 90, 205); /** * The color slateBlue. In the default sRGB space. * @since 19 */ public static final Color SLATE_BLUE = slateBlue; /** * The color slateGray. In the default sRGB space. * @since 19 */ public static final Color slateGray = new Color(112, 128, 144); /** * The color slateGray. In the default sRGB space. * @since 19 */ public static final Color SLATE_GRAY = slateGray; /** * The color slateGrey. In the default sRGB space. * @since 19 */ public static final Color slateGrey = new Color(112, 128, 144); /** * The color slateGrey. In the default sRGB space. * @since 19 */ public static final Color SLATE_GREY = slateGrey; /** * The color snow. In the default sRGB space. * @since 19 */ public static final Color snow = new Color(255, 250, 250); /** * The color snow. In the default sRGB space. * @since 19 */ public static final Color SNOW = snow; /** * The color springGreen. In the default sRGB space. * @since 19 */ public static final Color springGreen = new Color(0, 255, 127); /** * The color springGreen. In the default sRGB space. * @since 19 */ public static final Color SPRING_GREEN = springGreen; /** * The color steelBlue. In the default sRGB space. * @since 19 */ public static final Color steelBlue = new Color(70, 130, 180); /** * The color steelBlue. In the default sRGB space. * @since 19 */ public static final Color STEEL_BLUE = steelBlue; /** * The color tan. In the default sRGB space. * @since 19 */ public static final Color tan = new Color(210, 180, 140); /** * The color tan. In the default sRGB space. * @since 19 */ public static final Color TAN = tan; /** * The color teal. In the default sRGB space. * @since 19 */ public static final Color teal = new Color(0, 128, 128); /** * The color teal. In the default sRGB space. * @since 19 */ public static final Color TEAL = teal; /** * The color thistle. In the default sRGB space. * @since 19 */ public static final Color thistle = new Color(216, 191, 216); /** * The color thistle. In the default sRGB space. * @since 19 */ public static final Color THISTLE = thistle; /** * The color tomato. In the default sRGB space. * @since 19 */ public static final Color tomato = new Color(255, 99, 71); /** * The color tomato. In the default sRGB space. * @since 19 */ public static final Color TOMATO = tomato; /** * The color turquoise. In the default sRGB space. * @since 19 */ public static final Color turquoise = new Color(64, 224, 208); /** * The color turquoise. In the default sRGB space. * @since 19 */ public static final Color TURQUOISE = turquoise; /** * The color violet. In the default sRGB space. * @since 19 */ public static final Color violet = new Color(238, 130, 238); /** * The color violet. In the default sRGB space. * @since 19 */ public static final Color VIOLET = violet; /** * The color wheat. In the default sRGB space. * @since 19 */ public static final Color wheat = new Color(245, 222, 179); /** * The color wheat. In the default sRGB space. * @since 19 */ public static final Color WHEAT = wheat; /** * The color white. In the default sRGB space. */ public static final Color white = new Color(255, 255, 255); /** * The color white. In the default sRGB space. * @since 1.4 */ public static final Color WHITE = white; /** * The color whiteSmoke. In the default sRGB space. * @since 19 */ public static final Color whiteSmoke = new Color(245, 245, 245); /** * The color whiteSmoke. In the default sRGB space. * @since 19 */ public static final Color WHITE_SMOKE = whiteSmoke; /** * The color yellow. In the default sRGB space. */ public static final Color yellow = new Color(255, 255, 0); /** * The color yellow. In the default sRGB space. * @since 1.4 */ public static final Color YELLOW = yellow; /** * The color yellowGreen. In the default sRGB space. * @since 19 */ public static final Color yellowGreen = new Color(154, 205, 50); /** * The color yellowGreen. In the default sRGB space. * @since 19 */ public static final Color YELLOW_GREEN = yellowGreen; ```Color.java
named
method :construction: Rewrite this using TreeMap or Map.Method Summary
Clic to see the code
``` /** * Returns the {@code Color} matching the given color name, * if referenced. * @param name name of the color. * @return the {@code Color} or null if the name is not referenced. */ public Color named (String name) { Color color = switch(str.toLowerCase(Locale.ROOT)) { case "aliceblue" -> new Color(240, 248, 255); case "antiquewhite" -> new Color(250, 235, 215); case "aqua" -> new Color(0, 255, 255); case "aquamarine" -> new Color(127, 255, 212); case "azure" -> new Color(240, 255, 255); case "beige" -> new Color(245, 245, 220); case "bisque" -> new Color(255, 228, 196); case "black" -> new Color(0, 0, 0); case "blanchedalmond" -> new Color(255, 235, 205); case "blue" -> new Color(0, 0, 255); case "blueviolet" -> new Color(138, 43, 226); case "brown" -> new Color(165, 42, 42); case "burlywood" -> new Color(222, 184, 135); case "cadetblue" -> new Color(95, 158, 160); case "chartreuse" -> new Color(127, 255, 0); case "chocolate" -> new Color(210, 105, 30); case "coral" -> new Color(255, 127, 80); case "cornflowerblue" -> new Color(100, 149, 237); case "cornsilk" -> new Color(255, 248, 220); case "crimson" -> new Color(220, 20, 60); case "cyan" -> new Color(0, 255, 255); case "darkblue" -> new Color(0, 0, 139); case "darkcyan" -> new Color(0, 139, 139); case "darkgoldenrod" -> new Color(184, 134, 11); case "darkgray" -> new Color(169, 169, 169); case "darkgreen" -> new Color(0, 100, 0); case "darkgrey" -> new Color(169, 169, 169); case "darkkhaki" -> new Color(189, 183, 107); case "darkmagenta" -> new Color(139, 0, 139); case "darkolivegreen" -> new Color(85, 107, 47); case "darkorange" -> new Color(255, 140, 0); case "darkorchid" -> new Color(153, 50, 204); case "darkred" -> new Color(139, 0, 0); case "darksalmon" -> new Color(233, 150, 122); case "darkseagreen" -> new Color(143, 188, 143); case "darkslateblue" -> new Color(72, 61, 139); case "darkslategray" -> new Color(47, 79, 79); case "darkslategrey" -> new Color(47, 79, 79); case "darkturquoise" -> new Color(0, 206, 209); case "darkviolet" -> new Color(148, 0, 211); case "deeppink" -> new Color(255, 20, 147); case "deepskyblue" -> new Color(0, 191, 255); case "dimgray" -> new Color(105, 105, 105); case "dimgrey" -> new Color(105, 105, 105); case "dodgerblue" -> new Color(30, 144, 255); case "firebrick" -> new Color(178, 34, 34); case "floralwhite" -> new Color(255, 250, 240); case "forestgreen" -> new Color(34, 139, 34); case "fuchsia" -> new Color(255, 0, 255); case "gainsboro" -> new Color(220, 220, 220); case "ghostwhite" -> new Color(248, 248, 255); case "gold" -> new Color(255, 215, 0); case "goldenrod" -> new Color(218, 165, 32); case "gray" -> new Color(128, 128, 128); case "green" -> new Color(0, 128, 0); case "greenyellow" -> new Color(173, 255, 47); case "grey" -> new Color(128, 128, 128); case "honeydew" -> new Color(240, 255, 240); case "hotpink" -> new Color(255, 105, 180); case "indianred" -> new Color(205, 92, 92); case "indigo" -> new Color(75, 0, 130); case "ivory" -> new Color(255, 255, 240); case "khaki" -> new Color(240, 230, 140); case "lavender" -> new Color(230, 230, 250); case "lavenderblush" -> new Color(255, 240, 245); case "lawngreen" -> new Color(124, 252, 0); case "lemonchiffon" -> new Color(255, 250, 205); case "lightblue" -> new Color(173, 216, 230); case "lightcoral" -> new Color(240, 128, 128); case "lightcyan" -> new Color(224, 255, 255); case "lightgoldenrodyellow" -> new Color(250, 250, 210); case "lightgray" -> new Color(211, 211, 211); case "lightgreen" -> new Color(144, 238, 144); case "lightgrey" -> new Color(211, 211, 211); case "lightpink" -> new Color(255, 182, 193); case "lightsalmon" -> new Color(255, 160, 122); case "lightseagreen" -> new Color(32, 178, 170); case "lightskyblue" -> new Color(135, 206, 250); case "lightslategray" -> new Color(119, 136, 153); case "lightslategrey" -> new Color(119, 136, 153); case "lightsteelblue" -> new Color(176, 196, 222); case "lightyellow" -> new Color(255, 255, 224); case "lime" -> new Color(0, 255, 0); case "limegreen" -> new Color(50, 205, 50); case "linen" -> new Color(250, 240, 230); case "magenta" -> new Color(255, 0, 255); case "maroon" -> new Color(128, 0, 0); case "mediumaquamarine" -> new Color(102, 205, 170); case "mediumblue" -> new Color(0, 0, 205); case "mediumorchid" -> new Color(186, 85, 211); case "mediumpurple" -> new Color(147, 112, 219); case "mediumseagreen" -> new Color(60, 179, 113); case "mediumslateblue" -> new Color(123, 104, 238); case "mediumspringgreen" -> new Color(0, 250, 154); case "mediumturquoise" -> new Color(72, 209, 204); case "mediumvioletred" -> new Color(199, 21, 133); case "midnightblue" -> new Color(25, 25, 112); case "mintcream" -> new Color(245, 255, 250); case "mistyrose" -> new Color(255, 228, 225); case "moccasin" -> new Color(255, 228, 181); case "navajowhite" -> new Color(255, 222, 173); case "navy" -> new Color(0, 0, 128); case "oldlace" -> new Color(253, 245, 230); case "olive" -> new Color(128, 128, 0); case "olivedrab" -> new Color(107, 142, 35); case "orange" -> new Color(255, 165, 0); case "orangered" -> new Color(255, 69, 0); case "orchid" -> new Color(218, 112, 214); case "palegoldenrod" -> new Color(238, 232, 170); case "palegreen" -> new Color(152, 251, 152); case "paleturquoise" -> new Color(175, 238, 238); case "palevioletred" -> new Color(219, 112, 147); case "papayawhip" -> new Color(255, 239, 213); case "peachpuff" -> new Color(255, 218, 185); case "peru" -> new Color(205, 133, 63); case "pink" -> new Color(255, 192, 203); case "plum" -> new Color(221, 160, 221); case "powderblue" -> new Color(176, 224, 230); case "purple" -> new Color(128, 0, 128); case "rebeccapurple" -> new Color(102, 51, 153); case "red" -> new Color(255, 0, 0); case "rosybrown" -> new Color(188, 143, 143); case "royalblue" -> new Color(65, 105, 225); case "saddlebrown" -> new Color(139, 69, 19); case "salmon" -> new Color(250, 128, 114); case "sandybrown" -> new Color(244, 164, 96); case "seagreen" -> new Color(46, 139, 87); case "seashell" -> new Color(255, 245, 238); case "sienna" -> new Color(160, 82, 45); case "silver" -> new Color(192, 192, 192); case "skyblue" -> new Color(135, 206, 235); case "slateblue" -> new Color(106, 90, 205); case "slategray" -> new Color(112, 128, 144); case "slategrey" -> new Color(112, 128, 144); case "snow" -> new Color(255, 250, 250); case "springgreen" -> new Color(0, 255, 127); case "steelblue" -> new Color(70, 130, 180); case "tan" -> new Color(210, 180, 140); case "teal" -> new Color(0, 128, 128); case "thistle" -> new Color(216, 191, 216); case "tomato" -> new Color(255, 99, 71); case "turquoise" -> new Color(64, 224, 208); case "violet" -> new Color(238, 130, 238); case "wheat" -> new Color(245, 222, 179); case "white" -> new Color(255, 255, 255); case "whitesmoke" -> new Color(245, 245, 245); case "yellow" -> new Color(255, 255, 0); case "yellowgreen" -> new Color(154, 205, 50); default -> null; } return color; } ```About performance
Differences in sRGB and hex definitions.
#00ffff
#000000
#0000ff
#00ffff
#a9a9a9
#0000ff
#808080
#008000
#d3d3d3
#00ff00
#ff00ff
#800000
#000080
#808000
#FF8000
#ffa500
#ffc0cb
#800080
#ff0000
#c0c0c0
#008080
#ffffff
#ffff00