1 /*
   2  * Copyright (c) 2003, 2019, 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.awt.OSInfo;
  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         // Solaris's default color is MEDIUM_COLOR (4)
 439         // AIX's default color is HIGH_COLOR (8)
 440         int numOfColor = OSInfo.getOSType() == OSInfo.OSType.AIX ? 8 : 4;
 441 
 442         int idx = resourceString.indexOf("ColorUse:");
 443         if (idx > -1) {
 444             while ( (idx < len) && (resourceString.charAt(idx) != ':')) idx++;
 445             idx++; // skip :
 446             if (resourceString.charAt(idx) == '\t') idx++; // skip \t
 447             String colorUse = resourceString.substring(idx,resourceString.indexOf("\n",idx));
 448             if ("HIGH_COLOR".equalsIgnoreCase(colorUse)) {
 449                 numOfColor = 8;
 450             } else if ("MEDIUM_COLOR".equalsIgnoreCase(colorUse)) {
 451                 numOfColor = 4;
 452             }
 453         }
 454 
 455         if (4 == numOfColor) 
 456             loadSystemColorsForCDE4(systemColors, colors);
 457         else
 458             loadSystemColorsForCDE8(systemColors, colors);
 459    }
 460 
 461    private static void loadSystemColorsForCDE4(int[] systemColors, int[] colors) throws Exception {
 462         int r,g,b;
 463         systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
 464         systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
 465 
 466         systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
 467         systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
 468 
 469         systemColors[SystemColor.WINDOW] = colors[1];
 470 
 471         systemColors[SystemColor.WINDOW_BORDER] = colors[1];
 472         systemColors[SystemColor.MENU] = colors[1];
 473 
 474         systemColors[SystemColor.TEXT] = colors[3];
 475 
 476         systemColors[SystemColor.SCROLLBAR] = colors[1];
 477         systemColors[SystemColor.CONTROL] = colors[1];
 478 
 479         int activeFore;
 480         int inactiveFore;
 481         int textFore;
 482 
 483 
 484         r = (colors[0] & 0x00FF0000) >> 16;
 485         g = (colors[0] & 0x0000FF00) >> 8;
 486         b = (colors[0] & 0x000000FF);
 487 
 488         activeFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 489 
 490         r = (colors[1] & 0x00FF0000) >> 16;
 491         g = (colors[1] & 0x0000FF00) >> 8;
 492         b = (colors[1] & 0x000000FF);
 493 
 494         inactiveFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 495 
 496         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 497         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 498 
 499 
 500         r = (colors[3] & 0x00FF0000) >> 16;
 501         g = (colors[3] & 0x0000FF00) >> 8;
 502         b = (colors[3] & 0x000000FF);
 503 
 504         textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 505 
 506 
 507         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
 508         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
 509         systemColors[SystemColor.WINDOW_TEXT] = inactiveFore;
 510         systemColors[SystemColor.MENU_TEXT] = inactiveFore;
 511         systemColors[SystemColor.TEXT_TEXT] = textFore;
 512         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 513         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 514         systemColors[SystemColor.CONTROL_TEXT] = inactiveFore;
 515         Color tmp = new Color(top_shadow);
 516         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 517         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 518 
 519         tmp = new Color(bottom_shadow);
 520         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 521         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 522 
 523     }
 524 
 525     private static void loadSystemColorsForCDE8(int[] systemColors, int[] colors) throws Exception {
 526         int r,g,b;
 527         systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
 528         systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
 529 
 530         systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
 531         systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
 532 
 533         systemColors[SystemColor.WINDOW] = colors[4];
 534 
 535         systemColors[SystemColor.MENU] = colors[5];
 536 
 537         systemColors[SystemColor.TEXT] = colors[3];
 538         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = colors[3];
 539 
 540         systemColors[SystemColor.SCROLLBAR] = colors[4];
 541         systemColors[SystemColor.CONTROL] = colors[4];
 542         systemColors[SystemColor.INFO] =  colors[4];
 543 
 544         int activeFore;
 545         int inactiveFore;
 546         int textFore;
 547 
 548 
 549         r = (colors[0] & 0x00FF0000) >> 16;
 550         g = (colors[0] & 0x0000FF00) >> 8;
 551         b = (colors[0] & 0x000000FF);
 552 
 553         activeFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 554 
 555         r = (colors[1] & 0x00FF0000) >> 16;
 556         g = (colors[1] & 0x0000FF00) >> 8;
 557         b = (colors[1] & 0x000000FF);
 558 
 559         inactiveFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 560 
 561         r = (colors[3] & 0x00FF0000) >> 16;
 562         g = (colors[3] & 0x0000FF00) >> 8;
 563         b = (colors[3] & 0x000000FF);
 564 
 565         textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 566 
 567         r = (colors[4] & 0x00FF0000) >> 16;
 568         g = (colors[4] & 0x0000FF00) >> 8;
 569         b = (colors[4] & 0x000000FF);
 570 
 571         int windowFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 572 
 573         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 574         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 575 
 576 
 577         r = (colors[5] & 0x00FF0000) >> 16;
 578         g = (colors[5] & 0x0000FF00) >> 8;
 579         b = (colors[5] & 0x000000FF);
 580 
 581         int menuFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 582 
 583         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
 584         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
 585         systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.BLACK;
 586         systemColors[SystemColor.WINDOW_TEXT] = windowFore;
 587         systemColors[SystemColor.MENU_TEXT] = menuFore;
 588         systemColors[SystemColor.TEXT_TEXT] = textFore;
 589         systemColors[SystemColor.TEXT_HIGHLIGHT] = textFore;
 590         systemColors[SystemColor.CONTROL_TEXT] = windowFore;
 591         Color tmp = new Color(top_shadow);
 592         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 593         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 594 
 595         tmp = new Color(bottom_shadow);
 596         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 597         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 598 
 599         systemColors[SystemColor.INFO_TEXT] = windowFore;
 600 
 601     }
 602 
 603     static void loadMotifDefaultColors(int[] systemColors) {
 604         //fix for 5092883. WINDOW should be light gray and TEXT should be WHITE to look similar to Motif
 605         systemColors[SystemColor.WINDOW] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 606         systemColors[SystemColor.TEXT] = MotifColorUtilities.WHITE;
 607         systemColors[SystemColor.WINDOW_TEXT] = MotifColorUtilities.BLACK;
 608         systemColors[SystemColor.MENU_TEXT] = MotifColorUtilities.BLACK;
 609         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 610         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 611         systemColors[SystemColor.TEXT_TEXT] = MotifColorUtilities.BLACK;
 612         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 613         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 614         systemColors[SystemColor.CONTROL_TEXT] = MotifColorUtilities.BLACK;
 615         systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.DEFAULT_COLOR;
 616         systemColors[SystemColor.MENU] = MotifColorUtilities.DEFAULT_COLOR;
 617         systemColors[SystemColor.SCROLLBAR] = MotifColorUtilities.DEFAULT_COLOR;
 618         systemColors[SystemColor.CONTROL] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 619 
 620         int r = (MotifColorUtilities.DEFAULT_COLOR & 0x00FF0000) >> 16;
 621         int g = (MotifColorUtilities.DEFAULT_COLOR & 0x0000FF00) >> 8;
 622         int b = (MotifColorUtilities.DEFAULT_COLOR & 0x000000FF);
 623 
 624 
 625         int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
 626         int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
 627 
 628         Color tmp = new Color(top_shadow);
 629         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 630         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 631 
 632         tmp = new Color(bottom_shadow);
 633         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 634         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
 635 
 636     }
 637 
 638 
 639     static void loadSystemColors(int[] systemColors) {
 640         if ("Linux".equals(AccessController.doPrivileged(new GetPropertyAction("os.name")))) { // Load motif default colors on Linux.
 641             loadMotifDefaultColors(systemColors);
 642         }
 643         else
 644         {
 645             try {
 646                 loadSystemColorsForCDE(systemColors);
 647             }
 648             catch (Exception e) // Failure to load CDE colors.
 649             {
 650                 loadMotifDefaultColors(systemColors);
 651             }
 652         }
 653     }
 654 }