Merge from the pain train
[official-gcc.git] / libjava / java / awt / SystemColor.java
blob90aa577037b1dfd099676aa0ce7dcd31eae0eade
1 /* SystemColor.java -- access dynamic system color values
2 Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt;
41 import java.awt.geom.AffineTransform;
42 import java.awt.geom.Rectangle2D;
43 import java.awt.image.ColorModel;
44 import java.io.Serializable;
46 /**
47 * This class contains the various "system colors" in use by the native
48 * windowing system. The <code>getRGB()</code> method is dynamic on systems
49 * which support dynamic system color changes, and most methods in the
50 * superclass are written to use this dynamic value when reporting colors.
51 * However, the <code>equals()</code> method is not dynamic, and does not
52 * track the actual color of instances in this class. This means that equals
53 * may give surprising results; you are better off relying on getRGB.
55 * @author Aaron M. Renn (arenn@urbanophile.com)
56 * @author Eric Blake (ebb9@email.byu.edu)
57 * @since 1.1
58 * @status updated to 1.4
60 public final class SystemColor extends Color implements Serializable
62 // Implementation note: To be serial compatible with JDK, this class must
63 // violate the semantic meaning of super.value to be one of the
64 // NUM_COLORS constants instead of the actual RGB value. Hence there are
65 // a lot of ugly workarounds in Color and in this class. I would have
66 // designed it MUCH differently, making a separate id field in this class.
68 /**
69 * Compatible with JDK 1.1+.
71 private static final long serialVersionUID = 4503142729533789064L;
73 /**
74 * Array index of the desktop color. Used by
75 * {@link Toolkit#loadSystemColors(int[])}.
77 * @see #desktop
79 public static final int DESKTOP = 0;
81 /**
82 * Array index of the active caption color. Used by
83 * {@link Toolkit#loadSystemColors(int[])}.
85 * @see #activeCaption
87 public static final int ACTIVE_CAPTION = 1;
89 /**
90 * Array index of the active caption text color. Used by
91 * {@link Toolkit#loadSystemColors(int[])}.
93 * @see #activeCaptionText
95 public static final int ACTIVE_CAPTION_TEXT = 2;
97 /**
98 * Array index of the active caption border color. Used by
99 * {@link Toolkit#loadSystemColors(int[])}.
101 * @see #activeCaptionBorder
103 public static final int ACTIVE_CAPTION_BORDER = 3;
106 * Array index of the inactive caption color. Used by
107 * {@link Toolkit#loadSystemColors(int[])}.
109 * @see #inactiveCaption
111 public static final int INACTIVE_CAPTION = 4;
114 * Array index of the inactive caption text color. Used by
115 * {@link Toolkit#loadSystemColors(int[])}.
117 * @see #inactiveCaptionText
119 public static final int INACTIVE_CAPTION_TEXT = 5;
122 * Array index of the inactive caption border color. Used by
123 * {@link Toolkit#loadSystemColors(int[])}.
125 * @see #inactiveCaptionBorder
127 public static final int INACTIVE_CAPTION_BORDER = 6;
130 * Array index of the window background color. Used by
131 * {@link Toolkit#loadSystemColors(int[])}.
133 * @see #window
135 public static final int WINDOW = 7;
138 * Array index of the window border color. Used by
139 * {@link Toolkit#loadSystemColors(int[])}.
141 * @see #windowBorder
143 public static final int WINDOW_BORDER = 8;
146 * Array index of the window text color. Used by
147 * {@link Toolkit#loadSystemColors(int[])}.
149 * @see #windowText
151 public static final int WINDOW_TEXT = 9;
154 * Array index of the menu background color. Used by
155 * {@link Toolkit#loadSystemColors(int[])}.
157 * @see #menu
159 public static final int MENU = 10;
162 * Array index of the menu text color. Used by
163 * {@link Toolkit#loadSystemColors(int[])}.
165 * @see #menuText
167 public static final int MENU_TEXT = 11;
170 * Array index of the text background color. Used by
171 * {@link Toolkit#loadSystemColors(int[])}.
173 * @see #text
175 public static final int TEXT = 12;
178 * Array index of the text foreground color. Used by
179 * {@link Toolkit#loadSystemColors(int[])}.
181 * @see #textText
183 public static final int TEXT_TEXT = 13;
186 * Array index of the highlighted text background color. Used by
187 * {@link Toolkit#loadSystemColors(int[])}.
189 * @see #textHighlight
191 public static final int TEXT_HIGHLIGHT = 14;
194 * Array index of the highlighted text foreground color. Used by
195 * {@link Toolkit#loadSystemColors(int[])}.
197 * @see #textHighlightText
199 public static final int TEXT_HIGHLIGHT_TEXT = 15;
202 * Array index of the inactive text foreground color. Used by
203 * {@link Toolkit#loadSystemColors(int[])}.
205 * @see #textInactiveText
207 public static final int TEXT_INACTIVE_TEXT = 16;
210 * Array index of the control background color. Used by
211 * {@link Toolkit#loadSystemColors(int[])}.
213 * @see #control
215 public static final int CONTROL = 17;
218 * Array index of the control text color. Used by
219 * {@link Toolkit#loadSystemColors(int[])}.
221 * @see #controlText
223 public static final int CONTROL_TEXT = 18;
226 * Array index of the highlighted control background color. Used by
227 * {@link Toolkit#loadSystemColors(int[])}.
229 * @see #controlHighlight
231 public static final int CONTROL_HIGHLIGHT = 19;
234 * Array index of the lightly highlighted control background color. Used by
235 * {@link Toolkit#loadSystemColors(int[])}.
237 * @see #controlLtHighlight
239 public static final int CONTROL_LT_HIGHLIGHT = 20;
242 * Array index of the shadowed control background color. Used by
243 * {@link Toolkit#loadSystemColors(int[])}.
245 * @see #controlShadow
247 public static final int CONTROL_SHADOW = 21;
250 * Array index of the darkly shadowed control background color. Used by
251 * {@link Toolkit#loadSystemColors(int[])}.
253 * @see #controlDkShadow
255 public static final int CONTROL_DK_SHADOW = 22;
258 * Array index of the scrollbar background color. Used by
259 * {@link Toolkit#loadSystemColors(int[])}.
261 * @see #scrollbar
263 public static final int SCROLLBAR = 23;
266 * Array index of the info background color. Used by
267 * {@link Toolkit#loadSystemColors(int[])}.
269 * @see #info
271 public static final int INFO = 24;
274 * Array index of the info text color. Used by
275 * {@link Toolkit#loadSystemColors(int[])}.
277 * @see #infoText
279 public static final int INFO_TEXT = 25;
282 * The number of system colors. Used by
283 * {@link Toolkit#loadSystemColors(int[])}.
285 public static final int NUM_COLORS = 26;
288 * The internal array used to dynamically update <code>getRGB()</code>.
290 private static final int[] colors = new int[NUM_COLORS];
292 /** The desktop color. */
293 public static final SystemColor desktop
294 = new SystemColor(DESKTOP);
296 /** The active caption background color. */
297 public static final SystemColor activeCaption
298 = new SystemColor(ACTIVE_CAPTION);
300 /** The active caption text color. */
301 public static final SystemColor activeCaptionText
302 = new SystemColor(ACTIVE_CAPTION_TEXT);
304 /** The active caption border color. */
305 public static final SystemColor activeCaptionBorder
306 = new SystemColor(ACTIVE_CAPTION_BORDER);
308 /** The inactive caption background color. */
309 public static final SystemColor inactiveCaption
310 = new SystemColor(INACTIVE_CAPTION);
312 /** The inactive caption text color. */
313 public static final SystemColor inactiveCaptionText
314 = new SystemColor(INACTIVE_CAPTION_TEXT);
316 /** The inactive caption border color. */
317 public static final SystemColor inactiveCaptionBorder
318 = new SystemColor(INACTIVE_CAPTION_BORDER);
320 /** The window background color. */
321 public static final SystemColor window
322 = new SystemColor(WINDOW);
324 /** The window border color. */
325 public static final SystemColor windowBorder
326 = new SystemColor(WINDOW_BORDER);
328 /** The window text color. */
329 public static final SystemColor windowText
330 = new SystemColor(WINDOW_TEXT);
332 /** The menu background color. */
333 public static final SystemColor menu
334 = new SystemColor(MENU);
336 /** The menu text color. */
337 public static final SystemColor menuText
338 = new SystemColor(MENU_TEXT);
340 /** The text background color. */
341 public static final SystemColor text
342 = new SystemColor(TEXT);
344 /** The text foreground color. */
345 public static final SystemColor textText
346 = new SystemColor(TEXT_TEXT);
348 /** The highlighted text background color. */
349 public static final SystemColor textHighlight
350 = new SystemColor(TEXT_HIGHLIGHT);
352 /** The highlighted text foreground color. */
353 public static final SystemColor textHighlightText
354 = new SystemColor(TEXT_HIGHLIGHT_TEXT);
356 /** The inactive text color. */
357 public static final SystemColor textInactiveText
358 = new SystemColor(TEXT_INACTIVE_TEXT);
360 /** The control background color. */
361 public static final SystemColor control
362 = new SystemColor(CONTROL);
364 /** The control text color. */
365 public static final SystemColor controlText
366 = new SystemColor(CONTROL_TEXT);
368 /** The control highlight color. */
369 public static final SystemColor controlHighlight
370 = new SystemColor(CONTROL_HIGHLIGHT);
372 /** The control light highlight color. */
373 public static final SystemColor controlLtHighlight
374 = new SystemColor(CONTROL_LT_HIGHLIGHT);
376 /** The control shadow color. */
377 public static final SystemColor controlShadow
378 = new SystemColor(CONTROL_SHADOW);
380 /** The control dark shadow color. */
381 public static final SystemColor controlDkShadow
382 = new SystemColor(CONTROL_DK_SHADOW);
384 /** The scrollbar color. */
385 public static final SystemColor scrollbar
386 = new SystemColor(SCROLLBAR);
388 /** The info text background color. */
389 public static final SystemColor info
390 = new SystemColor(INFO);
392 /** The info text foreground color. */
393 public static final SystemColor infoText
394 = new SystemColor(INFO_TEXT);
397 * Construct a system color which is dynamically updated.
399 * @param id the color id
401 private SystemColor(int id)
403 // Note: See Color#Color(int, boolean) to explain why we use this
404 // particular constructor.
405 super(id, true);
409 * Returns the RGB value for this color, in the sRGB color space. The blue
410 * value will be in bits 0-7, green in 8-15, red in 6-23, and the alpha
411 * value (bits 24-31) is 0xff. This is dynamically updated, so it may not
412 * match the results of <code>getRed()</code>, <code>getGreen()</code>, or
413 * <code>getBlue()</code>.
415 * @return the current RGB value
417 public int getRGB()
419 Toolkit.getDefaultToolkit().loadSystemColors(colors);
420 return colors[value] | ALPHA_MASK;
424 * Returns a paint context, used for filling areas of a raster scan with
425 * the current value of this system color. Since the system colors may be
426 * dynamically updated, the returned value may not always be the same; but
427 * as the system color is solid, the context does not need any of the
428 * passed parameters to do its job.
430 * @param cm the requested color model
431 * @param deviceBounds the bounding box in device coordinates, ignored
432 * @param userBounds the bounding box in user coordinates, ignored
433 * @param xform the bounds transformation, ignored
434 * @param hints any rendering hints, ignored
435 * @return a context for painting this solid color
437 public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
438 Rectangle2D userBounds,
439 AffineTransform xform,
440 RenderingHints hints)
442 Toolkit.getDefaultToolkit().loadSystemColors(colors);
443 int color = colors[value] | ALPHA_MASK;
444 if (context == null || color != context.color || !context.getColorModel().equals(cm))
445 context = new ColorPaintContext(cm,color);
446 return context;
450 * Returns a string describing this color. This is in the format
451 * "java.awt.SystemColor[i=" + index + ']', where index is one of the
452 * integer constants of this class. Unfortunately, this description
453 * does not describe the current value of the color; for that you should
454 * use <code>new Color(syscolor.getRGB()).toString()</code>.
456 * @return a string describing this color
458 public String toString()
460 return "java.awt.SystemColor[i=" + value + ']';
462 } // class SystemColor