Showing the changes to java/pkg/java/awt/SystemColor.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,543 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | package java.awt; | ||
| 26 | |||
| 27 | import java.io.ObjectStreamException; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * A class to encapsulate symbolic colors representing the color of | ||
| 31 | * native GUI objects on a system. For systems which support the dynamic | ||
| 32 | * update of the system colors (when the user changes the colors) | ||
| 33 | * the actual RGB values of these symbolic colors will also change | ||
| 34 | * dynamically. In order to compare the "current" RGB value of a | ||
| 35 | * <code>SystemColor</code> object with a non-symbolic Color object, | ||
| 36 | * <code>getRGB</code> should be used rather than <code>equals</code>. | ||
| 37 | * <p> | ||
| 38 | * Note that the way in which these system colors are applied to GUI objects | ||
| 39 | * may vary slightly from platform to platform since GUI objects may be | ||
| 40 | * rendered differently on each platform. | ||
| 41 | * <p> | ||
| 42 | * System color values may also be available through the <code>getDesktopProperty</code> | ||
| 43 | * method on <code>java.awt.Toolkit</code>. | ||
| 44 | * | ||
| 45 | * @see Toolkit#getDesktopProperty | ||
| 46 | * | ||
| 47 | * @author Carl Quinn | ||
| 48 | * @author Amy Fowler | ||
| 49 | */ | ||
| 50 | public final class SystemColor extends Color implements java.io.Serializable { | ||
| 51 | |||
| 52 | /** | ||
| 53 | * The array index for the | ||
| 54 | * {@link #desktop} system color. | ||
| 55 | * @see SystemColor#desktop | ||
| 56 | */ | ||
| 57 | public final static int DESKTOP = 0; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * The array index for the | ||
| 61 | * {@link #activeCaption} system color. | ||
| 62 | * @see SystemColor#activeCaption | ||
| 63 | */ | ||
| 64 | public final static int ACTIVE_CAPTION = 1; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * The array index for the | ||
| 68 | * {@link #activeCaptionText} system color. | ||
| 69 | * @see SystemColor#activeCaptionText | ||
| 70 | */ | ||
| 71 | public final static int ACTIVE_CAPTION_TEXT = 2; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * The array index for the | ||
| 75 | * {@link #activeCaptionBorder} system color. | ||
| 76 | * @see SystemColor#activeCaptionBorder | ||
| 77 | */ | ||
| 78 | public final static int ACTIVE_CAPTION_BORDER = 3; | ||
| 79 | |||
| 80 | /** | ||
| 81 | * The array index for the | ||
| 82 | * {@link #inactiveCaption} system color. | ||
| 83 | * @see SystemColor#inactiveCaption | ||
| 84 | */ | ||
| 85 | public final static int INACTIVE_CAPTION = 4; | ||
| 86 | |||
| 87 | /** | ||
| 88 | * The array index for the | ||
| 89 | * {@link #inactiveCaptionText} system color. | ||
| 90 | * @see SystemColor#inactiveCaptionText | ||
| 91 | */ | ||
| 92 | public final static int INACTIVE_CAPTION_TEXT = 5; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * The array index for the | ||
| 96 | * {@link #inactiveCaptionBorder} system color. | ||
| 97 | * @see SystemColor#inactiveCaptionBorder | ||
| 98 | */ | ||
| 99 | public final static int INACTIVE_CAPTION_BORDER = 6; | ||
| 100 | |||
| 101 | /** | ||
| 102 | * The array index for the | ||
| 103 | * {@link #window} system color. | ||
| 104 | * @see SystemColor#window | ||
| 105 | */ | ||
| 106 | public final static int WINDOW = 7; | ||
| 107 | |||
| 108 | /** | ||
| 109 | * The array index for the | ||
| 110 | * {@link #windowBorder} system color. | ||
| 111 | * @see SystemColor#windowBorder | ||
| 112 | */ | ||
| 113 | public final static int WINDOW_BORDER = 8; | ||
| 114 | |||
| 115 | /** | ||
| 116 | * The array index for the | ||
| 117 | * {@link #windowText} system color. | ||
| 118 | * @see SystemColor#windowText | ||
| 119 | */ | ||
| 120 | public final static int WINDOW_TEXT = 9; | ||
| 121 | |||
| 122 | /** | ||
| 123 | * The array index for the | ||
| 124 | * {@link #menu} system color. | ||
| 125 | * @see SystemColor#menu | ||
| 126 | */ | ||
| 127 | public final static int MENU = 10; | ||
| 128 | |||
| 129 | /** | ||
| 130 | * The array index for the | ||
| 131 | * {@link #menuText} system color. | ||
| 132 | * @see SystemColor#menuText | ||
| 133 | */ | ||
| 134 | public final static int MENU_TEXT = 11; | ||
| 135 | |||
| 136 | /** | ||
| 137 | * The array index for the | ||
| 138 | * {@link #text} system color. | ||
| 139 | * @see SystemColor#text | ||
| 140 | */ | ||
| 141 | public final static int TEXT = 12; | ||
| 142 | |||
| 143 | /** | ||
| 144 | * The array index for the | ||
| 145 | * {@link #textText} system color. | ||
| 146 | * @see SystemColor#textText | ||
| 147 | */ | ||
| 148 | public final static int TEXT_TEXT = 13; | ||
| 149 | |||
| 150 | /** | ||
| 151 | * The array index for the | ||
| 152 | * {@link #textHighlight} system color. | ||
| 153 | * @see SystemColor#textHighlight | ||
| 154 | */ | ||
| 155 | public final static int TEXT_HIGHLIGHT = 14; | ||
| 156 | |||
| 157 | /** | ||
| 158 | * The array index for the | ||
| 159 | * {@link #textHighlightText} system color. | ||
| 160 | * @see SystemColor#textHighlightText | ||
| 161 | */ | ||
| 162 | public final static int TEXT_HIGHLIGHT_TEXT = 15; | ||
| 163 | |||
| 164 | /** | ||
| 165 | * The array index for the | ||
| 166 | * {@link #textInactiveText} system color. | ||
| 167 | * @see SystemColor#textInactiveText | ||
| 168 | */ | ||
| 169 | public final static int TEXT_INACTIVE_TEXT = 16; | ||
| 170 | |||
| 171 | /** | ||
| 172 | * The array index for the | ||
| 173 | * {@link #control} system color. | ||
| 174 | * @see SystemColor#control | ||
| 175 | */ | ||
| 176 | public final static int CONTROL = 17; | ||
| 177 | |||
| 178 | /** | ||
| 179 | * The array index for the | ||
| 180 | * {@link #controlText} system color. | ||
| 181 | * @see SystemColor#controlText | ||
| 182 | */ | ||
| 183 | public final static int CONTROL_TEXT = 18; | ||
| 184 | |||
| 185 | /** | ||
| 186 | * The array index for the | ||
| 187 | * {@link #controlHighlight} system color. | ||
| 188 | * @see SystemColor#controlHighlight | ||
| 189 | */ | ||
| 190 | public final static int CONTROL_HIGHLIGHT = 19; | ||
| 191 | |||
| 192 | /** | ||
| 193 | * The array index for the | ||
| 194 | * {@link #controlLtHighlight} system color. | ||
| 195 | * @see SystemColor#controlLtHighlight | ||
| 196 | */ | ||
| 197 | public final static int CONTROL_LT_HIGHLIGHT = 20; | ||
| 198 | |||
| 199 | /** | ||
| 200 | * The array index for the | ||
| 201 | * {@link #controlShadow} system color. | ||
| 202 | * @see SystemColor#controlShadow | ||
| 203 | */ | ||
| 204 | public final static int CONTROL_SHADOW = 21; | ||
| 205 | |||
| 206 | /** | ||
| 207 | * The array index for the | ||
| 208 | * {@link #controlDkShadow} system color. | ||
| 209 | * @see SystemColor#controlDkShadow | ||
| 210 | */ | ||
| 211 | public final static int CONTROL_DK_SHADOW = 22; | ||
| 212 | |||
| 213 | /** | ||
| 214 | * The array index for the | ||
| 215 | * {@link #scrollbar} system color. | ||
| 216 | * @see SystemColor#scrollbar | ||
| 217 | */ | ||
| 218 | public final static int SCROLLBAR = 23; | ||
| 219 | |||
| 220 | /** | ||
| 221 | * The array index for the | ||
| 222 | * {@link #info} system color. | ||
| 223 | * @see SystemColor#info | ||
| 224 | */ | ||
| 225 | public final static int INFO = 24; | ||
| 226 | |||
| 227 | /** | ||
| 228 | * The array index for the | ||
| 229 | * {@link #infoText} system color. | ||
| 230 | * @see SystemColor#infoText | ||
| 231 | */ | ||
| 232 | public final static int INFO_TEXT = 25; | ||
| 233 | |||
| 234 | /** | ||
| 235 | * The number of system colors in the array. | ||
| 236 | */ | ||
| 237 | public final static int NUM_COLORS = 26; | ||
| 238 | |||
| 239 | /******************************************************************************************/ | ||
| 240 | |||
| 241 | /* | ||
| 242 | * System colors with default initial values, overwritten by toolkit if | ||
| 243 | * system values differ and are available. | ||
| 244 | * Should put array initialization above first field that is using | ||
| 245 | * SystemColor constructor to initialize. | ||
| 246 | */ | ||
| 247 | private static int[] systemColors = { | ||
| 248 | 0xFF005C5C, // desktop = new Color(0,92,92); | ||
| 249 | 0xFF000080, // activeCaption = new Color(0,0,128); | ||
| 250 | 0xFFFFFFFF, // activeCaptionText = Color.white; | ||
| 251 | 0xFFC0C0C0, // activeCaptionBorder = Color.lightGray; | ||
| 252 | 0xFF808080, // inactiveCaption = Color.gray; | ||
| 253 | 0xFFC0C0C0, // inactiveCaptionText = Color.lightGray; | ||
| 254 | 0xFFC0C0C0, // inactiveCaptionBorder = Color.lightGray; | ||
| 255 | 0xFFFFFFFF, // window = Color.white; | ||
| 256 | 0xFF000000, // windowBorder = Color.black; | ||
| 257 | 0xFF000000, // windowText = Color.black; | ||
| 258 | 0xFFC0C0C0, // menu = Color.lightGray; | ||
| 259 | 0xFF000000, // menuText = Color.black; | ||
| 260 | 0xFFC0C0C0, // text = Color.lightGray; | ||
| 261 | 0xFF000000, // textText = Color.black; | ||
| 262 | 0xFF000080, // textHighlight = new Color(0,0,128); | ||
| 263 | 0xFFFFFFFF, // textHighlightText = Color.white; | ||
| 264 | 0xFF808080, // textInactiveText = Color.gray; | ||
| 265 | 0xFFC0C0C0, // control = Color.lightGray; | ||
| 266 | 0xFF000000, // controlText = Color.black; | ||
| 267 | 0xFFFFFFFF, // controlHighlight = Color.white; | ||
| 268 | 0xFFE0E0E0, // controlLtHighlight = new Color(224,224,224); | ||
| 269 | 0xFF808080, // controlShadow = Color.gray; | ||
| 270 | 0xFF000000, // controlDkShadow = Color.black; | ||
| 271 | 0xFFE0E0E0, // scrollbar = new Color(224,224,224); | ||
| 272 | 0xFFE0E000, // info = new Color(224,224,0); | ||
| 273 | 0xFF000000, // infoText = Color.black; | ||
| 274 | }; | ||
| 275 | |||
| 276 | /** | ||
| 277 | * The color rendered for the background of the desktop. | ||
| 278 | */ | ||
| 279 | public final static SystemColor desktop = new SystemColor((byte)DESKTOP); | ||
| 280 | |||
| 281 | /** | ||
| 282 | * The color rendered for the window-title background of the currently active window. | ||
| 283 | */ | ||
| 284 | public final static SystemColor activeCaption = new SystemColor((byte)ACTIVE_CAPTION); | ||
| 285 | |||
| 286 | /** | ||
| 287 | * The color rendered for the window-title text of the currently active window. | ||
| 288 | */ | ||
| 289 | public final static SystemColor activeCaptionText = new SystemColor((byte)ACTIVE_CAPTION_TEXT); | ||
| 290 | |||
| 291 | /** | ||
| 292 | * The color rendered for the border around the currently active window. | ||
| 293 | */ | ||
| 294 | public final static SystemColor activeCaptionBorder = new SystemColor((byte)ACTIVE_CAPTION_BORDER); | ||
| 295 | |||
| 296 | /** | ||
| 297 | * The color rendered for the window-title background of inactive windows. | ||
| 298 | */ | ||
| 299 | public final static SystemColor inactiveCaption = new SystemColor((byte)INACTIVE_CAPTION); | ||
| 300 | |||
| 301 | /** | ||
| 302 | * The color rendered for the window-title text of inactive windows. | ||
| 303 | */ | ||
| 304 | public final static SystemColor inactiveCaptionText = new SystemColor((byte)INACTIVE_CAPTION_TEXT); | ||
| 305 | |||
| 306 | /** | ||
| 307 | * The color rendered for the border around inactive windows. | ||
| 308 | */ | ||
| 309 | public final static SystemColor inactiveCaptionBorder = new SystemColor((byte)INACTIVE_CAPTION_BORDER); | ||
| 310 | |||
| 311 | /** | ||
| 312 | * The color rendered for the background of interior regions inside windows. | ||
| 313 | */ | ||
| 314 | public final static SystemColor window = new SystemColor((byte)WINDOW); | ||
| 315 | |||
| 316 | /** | ||
| 317 | * The color rendered for the border around interior regions inside windows. | ||
| 318 | */ | ||
| 319 | public final static SystemColor windowBorder = new SystemColor((byte)WINDOW_BORDER); | ||
| 320 | |||
| 321 | /** | ||
| 322 | * The color rendered for text of interior regions inside windows. | ||
| 323 | */ | ||
| 324 | public final static SystemColor windowText = new SystemColor((byte)WINDOW_TEXT); | ||
| 325 | |||
| 326 | /** | ||
| 327 | * The color rendered for the background of menus. | ||
| 328 | */ | ||
| 329 | public final static SystemColor menu = new SystemColor((byte)MENU); | ||
| 330 | |||
| 331 | /** | ||
| 332 | * The color rendered for the text of menus. | ||
| 333 | */ | ||
| 334 | public final static SystemColor menuText = new SystemColor((byte)MENU_TEXT); | ||
| 335 | |||
| 336 | /** | ||
| 337 | * The color rendered for the background of text control objects, such as | ||
| 338 | * textfields and comboboxes. | ||
| 339 | */ | ||
| 340 | public final static SystemColor text = new SystemColor((byte)TEXT); | ||
| 341 | |||
| 342 | /** | ||
| 343 | * The color rendered for the text of text control objects, such as textfields | ||
| 344 | * and comboboxes. | ||
| 345 | */ | ||
| 346 | public final static SystemColor textText = new SystemColor((byte)TEXT_TEXT); | ||
| 347 | |||
| 348 | /** | ||
| 349 | * The color rendered for the background of selected items, such as in menus, | ||
| 350 | * comboboxes, and text. | ||
| 351 | */ | ||
| 352 | public final static SystemColor textHighlight = new SystemColor((byte)TEXT_HIGHLIGHT); | ||
| 353 | |||
| 354 | /** | ||
| 355 | * The color rendered for the text of selected items, such as in menus, comboboxes, | ||
| 356 | * and text. | ||
| 357 | */ | ||
| 358 | public final static SystemColor textHighlightText = new SystemColor((byte)TEXT_HIGHLIGHT_TEXT); | ||
| 359 | |||
| 360 | /** | ||
| 361 | * The color rendered for the text of inactive items, such as in menus. | ||
| 362 | */ | ||
| 363 | public final static SystemColor textInactiveText = new SystemColor((byte)TEXT_INACTIVE_TEXT); | ||
| 364 | |||
| 365 | /** | ||
| 366 | * The color rendered for the background of control panels and control objects, | ||
| 367 | * such as pushbuttons. | ||
| 368 | */ | ||
| 369 | public final static SystemColor control = new SystemColor((byte)CONTROL); | ||
| 370 | |||
| 371 | /** | ||
| 372 | * The color rendered for the text of control panels and control objects, | ||
| 373 | * such as pushbuttons. | ||
| 374 | */ | ||
| 375 | public final static SystemColor controlText = new SystemColor((byte)CONTROL_TEXT); | ||
| 376 | |||
| 377 | /** | ||
| 378 | * The color rendered for light areas of 3D control objects, such as pushbuttons. | ||
| 379 | * This color is typically derived from the <code>control</code> background color | ||
| 380 | * to provide a 3D effect. | ||
| 381 | */ | ||
| 382 | public final static SystemColor controlHighlight = new SystemColor((byte)CONTROL_HIGHLIGHT); | ||
| 383 | |||
| 384 | /** | ||
| 385 | * The color rendered for highlight areas of 3D control objects, such as pushbuttons. | ||
| 386 | * This color is typically derived from the <code>control</code> background color | ||
| 387 | * to provide a 3D effect. | ||
| 388 | */ | ||
| 389 | public final static SystemColor controlLtHighlight = new SystemColor((byte)CONTROL_LT_HIGHLIGHT); | ||
| 390 | |||
| 391 | /** | ||
| 392 | * The color rendered for shadow areas of 3D control objects, such as pushbuttons. | ||
| 393 | * This color is typically derived from the <code>control</code> background color | ||
| 394 | * to provide a 3D effect. | ||
| 395 | */ | ||
| 396 | public final static SystemColor controlShadow = new SystemColor((byte)CONTROL_SHADOW); | ||
| 397 | |||
| 398 | /** | ||
| 399 | * The color rendered for dark shadow areas on 3D control objects, such as pushbuttons. | ||
| 400 | * This color is typically derived from the <code>control</code> background color | ||
| 401 | * to provide a 3D effect. | ||
| 402 | */ | ||
| 403 | public final static SystemColor controlDkShadow = new SystemColor((byte)CONTROL_DK_SHADOW); | ||
| 404 | |||
| 405 | /** | ||
| 406 | * The color rendered for the background of scrollbars. | ||
| 407 | */ | ||
| 408 | public final static SystemColor scrollbar = new SystemColor((byte)SCROLLBAR); | ||
| 409 | |||
| 410 | /** | ||
| 411 | * The color rendered for the background of tooltips or spot help. | ||
| 412 | */ | ||
| 413 | public final static SystemColor info = new SystemColor((byte)INFO); | ||
| 414 | |||
| 415 | /** | ||
| 416 | * The color rendered for the text of tooltips or spot help. | ||
| 417 | */ | ||
| 418 | public final static SystemColor infoText = new SystemColor((byte)INFO_TEXT); | ||
| 419 | |||
| 420 | /* | ||
| 421 | * JDK 1.1 serialVersionUID. | ||
| 422 | */ | ||
| 423 | private static final long serialVersionUID = 4503142729533789064L; | ||
| 424 | |||
| 425 | /* | ||
| 426 | * An index into either array of SystemColor objects or values. | ||
| 427 | */ | ||
| 428 | private transient int index; | ||
| 429 | |||
| 430 | private static SystemColor systemColorObjects [] = { | ||
| 431 | SystemColor.desktop, | ||
| 432 | SystemColor.activeCaption, | ||
| 433 | SystemColor.activeCaptionText, | ||
| 434 | SystemColor.activeCaptionBorder, | ||
| 435 | SystemColor.inactiveCaption, | ||
| 436 | SystemColor.inactiveCaptionText, | ||
| 437 | SystemColor.inactiveCaptionBorder, | ||
| 438 | SystemColor.window, | ||
| 439 | SystemColor.windowBorder, | ||
| 440 | SystemColor.windowText, | ||
| 441 | SystemColor.menu, | ||
| 442 | SystemColor.menuText, | ||
| 443 | SystemColor.text, | ||
| 444 | SystemColor.textText, | ||
| 445 | SystemColor.textHighlight, | ||
| 446 | SystemColor.textHighlightText, | ||
| 447 | SystemColor.textInactiveText, | ||
| 448 | SystemColor.control, | ||
| 449 | SystemColor.controlText, | ||
| 450 | SystemColor.controlHighlight, | ||
| 451 | SystemColor.controlLtHighlight, | ||
| 452 | SystemColor.controlShadow, | ||
| 453 | SystemColor.controlDkShadow, | ||
| 454 | SystemColor.scrollbar, | ||
| 455 | SystemColor.info, | ||
| 456 | SystemColor.infoText | ||
| 457 | }; | ||
| 458 | |||
| 459 | static { | ||
| 460 | updateSystemColors(); | ||
| 461 | } | ||
| 462 | |||
| 463 | /** | ||
| 464 | * Called from <init> & toolkit to update the above systemColors cache. | ||
| 465 | */ | ||
| 466 | private static void updateSystemColors() { | ||
| 467 | if (!GraphicsEnvironment.isHeadless()) { | ||
| 468 | Toolkit.getDefaultToolkit().loadSystemColors(systemColors); | ||
| 469 | } | ||
| 470 | for (int i = 0; i < systemColors.length; i++) { | ||
| 471 | systemColorObjects[i].value = systemColors[i]; | ||
| 472 | } | ||
| 473 | } | ||
| 474 | |||
| 475 | /** | ||
| 476 | * Creates a symbolic color that represents an indexed entry into system | ||
| 477 | * color cache. Used by above static system colors. | ||
| 478 | */ | ||
| 479 | private SystemColor(byte index) { | ||
| 480 | super(systemColors[index]); | ||
| 481 | this.index = index; | ||
| 482 | } | ||
| 483 | |||
| 484 | /** | ||
| 485 | * Returns a string representation of this <code>Color</code>'s values. | ||
| 486 | * This method is intended to be used only for debugging purposes, | ||
| 487 | * and the content and format of the returned string may vary between | ||
| 488 | * implementations. | ||
| 489 | * The returned string may be empty but may not be <code>null</code>. | ||
| 490 | * | ||
| 491 | * @return a string representation of this <code>Color</code> | ||
| 492 | */ | ||
| 493 | public String toString() { | ||
| 494 | return getClass().getName() + "[i=" + (index) + "]"; | ||
| 495 | } | ||
| 496 | |||
| 497 | /** | ||
| 498 | * The design of the {@code SystemColor} class assumes that | ||
| 499 | * the {@code SystemColor} object instances stored in the | ||
| 500 | * static final fields above are the only instances that can | ||
| 501 | * be used by developers. | ||
| 502 | * This method helps maintain those limits on instantiation | ||
| 503 | * by using the index stored in the value field of the | ||
| 504 | * serialized form of the object to replace the serialized | ||
| 505 | * object with the equivalent static object constant field | ||
| 506 | * of {@code SystemColor}. | ||
| 507 | * See the {@link #writeReplace} method for more information | ||
| 508 | * on the serialized form of these objects. | ||
| 509 | * @return one of the {@code SystemColor} static object | ||
| 510 | * fields that refers to the same system color. | ||
| 511 | */ | ||
| 512 | private Object readResolve() { | ||
| 513 | // The instances of SystemColor are tightly controlled and | ||
| 514 | // only the canonical instances appearing above as static | ||
| 515 | // constants are allowed. The serial form of SystemColor | ||
| 516 | // objects stores the color index as the value. Here we | ||
| 517 | // map that index back into the canonical instance. | ||
| 518 | return systemColorObjects[value]; | ||
| 519 | } | ||
| 520 | |||
| 521 | /** | ||
| 522 | * Returns a specialized version of the {@code SystemColor} | ||
| 523 | * object for writing to the serialized stream. | ||
| 524 | * @serialData | ||
| 525 | * The value field of a serialized {@code SystemColor} object | ||
| 526 | * contains the array index of the system color instead of the | ||
| 527 | * rgb data for the system color. | ||
| 528 | * This index is used by the {@link #readResolve} method to | ||
| 529 | * resolve the deserialized objects back to the original | ||
| 530 | * static constant versions to ensure unique instances of | ||
| 531 | * each {@code SystemColor} object. | ||
| 532 | * @return a proxy {@code SystemColor} object with its value | ||
| 533 | * replaced by the corresponding system color index. | ||
| 534 | */ | ||
| 535 | private Object writeReplace() throws ObjectStreamException | ||
| 536 | { | ||
| 537 | // we put an array index in the SystemColor.value while serialize | ||
| 538 | // to keep compatibility. | ||
| 539 | SystemColor color = new SystemColor((byte)index); | ||
| 540 | color.value = index; | ||
| 541 | return color; | ||
| 542 | } | ||
| 543 | } | ||