MCPcopy Create free account
hub / github.com/SimHacker/micropolis / ColorParser

Class ColorParser

micropolis-java/src/micropolisj/gui/ColorParser.java:13–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import java.awt.Color;
12
13public class ColorParser
14{
15 private ColorParser() {}
16
17 static Color parseColor(String str)
18 {
19 if (str.startsWith("#") && str.length() == 7) {
20 return new Color(Integer.parseInt(str.substring(1), 16));
21 }
22 else if (str.startsWith("rgba(") && str.endsWith(")")) {
23 String [] parts = str.substring(5,str.length()-1).split(",");
24 int r = Integer.parseInt(parts[0]);
25 int g = Integer.parseInt(parts[1]);
26 int b = Integer.parseInt(parts[2]);
27 double aa = Double.parseDouble(parts[3]);
28 int a = Math.min(255, (int)Math.floor(aa*256.0));
29 return new Color(r,g,b,a);
30 }
31 else {
32 throw new Error("invalid color format: "+str);
33 }
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected