1. /*
  2. * @(#)SystemColor.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 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
  13. * of 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 SystemColor
  17. * object with a non-symbolic Color object, getRGB() should be used
  18. * rather than equals().
  19. *
  20. * @version 1.16, 11/29/01
  21. * @author Carl Quinn
  22. * @author Amy Fowler
  23. */
  24. public final class SystemColor extends Color implements java.io.Serializable {
  25. /**
  26. * The array index for the desktop background color.
  27. */
  28. public final static int DESKTOP = 0;
  29. /**
  30. * The array index for the active caption background color.
  31. */
  32. public final static int ACTIVE_CAPTION = 1;
  33. /**
  34. * The array index for the action caption text color.
  35. */
  36. public final static int ACTIVE_CAPTION_TEXT = 2;
  37. /**
  38. * The array index for the active caption border color.
  39. */
  40. public final static int ACTIVE_CAPTION_BORDER = 3;
  41. /**
  42. * The array index for the inactive caption background color.
  43. */
  44. public final static int INACTIVE_CAPTION = 4;
  45. /**
  46. * The array index for the inactive caption text color.
  47. */
  48. public final static int INACTIVE_CAPTION_TEXT = 5;
  49. /**
  50. * The array index for the inactive caption border color.
  51. */
  52. public final static int INACTIVE_CAPTION_BORDER = 6;
  53. /**
  54. * The array index for the window background color.
  55. */
  56. public final static int WINDOW = 7;
  57. /**
  58. * The array index for the window border color.
  59. */
  60. public final static int WINDOW_BORDER = 8;
  61. /**
  62. * The array index for the window text color.
  63. */
  64. public final static int WINDOW_TEXT = 9;
  65. /**
  66. * The array index for the menu background color.
  67. */
  68. public final static int MENU = 10;
  69. /**
  70. * The array index for the menu text color.
  71. */
  72. public final static int MENU_TEXT = 11;
  73. /**
  74. * The array index for the text background color.
  75. */
  76. public final static int TEXT = 12;
  77. /**
  78. * The array index for the text text color.
  79. */
  80. public final static int TEXT_TEXT = 13;
  81. /**
  82. * The array index for the text highlight color.
  83. */
  84. public final static int TEXT_HIGHLIGHT = 14;
  85. /**
  86. * The array index for the text highlight text color.
  87. */
  88. public final static int TEXT_HIGHLIGHT_TEXT = 15;
  89. /**
  90. * The array index for the text inactive text color.
  91. */
  92. public final static int TEXT_INACTIVE_TEXT = 16;
  93. /**
  94. * The array index for the control background color.
  95. */
  96. public final static int CONTROL = 17;
  97. /**
  98. * The array index for the control text color.
  99. */
  100. public final static int CONTROL_TEXT = 18;
  101. /**
  102. * The array index for the control highlight color.
  103. */
  104. public final static int CONTROL_HIGHLIGHT = 19;
  105. /**
  106. * The array index for the control light highlight color.
  107. */
  108. public final static int CONTROL_LT_HIGHLIGHT = 20;
  109. /**
  110. * The array index for the control shadow color.
  111. */
  112. public final static int CONTROL_SHADOW = 21;
  113. /**
  114. * The array index for the control dark shadow color.
  115. */
  116. public final static int CONTROL_DK_SHADOW = 22;
  117. /**
  118. * The array index for the scrollbar background color.
  119. */
  120. public final static int SCROLLBAR = 23;
  121. /**
  122. * The array index for the info background color.
  123. */
  124. public final static int INFO = 24;
  125. /**
  126. * The array index for the info text color.
  127. */
  128. public final static int INFO_TEXT = 25;
  129. /**
  130. * The number of system colors in the array.
  131. */
  132. public final static int NUM_COLORS = 26;
  133. /**
  134. * The color of the desktop background.
  135. */
  136. public final static SystemColor desktop = new SystemColor((byte)DESKTOP);
  137. /**
  138. * The background color for captions in window borders.
  139. */
  140. public final static SystemColor activeCaption = new SystemColor((byte)ACTIVE_CAPTION);
  141. /**
  142. * The text color for captions in window borders.
  143. */
  144. public final static SystemColor activeCaptionText = new SystemColor((byte)ACTIVE_CAPTION_TEXT);
  145. /**
  146. * The border color for captions in window borders.
  147. */
  148. public final static SystemColor activeCaptionBorder = new SystemColor((byte)ACTIVE_CAPTION_BORDER);
  149. /**
  150. * The background color for inactive captions in window borders.
  151. */
  152. public final static SystemColor inactiveCaption = new SystemColor((byte)INACTIVE_CAPTION);
  153. /**
  154. * The text color for inactive captions in window borders.
  155. */
  156. public final static SystemColor inactiveCaptionText = new SystemColor((byte)INACTIVE_CAPTION_TEXT);
  157. /**
  158. * The border color for inactive captios in window borders.
  159. */
  160. public final static SystemColor inactiveCaptionBorder = new SystemColor((byte)INACTIVE_CAPTION_BORDER);
  161. /**
  162. * The background color for windows.
  163. */
  164. public final static SystemColor window = new SystemColor((byte)WINDOW);
  165. /**
  166. * The border color for windows.
  167. */
  168. public final static SystemColor windowBorder = new SystemColor((byte)WINDOW_BORDER);
  169. /**
  170. * The text color for windows.
  171. */
  172. public final static SystemColor windowText = new SystemColor((byte)WINDOW_TEXT);
  173. /**
  174. * The background color for menus.
  175. */
  176. public final static SystemColor menu = new SystemColor((byte)MENU);
  177. /**
  178. * The text color for menus.
  179. */
  180. public final static SystemColor menuText = new SystemColor((byte)MENU_TEXT);
  181. /**
  182. * The background color for text components.
  183. */
  184. public final static SystemColor text = new SystemColor((byte)TEXT);
  185. /**
  186. * The text color for text components.
  187. */
  188. public final static SystemColor textText = new SystemColor((byte)TEXT_TEXT);
  189. /**
  190. * The background color for highlighted text.
  191. */
  192. public final static SystemColor textHighlight = new SystemColor((byte)TEXT_HIGHLIGHT);
  193. /**
  194. * The text color for highlighted text.
  195. */
  196. public final static SystemColor textHighlightText = new SystemColor((byte)TEXT_HIGHLIGHT_TEXT);
  197. /**
  198. * The text color for inactive text.
  199. */
  200. public final static SystemColor textInactiveText = new SystemColor((byte)TEXT_INACTIVE_TEXT);
  201. /**
  202. * The background color for control objects.
  203. */
  204. public final static SystemColor control = new SystemColor((byte)CONTROL);
  205. /**
  206. * The text color for control objects.
  207. */
  208. public final static SystemColor controlText = new SystemColor((byte)CONTROL_TEXT);
  209. /**
  210. * The regular highlight color for control objects.
  211. */
  212. public final static SystemColor controlHighlight = new SystemColor((byte)CONTROL_HIGHLIGHT);
  213. /**
  214. * The light highlight color for control objects.
  215. */
  216. public final static SystemColor controlLtHighlight = new SystemColor((byte)CONTROL_LT_HIGHLIGHT);
  217. /**
  218. * The regular shadow color for control objects.
  219. */
  220. public final static SystemColor controlShadow = new SystemColor((byte)CONTROL_SHADOW);
  221. /**
  222. * The dark shadow color for control objects.
  223. */
  224. public final static SystemColor controlDkShadow = new SystemColor((byte)CONTROL_DK_SHADOW);
  225. /**
  226. * The background color for scrollbars.
  227. */
  228. public final static SystemColor scrollbar = new SystemColor((byte)SCROLLBAR);
  229. /**
  230. * The background color for info(help) text.
  231. */
  232. public final static SystemColor info = new SystemColor((byte)INFO);
  233. /**
  234. * The text color for info(help) text.
  235. */
  236. public final static SystemColor infoText = new SystemColor((byte)INFO_TEXT);
  237. /*
  238. * System colors with default initial values, overwritten by toolkit if
  239. * system values differ and are available.
  240. */
  241. private static int[] systemColors = {
  242. 0xFF005C5C, // desktop = new Color(0,92,92);
  243. 0xFF000080, // activeCaption = new Color(0,0,128);
  244. 0xFFFFFFFF, // activeCaptionText = Color.white;
  245. 0xFFC0C0C0, // activeCaptionBorder = Color.lightGray;
  246. 0xFF808080, // inactiveCaption = Color.gray;
  247. 0xFFC0C0C0, // inactiveCaptionText = Color.lightGray;
  248. 0xFFC0C0C0, // inactiveCaptionBorder = Color.lightGray;
  249. 0xFFFFFFFF, // window = Color.white;
  250. 0xFF000000, // windowBorder = Color.black;
  251. 0xFF000000, // windowText = Color.black;
  252. 0xFFC0C0C0, // menu = Color.lightGray;
  253. 0xFF000000, // menuText = Color.black;
  254. 0xFFC0C0C0, // text = Color.lightGray;
  255. 0xFF000000, // textText = Color.black;
  256. 0xFF000080, // textHighlight = new Color(0,0,128);
  257. 0xFFFFFFFF, // textHighlightText = Color.white;
  258. 0xFF808080, // textInactiveText = Color.gray;
  259. 0xFFC0C0C0, // control = Color.lightGray;
  260. 0xFF000000, // controlText = Color.black;
  261. 0xFFFFFFFF, // controlHighlight = Color.white;
  262. 0xFFE0E0E0, // controlLtHighlight = new Color(224,224,224);
  263. 0xFF808080, // controlShadow = Color.gray;
  264. 0xFF000000, // controlDkShadow = Color.black;
  265. 0xFFE0E0E0, // scrollbar = new Color(224,224,224);
  266. 0xFFE0E000, // info = new Color(224,224,0);
  267. 0xFF000000, // infoText = Color.black;
  268. };
  269. /*
  270. * JDK 1.1 serialVersionUID
  271. */
  272. private static final long serialVersionUID = 4503142729533789064L;
  273. static {
  274. updateSystemColors();
  275. }
  276. /**
  277. * called from <init> & toolkit to update the above systemColors cache
  278. */
  279. private static void updateSystemColors() {
  280. Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
  281. }
  282. /**
  283. * Create a symbolic color that represents an indexed entry into system
  284. * color cache. Used by above static system colors.
  285. */
  286. private SystemColor(byte index) {
  287. super(0, 0, 0);
  288. value = index;
  289. }
  290. /**
  291. * Gets the "current" RGB value representing the symbolic color.
  292. * (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).
  293. * @see java.awt.image.ColorModel#getRGBdefault
  294. * @see java.awt.Color#getBlue(int)
  295. * @see java.awt.Color#getGreen(int)
  296. * @see java.awt.Color#getRed(int)
  297. */
  298. // NOTE: This method may be called by privileged threads.
  299. // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  300. public int getRGB() {
  301. return systemColors[value];
  302. }
  303. /**
  304. * Create and return a PaintContext used to generate a solid color
  305. * pattern. This enables a Color object to be used as an argument to
  306. * any method requiring an object implementing the Paint interface.
  307. * @see Paint
  308. * @see PaintContext
  309. * @see Graphics2D#setPaint
  310. */
  311. public PaintContext createContext(ColorModel cm, Rectangle r,
  312. Rectangle2D r2d, AffineTransform xform,
  313. RenderingHints hints) {
  314. return new ColorPaintContext(value, cm);
  315. }
  316. /**
  317. * Returns the String representation of this Color's values.
  318. */
  319. public String toString() {
  320. return getClass().getName() + "[i=" + (value) + "]";
  321. }
  322. }