KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > Colour


1 /*********************************************************************
2  *
3  * Copyright (C) 2002 Andrew Khan
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  ***************************************************************************/

19
20 package jxl.format;
21
22 /**
23  * Enumeration class which contains the various colours available within
24  * the standard Excel colour palette
25  *
26  */

27 public /*final*/ class Colour
28 {
29   /**
30    * The internal numerical representation of the colour
31    */

32   private int value;
33
34   /**
35    * The default RGB value
36    */

37   private RGB rgb;
38
39   /**
40    * The display string for the colour. Used when presenting the
41    * format information
42    */

43   private String JavaDoc string;
44
45   /**
46    * The list of internal colours
47    */

48   private static Colour[] colours = new Colour[0];
49
50   /**
51    * Private constructor
52    *
53    * @param val
54    * @param s the display string
55    * @param r the default red value
56    * @param g the default green value
57    * @param b the default blue value
58    */

59   protected Colour(int val, String JavaDoc s, int r, int g, int b)
60   {
61     value = val;
62     string = s;
63     rgb = new RGB(r,g,b);
64
65     Colour[] oldcols = colours;
66     colours = new Colour[oldcols.length + 1];
67     System.arraycopy(oldcols, 0, colours, 0, oldcols.length);
68     colours[oldcols.length] = this;
69   }
70
71   /**
72    * Gets the value of this colour. This is the value that is written to
73    * the generated Excel file
74    *
75    * @return the binary value
76    */

77   public int getValue()
78   {
79     return value;
80   }
81
82   /**
83    * Gets the string description for display purposes
84    *
85    * @return the string description
86    */

87   public String JavaDoc getDescription()
88   {
89     return string;
90   }
91
92   /**
93    * Gets the default red content of this colour. Used when writing the
94    * default colour palette
95    *
96    * @return the red content of this colour
97    * @deprecated use getDefaultRGB instead
98    */

99   public int getDefaultRed()
100   {
101     return rgb.getRed();
102   }
103
104   /**
105    * Gets the default green content of this colour. Used when writing the
106    * default colour palette
107    *
108    * @return the green content of this colour
109    * @deprecated use getDefaultRGB instead
110    */

111   public int getDefaultGreen()
112   {
113     return rgb.getGreen();
114   }
115
116   /**
117    * Gets the default blue content of this colour. Used when writing the
118    * default colour palette
119    *
120    * @return the blue content of this colour
121    * @deprecated use getDefaultRGB instead
122    */

123   public int getDefaultBlue()
124   {
125     return rgb.getBlue();
126   }
127
128   /**
129    * Returns the default RGB of the colour
130    *
131    * @return the default RGB
132    */

133   public RGB getDefaultRGB()
134   {
135     return rgb;
136   }
137
138   /**
139    * Gets the internal colour from the value
140    *
141    * @param val
142    * @return the colour with that value
143    */

144   public static Colour getInternalColour(int val)
145   {
146     for (int i = 0 ; i < colours.length ; i++)
147     {
148       if (colours[i].getValue() == val)
149       {
150         return colours[i];
151       }
152     }
153
154     return UNKNOWN;
155   }
156
157   /**
158    * Returns all available colours - used when generating the default palette
159    *
160    * @return all available colours
161    */

162   public static Colour[] getAllColours()
163   {
164     return colours;
165   }
166
167   // Major colours
168
public final static Colour UNKNOWN =
169     new Colour(0x7fee, "unknown", 0, 0, 0);
170   public final static Colour BLACK =
171     new Colour(0x7fff, "black", 0, 0, 0);
172   public final static Colour WHITE =
173     new Colour(0x9, "white", 0xff, 0xff, 0xff);
174   public final static Colour DEFAULT_BACKGROUND1
175     = new Colour(0x0, "default background", 0xff, 0xff, 0xff);
176   public final static Colour DEFAULT_BACKGROUND
177     = new Colour(0xc0, "default background", 0xff, 0xff, 0xff);
178   public final static Colour PALETTE_BLACK =
179     new Colour(0x8, "black", 0x1, 0, 0);
180                                // the first item in the colour palette
181

182   // Other colours
183
public final static Colour RED = new Colour(0xa, "red",0xff,0,0);
184   public final static Colour BRIGHT_GREEN = new Colour(0xb, "bright green",0,0xff,0);
185   public final static Colour BLUE = new Colour(0xc, "blue",0,0,0xff); public final static Colour YELLOW = new Colour(0xd, "yellow",0xff,0xff,0);
186   public final static Colour PINK = new Colour(0xe, "pink",0xff,0,0xff);
187   public final static Colour TURQUOISE = new Colour(0xf, "turquoise",0,0xff,0xff);
188   public final static Colour DARK_RED = new Colour(0x10, "dark red",0x80,0,0);
189   public final static Colour GREEN = new Colour(0x11, "green",0,0x80,0);
190   public final static Colour DARK_BLUE = new Colour(0x12, "dark blue",0,0,0x80);
191   public final static Colour DARK_YELLOW = new Colour(0x13, "dark yellow",0x80,0x80,0);
192   public final static Colour VIOLET = new Colour(0x14, "violet",0x80,0x80,0);
193   public final static Colour TEAL = new Colour(0x15, "teal",0,0x80,0x80);
194   public final static Colour GREY_25_PERCENT = new Colour(0x16 ,"grey 25%",0xc0,0xc0,0xc0);
195   public final static Colour GREY_50_PERCENT = new Colour(0x17, "grey 50%",0x80,0x80,0x80);
196   public final static Colour PERIWINKLE = new Colour(0x18, "periwinkle%",0x99, 0x99, 0xff);
197   public final static Colour PLUM2 = new Colour(0x19, "plum",0x99, 0x33, 0x66);
198   public final static Colour IVORY = new Colour(0x1a, "ivory",0xff, 0xff, 0xcc);
199   public final static Colour LIGHT_TURQUOISE2= new Colour(0x1b, "light turquoise",0xcc, 0xff, 0xff);
200   public final static Colour DARK_PURPLE = new Colour(0x1c, "dark purple",0x66, 0x0, 0x66);
201   public final static Colour CORAL = new Colour(0x1d, "coral",0xff, 0x80, 0x80);
202   public final static Colour OCEAN_BLUE = new Colour(0x1e, "ocean blue",0x0, 0x66, 0xcc);
203   public final static Colour ICE_BLUE = new Colour(0x1f, "ice blue",0xcc, 0xcc, 0xff);
204   public final static Colour DARK_BLUE2 = new Colour(0x20, "dark blue",0,0,0x80);
205   public final static Colour PINK2 = new Colour(0x21, "pink",0xff,0,0xff);
206   public final static Colour YELLOW2 = new Colour(0x22, "yellow",0xff,0xff,0x0);
207   public final static Colour TURQOISE2 = new Colour(0x23, "turqoise",0x0,0xff,0xff);
208   public final static Colour VIOLET2 = new Colour(0x24, "violet",0x80,0x0,0x80);
209   public final static Colour DARK_RED2 = new Colour(0x25, "dark red",0x80,0x0,0x0);
210   public final static Colour TEAL2 = new Colour(0x26, "teal",0x0,0x80,0x80);
211   public final static Colour BLUE2 = new Colour(0x27, "blue",0x0,0x0,0xff);
212   public final static Colour SKY_BLUE = new Colour(0x28, "sky blue",0,0xcc,0xff);
213   public final static Colour LIGHT_TURQUOISE
214       = new Colour(0x29, "light turquoise",0xcc,0xff,0xff);
215   public final static Colour LIGHT_GREEN = new Colour(0x2a, "light green",0xcc,0xff,0xcc);
216   public final static Colour VERY_LIGHT_YELLOW
217     = new Colour(0x2b, "very light yellow",0xff,0xff,0x99);
218   public final static Colour PALE_BLUE = new Colour(0x2c, "pale blue",0x99,0xcc,0xff);
219   public final static Colour ROSE = new Colour(0x2d, "rose",0xff,0x99,0xcc);
220   public final static Colour LAVENDER = new Colour(0x2e, "lavender",0xcc,0x99,0xff);
221   public final static Colour TAN = new Colour(0x2f, "tan",0xff,0xcc,0x99);
222   public final static Colour LIGHT_BLUE = new Colour(0x30, "light blue", 0x33, 0x66, 0xff);
223   public final static Colour AQUA = new Colour(0x31, "aqua",0x33,0xcc,0xcc);
224   public final static Colour LIME = new Colour(0x32, "lime",0x99,0xcc,0);
225   public final static Colour GOLD = new Colour(0x33, "gold",0xff,0xcc,0);
226   public final static Colour LIGHT_ORANGE
227       = new Colour(0x34, "light orange",0xff,0x99,0);
228   public final static Colour ORANGE = new Colour(0x35, "orange",0xff,0x66,0);
229   public final static Colour BLUE_GREY = new Colour(0x36, "blue grey",0x66,0x66,0xcc);
230   public final static Colour GREY_40_PERCENT = new Colour(0x37, "grey 40%",0x96,0x96,0x96);
231   public final static Colour DARK_TEAL = new Colour(0x38, "dark teal",0,0x33,0x66);
232   public final static Colour SEA_GREEN = new Colour(0x39, "sea green",0x33,0x99,0x66);
233   public final static Colour DARK_GREEN = new Colour(0x3a, "dark green",0,0x33,0);
234   public final static Colour OLIVE_GREEN = new Colour(0x3b, "olive green",0x33,0x33,0);
235   public final static Colour BROWN = new Colour(0x3c, "brown",0x99,0x33,0);
236   public final static Colour PLUM = new Colour(0x3d, "plum",0x99,0x33,0x66);
237   public final static Colour INDIGO = new Colour(0x3e, "indigo",0x33,0x33,0x99);
238   public final static Colour GREY_80_PERCENT = new Colour(0x3f, "grey 80%",0x33,0x33,0x33);
239   public final static Colour AUTOMATIC = new Colour(0x40, "automatic", 0xff, 0xff, 0xff);
240
241   // Colours added for backwards compatibility
242
public final static Colour GRAY_80 = GREY_80_PERCENT;
243   public final static Colour GRAY_50 = GREY_50_PERCENT;
244   public final static Colour GRAY_25 = GREY_25_PERCENT;
245 }
246
247
248
249
250
251
252
253
254
255
256
257
Popular Tags