Thu, 15 Oct 2020 12:27:05 +0200
adds component entity
1 package de.uapcore.lightpit.types;
3 public final class WebColor {
5 private final String hex;
7 /**
8 * Constructs a color object from a hex string.
9 * @param hex the 6 digits hex string optionally preceded by a hash symbol
10 * @throws IllegalArgumentException if the given string does not specify a color
11 */
12 public WebColor(String hex) throws IllegalArgumentException {
13 this.hex = (hex.startsWith("#") ? hex : ("#"+hex)).toUpperCase();
14 if (!this.hex.matches("#[0-9A-F]{6}"))
15 throw new IllegalArgumentException(hex+" is not a color");
16 }
18 /**
19 * Returns the hex representation without th leading hash symbol.
20 * @return the hex representation of this color (e.g. FF0000 for red)
21 */
22 public String getHex() {
23 return hex.substring(1);
24 }
26 @Override
27 public String toString() {
28 return hex;
29 }
30 }