1
2 package org.catacomb.datalish;
3
4 import org.catacomb.be.DeReferencable;
5 import org.catacomb.be.ReReferencable;
6 import org.catacomb.report.E;
7
8
9 import java.awt.Color;
10
11
12
13
14
15
16
17
18
19 public class SColor implements DeReferencable, ReReferencable {
20
21 public String string;
22
23 private Color p_color;
24
25
26
27 public SColor() {
28 p_color = Color.red;
29 }
30
31 public SColor(String s) {
32 string = s;
33 p_color = parseColor(s);
34 }
35
36
37 public SColor(Color c) {
38 p_color = c;
39 }
40
41
42 public String toString() {
43 return serializeColor(p_color);
44 }
45
46 public void deReference() {
47 string = serializeColor(p_color);
48 }
49
50
51 public void reReference() {
52 p_color = parseColor(string);
53 }
54
55
56
57 public Color getColor() {
58 return p_color;
59 }
60
61
62
63 public static Color parseColor(String sin) {
64 String s = sin;
65 Color cret = null;
66 s = s.trim();
67 if (!s.startsWith("#")) {
68 s = ColorNames.getHexValue(s);
69 }
70
71 if (s == null) {
72 E.error("cant get color " + s);
73 } else {
74 try {
75 int ic = Integer.decode(s).intValue();
76 cret = new Color(ic);
77
78 } catch (NumberFormatException ex) {
79 E.error(" - cant decode color string " + s);
80 cret = Color.red;
81 }
82 }
83 return cret;
84 }
85
86
87
88
89 public static String serializeColor(Color c) {
90 int rgb = c.getRGB();
91
92
93 int xrgb = rgb | 0xff0000;
94
95 String fullhex = Integer.toHexString(xrgb);
96 String ret = "#" + fullhex.substring(2, 8);
97
98 return ret;
99 }
100
101
102
103
104
105
106 }