< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/MotifColorUtilities.java

Print this page




  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 
  33 /**
  34   *
  35   *  This class contains code that is need to mimic the
  36   *  Motif Color selection and color defaults code.
  37   *
  38   *  Portions of this code have been ported to java from
  39   *  Motif sources (Color.c) (ColorP.h) etc.
  40   *
  41   *  Author: Bino George
  42   *
  43   */
  44 
  45 class MotifColorUtilities {
  46 
  47 
  48     static final float XmRED_LUMINOSITY=0.30f;
  49     static final float XmGREEN_LUMINOSITY=0.59f;
  50     static final float XmBLUE_LUMINOSITY=0.11f;
  51     static final int XmINTENSITY_FACTOR=75;


 417             {
 418                 throw new FileNotFoundException("Could not open : "+ paletteFilePath);
 419             }
 420         }
 421         BufferedReader bfr = new BufferedReader(new FileReader(pFile));
 422 
 423         int colors[] = new int[8];
 424         int r,g,b;
 425         String temp,color;
 426 
 427         for (int i=0;i<8;i++) {
 428             temp = bfr.readLine();
 429             color = temp.substring(1,temp.length());
 430             r = Integer.valueOf(color.substring(0,4),16).intValue() >> 8;
 431             g = Integer.valueOf(color.substring(4,8),16).intValue() >> 8;
 432             b = Integer.valueOf(color.substring(8,12),16).intValue() >> 8;
 433             colors[i] = 0xff000000 | r<<16 | g<<8 | b;
 434             //  System.out.println("color["+i+"]="+Integer.toHexString(colors[i]) + "r = " +r + "g="+g+"b="+b);
 435         }
 436 





























 437         systemColors[SystemColor.ACTIVE_CAPTION] = colors[0];
 438         systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = colors[0];
 439 
 440         systemColors[SystemColor.INACTIVE_CAPTION] = colors[1];
 441         systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = colors[1];
 442 
 443         systemColors[SystemColor.WINDOW] = colors[1];
 444 
 445         systemColors[SystemColor.WINDOW_BORDER] = colors[1];
 446         systemColors[SystemColor.MENU] = colors[1];
 447 
 448         systemColors[SystemColor.TEXT] = colors[3];
 449 
 450         systemColors[SystemColor.SCROLLBAR] = colors[1];
 451         systemColors[SystemColor.CONTROL] = colors[1];
 452 
 453         int activeFore;
 454         int inactiveFore;
 455         int textFore;
 456 


 476         b = (colors[3] & 0x000000FF);
 477 
 478         textFore = MotifColorUtilities.calculateForegroundFromBackground(r,g,b);
 479 
 480 
 481         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = activeFore;
 482         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = inactiveFore;
 483         systemColors[SystemColor.WINDOW_TEXT] = inactiveFore;
 484         systemColors[SystemColor.MENU_TEXT] = inactiveFore;
 485         systemColors[SystemColor.TEXT_TEXT] = textFore;
 486         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 487         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 488         systemColors[SystemColor.CONTROL_TEXT] = inactiveFore;
 489         Color tmp = new Color(top_shadow);
 490         systemColors[SystemColor.CONTROL_HIGHLIGHT] =  top_shadow;
 491         systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] =  tmp.brighter().getRGB();
 492 
 493         tmp = new Color(bottom_shadow);
 494         systemColors[SystemColor.CONTROL_SHADOW] =  bottom_shadow;
 495         systemColors[SystemColor.CONTROL_DK_SHADOW] = tmp.darker().getRGB();














































































 496 
 497     }
 498 
 499     static void loadMotifDefaultColors(int[] systemColors) {
 500         //fix for 5092883. WINDOW should be light gray and TEXT should be WHITE to look similar to Motif
 501         systemColors[SystemColor.WINDOW] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 502         systemColors[SystemColor.TEXT] = MotifColorUtilities.WHITE;
 503         systemColors[SystemColor.WINDOW_TEXT] = MotifColorUtilities.BLACK;
 504         systemColors[SystemColor.MENU_TEXT] = MotifColorUtilities.BLACK;
 505         systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 506         systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = MotifColorUtilities.BLACK;
 507         systemColors[SystemColor.TEXT_TEXT] = MotifColorUtilities.BLACK;
 508         systemColors[SystemColor.TEXT_HIGHLIGHT] = MotifColorUtilities.BLACK;
 509         systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = MotifColorUtilities.DEFAULT_COLOR;
 510         systemColors[SystemColor.CONTROL_TEXT] = MotifColorUtilities.BLACK;
 511         systemColors[SystemColor.WINDOW_BORDER] = MotifColorUtilities.DEFAULT_COLOR;
 512         systemColors[SystemColor.MENU] = MotifColorUtilities.DEFAULT_COLOR;
 513         systemColors[SystemColor.SCROLLBAR] = MotifColorUtilities.DEFAULT_COLOR;
 514         systemColors[SystemColor.CONTROL] = MotifColorUtilities.MOTIF_WINDOW_COLOR;
 515 




  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;


 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 


 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 


< prev index next >