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