1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwtwidgets.client.style;
18
19 /***
20 * This class is under consideration for removal,
21 * if you have an opion please comment on http://gwtwidgets.blogspot.com.
22 */
23 public class Color
24 {
25 public final static Color WHITE = new Color(255, 255, 255);
26 public final static Color LIGHT_GRAY = new Color(192, 192, 192);
27 public final static Color GRAY = new Color(128, 128, 128);
28 public final static Color DARK_GRAY = new Color(64, 64, 64);
29 public final static Color BLACK = new Color(0, 0, 0);
30 public final static Color RED = new Color(255, 0, 0);
31 public final static Color PINK = new Color(255, 175, 175);
32 public final static Color ORANGE = new Color(255, 200, 0);
33 public final static Color YELLOW = new Color(255, 255, 0);
34 public final static Color GREEN = new Color(0, 255, 0);
35 public final static Color MAGENTA = new Color(255, 0, 255);
36 public final static Color CYAN = new Color(0, 255, 255);
37 public final static Color BLUE = new Color(0, 0, 255);
38 public static final Color NONE = new Color("");
39
40 private int r, g, b;
41
42
43 private String colorText = null;
44
45 private Color (String colorText) {
46 this.colorText = colorText;
47 }
48
49 public Color (int r, int g, int b)
50 {
51 this.r = r;
52 this.g = g;
53 this.b = b;
54 }
55
56 public int getRed ()
57 {
58 return r;
59 }
60
61 public int getGreen ()
62 {
63 return g;
64 }
65
66 public int getBlue ()
67 {
68 return b;
69 }
70
71 public String getHexValue ()
72 {
73 if (colorText != null) {
74 return colorText;
75 }
76
77 return "#"
78 + pad(Integer.toHexString(r))
79 + pad(Integer.toHexString(g))
80 + pad(Integer.toHexString(b));
81 }
82
83 private String pad (String in)
84 {
85 if (in.length() == 0) {
86 return "00";
87 }
88 if (in.length() == 1) {
89 return "0" + in;
90 }
91 return in;
92 }
93
94 public String toString ()
95 {
96 if (colorText != null) {
97 return colorText;
98 }
99 return "red=" + r + ", green=" + g + ", blue=" + b;
100 }
101 }