1. /*
  2. * @(#)SystemColor.java 1.24 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.geom.AffineTransform;
  9. import java.awt.geom.Rectangle2D;
  10. import java.awt.image.ColorModel;
  11. /**
  12. * A class to encapsulate symbolic colors representing the color of
  13. * native GUI objects on a system. For systems which support the dynamic
  14. * update of the system colors (when the user changes the colors)
  15. * the actual RGB values of these symbolic colors will also change
  16. * dynamically. In order to compare the "current" RGB value of a
  17. * <code>SystemColor</code> object with a non-symbolic Color object,
  18. * <code>getRGB</code> should be used rather than <code>equals</code>.
  19. * <p>
  20. * Note that the way in which these system colors are applied to GUI objects
  21. * may vary slightly from platform to platform since GUI objects may be
  22. * rendered differently on each platform.
  23. * <p>
  24. * System color values may also be available through the <code>getDesktopProperty</code>
  25. * method on <code>java.awt.Toolkit</code>.
  26. *
  27. * @see Toolkit#getDesktopProperty
  28. *
  29. * @version 1.24, 12/19/03
  30. * @author Carl Quinn
  31. * @author Amy Fowler
  32. */
  33. public final class SystemColor extends Color implements java.io.Serializable {
  34. /**
  35. * The array index for the
  36. * <a href="#desktop"><code>desktop</code></a> system color.
  37. * @see SystemColor#desktop
  38. */
  39. public final static int DESKTOP = 0;
  40. /**
  41. * The array index for the
  42. * <a href="#activeCaption"><code>activeCaption</code></a> system color.
  43. * @see SystemColor#activeCaption
  44. */
  45. public final static int ACTIVE_CAPTION = 1;
  46. /**
  47. * The array index for the
  48. * <a href="#activeCaptionText"><code>activeCaptionText</code></a> system color.
  49. * @see SystemColor#activeCaptionText
  50. */
  51. public final static int ACTIVE_CAPTION_TEXT = 2;
  52. /**
  53. * The array index for the
  54. * <a href="#activeCaptionBorder"><code>activeCaptionBorder</code></a> system color.
  55. * @see SystemColor#activeCaptionBorder
  56. */
  57. public final static int ACTIVE_CAPTION_BORDER = 3;
  58. /**
  59. * The array index for the
  60. * <a href="#inactiveCaption"><code>inactiveCaption</code></a> system color.
  61. * @see SystemColor#inactiveCaption
  62. */
  63. public final static int INACTIVE_CAPTION = 4;
  64. /**
  65. * The array index for the
  66. * <a href="#inactiveCaptionText"><code>inactiveCaptionText</code></a> system color.
  67. * @see SystemColor#inactiveCaptionText
  68. */
  69. public final static int INACTIVE_CAPTION_TEXT = 5;
  70. /**
  71. * The array index for the
  72. * <a href="#inactiveCaptionBorder"><code>inactiveCaptionBorder</code></a> system color.
  73. * @see SystemColor#inactiveCaptionBorder
  74. */
  75. public final static int INACTIVE_CAPTION_BORDER = 6;
  76. /**
  77. * The array index for the
  78. * <a href="#window"><code>window</code></a> system color.
  79. * @see SystemColor#window
  80. */
  81. public final static int WINDOW = 7;
  82. /**
  83. * The array index for the
  84. * <a href="#windowBorder"><code>windowBorder</code></a> system color.
  85. * @see SystemColor#windowBorder
  86. */
  87. public final static int WINDOW_BORDER = 8;
  88. /**
  89. * The array index for the
  90. * <a href="#windowText"><code>windowText</code></a> system color.
  91. * @see SystemColor#windowText
  92. */
  93. public final static int WINDOW_TEXT = 9;
  94. /**
  95. * The array index for the
  96. * <a href="#menu"><code>menu</code></a> system color.
  97. * @see SystemColor#menu
  98. */
  99. public final static int MENU = 10;
  100. /**
  101. * The array index for the
  102. * <a href="#menuText"><code>menuText</code></a> system color.
  103. * @see SystemColor#menuText
  104. */
  105. public final static int MENU_TEXT = 11;
  106. /**
  107. * The array index for the
  108. * <a href="#text"><code>text</code></a> system color.
  109. * @see SystemColor#text
  110. */
  111. public final static int TEXT = 12;
  112. /**
  113. * The array index for the
  114. * <a href="#textText"><code>textText</code></a> system color.
  115. * @see SystemColor#textText
  116. */
  117. public final static int TEXT_TEXT = 13;
  118. /**
  119. * The array index for the
  120. * <a href="#textHighlight"><code>textHighlight</code></a> system color.
  121. * @see SystemColor#textHighlight
  122. */
  123. public final static int TEXT_HIGHLIGHT = 14;
  124. /**
  125. * The array index for the
  126. * <a href="#textHighlightText"><code>textHighlightText</code></a> system color.
  127. * @see SystemColor#textHighlightText
  128. */
  129. public final static int TEXT_HIGHLIGHT_TEXT = 15;
  130. /**
  131. * The array index for the
  132. * <a href="#textInactiveText"><code>textInactiveText</code></a> system color.
  133. * @see SystemColor#textInactiveText
  134. */
  135. public final static int TEXT_INACTIVE_TEXT = 16;
  136. /**
  137. * The array index for the
  138. * <a href="#control"><code>control</code></a> system color.
  139. * @see SystemColor#control
  140. */
  141. public final static int CONTROL = 17;
  142. /**
  143. * The array index for the
  144. * <a href="#controlText"><code>controlText</code></a> system color.
  145. * @see SystemColor#controlText
  146. */
  147. public final static int CONTROL_TEXT = 18;
  148. /**
  149. * The array index for the
  150. * <a href="#controlHighlight"><code>controlHighlight</code></a> system color.
  151. * @see SystemColor#controlHighlight
  152. */
  153. public final static int CONTROL_HIGHLIGHT = 19;
  154. /**
  155. * The array index for the
  156. * <a href="#controlLtHighlight"><code>controlLtHighlight</code></a> system color.
  157. * @see SystemColor#controlLtHighlight
  158. */
  159. public final static int CONTROL_LT_HIGHLIGHT = 20;
  160. /**
  161. * The array index for the
  162. * <a href="#controlShadow"><code>controlShadow</code></a> system color.
  163. * @see SystemColor#controlShadow
  164. */
  165. public final static int CONTROL_SHADOW = 21;
  166. /**
  167. * The array index for the
  168. * <a href="#controlDkShadow"><code>controlDkShadow</code></a> system color.
  169. * @see SystemColor#controlDkShadow
  170. */
  171. public final static int CONTROL_DK_SHADOW = 22;
  172. /**
  173. * The array index for the
  174. * <a href="#scrollbar"><code>scrollbar</code></a> system color.
  175. * @see SystemColor#scrollbar
  176. */
  177. public final static int SCROLLBAR = 23;
  178. /**
  179. * The array index for the
  180. * <a href="#info"><code>info</code></a> system color.
  181. * @see SystemColor#info
  182. */
  183. public final static int INFO = 24;
  184. /**
  185. * The array index for the
  186. * <a href="#infoText"><code>infoText</code></a> system color.
  187. * @see SystemColor#infoText
  188. */
  189. public final static int INFO_TEXT = 25;
  190. /**
  191. * The number of system colors in the array.
  192. */
  193. public final static int NUM_COLORS = 26;
  194. /******************************************************************************************/
  195. /**
  196. * The color rendered for the background of the desktop.
  197. */
  198. public final static SystemColor desktop = new SystemColor((byte)DESKTOP);
  199. /**
  200. * The color rendered for the window-title background of the currently active window.
  201. */
  202. public final static SystemColor activeCaption = new SystemColor((byte)ACTIVE_CAPTION);
  203. /**
  204. * The color rendered for the window-title text of the currently active window.
  205. */
  206. public final static SystemColor activeCaptionText = new SystemColor((byte)ACTIVE_CAPTION_TEXT);
  207. /**
  208. * The color rendered for the border around the currently active window.
  209. */
  210. public final static SystemColor activeCaptionBorder = new SystemColor((byte)ACTIVE_CAPTION_BORDER);
  211. /**
  212. * The color rendered for the window-title background of inactive windows.
  213. */
  214. public final static SystemColor inactiveCaption = new SystemColor((byte)INACTIVE_CAPTION);
  215. /**
  216. * The color rendered for the window-title text of inactive windows.
  217. */
  218. public final static SystemColor inactiveCaptionText = new SystemColor((byte)INACTIVE_CAPTION_TEXT);
  219. /**
  220. * The color rendered for the border around inactive windows.
  221. */
  222. public final static SystemColor inactiveCaptionBorder = new SystemColor((byte)INACTIVE_CAPTION_BORDER);
  223. /**
  224. * The color rendered for the background of interior regions inside windows.
  225. */
  226. public final static SystemColor window = new SystemColor((byte)WINDOW);
  227. /**
  228. * The color rendered for the border around interior regions inside windows.
  229. */
  230. public final static SystemColor windowBorder = new SystemColor((byte)WINDOW_BORDER);
  231. /**
  232. * The color rendered for text of interior regions inside windows.
  233. */
  234. public final static SystemColor windowText = new SystemColor((byte)WINDOW_TEXT);
  235. /**
  236. * The color rendered for the background of menus.
  237. */
  238. public final static SystemColor menu = new SystemColor((byte)MENU);
  239. /**
  240. * The color rendered for the text of menus.
  241. */
  242. public final static SystemColor menuText = new SystemColor((byte)MENU_TEXT);
  243. /**
  244. * The color rendered for the background of text control objects, such as
  245. * textfields and comboboxes.
  246. */
  247. public final static SystemColor text = new SystemColor((byte)TEXT);
  248. /**
  249. * The color rendered for the text of text control objects, such as textfields
  250. * and comboboxes.
  251. */
  252. public final static SystemColor textText = new SystemColor((byte)TEXT_TEXT);
  253. /**
  254. * The color rendered for the background of selected items, such as in menus,
  255. * comboboxes, and text.
  256. */
  257. public final static SystemColor textHighlight = new SystemColor((byte)TEXT_HIGHLIGHT);
  258. /**
  259. * The color rendered for the text of selected items, such as in menus, comboboxes,
  260. * and text.
  261. */
  262. public final static SystemColor textHighlightText = new SystemColor((byte)TEXT_HIGHLIGHT_TEXT);
  263. /**
  264. * The color rendered for the text of inactive items, such as in menus.
  265. */
  266. public final static SystemColor textInactiveText = new SystemColor((byte)TEXT_INACTIVE_TEXT);
  267. /**
  268. * The color rendered for the background of control panels and control objects,
  269. * such as pushbuttons.
  270. */
  271. public final static SystemColor control = new SystemColor((byte)CONTROL);
  272. /**
  273. * The color rendered for the text of control panels and control objects,
  274. * such as pushbuttons.
  275. */
  276. public final static SystemColor controlText = new SystemColor((byte)CONTROL_TEXT);
  277. /**
  278. * The color rendered for light areas of 3D control objects, such as pushbuttons.
  279. * This color is typically derived from the <code>control</code> background color
  280. * to provide a 3D effect.
  281. */
  282. public final static SystemColor controlHighlight = new SystemColor((byte)CONTROL_HIGHLIGHT);
  283. /**
  284. * The color rendered for highlight areas of 3D control objects, such as pushbuttons.
  285. * This color is typically derived from the <code>control</code> background color
  286. * to provide a 3D effect.
  287. */
  288. public final static SystemColor controlLtHighlight = new SystemColor((byte)CONTROL_LT_HIGHLIGHT);
  289. /**
  290. * The color rendered for shadow areas of 3D control objects, such as pushbuttons.
  291. * This color is typically derived from the <code>control</code> background color
  292. * to provide a 3D effect.
  293. */
  294. public final static SystemColor controlShadow = new SystemColor((byte)CONTROL_SHADOW);
  295. /**
  296. * The color rendered for dark shadow areas on 3D control objects, such as pushbuttons.
  297. * This color is typically derived from the <code>control</code> background color
  298. * to provide a 3D effect.
  299. */
  300. public final static SystemColor controlDkShadow = new SystemColor((byte)CONTROL_DK_SHADOW);
  301. /**
  302. * The color rendered for the background of scrollbars.
  303. */
  304. public final static SystemColor scrollbar = new SystemColor((byte)SCROLLBAR);
  305. /**
  306. * The color rendered for the background of tooltips or spot help.
  307. */
  308. public final static SystemColor info = new SystemColor((byte)INFO);
  309. /**
  310. * The color rendered for the text of tooltips or spot help.
  311. */
  312. public final static SystemColor infoText = new SystemColor((byte)INFO_TEXT);
  313. /*
  314. * System colors with default initial values, overwritten by toolkit if
  315. * system values differ and are available.
  316. */
  317. private static int[] systemColors = {
  318. 0xFF005C5C, // desktop = new Color(0,92,92);
  319. 0xFF000080, // activeCaption = new Color(0,0,128);
  320. 0xFFFFFFFF, // activeCaptionText = Color.white;
  321. 0xFFC0C0C0, // activeCaptionBorder = Color.lightGray;
  322. 0xFF808080, // inactiveCaption = Color.gray;
  323. 0xFFC0C0C0, // inactiveCaptionText = Color.lightGray;
  324. 0xFFC0C0C0, // inactiveCaptionBorder = Color.lightGray;
  325. 0xFFFFFFFF, // window = Color.white;
  326. 0xFF000000, // windowBorder = Color.black;
  327. 0xFF000000, // windowText = Color.black;
  328. 0xFFC0C0C0, // menu = Color.lightGray;
  329. 0xFF000000, // menuText = Color.black;
  330. 0xFFC0C0C0, // text = Color.lightGray;
  331. 0xFF000000, // textText = Color.black;
  332. 0xFF000080, // textHighlight = new Color(0,0,128);
  333. 0xFFFFFFFF, // textHighlightText = Color.white;
  334. 0xFF808080, // textInactiveText = Color.gray;
  335. 0xFFC0C0C0, // control = Color.lightGray;
  336. 0xFF000000, // controlText = Color.black;
  337. 0xFFFFFFFF, // controlHighlight = Color.white;
  338. 0xFFE0E0E0, // controlLtHighlight = new Color(224,224,224);
  339. 0xFF808080, // controlShadow = Color.gray;
  340. 0xFF000000, // controlDkShadow = Color.black;
  341. 0xFFE0E0E0, // scrollbar = new Color(224,224,224);
  342. 0xFFE0E000, // info = new Color(224,224,0);
  343. 0xFF000000, // infoText = Color.black;
  344. };
  345. /*
  346. * JDK 1.1 serialVersionUID.
  347. */
  348. private static final long serialVersionUID = 4503142729533789064L;
  349. static {
  350. updateSystemColors();
  351. }
  352. /**
  353. * Called from <init> & toolkit to update the above systemColors cache.
  354. */
  355. private static void updateSystemColors() {
  356. if (!GraphicsEnvironment.isHeadless()) {
  357. Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
  358. }
  359. }
  360. /**
  361. * Creates a symbolic color that represents an indexed entry into system
  362. * color cache. Used by above static system colors.
  363. */
  364. private SystemColor(byte index) {
  365. super(0, 0, 0);
  366. value = index;
  367. }
  368. /**
  369. * Gets the "current" RGB value representing the symbolic color.
  370. * (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).
  371. * @see java.awt.image.ColorModel#getRGBdefault
  372. * @see java.awt.Color#getBlue()
  373. * @see java.awt.Color#getGreen()
  374. * @see java.awt.Color#getRed()
  375. */
  376. // NOTE: This method may be called by privileged threads.
  377. // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  378. public int getRGB() {
  379. return systemColors[value];
  380. }
  381. /**
  382. * Creates and returns a <code>PaintContext</code> used to generate
  383. * a solid color pattern. This enables a Color object to be used
  384. * as an argument to any method requiring an object implementing
  385. * the Paint interface.
  386. * @see Paint
  387. * @see PaintContext
  388. * @see Graphics2D#setPaint
  389. */
  390. public PaintContext createContext(ColorModel cm, Rectangle r,
  391. Rectangle2D r2d, AffineTransform xform,
  392. RenderingHints hints) {
  393. return new ColorPaintContext(value, cm);
  394. }
  395. /**
  396. * Returns a string representation of this <code>Color</code>'s values.
  397. * This method is intended to be used only for debugging purposes,
  398. * and the content and format of the returned string may vary between
  399. * implementations.
  400. * The returned string may be empty but may not be <code>null</code>.
  401. *
  402. * @return a string representation of this <code>Color</code>
  403. */
  404. public String toString() {
  405. return getClass().getName() + "[i=" + (value) + "]";
  406. }
  407. }