├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── gradle-local.template.properties ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── license-header.txt └── src ├── main └── java │ ├── module-info.java │ └── org │ └── beryx │ └── awt │ └── color │ └── ColorFactory.java └── test └── java └── org └── beryx └── awt └── color └── ColorFactoryTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # directory names ending with / will be excluded from all IDEA modules (see ide.gradle) 2 | 3 | gradle-local.properties 4 | gpg/ 5 | .gradle/ 6 | build/ 7 | *.class 8 | *.log 9 | *.settings.xml 10 | 11 | # Eclipse 12 | .classpath 13 | .project 14 | .settings/ 15 | bin/ 16 | 17 | # IDEA 18 | *.iml 19 | *.ipr 20 | *.iws 21 | .idea/ 22 | out/ 23 | 24 | hs_err_pid* 25 | _ignore* 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | sudo: false 4 | 5 | jdk: 6 | - openjdk11 7 | 8 | install: 9 | - chmod a+x ./gradlew 10 | 11 | cache: 12 | directories: 13 | - $HOME/.gradle 14 | 15 | script: ./gradlew --info --stacktrace build 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | "CLASSPATH" EXCEPTION TO THE GPL 342 | 343 | Linking this library statically or dynamically with other modules is making 344 | a combined work based on this library. Thus, the terms and conditions of 345 | the GNU General Public License cover the whole combination. 346 | 347 | As a special exception, the copyright holders of this library 348 | give you permission to link this library with independent modules 349 | to produce an executable, regardless of the license terms of these 350 | independent modules, and to copy and distribute the resulting 351 | executable under terms of your choice, provided that you also meet, 352 | for each linked independent module, the terms and conditions of the 353 | license of that module. An independent module is a module which is 354 | not derived from or based on this library. If you modify this 355 | library, you may extend this exception to your version of the 356 | library, but you are not obligated to do so. If you do not wish to 357 | do so, delete this exception statement from your version. 358 | 359 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 2 | [![License](https://img.shields.io/badge/License-GPL%202%20with%20Classpath%20exception-blue.svg)](https://github.com/beryx/awt-color-factory/blob/master/LICENSE#L347-L357) 3 | [![Build Status](https://img.shields.io/travis/beryx/awt-color-factory/master.svg?label=Build)](https://travis-ci.org/beryx/awt-color-factory) 4 | [![Javadocs](http://www.javadoc.io/badge/org.beryx/awt-color-factory.png?color=red)](http://www.javadoc.io/doc/org.beryx/awt-color-factory) 5 | 6 | # AWT Color Factory 7 | 8 | 9 | ### :bulb: _You can use this library regardless of the license under which your software is distributed._ 10 | 11 | In JavaFX you can easily create a javafx.scene.paint.Color object from a string representation such as 12 | "lightblue", "#aa38e0", or "0x40A8CC" by using 13 | [Color.web(String colorString)](https://docs.oracle.com/javase/10/docs/api/javafx/scene/paint/Color.html#web(java.lang.String)), 14 | [Color.web(String colorString, double opacity)](https://docs.oracle.com/javase/10/docs/api/javafx/scene/paint/Color.html#web(java.lang.String,double)), 15 | or [Color.valueOf(String value)](https://docs.oracle.com/javase/10/docs/api/javafx/scene/paint/Color.html#valueOf(java.lang.String)). 16 | 17 | This one-class project provides equivalent methods for creating java.awt.Color objects. 18 | 19 | ### Example usage 20 | 21 | Color c1 = ColorFactory.valueOf("firebrick"); 22 | Color c2 = ColorFactory.valueOf("#aa38e0"); 23 | Color c3 = ColorFactory.valueOf("0x40A8CC"); 24 | Color c4 = ColorFactory.valueOf("rgba(112,36,228,0.9)"); 25 | Color c5 = ColorFactory.web("forestgreen", 0.7); 26 | Color c6 = ColorFactory.web("hsl(270,90%,70%)", 0.8); 27 | 28 | See the [javadoc](https://static.javadoc.io/org.beryx/awt-color-factory/1.0.1/org/beryx/awt/color/ColorFactory.html) 29 | for more details. 30 | 31 | Why should you use this library? Can't you just call the JavaFX methods and convert the returned javafx.scene.paint.Color into a java.awt.Color? 32 | Of course you can. But you may find this little library useful if you don't want your code to depend on JavaFX. 33 | And remember, starting with JDK 11, JavaFX is no longer part of the JDK. 34 | 35 | 36 | 37 | _AWT Color Factory_ is available in JCenter and Maven Central. 38 | 39 | **Maven** 40 | 41 | 42 | org.beryx 43 | awt-color-factory 44 | 1.0.1 45 | 46 | 47 | **Gradle** 48 | 49 | compile 'org.beryx:awt-color-factory:1.0.1' 50 | 51 | 52 | _AWT Color Factory_ contains code that is almost identical to that found in javafx.scene.paint.Color, 53 | therefore the library is distributed under the same license as OpenJFX: the [GPL 2 with Classpath exception](http://openjdk.java.net/legal/gplv2+ce.html). 54 | **The _Classpath exception_ clause gives you permission to include this library in your executable code, 55 | regardless of the license under which your software is distributed.** 56 | 57 | This library requires Java 7 or newer. 58 | The jar artifact is modularized under the name [org.beryx.awt.color](https://github.com/beryx/awt-color-factory/raw/master/src/main/java/module-info.java). 59 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import org.gradle.plugins.signing.Sign 2 | import javax.swing.* 3 | 4 | plugins { 5 | id 'idea' 6 | id 'maven-publish' 7 | id "org.javamodularity.moduleplugin" version "1.7.0" 8 | id "com.github.ethankhall.semantic-versioning" version "1.1.0" 9 | id "com.github.hierynomus.license" version "0.15.0" 10 | id "com.jfrog.bintray" version "1.8.5" 11 | id "net.saliman.properties" version "1.5.1" 12 | } 13 | modularity.mixedJavaRelease 7 14 | 15 | project.version.with { 16 | major = awtColorFactoryVersionMajor as int 17 | minor= awtColorFactoryVersionMinor as int 18 | patch = awtColorFactoryVersionPatch as int 19 | if (project.hasProperty('awtColorFactoryVersionLabel')) { 20 | preRelease = awtColorFactoryVersionLabel 21 | } 22 | releaseBuild = Boolean.valueOf(awtColorFactoryReleaseBuild) 23 | } 24 | 25 | ext { 26 | awtColorFactoryVersion = project.version as String 27 | awtColorFactoryTag = Boolean.valueOf(awtColorFactoryReleaseBuild) ? "v$ext.awtColorFactoryVersion" : 'master' 28 | 29 | moduleName = 'org.beryx.awt.color' 30 | } 31 | 32 | def pomConfig = { 33 | url "https://github.com/beryx/awt-color-factory" 34 | developers { 35 | developer { 36 | id "siordache" 37 | name "Serban Iordache" 38 | } 39 | } 40 | scm { 41 | connection "https://github.com/beryx/awt-color-factory.git" 42 | developerConnection "https://github.com/beryx/awt-color-factory.git" 43 | url "https://github.com/beryx/awt-color-factory" 44 | } 45 | } 46 | 47 | apply plugin: 'signing' 48 | repositories { 49 | jcenter() 50 | mavenCentral() 51 | maven { url 'https://jitpack.io' } 52 | } 53 | 54 | apply plugin: 'java-library' 55 | apply plugin: 'java' 56 | apply plugin: 'eclipse' 57 | apply plugin: 'idea' 58 | apply plugin: 'com.github.hierynomus.license' 59 | 60 | group = 'org.beryx' 61 | version = awtColorFactoryVersion 62 | 63 | def defaultEncoding = 'UTF-8' 64 | [compileJava, compileTestJava]*.options*.encoding = defaultEncoding 65 | 66 | license { 67 | header rootProject.file("license-header.txt") 68 | skipExistingHeaders true 69 | ignoreFailures false 70 | } 71 | 72 | signing { 73 | sign configurations.archives 74 | } 75 | 76 | signArchives { 77 | onlyIf { gradle.taskGraph.allTasks.findAll {task -> isPublishTask(task)} } 78 | } 79 | 80 | dependencies { 81 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0' 82 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0' 83 | } 84 | 85 | jar { 86 | manifest { 87 | attributes 'Implementation-Title': "awt-color-factory", 88 | 'Implementation-Version': awtColorFactoryVersion 89 | } 90 | } 91 | task sourcesJar(type: Jar, dependsOn: classes) { 92 | classifier = 'sources' 93 | from sourceSets.main.allSource 94 | } 95 | 96 | task javadocJar(type: Jar, dependsOn: classes) { 97 | classifier "javadoc" 98 | from javadoc 99 | } 100 | 101 | artifacts { 102 | archives(sourcesJar, javadocJar) 103 | } 104 | 105 | publishing { 106 | publications { 107 | "awt-color-factory"(MavenPublication) { 108 | from components.java 109 | artifact sourcesJar { classifier "sources" } 110 | artifact javadocJar { classifier "javadoc" } 111 | groupId 'org.beryx' 112 | artifactId project.name 113 | version awtColorFactoryVersion 114 | pom.withXml { 115 | def root = asNode() 116 | root.appendNode('name', "Module $project.name") 117 | root.appendNode('description', "The $project.name artifact") 118 | root.children().last() + pomConfig 119 | 120 | // We cannot configure the licenses in pomConfig due to a name conflict with the 'license' extension defined by the com.github.hierynomus.license plugin 121 | def licenseNode = root.appendNode('licenses').appendNode('license') 122 | licenseNode.appendNode('name', 'GNU General Public License, version 2, with the Classpath Exception') 123 | licenseNode.appendNode('url', 'https://openjdk.java.net/legal/gplv2+ce.html') 124 | licenseNode.appendNode('distribution', 'repo') 125 | } 126 | } 127 | } 128 | } 129 | 130 | def readPasswordFromConsole(title, prompt) { 131 | JPanel panel = new JPanel() 132 | JLabel label = new JLabel(prompt) 133 | JPasswordField pass = new JPasswordField(24) 134 | panel.add(label) 135 | panel.add(pass) 136 | def options = ["OK", "Cancel"] as Object[] 137 | int option = JOptionPane.showOptionDialog(null, panel, title, 138 | JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null) 139 | if(option != 0) throw new InvalidUserDataException("Operation cancelled by the user.") 140 | new String(pass.password) 141 | } 142 | 143 | def isPublishTask(task) { 144 | task.name.startsWith('publish') 145 | } 146 | 147 | gradle.taskGraph.whenReady { taskGraph -> 148 | if (gradle.taskGraph.allTasks.findAll {task -> isPublishTask(task)}) { 149 | if(!project.hasProperty('signingKeyId') || !project.hasProperty('signingSecretKeyRingFile')) 150 | throw new InvalidUserDataException("Please configure your signing credentials in gradle-local.properties.") 151 | def password = readPasswordFromConsole('Please enter your PGP credentials:', 'PGP Private Key Password') 152 | allprojects { ext."signing.keyId" = signingKeyId } 153 | allprojects { ext."signing.secretKeyRingFile" = signingSecretKeyRingFile } 154 | allprojects { ext."signing.password" = password } 155 | } 156 | } 157 | 158 | bintray { 159 | user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : "unknownUser" 160 | key = project.hasProperty('bintrayKey') ? project.getProperty('bintrayKey') : "unknownKey" 161 | publications = ['awt-color-factory'] 162 | pkg { 163 | repo = 'maven' 164 | name = 'awt-color-factory' 165 | userOrg = 'beryx' 166 | licenses = ['GPL-2.0+CE'] 167 | vcsUrl = 'https://github.com/beryx/awt-color-factory.git' 168 | 169 | version { 170 | name = awtColorFactoryVersion 171 | desc = "AWT Color Factory $awtColorFactoryVersion" 172 | released = new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZZ") 173 | vcsTag = awtColorFactoryVersion 174 | gpg { 175 | sign = true 176 | } 177 | } 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /gradle-local.template.properties: -------------------------------------------------------------------------------- 1 | signingKeyId = A0B1C2D3 2 | signingSecretKeyRingFile = /users/siordache/gpg/beryx.gpg 3 | 4 | bintrayUser = siordache 5 | bintrayKey = a0b1c2d3e4f5a0b1c2d3e4f5a0b1c2d3e4f5a0b1 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | awtColorFactoryVersionMajor = 1 2 | awtColorFactoryVersionMinor = 0 3 | awtColorFactoryVersionPatch = 2 4 | # awtColorFactoryVersionLabel = rc-1 5 | awtColorFactoryReleaseBuild = true 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beryx/awt-color-factory/9fe62d1d7e6f390f4fc78cbff7cda2bc4fd9ad03/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Apr 25 12:16:33 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /license-header.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 the original author or authors 2 | 3 | This code is free software; you can redistribute it and/or modify it 4 | under the terms of the GNU General Public License version 2 only, as 5 | published by the Free Software Foundation. The authors designate this 6 | particular file as subject to the "Classpath" exception as provided 7 | by the authors in the LICENSE file that accompanied this code. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | -------------------------------------------------------------------------------- /src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 the original author or authors 3 | * 4 | * This code is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License version 2 only, as 6 | * published by the Free Software Foundation. The authors designate this 7 | * particular file as subject to the "Classpath" exception as provided 8 | * by the authors in the LICENSE file that accompanied this code. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | module org.beryx.awt.color { 20 | requires java.desktop; 21 | exports org.beryx.awt.color; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/beryx/awt/color/ColorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 the original author or authors 3 | * 4 | * This code is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License version 2 only, as 6 | * published by the Free Software Foundation. The authors designate this 7 | * particular file as subject to the "Classpath" exception as provided 8 | * by the authors in the LICENSE file that accompanied this code. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | // This file contains code adapted from the OpenJFX project, which is part of OpenJDK. 22 | // Specifically, code portions from the following classes appear (in changed or unchanged form) in this file: 23 | // javafx.scene.paint.Color.java (http://hg.openjdk.java.net/openjfx/jfx-dev/rt/raw-file/2c80e5ef751e/modules/javafx.graphics/src/main/java/javafx/scene/paint/Color.java) 24 | // com.sun.javafx.util.Utils.java (http://hg.openjdk.java.net/openjfx/jfx-dev/rt/raw-file/2c80e5ef751e/modules/javafx.graphics/src/main/java/com/sun/javafx/util/Utils.java) 25 | // 26 | // The original copyright header attached to the above mentioned sources is included below: 27 | 28 | /* 29 | * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. 30 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31 | * 32 | * This code is free software; you can redistribute it and/or modify it 33 | * under the terms of the GNU General Public License version 2 only, as 34 | * published by the Free Software Foundation. Oracle designates this 35 | * particular file as subject to the "Classpath" exception as provided 36 | * by Oracle in the LICENSE file that accompanied this code. 37 | * 38 | * This code is distributed in the hope that it will be useful, but WITHOUT 39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41 | * version 2 for more details (a copy is included in the LICENSE file that 42 | * accompanied this code). 43 | * 44 | * You should have received a copy of the GNU General Public License version 45 | * 2 along with this work; if not, write to the Free Software Foundation, 46 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47 | * 48 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49 | * or visit www.oracle.com if you need additional information or have any 50 | * questions. 51 | */ 52 | 53 | package org.beryx.awt.color; 54 | 55 | import java.awt.*; 56 | import java.util.HashMap; 57 | import java.util.Locale; 58 | import java.util.Map; 59 | 60 | public final class ColorFactory { 61 | /** 62 | * Creates a {@code Color} based on the specified values in the HSB color model, 63 | * and a given opacity. 64 | * 65 | * @param hue the hue, in degrees 66 | * @param saturation the saturation, {@code 0.0 to 1.0} 67 | * @param brightness the brightness, {@code 0.0 to 1.0} 68 | * @param opacity the opacity, {@code 0.0 to 1.0} 69 | * @return the {@code Color} 70 | * @throws IllegalArgumentException if {@code saturation}, {@code brightness} or 71 | * {@code opacity} are out of range 72 | */ 73 | public static Color hsb(double hue, double saturation, double brightness, double opacity) { 74 | checkSB(saturation, brightness); 75 | double[] rgb = HSBtoRGB(hue, saturation, brightness); 76 | Color result = new Color((float)rgb[0], (float)rgb[1], (float)rgb[2], (float)opacity); 77 | return result; 78 | } 79 | 80 | /** 81 | * Creates an opaque {@code Color} based on the specified values in the HSB color model. 82 | * 83 | * @param hue the hue, in degrees 84 | * @param saturation the saturation, {@code 0.0 to 1.0} 85 | * @param brightness the brightness, {@code 0.0 to 1.0} 86 | * @return the {@code Color} 87 | * @throws IllegalArgumentException if {@code saturation} or {@code brightness} are 88 | * out of range 89 | */ 90 | public static Color hsb(double hue, double saturation, double brightness) { 91 | return hsb(hue, saturation, brightness, 1.0); 92 | } 93 | 94 | private static void checkSB(double saturation, double brightness) { 95 | if (saturation < 0.0 || saturation > 1.0) { 96 | throw new IllegalArgumentException("Color.hsb's saturation parameter (" + saturation + ") expects values 0.0-1.0"); 97 | } 98 | if (brightness < 0.0 || brightness > 1.0) { 99 | throw new IllegalArgumentException("Color.hsb's brightness parameter (" + brightness + ") expects values 0.0-1.0"); 100 | } 101 | } 102 | 103 | /** 104 | * Creates an RGB color specified with an HTML or CSS attribute string. 105 | * 106 | *

107 | * This method supports the following formats: 108 | *

    109 | *
  • Any standard HTML color name 110 | *
  • An HTML long or short format hex string with an optional hex alpha 111 | * channel. 112 | * Hexadecimal values may be preceded by either {@code "0x"} or {@code "#"} 113 | * and can either be 2 digits in the range {@code 00} to {@code 0xFF} or a 114 | * single digit in the range {@code 0} to {@code F}. 115 | *
  • An {@code rgb(r,g,b)} or {@code rgba(r,g,b,a)} format string. 116 | * Each of the {@code r}, {@code g}, or {@code b} values can be an integer 117 | * from 0 to 255 or a floating point percentage value from 0.0 to 100.0 118 | * followed by the percent ({@code %}) character. 119 | * The alpha component, if present, is a 120 | * floating point value from 0.0 to 1.0. Spaces are allowed before or 121 | * after the numbers and between the percentage number and its percent 122 | * sign ({@code %}). 123 | *
  • An {@code hsl(h,s,l)} or {@code hsla(h,s,l,a)} format string. 124 | * The {@code h} value is a floating point number from 0.0 to 360.0 125 | * representing the hue angle on a color wheel in degrees with 126 | * {@code 0.0} or {@code 360.0} representing red, {@code 120.0} 127 | * representing green, and {@code 240.0} representing blue. The 128 | * {@code s} value is the saturation of the desired color represented 129 | * as a floating point percentage from gray ({@code 0.0}) to 130 | * the fully saturated color ({@code 100.0}) and the {@code l} value 131 | * is the desired lightness or brightness of the desired color represented 132 | * as a floating point percentage from black ({@code 0.0}) to the full 133 | * brightness of the color ({@code 100.0}). 134 | * The alpha component, if present, is a floating 135 | * point value from 0.0 to 1.0. Spaces are allowed before or 136 | * after the numbers and between the percentage number and its percent 137 | * sign ({@code %}). 138 | *
139 | * 140 | *

For formats without an alpha component and for named colors, opacity 141 | * is set according to the {@code opacity} argument. For colors specified 142 | * with an alpha component, the resulting opacity is a combination of the 143 | * parsed alpha component and the {@code opacity} argument, so a 144 | * transparent color becomes more transparent by specifying opacity.

145 | * 146 | *

Examples:

147 | *
148 | * 149 | * 150 | * 151 | * 152 | * 153 | * 154 | * 155 | * 156 | * 157 | * 158 | * 159 | * 160 | * 161 | * 162 | * 163 | * 164 | * 165 | * 166 | * 167 | * 168 | * 169 | * 170 | * 171 | * 172 | * 173 | * 174 | * 175 | * 176 | * 177 | * 178 | * 179 | * 180 | * 181 | * 182 | * 183 | * 184 | * 185 | * 186 | * 187 | * 188 | * 189 | * 190 | * 191 | * 194 | * 197 | * 198 | *
Web Color Format Table
Web Format StringEquivalent constructor or factory call
Color.web("orange", 0.5);new Color(1.0, 0xA5/255.0, 0.0, 0.5)
Color.web("0xff66cc33", 0.5);new Color(1.0, 0.4, 0.8, 0.1)
Color.web("0xff66cc", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("#ff66cc", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("#f68", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("rgb(255,102,204)", 0.5);new Color(1.0, 0.4, 0.8, 0.5)
Color.web("rgb(100%,50%,50%)", 0.5);new Color(1.0, 0.5, 0.5, 0.5)
Color.web("rgb(255,50%,50%,0.25)", 0.5);new Color(1.0, 0.5, 0.5, 0.125)
Color.web("hsl(240,100%,100%)", 0.5);Color.hsb(240.0, 1.0, 1.0, 0.5)
192 | * Color.web("hsla(120,0%,0%,0.25)", 0.5); 193 | * 195 | * Color.hsb(120.0, 0.0, 0.0, 0.125) 196 | *
199 | *
200 | * 201 | * @param colorString the name or numeric representation of the color 202 | * in one of the supported formats 203 | * @param opacity the opacity component in range from 0.0 (transparent) 204 | * to 1.0 (opaque) 205 | * @return the RGB color specified with the colorString 206 | * @throws NullPointerException if {@code colorString} is {@code null} 207 | * @throws IllegalArgumentException if {@code colorString} specifies 208 | * an unsupported color name or contains an illegal numeric value 209 | */ 210 | public static Color web(String colorString, double opacity) { 211 | if (colorString == null) { 212 | throw new NullPointerException( 213 | "The color components or name must be specified"); 214 | } 215 | if (colorString.isEmpty()) { 216 | throw new IllegalArgumentException("Invalid color specification"); 217 | } 218 | 219 | String color = colorString.toLowerCase(Locale.ROOT); 220 | 221 | if (color.startsWith("#")) { 222 | color = color.substring(1); 223 | } else if (color.startsWith("0x")) { 224 | color = color.substring(2); 225 | } else if (color.startsWith("rgb")) { 226 | if (color.startsWith("(", 3)) { 227 | return parseRGBColor(color, 4, false, opacity); 228 | } else if (color.startsWith("a(", 3)) { 229 | return parseRGBColor(color, 5, true, opacity); 230 | } 231 | } else if (color.startsWith("hsl")) { 232 | if (color.startsWith("(", 3)) { 233 | return parseHSLColor(color, 4, false, opacity); 234 | } else if (color.startsWith("a(", 3)) { 235 | return parseHSLColor(color, 5, true, opacity); 236 | } 237 | } else { 238 | Color col = NamedColors.get(color); 239 | if (col != null) { 240 | if (opacity == 1.0) { 241 | return col; 242 | } else { 243 | return new Color(col.getRed(), col.getGreen(), col.getBlue(), (int)(255 * opacity + 0.5)); 244 | } 245 | } 246 | } 247 | 248 | int len = color.length(); 249 | 250 | try { 251 | int r; 252 | int g; 253 | int b; 254 | int a; 255 | 256 | if (len == 3) { 257 | r = Integer.parseInt(color.substring(0, 1), 16); 258 | g = Integer.parseInt(color.substring(1, 2), 16); 259 | b = Integer.parseInt(color.substring(2, 3), 16); 260 | return new Color(r / 15.0f, g / 15.0f, b / 15.0f, (float)opacity); 261 | } else if (len == 4) { 262 | r = Integer.parseInt(color.substring(0, 1), 16); 263 | g = Integer.parseInt(color.substring(1, 2), 16); 264 | b = Integer.parseInt(color.substring(2, 3), 16); 265 | a = Integer.parseInt(color.substring(3, 4), 16); 266 | return new Color(r / 15.0f, g / 15.0f, b / 15.0f, (float)(opacity * a / 15.0)); 267 | } else if (len == 6) { 268 | r = Integer.parseInt(color.substring(0, 2), 16); 269 | g = Integer.parseInt(color.substring(2, 4), 16); 270 | b = Integer.parseInt(color.substring(4, 6), 16); 271 | return new Color(r, g, b, (int)(opacity*255+0.5)); 272 | } else if (len == 8) { 273 | r = Integer.parseInt(color.substring(0, 2), 16); 274 | g = Integer.parseInt(color.substring(2, 4), 16); 275 | b = Integer.parseInt(color.substring(4, 6), 16); 276 | a = Integer.parseInt(color.substring(6, 8), 16); 277 | return new Color(r, g, b, (int)(opacity * a + 0.5)); 278 | } 279 | } catch (NumberFormatException nfe) {} 280 | 281 | throw new IllegalArgumentException("Invalid color specification"); 282 | } 283 | 284 | private static Color parseRGBColor(String color, int roff, 285 | boolean hasAlpha, double a) 286 | { 287 | try { 288 | int rend = color.indexOf(',', roff); 289 | int gend = rend < 0 ? -1 : color.indexOf(',', rend+1); 290 | int bend = gend < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', gend+1); 291 | int aend = hasAlpha ? (bend < 0 ? -1 : color.indexOf(')', bend+1)) : bend; 292 | if (aend >= 0) { 293 | double r = parseComponent(color, roff, rend, PARSE_COMPONENT); 294 | double g = parseComponent(color, rend+1, gend, PARSE_COMPONENT); 295 | double b = parseComponent(color, gend+1, bend, PARSE_COMPONENT); 296 | if (hasAlpha) { 297 | a *= parseComponent(color, bend+1, aend, PARSE_ALPHA); 298 | } 299 | return new Color((float)r, (float)g, (float)b, (float)a); 300 | } 301 | } catch (NumberFormatException nfe) {} 302 | 303 | throw new IllegalArgumentException("Invalid color specification"); 304 | } 305 | 306 | private static Color parseHSLColor(String color, int hoff, 307 | boolean hasAlpha, double a) 308 | { 309 | try { 310 | int hend = color.indexOf(',', hoff); 311 | int send = hend < 0 ? -1 : color.indexOf(',', hend+1); 312 | int lend = send < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', send+1); 313 | int aend = hasAlpha ? (lend < 0 ? -1 : color.indexOf(')', lend+1)) : lend; 314 | if (aend >= 0) { 315 | double h = parseComponent(color, hoff, hend, PARSE_ANGLE); 316 | double s = parseComponent(color, hend+1, send, PARSE_PERCENT); 317 | double l = parseComponent(color, send+1, lend, PARSE_PERCENT); 318 | if (hasAlpha) { 319 | a *= parseComponent(color, lend+1, aend, PARSE_ALPHA); 320 | } 321 | return hsb(h, s, l, a); 322 | } 323 | } catch (NumberFormatException nfe) {} 324 | 325 | throw new IllegalArgumentException("Invalid color specification"); 326 | } 327 | 328 | private static final int PARSE_COMPONENT = 0; // percent, or clamped to [0,255] => [0,1] 329 | private static final int PARSE_PERCENT = 1; // clamped to [0,100]% => [0,1] 330 | private static final int PARSE_ANGLE = 2; // clamped to [0,360] 331 | private static final int PARSE_ALPHA = 3; // clamped to [0.0,1.0] 332 | private static double parseComponent(String color, int off, int end, int type) { 333 | color = color.substring(off, end).trim(); 334 | if (color.endsWith("%")) { 335 | if (type > PARSE_PERCENT) { 336 | throw new IllegalArgumentException("Invalid color specification"); 337 | } 338 | type = PARSE_PERCENT; 339 | color = color.substring(0, color.length()-1).trim(); 340 | } else if (type == PARSE_PERCENT) { 341 | throw new IllegalArgumentException("Invalid color specification"); 342 | } 343 | double c = ((type == PARSE_COMPONENT) 344 | ? Integer.parseInt(color) 345 | : Double.parseDouble(color)); 346 | switch (type) { 347 | case PARSE_ALPHA: 348 | return (c < 0.0) ? 0.0 : ((c > 1.0) ? 1.0 : c); 349 | case PARSE_PERCENT: 350 | return (c <= 0.0) ? 0.0 : ((c >= 100.0) ? 1.0 : (c / 100.0)); 351 | case PARSE_COMPONENT: 352 | return (c <= 0.0) ? 0.0 : ((c >= 255.0) ? 1.0 : (c / 255.0)); 353 | case PARSE_ANGLE: 354 | return ((c < 0.0) 355 | ? ((c % 360.0) + 360.0) 356 | : ((c > 360.0) 357 | ? (c % 360.0) 358 | : c)); 359 | } 360 | 361 | throw new IllegalArgumentException("Invalid color specification"); 362 | } 363 | 364 | /** 365 | * Creates an RGB color specified with an HTML or CSS attribute string. 366 | * 367 | *

368 | * This method supports the following formats: 369 | *

    370 | *
  • Any standard HTML color name 371 | *
  • An HTML long or short format hex string with an optional hex alpha 372 | * channel. 373 | * Hexadecimal values may be preceded by either {@code "0x"} or {@code "#"} 374 | * and can either be 2 digits in the range {@code 00} to {@code 0xFF} or a 375 | * single digit in the range {@code 0} to {@code F}. 376 | *
  • An {@code rgb(r,g,b)} or {@code rgba(r,g,b,a)} format string. 377 | * Each of the {@code r}, {@code g}, or {@code b} values can be an integer 378 | * from 0 to 255 or a floating point percentage value from 0.0 to 100.0 379 | * followed by the percent ({@code %}) character. 380 | * The alpha component, if present, is a 381 | * floating point value from 0.0 to 1.0. Spaces are allowed before or 382 | * after the numbers and between the percentage number and its percent 383 | * sign ({@code %}). 384 | *
  • An {@code hsl(h,s,l)} or {@code hsla(h,s,l,a)} format string. 385 | * The {@code h} value is a floating point number from 0.0 to 360.0 386 | * representing the hue angle on a color wheel in degrees with 387 | * {@code 0.0} or {@code 360.0} representing red, {@code 120.0} 388 | * representing green, and {@code 240.0} representing blue. The 389 | * {@code s} value is the saturation of the desired color represented 390 | * as a floating point percentage from gray ({@code 0.0}) to 391 | * the fully saturated color ({@code 100.0}) and the {@code l} value 392 | * is the desired lightness or brightness of the desired color represented 393 | * as a floating point percentage from black ({@code 0.0}) to the full 394 | * brightness of the color ({@code 100.0}). 395 | * The alpha component, if present, is a floating 396 | * point value from 0.0 to 1.0. Spaces are allowed before or 397 | * after the numbers and between the percentage number and its percent 398 | * sign ({@code %}). 399 | *
400 | * 401 | *

Examples:

402 | *
403 | * 404 | * 405 | * 406 | * 407 | * 408 | * 409 | * 410 | * 411 | * 412 | * 413 | * 414 | * 415 | * 416 | * 417 | * 418 | * 419 | * 420 | * 421 | * 422 | * 423 | * 424 | * 425 | * 426 | * 427 | * 428 | * 429 | * 430 | * 431 | * 432 | * 433 | * 434 | * 435 | * 436 | * 437 | * 438 | * 439 | * 440 | * 441 | * 442 | * 443 | * 444 | * 445 | * 446 | * 449 | * 452 | * 453 | *
Web Color Format Table
Web Format StringEquivalent constant or factory call
Color.web("orange");Color.ORANGE
Color.web("0xff668840");Color.rgb(255, 102, 136, 0.25)
Color.web("0xff6688");Color.rgb(255, 102, 136, 1.0)
Color.web("#ff6688");Color.rgb(255, 102, 136, 1.0)
Color.web("#f68");Color.rgb(255, 102, 136, 1.0)
Color.web("rgb(255,102,136)");Color.rgb(255, 102, 136, 1.0)
Color.web("rgb(100%,50%,50%)");Color.rgb(255, 128, 128, 1.0)
Color.web("rgb(255,50%,50%,0.25)");Color.rgb(255, 128, 128, 0.25)
Color.web("hsl(240,100%,100%)");Color.hsb(240.0, 1.0, 1.0, 1.0)
447 | * Color.web("hsla(120,0%,0%,0.25)"); 448 | * 450 | * Color.hsb(120.0, 0.0, 0.0, 0.25) 451 | *
454 | *
455 | * 456 | * @param colorString the name or numeric representation of the color 457 | * in one of the supported formats 458 | * @return an RGB color 459 | * @throws NullPointerException if {@code colorString} is {@code null} 460 | * @throws IllegalArgumentException if {@code colorString} specifies 461 | * an unsupported color name or contains an illegal numeric value 462 | */ 463 | public static Color web(String colorString) { 464 | return web(colorString, 1.0); 465 | } 466 | 467 | /** 468 | * Creates a color value from a string representation. The format 469 | * of the string representation is the same as in {@link #web(String)}. 470 | * 471 | * @param value the string to convert 472 | * @throws NullPointerException if the {@code value} is {@code null} 473 | * @throws IllegalArgumentException if the {@code value} specifies 474 | * an unsupported color name or illegal hexadecimal value 475 | * @return a {@code Color} object holding the value represented 476 | * by the string argument 477 | * @see #web(String) 478 | */ 479 | public static Color valueOf(String value) { 480 | if (value == null) { 481 | throw new NullPointerException("color must be specified"); 482 | } 483 | 484 | return web(value); 485 | } 486 | 487 | private static int to32BitInteger(int red, int green, int blue, int alpha) { 488 | int i = red; 489 | i = i << 8; 490 | i = i | green; 491 | i = i << 8; 492 | i = i | blue; 493 | i = i << 8; 494 | i = i | alpha; 495 | return i; 496 | } 497 | 498 | /** 499 | * A fully transparent color with an ARGB value of #00000000. 500 | */ 501 | public static final Color TRANSPARENT = new Color(0f, 0f, 0f, 0f); 502 | 503 | /** 504 | * The color alice blue with an RGB value of #F0F8FF 505 | *
506 | */ 507 | public static final Color ALICEBLUE = new Color(0.9411765f, 0.972549f, 1.0f); 508 | 509 | /** 510 | * The color antique white with an RGB value of #FAEBD7 511 | *
512 | */ 513 | public static final Color ANTIQUEWHITE = new Color(0.98039216f, 0.92156863f, 0.84313726f); 514 | 515 | /** 516 | * The color aqua with an RGB value of #00FFFF 517 | *
518 | */ 519 | public static final Color AQUA = new Color(0.0f, 1.0f, 1.0f); 520 | 521 | /** 522 | * The color aquamarine with an RGB value of #7FFFD4 523 | *
524 | */ 525 | public static final Color AQUAMARINE = new Color(0.49803922f, 1.0f, 0.83137256f); 526 | 527 | /** 528 | * The color azure with an RGB value of #F0FFFF 529 | *
530 | */ 531 | public static final Color AZURE = new Color(0.9411765f, 1.0f, 1.0f); 532 | 533 | /** 534 | * The color beige with an RGB value of #F5F5DC 535 | *
536 | */ 537 | public static final Color BEIGE = new Color(0.9607843f, 0.9607843f, 0.8627451f); 538 | 539 | /** 540 | * The color bisque with an RGB value of #FFE4C4 541 | *
542 | */ 543 | public static final Color BISQUE = new Color(1.0f, 0.89411765f, 0.76862746f); 544 | 545 | /** 546 | * The color black with an RGB value of #000000 547 | *
548 | */ 549 | public static final Color BLACK = new Color(0.0f, 0.0f, 0.0f); 550 | 551 | /** 552 | * The color blanched almond with an RGB value of #FFEBCD 553 | *
554 | */ 555 | public static final Color BLANCHEDALMOND = new Color(1.0f, 0.92156863f, 0.8039216f); 556 | 557 | /** 558 | * The color blue with an RGB value of #0000FF 559 | *
560 | */ 561 | public static final Color BLUE = new Color(0.0f, 0.0f, 1.0f); 562 | 563 | /** 564 | * The color blue violet with an RGB value of #8A2BE2 565 | *
566 | */ 567 | public static final Color BLUEVIOLET = new Color(0.5411765f, 0.16862746f, 0.8862745f); 568 | 569 | /** 570 | * The color brown with an RGB value of #A52A2A 571 | *
572 | */ 573 | public static final Color BROWN = new Color(0.64705884f, 0.16470589f, 0.16470589f); 574 | 575 | /** 576 | * The color burly wood with an RGB value of #DEB887 577 | *
578 | */ 579 | public static final Color BURLYWOOD = new Color(0.87058824f, 0.72156864f, 0.5294118f); 580 | 581 | /** 582 | * The color cadet blue with an RGB value of #5F9EA0 583 | *
584 | */ 585 | public static final Color CADETBLUE = new Color(0.37254903f, 0.61960787f, 0.627451f); 586 | 587 | /** 588 | * The color chartreuse with an RGB value of #7FFF00 589 | *
590 | */ 591 | public static final Color CHARTREUSE = new Color(0.49803922f, 1.0f, 0.0f); 592 | 593 | /** 594 | * The color chocolate with an RGB value of #D2691E 595 | *
596 | */ 597 | public static final Color CHOCOLATE = new Color(0.8235294f, 0.4117647f, 0.11764706f); 598 | 599 | /** 600 | * The color coral with an RGB value of #FF7F50 601 | *
602 | */ 603 | public static final Color CORAL = new Color(1.0f, 0.49803922f, 0.3137255f); 604 | 605 | /** 606 | * The color cornflower blue with an RGB value of #6495ED 607 | *
608 | */ 609 | public static final Color CORNFLOWERBLUE = new Color(0.39215687f, 0.58431375f, 0.92941177f); 610 | 611 | /** 612 | * The color cornsilk with an RGB value of #FFF8DC 613 | *
614 | */ 615 | public static final Color CORNSILK = new Color(1.0f, 0.972549f, 0.8627451f); 616 | 617 | /** 618 | * The color crimson with an RGB value of #DC143C 619 | *
620 | */ 621 | public static final Color CRIMSON = new Color(0.8627451f, 0.078431375f, 0.23529412f); 622 | 623 | /** 624 | * The color cyan with an RGB value of #00FFFF 625 | *
626 | */ 627 | public static final Color CYAN = new Color(0.0f, 1.0f, 1.0f); 628 | 629 | /** 630 | * The color dark blue with an RGB value of #00008B 631 | *
632 | */ 633 | public static final Color DARKBLUE = new Color(0.0f, 0.0f, 0.54509807f); 634 | 635 | /** 636 | * The color dark cyan with an RGB value of #008B8B 637 | *
638 | */ 639 | public static final Color DARKCYAN = new Color(0.0f, 0.54509807f, 0.54509807f); 640 | 641 | /** 642 | * The color dark goldenrod with an RGB value of #B8860B 643 | *
644 | */ 645 | public static final Color DARKGOLDENROD = new Color(0.72156864f, 0.5254902f, 0.043137256f); 646 | 647 | /** 648 | * The color dark gray with an RGB value of #A9A9A9 649 | *
650 | */ 651 | public static final Color DARKGRAY = new Color(0.6627451f, 0.6627451f, 0.6627451f); 652 | 653 | /** 654 | * The color dark green with an RGB value of #006400 655 | *
656 | */ 657 | public static final Color DARKGREEN = new Color(0.0f, 0.39215687f, 0.0f); 658 | 659 | /** 660 | * The color dark grey with an RGB value of #A9A9A9 661 | *
662 | */ 663 | public static final Color DARKGREY = DARKGRAY; 664 | 665 | /** 666 | * The color dark khaki with an RGB value of #BDB76B 667 | *
668 | */ 669 | public static final Color DARKKHAKI = new Color(0.7411765f, 0.7176471f, 0.41960785f); 670 | 671 | /** 672 | * The color dark magenta with an RGB value of #8B008B 673 | *
674 | */ 675 | public static final Color DARKMAGENTA = new Color(0.54509807f, 0.0f, 0.54509807f); 676 | 677 | /** 678 | * The color dark olive green with an RGB value of #556B2F 679 | *
680 | */ 681 | public static final Color DARKOLIVEGREEN = new Color(0.33333334f, 0.41960785f, 0.18431373f); 682 | 683 | /** 684 | * The color dark orange with an RGB value of #FF8C00 685 | *
686 | */ 687 | public static final Color DARKORANGE = new Color(1.0f, 0.54901963f, 0.0f); 688 | 689 | /** 690 | * The color dark orchid with an RGB value of #9932CC 691 | *
692 | */ 693 | public static final Color DARKORCHID = new Color(0.6f, 0.19607843f, 0.8f); 694 | 695 | /** 696 | * The color dark red with an RGB value of #8B0000 697 | *
698 | */ 699 | public static final Color DARKRED = new Color(0.54509807f, 0.0f, 0.0f); 700 | 701 | /** 702 | * The color dark salmon with an RGB value of #E9967A 703 | *
704 | */ 705 | public static final Color DARKSALMON = new Color(0.9137255f, 0.5882353f, 0.47843137f); 706 | 707 | /** 708 | * The color dark sea green with an RGB value of #8FBC8F 709 | *
710 | */ 711 | public static final Color DARKSEAGREEN = new Color(0.56078434f, 0.7372549f, 0.56078434f); 712 | 713 | /** 714 | * The color dark slate blue with an RGB value of #483D8B 715 | *
716 | */ 717 | public static final Color DARKSLATEBLUE = new Color(0.28235295f, 0.23921569f, 0.54509807f); 718 | 719 | /** 720 | * The color dark slate gray with an RGB value of #2F4F4F 721 | *
722 | */ 723 | public static final Color DARKSLATEGRAY = new Color(0.18431373f, 0.30980393f, 0.30980393f); 724 | 725 | /** 726 | * The color dark slate grey with an RGB value of #2F4F4F 727 | *
728 | */ 729 | public static final Color DARKSLATEGREY = DARKSLATEGRAY; 730 | 731 | /** 732 | * The color dark turquoise with an RGB value of #00CED1 733 | *
734 | */ 735 | public static final Color DARKTURQUOISE = new Color(0.0f, 0.80784315f, 0.81960785f); 736 | 737 | /** 738 | * The color dark violet with an RGB value of #9400D3 739 | *
740 | */ 741 | public static final Color DARKVIOLET = new Color(0.5803922f, 0.0f, 0.827451f); 742 | 743 | /** 744 | * The color deep pink with an RGB value of #FF1493 745 | *
746 | */ 747 | public static final Color DEEPPINK = new Color(1.0f, 0.078431375f, 0.5764706f); 748 | 749 | /** 750 | * The color deep sky blue with an RGB value of #00BFFF 751 | *
752 | */ 753 | public static final Color DEEPSKYBLUE = new Color(0.0f, 0.7490196f, 1.0f); 754 | 755 | /** 756 | * The color dim gray with an RGB value of #696969 757 | *
758 | */ 759 | public static final Color DIMGRAY = new Color(0.4117647f, 0.4117647f, 0.4117647f); 760 | 761 | /** 762 | * The color dim grey with an RGB value of #696969 763 | *
764 | */ 765 | public static final Color DIMGREY = DIMGRAY; 766 | 767 | /** 768 | * The color dodger blue with an RGB value of #1E90FF 769 | *
770 | */ 771 | public static final Color DODGERBLUE = new Color(0.11764706f, 0.5647059f, 1.0f); 772 | 773 | /** 774 | * The color firebrick with an RGB value of #B22222 775 | *
776 | */ 777 | public static final Color FIREBRICK = new Color(0.69803923f, 0.13333334f, 0.13333334f); 778 | 779 | /** 780 | * The color floral white with an RGB value of #FFFAF0 781 | *
782 | */ 783 | public static final Color FLORALWHITE = new Color(1.0f, 0.98039216f, 0.9411765f); 784 | 785 | /** 786 | * The color forest green with an RGB value of #228B22 787 | *
788 | */ 789 | public static final Color FORESTGREEN = new Color(0.13333334f, 0.54509807f, 0.13333334f); 790 | 791 | /** 792 | * The color fuchsia with an RGB value of #FF00FF 793 | *
794 | */ 795 | public static final Color FUCHSIA = new Color(1.0f, 0.0f, 1.0f); 796 | 797 | /** 798 | * The color gainsboro with an RGB value of #DCDCDC 799 | *
800 | */ 801 | public static final Color GAINSBORO = new Color(0.8627451f, 0.8627451f, 0.8627451f); 802 | 803 | /** 804 | * The color ghost white with an RGB value of #F8F8FF 805 | *
806 | */ 807 | public static final Color GHOSTWHITE = new Color(0.972549f, 0.972549f, 1.0f); 808 | 809 | /** 810 | * The color gold with an RGB value of #FFD700 811 | *
812 | */ 813 | public static final Color GOLD = new Color(1.0f, 0.84313726f, 0.0f); 814 | 815 | /** 816 | * The color goldenrod with an RGB value of #DAA520 817 | *
818 | */ 819 | public static final Color GOLDENROD = new Color(0.85490197f, 0.64705884f, 0.1254902f); 820 | 821 | /** 822 | * The color gray with an RGB value of #808080 823 | *
824 | */ 825 | public static final Color GRAY = new Color(0.5019608f, 0.5019608f, 0.5019608f); 826 | 827 | /** 828 | * The color green with an RGB value of #008000 829 | *
830 | */ 831 | public static final Color GREEN = new Color(0.0f, 0.5019608f, 0.0f); 832 | 833 | /** 834 | * The color green yellow with an RGB value of #ADFF2F 835 | *
836 | */ 837 | public static final Color GREENYELLOW = new Color(0.6784314f, 1.0f, 0.18431373f); 838 | 839 | /** 840 | * The color grey with an RGB value of #808080 841 | *
842 | */ 843 | public static final Color GREY = GRAY; 844 | 845 | /** 846 | * The color honeydew with an RGB value of #F0FFF0 847 | *
848 | */ 849 | public static final Color HONEYDEW = new Color(0.9411765f, 1.0f, 0.9411765f); 850 | 851 | /** 852 | * The color hot pink with an RGB value of #FF69B4 853 | *
854 | */ 855 | public static final Color HOTPINK = new Color(1.0f, 0.4117647f, 0.7058824f); 856 | 857 | /** 858 | * The color indian red with an RGB value of #CD5C5C 859 | *
860 | */ 861 | public static final Color INDIANRED = new Color(0.8039216f, 0.36078432f, 0.36078432f); 862 | 863 | /** 864 | * The color indigo with an RGB value of #4B0082 865 | *
866 | */ 867 | public static final Color INDIGO = new Color(0.29411766f, 0.0f, 0.50980395f); 868 | 869 | /** 870 | * The color ivory with an RGB value of #FFFFF0 871 | *
872 | */ 873 | public static final Color IVORY = new Color(1.0f, 1.0f, 0.9411765f); 874 | 875 | /** 876 | * The color khaki with an RGB value of #F0E68C 877 | *
878 | */ 879 | public static final Color KHAKI = new Color(0.9411765f, 0.9019608f, 0.54901963f); 880 | 881 | /** 882 | * The color lavender with an RGB value of #E6E6FA 883 | *
884 | */ 885 | public static final Color LAVENDER = new Color(0.9019608f, 0.9019608f, 0.98039216f); 886 | 887 | /** 888 | * The color lavender blush with an RGB value of #FFF0F5 889 | *
890 | */ 891 | public static final Color LAVENDERBLUSH = new Color(1.0f, 0.9411765f, 0.9607843f); 892 | 893 | /** 894 | * The color lawn green with an RGB value of #7CFC00 895 | *
896 | */ 897 | public static final Color LAWNGREEN = new Color(0.4862745f, 0.9882353f, 0.0f); 898 | 899 | /** 900 | * The color lemon chiffon with an RGB value of #FFFACD 901 | *
902 | */ 903 | public static final Color LEMONCHIFFON = new Color(1.0f, 0.98039216f, 0.8039216f); 904 | 905 | /** 906 | * The color light blue with an RGB value of #ADD8E6 907 | *
908 | */ 909 | public static final Color LIGHTBLUE = new Color(0.6784314f, 0.84705883f, 0.9019608f); 910 | 911 | /** 912 | * The color light coral with an RGB value of #F08080 913 | *
914 | */ 915 | public static final Color LIGHTCORAL = new Color(0.9411765f, 0.5019608f, 0.5019608f); 916 | 917 | /** 918 | * The color light cyan with an RGB value of #E0FFFF 919 | *
920 | */ 921 | public static final Color LIGHTCYAN = new Color(0.8784314f, 1.0f, 1.0f); 922 | 923 | /** 924 | * The color light goldenrod yellow with an RGB value of #FAFAD2 925 | *
926 | */ 927 | public static final Color LIGHTGOLDENRODYELLOW = new Color(0.98039216f, 0.98039216f, 0.8235294f); 928 | 929 | /** 930 | * The color light gray with an RGB value of #D3D3D3 931 | *
932 | */ 933 | public static final Color LIGHTGRAY = new Color(0.827451f, 0.827451f, 0.827451f); 934 | 935 | /** 936 | * The color light green with an RGB value of #90EE90 937 | *
938 | */ 939 | public static final Color LIGHTGREEN = new Color(0.5647059f, 0.93333334f, 0.5647059f); 940 | 941 | /** 942 | * The color light grey with an RGB value of #D3D3D3 943 | *
944 | */ 945 | public static final Color LIGHTGREY = LIGHTGRAY; 946 | 947 | /** 948 | * The color light pink with an RGB value of #FFB6C1 949 | *
950 | */ 951 | public static final Color LIGHTPINK = new Color(1.0f, 0.7137255f, 0.75686276f); 952 | 953 | /** 954 | * The color light salmon with an RGB value of #FFA07A 955 | *
956 | */ 957 | public static final Color LIGHTSALMON = new Color(1.0f, 0.627451f, 0.47843137f); 958 | 959 | /** 960 | * The color light sea green with an RGB value of #20B2AA 961 | *
962 | */ 963 | public static final Color LIGHTSEAGREEN = new Color(0.1254902f, 0.69803923f, 0.6666667f); 964 | 965 | /** 966 | * The color light sky blue with an RGB value of #87CEFA 967 | *
968 | */ 969 | public static final Color LIGHTSKYBLUE = new Color(0.5294118f, 0.80784315f, 0.98039216f); 970 | 971 | /** 972 | * The color light slate gray with an RGB value of #778899 973 | *
974 | */ 975 | public static final Color LIGHTSLATEGRAY = new Color(0.46666667f, 0.53333336f, 0.6f); 976 | 977 | /** 978 | * The color light slate grey with an RGB value of #778899 979 | *
980 | */ 981 | public static final Color LIGHTSLATEGREY = LIGHTSLATEGRAY; 982 | 983 | /** 984 | * The color light steel blue with an RGB value of #B0C4DE 985 | *
986 | */ 987 | public static final Color LIGHTSTEELBLUE = new Color(0.6901961f, 0.76862746f, 0.87058824f); 988 | 989 | /** 990 | * The color light yellow with an RGB value of #FFFFE0 991 | *
992 | */ 993 | public static final Color LIGHTYELLOW = new Color(1.0f, 1.0f, 0.8784314f); 994 | 995 | /** 996 | * The color lime with an RGB value of #00FF00 997 | *
998 | */ 999 | public static final Color LIME = new Color(0.0f, 1.0f, 0.0f); 1000 | 1001 | /** 1002 | * The color lime green with an RGB value of #32CD32 1003 | *
1004 | */ 1005 | public static final Color LIMEGREEN = new Color(0.19607843f, 0.8039216f, 0.19607843f); 1006 | 1007 | /** 1008 | * The color linen with an RGB value of #FAF0E6 1009 | *
1010 | */ 1011 | public static final Color LINEN = new Color(0.98039216f, 0.9411765f, 0.9019608f); 1012 | 1013 | /** 1014 | * The color magenta with an RGB value of #FF00FF 1015 | *
1016 | */ 1017 | public static final Color MAGENTA = new Color(1.0f, 0.0f, 1.0f); 1018 | 1019 | /** 1020 | * The color maroon with an RGB value of #800000 1021 | *
1022 | */ 1023 | public static final Color MAROON = new Color(0.5019608f, 0.0f, 0.0f); 1024 | 1025 | /** 1026 | * The color medium aquamarine with an RGB value of #66CDAA 1027 | *
1028 | */ 1029 | public static final Color MEDIUMAQUAMARINE = new Color(0.4f, 0.8039216f, 0.6666667f); 1030 | 1031 | /** 1032 | * The color medium blue with an RGB value of #0000CD 1033 | *
1034 | */ 1035 | public static final Color MEDIUMBLUE = new Color(0.0f, 0.0f, 0.8039216f); 1036 | 1037 | /** 1038 | * The color medium orchid with an RGB value of #BA55D3 1039 | *
1040 | */ 1041 | public static final Color MEDIUMORCHID = new Color(0.7294118f, 0.33333334f, 0.827451f); 1042 | 1043 | /** 1044 | * The color medium purple with an RGB value of #9370DB 1045 | *
1046 | */ 1047 | public static final Color MEDIUMPURPLE = new Color(0.5764706f, 0.4392157f, 0.85882354f); 1048 | 1049 | /** 1050 | * The color medium sea green with an RGB value of #3CB371 1051 | *
1052 | */ 1053 | public static final Color MEDIUMSEAGREEN = new Color(0.23529412f, 0.7019608f, 0.44313726f); 1054 | 1055 | /** 1056 | * The color medium slate blue with an RGB value of #7B68EE 1057 | *
1058 | */ 1059 | public static final Color MEDIUMSLATEBLUE = new Color(0.48235294f, 0.40784314f, 0.93333334f); 1060 | 1061 | /** 1062 | * The color medium spring green with an RGB value of #00FA9A 1063 | *
1064 | */ 1065 | public static final Color MEDIUMSPRINGGREEN = new Color(0.0f, 0.98039216f, 0.6039216f); 1066 | 1067 | /** 1068 | * The color medium turquoise with an RGB value of #48D1CC 1069 | *
1070 | */ 1071 | public static final Color MEDIUMTURQUOISE = new Color(0.28235295f, 0.81960785f, 0.8f); 1072 | 1073 | /** 1074 | * The color medium violet red with an RGB value of #C71585 1075 | *
1076 | */ 1077 | public static final Color MEDIUMVIOLETRED = new Color(0.78039217f, 0.08235294f, 0.52156866f); 1078 | 1079 | /** 1080 | * The color midnight blue with an RGB value of #191970 1081 | *
1082 | */ 1083 | public static final Color MIDNIGHTBLUE = new Color(0.09803922f, 0.09803922f, 0.4392157f); 1084 | 1085 | /** 1086 | * The color mint cream with an RGB value of #F5FFFA 1087 | *
1088 | */ 1089 | public static final Color MINTCREAM = new Color(0.9607843f, 1.0f, 0.98039216f); 1090 | 1091 | /** 1092 | * The color misty rose with an RGB value of #FFE4E1 1093 | *
1094 | */ 1095 | public static final Color MISTYROSE = new Color(1.0f, 0.89411765f, 0.88235295f); 1096 | 1097 | /** 1098 | * The color moccasin with an RGB value of #FFE4B5 1099 | *
1100 | */ 1101 | public static final Color MOCCASIN = new Color(1.0f, 0.89411765f, 0.70980394f); 1102 | 1103 | /** 1104 | * The color navajo white with an RGB value of #FFDEAD 1105 | *
1106 | */ 1107 | public static final Color NAVAJOWHITE = new Color(1.0f, 0.87058824f, 0.6784314f); 1108 | 1109 | /** 1110 | * The color navy with an RGB value of #000080 1111 | *
1112 | */ 1113 | public static final Color NAVY = new Color(0.0f, 0.0f, 0.5019608f); 1114 | 1115 | /** 1116 | * The color old lace with an RGB value of #FDF5E6 1117 | *
1118 | */ 1119 | public static final Color OLDLACE = new Color(0.99215686f, 0.9607843f, 0.9019608f); 1120 | 1121 | /** 1122 | * The color olive with an RGB value of #808000 1123 | *
1124 | */ 1125 | public static final Color OLIVE = new Color(0.5019608f, 0.5019608f, 0.0f); 1126 | 1127 | /** 1128 | * The color olive drab with an RGB value of #6B8E23 1129 | *
1130 | */ 1131 | public static final Color OLIVEDRAB = new Color(0.41960785f, 0.5568628f, 0.13725491f); 1132 | 1133 | /** 1134 | * The color orange with an RGB value of #FFA500 1135 | *
1136 | */ 1137 | public static final Color ORANGE = new Color(1.0f, 0.64705884f, 0.0f); 1138 | 1139 | /** 1140 | * The color orange red with an RGB value of #FF4500 1141 | *
1142 | */ 1143 | public static final Color ORANGERED = new Color(1.0f, 0.27058825f, 0.0f); 1144 | 1145 | /** 1146 | * The color orchid with an RGB value of #DA70D6 1147 | *
1148 | */ 1149 | public static final Color ORCHID = new Color(0.85490197f, 0.4392157f, 0.8392157f); 1150 | 1151 | /** 1152 | * The color pale goldenrod with an RGB value of #EEE8AA 1153 | *
1154 | */ 1155 | public static final Color PALEGOLDENROD = new Color(0.93333334f, 0.9098039f, 0.6666667f); 1156 | 1157 | /** 1158 | * The color pale green with an RGB value of #98FB98 1159 | *
1160 | */ 1161 | public static final Color PALEGREEN = new Color(0.59607846f, 0.9843137f, 0.59607846f); 1162 | 1163 | /** 1164 | * The color pale turquoise with an RGB value of #AFEEEE 1165 | *
1166 | */ 1167 | public static final Color PALETURQUOISE = new Color(0.6862745f, 0.93333334f, 0.93333334f); 1168 | 1169 | /** 1170 | * The color pale violet red with an RGB value of #DB7093 1171 | *
1172 | */ 1173 | public static final Color PALEVIOLETRED = new Color(0.85882354f, 0.4392157f, 0.5764706f); 1174 | 1175 | /** 1176 | * The color papaya whip with an RGB value of #FFEFD5 1177 | *
1178 | */ 1179 | public static final Color PAPAYAWHIP = new Color(1.0f, 0.9372549f, 0.8352941f); 1180 | 1181 | /** 1182 | * The color peach puff with an RGB value of #FFDAB9 1183 | *
1184 | */ 1185 | public static final Color PEACHPUFF = new Color(1.0f, 0.85490197f, 0.7254902f); 1186 | 1187 | /** 1188 | * The color peru with an RGB value of #CD853F 1189 | *
1190 | */ 1191 | public static final Color PERU = new Color(0.8039216f, 0.52156866f, 0.24705882f); 1192 | 1193 | /** 1194 | * The color pink with an RGB value of #FFC0CB 1195 | *
1196 | */ 1197 | public static final Color PINK = new Color(1.0f, 0.7529412f, 0.79607844f); 1198 | 1199 | /** 1200 | * The color plum with an RGB value of #DDA0DD 1201 | *
1202 | */ 1203 | public static final Color PLUM = new Color(0.8666667f, 0.627451f, 0.8666667f); 1204 | 1205 | /** 1206 | * The color powder blue with an RGB value of #B0E0E6 1207 | *
1208 | */ 1209 | public static final Color POWDERBLUE = new Color(0.6901961f, 0.8784314f, 0.9019608f); 1210 | 1211 | /** 1212 | * The color purple with an RGB value of #800080 1213 | *
1214 | */ 1215 | public static final Color PURPLE = new Color(0.5019608f, 0.0f, 0.5019608f); 1216 | 1217 | /** 1218 | * The color red with an RGB value of #FF0000 1219 | *
1220 | */ 1221 | public static final Color RED = new Color(1.0f, 0.0f, 0.0f); 1222 | 1223 | /** 1224 | * The color rosy brown with an RGB value of #BC8F8F 1225 | *
1226 | */ 1227 | public static final Color ROSYBROWN = new Color(0.7372549f, 0.56078434f, 0.56078434f); 1228 | 1229 | /** 1230 | * The color royal blue with an RGB value of #4169E1 1231 | *
1232 | */ 1233 | public static final Color ROYALBLUE = new Color(0.25490198f, 0.4117647f, 0.88235295f); 1234 | 1235 | /** 1236 | * The color saddle brown with an RGB value of #8B4513 1237 | *
1238 | */ 1239 | public static final Color SADDLEBROWN = new Color(0.54509807f, 0.27058825f, 0.07450981f); 1240 | 1241 | /** 1242 | * The color salmon with an RGB value of #FA8072 1243 | *
1244 | */ 1245 | public static final Color SALMON = new Color(0.98039216f, 0.5019608f, 0.44705883f); 1246 | 1247 | /** 1248 | * The color sandy brown with an RGB value of #F4A460 1249 | *
1250 | */ 1251 | public static final Color SANDYBROWN = new Color(0.95686275f, 0.6431373f, 0.3764706f); 1252 | 1253 | /** 1254 | * The color sea green with an RGB value of #2E8B57 1255 | *
1256 | */ 1257 | public static final Color SEAGREEN = new Color(0.18039216f, 0.54509807f, 0.34117648f); 1258 | 1259 | /** 1260 | * The color sea shell with an RGB value of #FFF5EE 1261 | *
1262 | */ 1263 | public static final Color SEASHELL = new Color(1.0f, 0.9607843f, 0.93333334f); 1264 | 1265 | /** 1266 | * The color sienna with an RGB value of #A0522D 1267 | *
1268 | */ 1269 | public static final Color SIENNA = new Color(0.627451f, 0.32156864f, 0.1764706f); 1270 | 1271 | /** 1272 | * The color silver with an RGB value of #C0C0C0 1273 | *
1274 | */ 1275 | public static final Color SILVER = new Color(0.7529412f, 0.7529412f, 0.7529412f); 1276 | 1277 | /** 1278 | * The color sky blue with an RGB value of #87CEEB 1279 | *
1280 | */ 1281 | public static final Color SKYBLUE = new Color(0.5294118f, 0.80784315f, 0.92156863f); 1282 | 1283 | /** 1284 | * The color slate blue with an RGB value of #6A5ACD 1285 | *
1286 | */ 1287 | public static final Color SLATEBLUE = new Color(0.41568628f, 0.3529412f, 0.8039216f); 1288 | 1289 | /** 1290 | * The color slate gray with an RGB value of #708090 1291 | *
1292 | */ 1293 | public static final Color SLATEGRAY = new Color(0.4392157f, 0.5019608f, 0.5647059f); 1294 | 1295 | /** 1296 | * The color slate grey with an RGB value of #708090 1297 | *
1298 | */ 1299 | public static final Color SLATEGREY = SLATEGRAY; 1300 | 1301 | /** 1302 | * The color snow with an RGB value of #FFFAFA 1303 | *
1304 | */ 1305 | public static final Color SNOW = new Color(1.0f, 0.98039216f, 0.98039216f); 1306 | 1307 | /** 1308 | * The color spring green with an RGB value of #00FF7F 1309 | *
1310 | */ 1311 | public static final Color SPRINGGREEN = new Color(0.0f, 1.0f, 0.49803922f); 1312 | 1313 | /** 1314 | * The color steel blue with an RGB value of #4682B4 1315 | *
1316 | */ 1317 | public static final Color STEELBLUE = new Color(0.27450982f, 0.50980395f, 0.7058824f); 1318 | 1319 | /** 1320 | * The color tan with an RGB value of #D2B48C 1321 | *
1322 | */ 1323 | public static final Color TAN = new Color(0.8235294f, 0.7058824f, 0.54901963f); 1324 | 1325 | /** 1326 | * The color teal with an RGB value of #008080 1327 | *
1328 | */ 1329 | public static final Color TEAL = new Color(0.0f, 0.5019608f, 0.5019608f); 1330 | 1331 | /** 1332 | * The color thistle with an RGB value of #D8BFD8 1333 | *
1334 | */ 1335 | public static final Color THISTLE = new Color(0.84705883f, 0.7490196f, 0.84705883f); 1336 | 1337 | /** 1338 | * The color tomato with an RGB value of #FF6347 1339 | *
1340 | */ 1341 | public static final Color TOMATO = new Color(1.0f, 0.3882353f, 0.2784314f); 1342 | 1343 | /** 1344 | * The color turquoise with an RGB value of #40E0D0 1345 | *
1346 | */ 1347 | public static final Color TURQUOISE = new Color(0.2509804f, 0.8784314f, 0.8156863f); 1348 | 1349 | /** 1350 | * The color violet with an RGB value of #EE82EE 1351 | *
1352 | */ 1353 | public static final Color VIOLET = new Color(0.93333334f, 0.50980395f, 0.93333334f); 1354 | 1355 | /** 1356 | * The color wheat with an RGB value of #F5DEB3 1357 | *
1358 | */ 1359 | public static final Color WHEAT = new Color(0.9607843f, 0.87058824f, 0.7019608f); 1360 | 1361 | /** 1362 | * The color white with an RGB value of #FFFFFF 1363 | *
1364 | */ 1365 | public static final Color WHITE = new Color(1.0f, 1.0f, 1.0f); 1366 | 1367 | /** 1368 | * The color white smoke with an RGB value of #F5F5F5 1369 | *
1370 | */ 1371 | public static final Color WHITESMOKE = new Color(0.9607843f, 0.9607843f, 0.9607843f); 1372 | 1373 | /** 1374 | * The color yellow with an RGB value of #FFFF00 1375 | *
1376 | */ 1377 | public static final Color YELLOW = new Color(1.0f, 1.0f, 0.0f); 1378 | 1379 | /** 1380 | * The color yellow green with an RGB value of #9ACD32 1381 | *
1382 | */ 1383 | public static final Color YELLOWGREEN = new Color(0.6039216f, 0.8039216f, 0.19607843f); 1384 | 1385 | /* 1386 | * Named colors moved to nested class to initialize them only when they 1387 | * are needed. 1388 | */ 1389 | private static final class NamedColors { 1390 | private static final Map namedColors = 1391 | createNamedColors(); 1392 | 1393 | private NamedColors() { 1394 | } 1395 | 1396 | private static Color get(String name) { 1397 | return namedColors.get(name); 1398 | } 1399 | 1400 | private static Map createNamedColors() { 1401 | Map colors = new HashMap<>(256); 1402 | 1403 | colors.put("aliceblue", ALICEBLUE); 1404 | colors.put("antiquewhite", ANTIQUEWHITE); 1405 | colors.put("aqua", AQUA); 1406 | colors.put("aquamarine", AQUAMARINE); 1407 | colors.put("azure", AZURE); 1408 | colors.put("beige", BEIGE); 1409 | colors.put("bisque", BISQUE); 1410 | colors.put("black", BLACK); 1411 | colors.put("blanchedalmond", BLANCHEDALMOND); 1412 | colors.put("blue", BLUE); 1413 | colors.put("blueviolet", BLUEVIOLET); 1414 | colors.put("brown", BROWN); 1415 | colors.put("burlywood", BURLYWOOD); 1416 | colors.put("cadetblue", CADETBLUE); 1417 | colors.put("chartreuse", CHARTREUSE); 1418 | colors.put("chocolate", CHOCOLATE); 1419 | colors.put("coral", CORAL); 1420 | colors.put("cornflowerblue", CORNFLOWERBLUE); 1421 | colors.put("cornsilk", CORNSILK); 1422 | colors.put("crimson", CRIMSON); 1423 | colors.put("cyan", CYAN); 1424 | colors.put("darkblue", DARKBLUE); 1425 | colors.put("darkcyan", DARKCYAN); 1426 | colors.put("darkgoldenrod", DARKGOLDENROD); 1427 | colors.put("darkgray", DARKGRAY); 1428 | colors.put("darkgreen", DARKGREEN); 1429 | colors.put("darkgrey", DARKGREY); 1430 | colors.put("darkkhaki", DARKKHAKI); 1431 | colors.put("darkmagenta", DARKMAGENTA); 1432 | colors.put("darkolivegreen", DARKOLIVEGREEN); 1433 | colors.put("darkorange", DARKORANGE); 1434 | colors.put("darkorchid", DARKORCHID); 1435 | colors.put("darkred", DARKRED); 1436 | colors.put("darksalmon", DARKSALMON); 1437 | colors.put("darkseagreen", DARKSEAGREEN); 1438 | colors.put("darkslateblue", DARKSLATEBLUE); 1439 | colors.put("darkslategray", DARKSLATEGRAY); 1440 | colors.put("darkslategrey", DARKSLATEGREY); 1441 | colors.put("darkturquoise", DARKTURQUOISE); 1442 | colors.put("darkviolet", DARKVIOLET); 1443 | colors.put("deeppink", DEEPPINK); 1444 | colors.put("deepskyblue", DEEPSKYBLUE); 1445 | colors.put("dimgray", DIMGRAY); 1446 | colors.put("dimgrey", DIMGREY); 1447 | colors.put("dodgerblue", DODGERBLUE); 1448 | colors.put("firebrick", FIREBRICK); 1449 | colors.put("floralwhite", FLORALWHITE); 1450 | colors.put("forestgreen", FORESTGREEN); 1451 | colors.put("fuchsia", FUCHSIA); 1452 | colors.put("gainsboro", GAINSBORO); 1453 | colors.put("ghostwhite", GHOSTWHITE); 1454 | colors.put("gold", GOLD); 1455 | colors.put("goldenrod", GOLDENROD); 1456 | colors.put("gray", GRAY); 1457 | colors.put("green", GREEN); 1458 | colors.put("greenyellow", GREENYELLOW); 1459 | colors.put("grey", GREY); 1460 | colors.put("honeydew", HONEYDEW); 1461 | colors.put("hotpink", HOTPINK); 1462 | colors.put("indianred", INDIANRED); 1463 | colors.put("indigo", INDIGO); 1464 | colors.put("ivory", IVORY); 1465 | colors.put("khaki", KHAKI); 1466 | colors.put("lavender", LAVENDER); 1467 | colors.put("lavenderblush", LAVENDERBLUSH); 1468 | colors.put("lawngreen", LAWNGREEN); 1469 | colors.put("lemonchiffon", LEMONCHIFFON); 1470 | colors.put("lightblue", LIGHTBLUE); 1471 | colors.put("lightcoral", LIGHTCORAL); 1472 | colors.put("lightcyan", LIGHTCYAN); 1473 | colors.put("lightgoldenrodyellow", LIGHTGOLDENRODYELLOW); 1474 | colors.put("lightgray", LIGHTGRAY); 1475 | colors.put("lightgreen", LIGHTGREEN); 1476 | colors.put("lightgrey", LIGHTGREY); 1477 | colors.put("lightpink", LIGHTPINK); 1478 | colors.put("lightsalmon", LIGHTSALMON); 1479 | colors.put("lightseagreen", LIGHTSEAGREEN); 1480 | colors.put("lightskyblue", LIGHTSKYBLUE); 1481 | colors.put("lightslategray", LIGHTSLATEGRAY); 1482 | colors.put("lightslategrey", LIGHTSLATEGREY); 1483 | colors.put("lightsteelblue", LIGHTSTEELBLUE); 1484 | colors.put("lightyellow", LIGHTYELLOW); 1485 | colors.put("lime", LIME); 1486 | colors.put("limegreen", LIMEGREEN); 1487 | colors.put("linen", LINEN); 1488 | colors.put("magenta", MAGENTA); 1489 | colors.put("maroon", MAROON); 1490 | colors.put("mediumaquamarine", MEDIUMAQUAMARINE); 1491 | colors.put("mediumblue", MEDIUMBLUE); 1492 | colors.put("mediumorchid", MEDIUMORCHID); 1493 | colors.put("mediumpurple", MEDIUMPURPLE); 1494 | colors.put("mediumseagreen", MEDIUMSEAGREEN); 1495 | colors.put("mediumslateblue", MEDIUMSLATEBLUE); 1496 | colors.put("mediumspringgreen", MEDIUMSPRINGGREEN); 1497 | colors.put("mediumturquoise", MEDIUMTURQUOISE); 1498 | colors.put("mediumvioletred", MEDIUMVIOLETRED); 1499 | colors.put("midnightblue", MIDNIGHTBLUE); 1500 | colors.put("mintcream", MINTCREAM); 1501 | colors.put("mistyrose", MISTYROSE); 1502 | colors.put("moccasin", MOCCASIN); 1503 | colors.put("navajowhite", NAVAJOWHITE); 1504 | colors.put("navy", NAVY); 1505 | colors.put("oldlace", OLDLACE); 1506 | colors.put("olive", OLIVE); 1507 | colors.put("olivedrab", OLIVEDRAB); 1508 | colors.put("orange", ORANGE); 1509 | colors.put("orangered", ORANGERED); 1510 | colors.put("orchid", ORCHID); 1511 | colors.put("palegoldenrod", PALEGOLDENROD); 1512 | colors.put("palegreen", PALEGREEN); 1513 | colors.put("paleturquoise", PALETURQUOISE); 1514 | colors.put("palevioletred", PALEVIOLETRED); 1515 | colors.put("papayawhip", PAPAYAWHIP); 1516 | colors.put("peachpuff", PEACHPUFF); 1517 | colors.put("peru", PERU); 1518 | colors.put("pink", PINK); 1519 | colors.put("plum", PLUM); 1520 | colors.put("powderblue", POWDERBLUE); 1521 | colors.put("purple", PURPLE); 1522 | colors.put("red", RED); 1523 | colors.put("rosybrown", ROSYBROWN); 1524 | colors.put("royalblue", ROYALBLUE); 1525 | colors.put("saddlebrown", SADDLEBROWN); 1526 | colors.put("salmon", SALMON); 1527 | colors.put("sandybrown", SANDYBROWN); 1528 | colors.put("seagreen", SEAGREEN); 1529 | colors.put("seashell", SEASHELL); 1530 | colors.put("sienna", SIENNA); 1531 | colors.put("silver", SILVER); 1532 | colors.put("skyblue", SKYBLUE); 1533 | colors.put("slateblue", SLATEBLUE); 1534 | colors.put("slategray", SLATEGRAY); 1535 | colors.put("slategrey", SLATEGREY); 1536 | colors.put("snow", SNOW); 1537 | colors.put("springgreen", SPRINGGREEN); 1538 | colors.put("steelblue", STEELBLUE); 1539 | colors.put("tan", TAN); 1540 | colors.put("teal", TEAL); 1541 | colors.put("thistle", THISTLE); 1542 | colors.put("tomato", TOMATO); 1543 | colors.put("transparent", TRANSPARENT); 1544 | colors.put("turquoise", TURQUOISE); 1545 | colors.put("violet", VIOLET); 1546 | colors.put("wheat", WHEAT); 1547 | colors.put("white", WHITE); 1548 | colors.put("whitesmoke", WHITESMOKE); 1549 | colors.put("yellow", YELLOW); 1550 | colors.put("yellowgreen", YELLOWGREEN); 1551 | 1552 | return colors; 1553 | } 1554 | } 1555 | 1556 | public static double[] HSBtoRGB(double hue, double saturation, double brightness) { 1557 | // normalize the hue 1558 | double normalizedHue = ((hue % 360) + 360) % 360; 1559 | hue = normalizedHue/360; 1560 | 1561 | double r = 0, g = 0, b = 0; 1562 | if (saturation == 0) { 1563 | r = g = b = brightness; 1564 | } else { 1565 | double h = (hue - Math.floor(hue)) * 6.0; 1566 | double f = h - java.lang.Math.floor(h); 1567 | double p = brightness * (1.0 - saturation); 1568 | double q = brightness * (1.0 - saturation * f); 1569 | double t = brightness * (1.0 - (saturation * (1.0 - f))); 1570 | switch ((int) h) { 1571 | case 0: 1572 | r = brightness; 1573 | g = t; 1574 | b = p; 1575 | break; 1576 | case 1: 1577 | r = q; 1578 | g = brightness; 1579 | b = p; 1580 | break; 1581 | case 2: 1582 | r = p; 1583 | g = brightness; 1584 | b = t; 1585 | break; 1586 | case 3: 1587 | r = p; 1588 | g = q; 1589 | b = brightness; 1590 | break; 1591 | case 4: 1592 | r = t; 1593 | g = p; 1594 | b = brightness; 1595 | break; 1596 | case 5: 1597 | r = brightness; 1598 | g = p; 1599 | b = q; 1600 | break; 1601 | } 1602 | } 1603 | double[] f = new double[3]; 1604 | f[0] = r; 1605 | f[1] = g; 1606 | f[2] = b; 1607 | return f; 1608 | } 1609 | 1610 | public static double[] RGBtoHSB(double r, double g, double b) { 1611 | double hue, saturation, brightness; 1612 | double[] hsbvals = new double[3]; 1613 | double cmax = (r > g) ? r : g; 1614 | if (b > cmax) cmax = b; 1615 | double cmin = (r < g) ? r : g; 1616 | if (b < cmin) cmin = b; 1617 | 1618 | brightness = cmax; 1619 | if (cmax != 0) 1620 | saturation = (double) (cmax - cmin) / cmax; 1621 | else 1622 | saturation = 0; 1623 | 1624 | if (saturation == 0) { 1625 | hue = 0; 1626 | } else { 1627 | double redc = (cmax - r) / (cmax - cmin); 1628 | double greenc = (cmax - g) / (cmax - cmin); 1629 | double bluec = (cmax - b) / (cmax - cmin); 1630 | if (r == cmax) 1631 | hue = bluec - greenc; 1632 | else if (g == cmax) 1633 | hue = 2.0 + redc - bluec; 1634 | else 1635 | hue = 4.0 + greenc - redc; 1636 | hue = hue / 6.0; 1637 | if (hue < 0) 1638 | hue = hue + 1.0; 1639 | } 1640 | hsbvals[0] = hue * 360; 1641 | hsbvals[1] = saturation; 1642 | hsbvals[2] = brightness; 1643 | return hsbvals; 1644 | } 1645 | } 1646 | -------------------------------------------------------------------------------- /src/test/java/org/beryx/awt/color/ColorFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 the original author or authors 3 | * 4 | * This code is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License version 2 only, as 6 | * published by the Free Software Foundation. The authors designate this 7 | * particular file as subject to the "Classpath" exception as provided 8 | * by the authors in the LICENSE file that accompanied this code. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | package org.beryx.awt.color; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.awt.*; 24 | import static org.junit.jupiter.api.Assertions.*; 25 | 26 | public class ColorFactoryTest { 27 | @Test 28 | public void valueOfTest() { 29 | assertEquals(Color.red, ColorFactory.valueOf("red")); 30 | assertEquals(ColorFactory.FIREBRICK, ColorFactory.valueOf("firebrick")); 31 | assertEquals(new Color(170, 56, 224), ColorFactory.valueOf("#aa38e0")); 32 | assertEquals(new Color(64, 168, 204), ColorFactory.valueOf("0x40A8CC")); 33 | assertEquals(new Color(0, 255, 255, 100), ColorFactory.valueOf("00FFFF64")); 34 | assertEquals(new Color(0, 255, 255, 102), ColorFactory.valueOf("0FF6")); 35 | assertEquals(new Color(112, 36, 228, (int)(0.9 * 255 + 0.5)), ColorFactory.valueOf("rgba(112,36,228,0.9)")); 36 | assertEquals(new Color(128, 0, 255), ColorFactory.valueOf("hsla(270,100%,100%,1.0)")); 37 | } 38 | 39 | @Test 40 | public void webTest() { 41 | assertEquals(new Color(170, 56, 224, (int)(0.3 * 255 + 0.5)), ColorFactory.web("#aa38e0", 0.3)); 42 | assertEquals(new Color(64, 168, 204, (int)(0.7 * 255 + 0.5)), ColorFactory.web("0x40A8CC", 0.7)); 43 | assertEquals(new Color(34, 139, 34, (int)(0.6 * 255 + 0.5)), ColorFactory.web("forestgreen", 0.6)); 44 | assertEquals(new Color(98, 18, 179, (int)(0.8 * 255 + 0.5)), ColorFactory.web("hsl(270,90%,70%)", 0.8)); 45 | assertEquals(new Color(0, 255, 255, 100), ColorFactory.valueOf("00FFFF64")); 46 | assertEquals(new Color(0, 255, 255, 102), ColorFactory.valueOf("0FF6")); 47 | } 48 | } 49 | --------------------------------------------------------------------------------