View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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      // only for special cases, like no color, or maybe named colors
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 }