1 /*
   2  * Copyright (c) 2003, 2006, 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 
  26 package sun.awt.X11;
  27 
  28 import java.awt.*;
  29 import java.io.*;
  30 import sun.security.action.GetPropertyAction;
  31 import java.security.AccessController;
  32 import sun.font.FontUtilities;
  33 
  34 /**
  35   *
  36   *  This class contains code that is need to mimic the
  37   *  Motif Color selection and color defaults code.
  38   *
  39   *  Portions of this code have been ported to java from
  40   *  Motif sources (Color.c) (ColorP.h) etc.
  41   *
  42   *  Author: Bino George
  43   *
  44   */
  45 
  46 class MotifColorUtilities {
  47 
  48 
  49     static final float XmRED_LUMINOSITY=0.30f;
  50     static final float XmGREEN_LUMINOSITY=0.59f;
  51     static final float XmBLUE_LUMINOSITY=0.11f;
  52     static final int XmINTENSITY_FACTOR=75;
  53     static final int XmLIGHT_FACTOR=0;
  54     static final int XmLUMINOSITY_FACTOR=25;
  55 
  56     static final int XmMAX_SHORT=65535;
  57 
  58 
  59     static final int XmCOLOR_PERCENTILE=(XmMAX_SHORT / 100);
  60 
  61     static final int XmDEFAULT_DARK_THRESHOLD=20;
  62     static final int XmDEFAULT_LIGHT_THRESHOLD=93;
  63     static final int XmDEFAULT_FOREGROUND_THRESHOLD=70;
  64 
  65     static final int BLACK = 0xFF000000;
  66     static final int WHITE = 0xFFFFFFFF;
  67     static final int MOTIF_WINDOW_COLOR= 0xFFDFDFDF;
  68 
  69     static final int DEFAULT_COLOR =  0xFFC4C4C4;
  70 
  71     static final int  XmCOLOR_LITE_THRESHOLD = XmDEFAULT_LIGHT_THRESHOLD * XmCOLOR_PERCENTILE;
  72     static final int  XmCOLOR_DARK_THRESHOLD = XmDEFAULT_DARK_THRESHOLD * XmCOLOR_PERCENTILE;
  73     static final int  XmFOREGROUND_THRESHOLD = XmDEFAULT_FOREGROUND_THRESHOLD * XmCOLOR_PERCENTILE;
  74 
  75     /* LITE color model
  76        percent to interpolate RGB towards black for SEL, BS, TS */
  77 
  78     static final int XmCOLOR_LITE_SEL_FACTOR = 15;
  79     static final int XmCOLOR_LITE_BS_FACTOR =  40;
  80     static final int XmCOLOR_LITE_TS_FACTOR =  20;
  81 
  82     /* DARK color model
  83        percent to interpolate RGB towards white for SEL, BS, TS */
  84 
  85     static final int XmCOLOR_DARK_SEL_FACTOR=  15;
  86     static final int XmCOLOR_DARK_BS_FACTOR =  30;
  87     static final int XmCOLOR_DARK_TS_FACTOR =  50;
  88 
  89     /* STD color model
  90        percent to interpolate RGB towards black for SEL, BS
  91        percent to interpolate RGB towards white for TS
  92        HI values used for high brightness (within STD)
  93        LO values used for low brightness (within STD)
  94        Interpolate factors between HI & LO values based on brightness */
  95 
  96     static final int XmCOLOR_HI_SEL_FACTOR = 15;
  97     static final int XmCOLOR_HI_BS_FACTOR =  40;
  98     static final int XmCOLOR_HI_TS_FACTOR =  60;
  99 
 100     static final int XmCOLOR_LO_SEL_FACTOR=  15;
 101     static final int XmCOLOR_LO_BS_FACTOR =  60;
 102     static final int XmCOLOR_LO_TS_FACTOR =  50;
 103 
 104     static int brightness( int red, int green, int blue )
 105     {
 106         float brightness;
 107         float intensity;
 108         float light;
 109         float luminosity, maxprimary, minprimary;
 110 
 111         // To mimix Motif logic, we need to convert to 16 bit color values.
 112 
 113         red = red << 8;
 114         green = green << 8;
 115         blue = blue << 8;
 116 
 117 
 118         intensity = (red + green + blue) / 3;
 119 
 120 
 121         /*
 122          * The casting nonsense below is to try to control the point at
 123          * the truncation occurs.
 124          */
 125 
 126         luminosity = (int) ((XmRED_LUMINOSITY * (float) red)
 127                 + (XmGREEN_LUMINOSITY * (float) green)
 128                 + (XmBLUE_LUMINOSITY * (float) blue));
 129 
 130         maxprimary = ( (red > green) ?
 131                 ( (red > blue) ? red : blue ) :
 132                 ( (green > blue) ? green : blue ) );
 133 
 134         minprimary = ( (red < green) ?
 135                 ( (red < blue) ? red : blue ) :
 136                 ( (green < blue) ? green : blue ) );
 137 
 138         light = (minprimary + maxprimary) / 2;
 139 
 140         brightness = ( (intensity * XmINTENSITY_FACTOR) +
 141                 (light * XmLIGHT_FACTOR) +
 142                 (luminosity * XmLUMINOSITY_FACTOR) ) / 100;
 143         return Math.round(brightness);
 144     }
 145 
 146     static int calculateForegroundFromBackground(int r, int g, int b) {
 147 
 148         int foreground = WHITE;
 149         int  brightness = brightness(r,g,b);
 150 
 151         if (brightness >  XmFOREGROUND_THRESHOLD) {
 152             foreground = BLACK;
 153         }
 154         else foreground = WHITE;
 155 
 156         return foreground;
 157     }
 158 
 159     static int calculateTopShadowFromBackground(int r, int g, int b) {
 160 
 161         float color_value,f;
 162 
 163         int br = r << 8;
 164         int bg = g << 8;
 165         int bb = b << 8;
 166 
 167         int brightness = brightness(r,g,b);
 168 
 169         float red;
 170         float green;
 171         float blue;
 172 
 173         if (brightness < XmCOLOR_DARK_THRESHOLD) {
 174             // dark background
 175 
 176             color_value = br;
 177             color_value += XmCOLOR_DARK_TS_FACTOR *
 178                 (XmMAX_SHORT - color_value) / 100;
 179             red = color_value;
 180 
 181             color_value = bg;
 182             color_value += XmCOLOR_DARK_TS_FACTOR *
 183                 (XmMAX_SHORT - color_value) / 100;
 184             green = color_value;
 185 
 186             color_value = bb;
 187             color_value += XmCOLOR_DARK_TS_FACTOR *
 188                 (XmMAX_SHORT - color_value) / 100;
 189             blue = color_value;
 190         }
 191         else if (brightness > XmCOLOR_LITE_THRESHOLD) {
 192             // lite background
 193 
 194             color_value = br;
 195             color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
 196             red = color_value;
 197 
 198             color_value = bg;
 199             color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
 200             green = color_value;
 201 
 202             color_value = bb;
 203             color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
 204             blue = color_value;
 205 
 206         }
 207         else {
 208             // medium
 209             f = XmCOLOR_LO_TS_FACTOR + (brightness
 210                     * ( XmCOLOR_HI_TS_FACTOR - XmCOLOR_LO_TS_FACTOR )
 211                     / XmMAX_SHORT);
 212 
 213             color_value = br;
 214             color_value += f * ( XmMAX_SHORT - color_value ) / 100;
 215             red = color_value;
 216 
 217             color_value = bg;
 218             color_value += f * ( XmMAX_SHORT - color_value ) / 100;
 219             green = color_value;
 220 
 221             color_value = bb;
 222             color_value += f * ( XmMAX_SHORT - color_value ) / 100;
 223             blue = color_value;
 224 
 225 
 226         }
 227 
 228 
 229         int ired = ((int)red) >> 8;
 230         int igreen = ((int)green) >> 8;
 231         int iblue = ((int)blue) >> 8;
 232 
 233         int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
 234 
 235         return ret;
 236     }
 237 
 238 
 239     static int calculateBottomShadowFromBackground(int r, int g, int b) {
 240 
 241         float color_value,f;
 242 
 243         int br = r << 8;
 244         int bg = g << 8;
 245         int bb = b << 8;
 246 
 247         int brightness = brightness(r,g,b);
 248 
 249         float red;
 250         float green;
 251         float blue;
 252 
 253         if (brightness < XmCOLOR_DARK_THRESHOLD) {
 254             // dark background
 255             color_value = br;
 256             color_value += XmCOLOR_DARK_BS_FACTOR *
 257                 (XmMAX_SHORT - color_value) / 100;
 258             red = color_value;
 259 
 260             color_value = bg;
 261             color_value += XmCOLOR_DARK_BS_FACTOR *
 262                 (XmMAX_SHORT - color_value) / 100;
 263             green = color_value;
 264 
 265             color_value = bb;
 266             color_value += XmCOLOR_DARK_BS_FACTOR *
 267                 (XmMAX_SHORT - color_value) / 100;
 268             blue = color_value;
 269 
 270         }
 271         else if (brightness > XmCOLOR_LITE_THRESHOLD) {
 272             // lite background
 273             color_value = br;
 274             color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
 275             red = color_value;
 276 
 277             color_value = bg;
 278             color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
 279             green = color_value;
 280 
 281             color_value = bb;
 282             color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
 283             blue = color_value;
 284 
 285         }
 286         else {
 287             // medium
 288             f = XmCOLOR_LO_BS_FACTOR + (brightness
 289                     * ( XmCOLOR_HI_BS_FACTOR - XmCOLOR_LO_BS_FACTOR )
 290                     / XmMAX_SHORT);
 291 
 292             color_value = br;
 293             color_value -= (color_value * f) / 100;
 294             red = color_value;
 295 
 296             color_value = bg;
 297             color_value -= (color_value * f) / 100;
 298             green = color_value;
 299 
 300             color_value = bb;
 301             color_value -= (color_value * f) / 100;
 302             blue = color_value;
 303         }
 304 
 305 
 306         int ired = ((int)red) >> 8;
 307         int igreen = ((int)green) >> 8;
 308         int iblue = ((int)blue) >> 8;
 309 
 310         int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
 311 
 312         return ret;
 313     }
 314 
 315     static int calculateSelectFromBackground(int r, int g, int b) {
 316 
 317         float color_value,f;
 318 
 319         int br = r << 8;
 320         int bg = g << 8;
 321         int bb = b << 8;
 322 
 323         int brightness = brightness(r,g,b);
 324 
 325         float red;
 326         float green;
 327         float blue;
 328 
 329         if (brightness < XmCOLOR_DARK_THRESHOLD) {
 330             // dark background
 331             color_value = br;
 332             color_value += XmCOLOR_DARK_SEL_FACTOR *
 333                 (XmMAX_SHORT - color_value) / 100;
 334             red = color_value;
 335 
 336             color_value = bg;
 337             color_value += XmCOLOR_DARK_SEL_FACTOR *
 338                 (XmMAX_SHORT - color_value) / 100;
 339             green = color_value;
 340 
 341             color_value = bb;
 342             color_value += XmCOLOR_DARK_SEL_FACTOR *
 343                 (XmMAX_SHORT - color_value) / 100;
 344             blue = color_value;
 345 
 346         }
 347         else if (brightness > XmCOLOR_LITE_THRESHOLD) {
 348             // lite background
 349             color_value = br;
 350             color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
 351             red = color_value;
 352 
 353             color_value = bg;
 354             color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
 355             green = color_value;
 356 
 357             color_value = bb;
 358             color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
 359             blue = color_value;
 360 
 361         }
 362         else {
 363             // medium
 364             f = XmCOLOR_LO_SEL_FACTOR + (brightness
 365                     * ( XmCOLOR_HI_SEL_FACTOR - XmCOLOR_LO_SEL_FACTOR )
 366                     / XmMAX_SHORT);
 367 
 368             color_value = br;
 369             color_value -= (color_value * f) / 100;
 370             red = color_value;
 371 
 372             color_value = bg;
 373             color_value -= (color_value * f) / 100;
 374             green = color_value;
 375 
 376             color_value = bb;
 377             color_value -= (color_value * f) / 100;
 378             blue = color_value;
 379         }
 380 
 381 
 382         int ired = ((int)red) >> 8;
 383         int igreen = ((int)green) >> 8;
 384         int iblue = ((int)blue) >> 8;
 385 
 386         int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
 387 
 388         return ret;
 389     }
 390 
 391    static void loadSystemColorsForCDE(int[] systemColors) throws Exception  {
 392         // System.out.println("loadSystemColorsForCDE");
 393         XAtom resourceManager = XAtom.get("RESOURCE_MANAGER");
 394 
 395         String resourceString = resourceManager.getProperty(XToolkit.getDefaultRootWindow());
 396 
 397         int index = resourceString.indexOf("ColorPalette:");
 398         int len = resourceString.length();
 399         while ( (index < len) && (resourceString.charAt(index) != ':')) index++;
 400         index++; // skip :
 401         if (resourceString.charAt(index) == '\t') index++; // skip \t
 402 
 403         String paletteFile = resourceString.substring(index,resourceString.indexOf("\n",index));
 404 
 405         //System.out.println("Palette File = " + paletteFile);
 406 
 407         // Check if palette is a user palette.
 408 
 409         String  paletteFilePath = System.getProperty("user.home") + "/.dt/palettes/" + paletteFile;
 410 
 411         File pFile = new File(paletteFilePath);
 412         if (!pFile.exists())
 413         {
 414             // Must be a system palette
 415             paletteFilePath = "/usr/dt/palettes/" + paletteFile;
 416             pFile = new File(paletteFilePath);
 417             if (!pFile.exists())
 418             {
 419                 throw new FileNotFoundException("Could not open : "+ paletteFilePath);
 420             }
 421         }
 422         BufferedReader bfr = new BufferedReader(new FileReader(pFile));
 423 
 424         int colors[] = new int[8];
 425         int r,g,b;
 426         String temp,color;
 427 
 428         for (int i=0;i<8;i++) {
 429             temp = bfr.readLine();
 430             color = temp.substring(1,temp.length());
 431             r = Integer.valueOf(color.substring(0,4),16).intValue() >> 8;
 432             g = Integer.valueOf(color.substring(4,8),16).intValue() >> 8;
 433             b = Integer.valueOf(color.substring(8,12),16).intValue() >> 8;
 434             colors[i] = 0xff000000 | r<<16 | g<<8 | b;
 435             //  System.out.println("color["+i+"]="+Integer.toHexString(colors[i]) + "r = " +r + "g="+g+"b="+b);
 436         }
 437 
 438         int numOfColor = 4;
 439         if (!Boolean.parseBoolean(AccessController.doPrivileged(
 440                new GetPropertyAction("ibm.awt.mediumColor")))) {
 441 
 442             if (FontUtilities.isAIX) {
 443                 numOfColor = 8;
 444             }
 445             int idx = resourceString.indexOf("ColorUse:");
 446             if (idx > -1) {
 447                 while ( (idx < len) && (resourceString.charAt(idx) != ':')) idx++;
 448                 idx++; // skip :
 449                 if (resourceString.charAt(idx) == '\t') idx++; // skip \t
 450                 String colorUse = resourceString.substring(idx,resourceString.indexOf("\n",idx));
 451                 if ("HIGH_COLOR".equalsIgnoreCase(colorUse)) {
 452                     numOfColor = 8;
 453                 } else if ("MEDIUM_COLOR".equalsIgnoreCase(colorUse)) {
 454                     numOfColor = 4;
 455                 }
 456             }
 457         }
 458 
 459         if (4 == numOfColor) 
 460             loadSystemColorsForCDE4(systemColors, colors);
 461         else
 462             loadSystemColorsForCDE8(systemColors, colors);
 463    }
 464 
 465    private static void loadSystemColorsForCDE4(int[] systemColors, int[] colors) throws Exception {
 466         int r,g,b;
 467         systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
 468         systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
 469 
 470         systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
 471         systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
 472 
 473         systemColors[SystemColor.WINDOW] = colors[1];
 474 
 475         systemColors[SystemColor.WINDOW_BORDER] = colors[1];
 476         systemColors[SystemColor.MENU] = colors[1];
 477 
 478         systemColors[SystemColor.TEXT] = colors[3];
 479 
 480         systemColors[SystemColor.SCROLLBAR] = colors[1];
 481         systemColors[SystemColor.CONTROL] = colors[1];
 482 
 483         int activeFore;
 484         int inactiveFore;
 485         int textFore;
 486 
 487 
 488         r = (colors[0] & 0x00FF0000) >> 16;
 489         g = (colors[0] & 0x0000FF00) >> 8;
 490         b = (colors[0] & 0x000000FF);
 491 
 492         activeFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 493 
 494         r = (colors[1] & 0x00FF0000) >> 16;
 495         g = (colors[1] & 0x0000FF00) >> 8;
 496         b = (colors[1] & 0x000000FF);
 497 
 498         inactiveFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 499 
 500         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 501         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 502 
 503 
 504         r = (colors[3] & 0x00FF0000) >> 16;
 505         g = (colors[3] & 0x0000FF00) >> 8;
 506         b = (colors[3] & 0x000000FF);
 507 
 508         textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 509 
 510 
 511         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
 512         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
 513         systemColors[SystemColor.WINDOW_TEXT] = inactiveFore;
 514         systemColors[SystemColor.MENU_TEXT] = inactiveFore;
 515         systemColors[SystemColor.TEXT_TEXT] = textFore;
 516         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 517         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 518         systemColors[SystemColor.CONTROL_TEXT] = inactiveFore;
 519         Color tmp = new Color(top_shadow);
 520         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 521         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 522 
 523         tmp = new Color(bottom_shadow);
 524         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 525         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 526 
 527     }
 528 
 529     private static void loadSystemColorsForCDE8(int[] systemColors, int[] colors) throws Exception {
 530         int r,g,b;
 531         systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
 532         systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
 533 
 534         systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
 535         systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
 536 
 537         systemColors[SystemColor.WINDOW] = colors[4];
 538 
 539         systemColors[SystemColor.MENU] = colors[5];
 540 
 541         systemColors[SystemColor.TEXT] = colors[3];
 542         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = colors[3];
 543 
 544         systemColors[SystemColor.SCROLLBAR] = colors[4];
 545         systemColors[SystemColor.CONTROL] = colors[4];
 546         systemColors[SystemColor.INFO] =  colors[4];
 547 
 548         int activeFore;
 549         int inactiveFore;
 550         int textFore;
 551 
 552 
 553         r = (colors[0] & 0x00FF0000) >> 16;
 554         g = (colors[0] & 0x0000FF00) >> 8;
 555         b = (colors[0] & 0x000000FF);
 556 
 557         activeFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 558 
 559         r = (colors[1] & 0x00FF0000) >> 16;
 560         g = (colors[1] & 0x0000FF00) >> 8;
 561         b = (colors[1] & 0x000000FF);
 562 
 563         inactiveFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 564 
 565         r = (colors[3] & 0x00FF0000) >> 16;
 566         g = (colors[3] & 0x0000FF00) >> 8;
 567         b = (colors[3] & 0x000000FF);
 568 
 569         textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 570 
 571         r = (colors[4] & 0x00FF0000) >> 16;
 572         g = (colors[4] & 0x0000FF00) >> 8;
 573         b = (colors[4] & 0x000000FF);
 574 
 575         int windowFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 576 
 577         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 578         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 579 
 580 
 581         r = (colors[5] & 0x00FF0000) >> 16;
 582         g = (colors[5] & 0x0000FF00) >> 8;
 583         b = (colors[5] & 0x000000FF);
 584 
 585         int menuFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 586 
 587         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
 588         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
 589         systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.BLACK;
 590         systemColors[SystemColor.WINDOW_TEXT] = windowFore;
 591         systemColors[SystemColor.MENU_TEXT] = menuFore;
 592         systemColors[SystemColor.TEXT_TEXT] = textFore;
 593         systemColors[SystemColor.TEXT_HIGHLIGHT] = textFore;
 594         systemColors[SystemColor.CONTROL_TEXT] = windowFore;
 595         Color tmp = new Color(top_shadow);
 596         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 597         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 598 
 599         tmp = new Color(bottom_shadow);
 600         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 601         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 602 
 603         systemColors[SystemColor.INFO_TEXT] = windowFore;
 604 
 605     }
 606 
 607     static void loadMotifDefaultColors(int[] systemColors) {
 608         //fix for 5092883. WINDOW should be light gray and TEXT should be WHITE to look similar to Motif
 609         systemColors[SystemColor.WINDOW] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 610         systemColors[SystemColor.TEXT] = MotifColorUtilities.WHITE;
 611         systemColors[SystemColor.WINDOW_TEXT] = MotifColorUtilities.BLACK;
 612         systemColors[SystemColor.MENU_TEXT] = MotifColorUtilities.BLACK;
 613         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 614         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 615         systemColors[SystemColor.TEXT_TEXT] = MotifColorUtilities.BLACK;
 616         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 617         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 618         systemColors[SystemColor.CONTROL_TEXT] = MotifColorUtilities.BLACK;
 619         systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.DEFAULT_COLOR;
 620         systemColors[SystemColor.MENU] = MotifColorUtilities.DEFAULT_COLOR;
 621         systemColors[SystemColor.SCROLLBAR] = MotifColorUtilities.DEFAULT_COLOR;
 622         systemColors[SystemColor.CONTROL] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 623 
 624         int r = (MotifColorUtilities.DEFAULT_COLOR & 0x00FF0000) >> 16;
 625         int g = (MotifColorUtilities.DEFAULT_COLOR & 0x0000FF00) >> 8;
 626         int b = (MotifColorUtilities.DEFAULT_COLOR & 0x000000FF);
 627 
 628 
 629         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 630         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 631 
 632         Color tmp = new Color(top_shadow);
 633         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 634         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 635 
 636         tmp = new Color(bottom_shadow);
 637         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 638         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 639 
 640     }
 641 
 642 
 643     static void loadSystemColors(int[] systemColors) {
 644         if ("Linux".equals(AccessController.doPrivileged(new GetPropertyAction("os.name")))) { // Load motif default colors on Linux.
 645             loadMotifDefaultColors(systemColors);
 646         }
 647         else
 648         {
 649             try {
 650                 loadSystemColorsForCDE(systemColors);
 651             }
 652             catch (Exception e) // Failure to load CDE colors.
 653             {
 654                 loadMotifDefaultColors(systemColors);
 655             }
 656         }
 657     }
 658 }