jdk/src/solaris/classes/sun/awt/X11/MotifColorUtilities.java
author asaha
Wed, 21 Oct 2009 11:28:46 -0700
changeset 4214 0fa32d38146b
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  *  This class contains code that is need to mimic the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  *  Motif Color selection and color defaults code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  *  Portions of this code have been ported to java from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  *  Motif sources (Color.c) (ColorP.h) etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  *  Author: Bino George
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class MotifColorUtilities {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final float XmRED_LUMINOSITY=0.30f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final float XmGREEN_LUMINOSITY=0.59f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final float XmBLUE_LUMINOSITY=0.11f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final int XmINTENSITY_FACTOR=75;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final int XmLIGHT_FACTOR=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int XmLUMINOSITY_FACTOR=25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static final int XmMAX_SHORT=65535;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static final int XmCOLOR_PERCENTILE=(XmMAX_SHORT / 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final int XmDEFAULT_DARK_THRESHOLD=20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final int XmDEFAULT_LIGHT_THRESHOLD=93;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final int XmDEFAULT_FOREGROUND_THRESHOLD=70;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static final int BLACK = 0xFF000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static final int WHITE = 0xFFFFFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static final int MOTIF_WINDOW_COLOR= 0xFFDFDFDF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static final int DEFAULT_COLOR =  0xFFC4C4C4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static final int  XmCOLOR_LITE_THRESHOLD = XmDEFAULT_LIGHT_THRESHOLD * XmCOLOR_PERCENTILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static final int  XmCOLOR_DARK_THRESHOLD = XmDEFAULT_DARK_THRESHOLD * XmCOLOR_PERCENTILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static final int  XmFOREGROUND_THRESHOLD = XmDEFAULT_FOREGROUND_THRESHOLD * XmCOLOR_PERCENTILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* LITE color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
       percent to interpolate RGB towards black for SEL, BS, TS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static final int XmCOLOR_LITE_SEL_FACTOR = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static final int XmCOLOR_LITE_BS_FACTOR =  40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static final int XmCOLOR_LITE_TS_FACTOR =  20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /* DARK color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
       percent to interpolate RGB towards white for SEL, BS, TS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static final int XmCOLOR_DARK_SEL_FACTOR=  15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static final int XmCOLOR_DARK_BS_FACTOR =  30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static final int XmCOLOR_DARK_TS_FACTOR =  50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /* STD color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
       percent to interpolate RGB towards black for SEL, BS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
       percent to interpolate RGB towards white for TS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
       HI values used for high brightness (within STD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
       LO values used for low brightness (within STD)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
       Interpolate factors between HI & LO values based on brightness */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static final int XmCOLOR_HI_SEL_FACTOR = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    static final int XmCOLOR_HI_BS_FACTOR =  40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    static final int XmCOLOR_HI_TS_FACTOR =  60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static final int XmCOLOR_LO_SEL_FACTOR=  15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static final int XmCOLOR_LO_BS_FACTOR =  60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static final int XmCOLOR_LO_TS_FACTOR =  50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static int brightness( int red, int green, int blue )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        float brightness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        float intensity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        float light;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        float luminosity, maxprimary, minprimary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // To mimix Motif logic, we need to convert to 16 bit color values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        red = red << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        green = green << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        blue = blue << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        intensity = (red + green + blue) / 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * The casting nonsense below is to try to control the point at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * the truncation occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        luminosity = (int) ((XmRED_LUMINOSITY * (float) red)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                + (XmGREEN_LUMINOSITY * (float) green)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                + (XmBLUE_LUMINOSITY * (float) blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        maxprimary = ( (red > green) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                ( (red > blue) ? red : blue ) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                ( (green > blue) ? green : blue ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        minprimary = ( (red < green) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                ( (red < blue) ? red : blue ) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                ( (green < blue) ? green : blue ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        light = (minprimary + maxprimary) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        brightness = ( (intensity * XmINTENSITY_FACTOR) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                (light * XmLIGHT_FACTOR) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                (luminosity * XmLUMINOSITY_FACTOR) ) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return Math.round(brightness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static int calculateForegroundFromBackground(int r, int g, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        int foreground = WHITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        int  brightness = brightness(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (brightness >  XmFOREGROUND_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            foreground = BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        else foreground = WHITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static int calculateTopShadowFromBackground(int r, int g, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        float color_value,f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int br = r << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int bg = g << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int bb = b << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int brightness = brightness(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        float red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        float green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        float blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (brightness < XmCOLOR_DARK_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // dark background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            color_value += XmCOLOR_DARK_TS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            color_value += XmCOLOR_DARK_TS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            color_value += XmCOLOR_DARK_TS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else if (brightness > XmCOLOR_LITE_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // lite background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            color_value -= (color_value * XmCOLOR_LITE_TS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // medium
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            f = XmCOLOR_LO_TS_FACTOR + (brightness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    * ( XmCOLOR_HI_TS_FACTOR - XmCOLOR_LO_TS_FACTOR )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    / XmMAX_SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            color_value += f * ( XmMAX_SHORT - color_value ) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            color_value += f * ( XmMAX_SHORT - color_value ) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            color_value += f * ( XmMAX_SHORT - color_value ) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int ired = ((int)red) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int igreen = ((int)green) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int iblue = ((int)blue) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    static int calculateBottomShadowFromBackground(int r, int g, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        float color_value,f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        int br = r << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int bg = g << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int bb = b << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int brightness = brightness(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        float red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        float green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        float blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (brightness < XmCOLOR_DARK_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            // dark background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            color_value += XmCOLOR_DARK_BS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            color_value += XmCOLOR_DARK_BS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            color_value += XmCOLOR_DARK_BS_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        else if (brightness > XmCOLOR_LITE_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // lite background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            color_value -= (color_value * XmCOLOR_LITE_BS_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            // medium
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            f = XmCOLOR_LO_BS_FACTOR + (brightness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    * ( XmCOLOR_HI_BS_FACTOR - XmCOLOR_LO_BS_FACTOR )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    / XmMAX_SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        int ired = ((int)red) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        int igreen = ((int)green) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int iblue = ((int)blue) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    static int calculateSelectFromBackground(int r, int g, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        float color_value,f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int br = r << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int bg = g << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int bb = b << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int brightness = brightness(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        float red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        float green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        float blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (brightness < XmCOLOR_DARK_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            // dark background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            color_value += XmCOLOR_DARK_SEL_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            color_value += XmCOLOR_DARK_SEL_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            color_value += XmCOLOR_DARK_SEL_FACTOR *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                (XmMAX_SHORT - color_value) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        else if (brightness > XmCOLOR_LITE_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            // lite background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            color_value -= (color_value * XmCOLOR_LITE_SEL_FACTOR) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // medium
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            f = XmCOLOR_LO_SEL_FACTOR + (brightness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    * ( XmCOLOR_HI_SEL_FACTOR - XmCOLOR_LO_SEL_FACTOR )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    / XmMAX_SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            color_value = br;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            red = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            color_value = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            green = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            color_value = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            color_value -= (color_value * f) / 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            blue = color_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        int ired = ((int)red) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        int igreen = ((int)green) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        int iblue = ((int)blue) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int ret = 0xff000000 | ired <<16 | igreen<<8 | iblue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
   static void loadSystemColorsForCDE(int[] systemColors) throws Exception  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        // System.out.println("loadSystemColorsForCDE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        XAtom resourceManager = XAtom.get("RESOURCE_MANAGER");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        String resourceString = resourceManager.getProperty(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        int index = resourceString.indexOf("ColorPalette:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        int len = resourceString.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        while ( (index < len) && (resourceString.charAt(index) != ':')) index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        index++; // skip :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (resourceString.charAt(index) == '\t') index++; // skip \t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        String paletteFile = resourceString.substring(index,resourceString.indexOf("\n",index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        //System.out.println("Palette File = " + paletteFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // Check if palette is a user palette.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String  paletteFilePath = System.getProperty("user.home") + "/.dt/palettes/" + paletteFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        File pFile = new File(paletteFilePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (!pFile.exists())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            // Must be a system palette
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            paletteFilePath = "/usr/dt/palettes/" + paletteFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            pFile = new File(paletteFilePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (!pFile.exists())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                throw new FileNotFoundException("Could not open : "+ paletteFilePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        BufferedReader bfr = new BufferedReader(new FileReader(pFile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        int colors[] = new int[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int r,g,b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        String temp,color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for (int i=0;i<8;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            temp = bfr.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            color = temp.substring(1,temp.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            r = Integer.valueOf(color.substring(0,4),16).intValue() >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            g = Integer.valueOf(color.substring(4,8),16).intValue() >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            b = Integer.valueOf(color.substring(8,12),16).intValue() >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            colors[i] = 0xff000000 | r<<16 | g<<8 | b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            //  System.out.println("color["+i+"]="+Integer.toHexString(colors[i]) + "r = " +r + "g="+g+"b="+b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        systemColors[SystemColor.WINDOW] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        systemColors[SystemColor.WINDOW_BORDER] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        systemColors[SystemColor.MENU] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        systemColors[SystemColor.TEXT] = colors[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        systemColors[SystemColor.SCROLLBAR] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        systemColors[SystemColor.CONTROL] = colors[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        int activeFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        int inactiveFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        int textFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        r = (colors[0] & 0x00FF0000) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        g = (colors[0] & 0x0000FF00) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        b = (colors[0] & 0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        activeFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        r = (colors[1] & 0x00FF0000) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        g = (colors[1] & 0x0000FF00) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        b = (colors[1] & 0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        inactiveFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        r = (colors[3] & 0x00FF0000) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        g = (colors[3] & 0x0000FF00) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        b = (colors[3] & 0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        systemColors[SystemColor.WINDOW_TEXT] = inactiveFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        systemColors[SystemColor.MENU_TEXT] = inactiveFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        systemColors[SystemColor.TEXT_TEXT] = textFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        systemColors[SystemColor.CONTROL_TEXT] = inactiveFore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        Color tmp = new Color(top_shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        tmp = new Color(bottom_shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    static void loadMotifDefaultColors(int[] systemColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        //fix for 5092883. WINDOW should be light gray and TEXT should be WHITE to look similar to Motif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        systemColors[SystemColor.WINDOW] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        systemColors[SystemColor.TEXT] = MotifColorUtilities.WHITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        systemColors[SystemColor.WINDOW_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        systemColors[SystemColor.MENU_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        systemColors[SystemColor.TEXT_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        systemColors[SystemColor.CONTROL_TEXT] = MotifColorUtilities.BLACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.DEFAULT_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        systemColors[SystemColor.MENU] = MotifColorUtilities.DEFAULT_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        systemColors[SystemColor.SCROLLBAR] = MotifColorUtilities.DEFAULT_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        systemColors[SystemColor.CONTROL] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int r = (MotifColorUtilities.DEFAULT_COLOR & 0x00FF0000) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        int g = (MotifColorUtilities.DEFAULT_COLOR & 0x0000FF00) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int b = (MotifColorUtilities.DEFAULT_COLOR & 0x000000FF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        int top_shadow = MotifColorUtilities.calculateTopShadowFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        int bottom_shadow = MotifColorUtilities.calculateBottomShadowFromBackground(r,g,b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Color tmp = new Color(top_shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        tmp = new Color(bottom_shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    static void loadSystemColors(int[] systemColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if ("Linux".equals(AccessController.doPrivileged(new GetPropertyAction("os.name")))) { // Load motif default colors on Linux.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            loadMotifDefaultColors(systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                loadSystemColorsForCDE(systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            catch (Exception e) // Failure to load CDE colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                loadMotifDefaultColors(systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
}