< 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 (FontUtilities.isAIX) {
 440             numOfColor = 8;
 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 


 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 


< prev index next >