home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / SystemColor.java < prev    next >
Text File  |  1997-05-20  |  12KB  |  382 lines

  1. /*
  2.  * @(#)SystemColor.java    1.7 97/02/20
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22. package java.awt;
  23.  
  24. /**
  25.  * A class to encapsulate symbolic colors representing the color
  26.  * of GUI objects on a system.  For systems which support the dynamic
  27.  * update of the system colors (when the user changes the colors)
  28.  * the actual RGB values of these symbolic colors will also change
  29.  * dynamically.  In order to compare the "current" RGB value of a SystemColor
  30.  * object with a non-symbolic Color object, getRGB() should be used
  31.  * rather than equals(). 
  32.  *
  33.  * @version     1.7, 02/20/97
  34.  * @author     Carl Quinn
  35.  * @author      Amy Fowler
  36.  */
  37. public final class SystemColor extends Color implements java.io.Serializable {
  38.  
  39.     /**
  40.      * The array index for the desktop background color.
  41.      */
  42.     public final static int DESKTOP = 0;
  43.  
  44.     /**
  45.      * The array index for the active caption background color.
  46.      */
  47.     public final static int ACTIVE_CAPTION = 1;
  48.  
  49.     /**
  50.      * The array index for the action caption text color.
  51.      */
  52.     public final static int ACTIVE_CAPTION_TEXT = 2;
  53.  
  54.     /**
  55.      * The array index for the active caption border color.
  56.      */
  57.     public final static int ACTIVE_CAPTION_BORDER = 3;
  58.  
  59.     /**
  60.      * The array index for the inactive caption background color.
  61.      */
  62.     public final static int INACTIVE_CAPTION = 4;
  63.  
  64.     /**
  65.      * The array index for the inactive caption text color.
  66.      */
  67.     public final static int INACTIVE_CAPTION_TEXT = 5;
  68.  
  69.     /**
  70.      * The array index for the inactive caption border color.
  71.      */
  72.     public final static int INACTIVE_CAPTION_BORDER = 6;
  73.  
  74.     /**
  75.      * The array index for the window background color.
  76.      */
  77.     public final static int WINDOW = 7;
  78.  
  79.     /**
  80.      * The array index for the window border color.
  81.      */
  82.     public final static int WINDOW_BORDER = 8;
  83.  
  84.     /**
  85.      * The array index for the window text color.
  86.      */
  87.     public final static int WINDOW_TEXT = 9;
  88.  
  89.     /**
  90.      * The array index for the menu background color.
  91.      */
  92.     public final static int MENU = 10;
  93.  
  94.     /**
  95.      * The array index for the menu text color.
  96.      */
  97.     public final static int MENU_TEXT = 11;
  98.  
  99.     /**
  100.      * The array index for the text background color.
  101.      */
  102.     public final static int TEXT = 12;
  103.  
  104.     /**
  105.      * The array index for the text text color.
  106.      */
  107.     public final static int TEXT_TEXT = 13;
  108.  
  109.     /**
  110.      * The array index for the text highlight color.
  111.      */
  112.     public final static int TEXT_HIGHLIGHT = 14;
  113.  
  114.     /**
  115.      * The array index for the text highlight text color.
  116.      */
  117.     public final static int TEXT_HIGHLIGHT_TEXT = 15;
  118.  
  119.     /**
  120.      * The array index for the text inactive text color.
  121.      */
  122.     public final static int TEXT_INACTIVE_TEXT = 16;
  123.  
  124.     /**
  125.      * The array index for the control background color.
  126.      */
  127.     public final static int CONTROL = 17;
  128.  
  129.     /**
  130.      * The array index for the control text color.
  131.      */
  132.     public final static int CONTROL_TEXT = 18;
  133.  
  134.     /**
  135.      * The array index for the control highlight color.
  136.      */
  137.     public final static int CONTROL_HIGHLIGHT = 19;
  138.  
  139.     /**
  140.      * The array index for the control light highlight color.
  141.      */
  142.     public final static int CONTROL_LT_HIGHLIGHT = 20;
  143.  
  144.     /**
  145.      * The array index for the control shadow color.
  146.      */
  147.     public final static int CONTROL_SHADOW = 21;
  148.  
  149.     /**
  150.      * The array index for the control dark shadow color.
  151.      */
  152.     public final static int CONTROL_DK_SHADOW = 22;
  153.  
  154.     /**
  155.      * The array index for the scrollbar background color.
  156.      */
  157.     public final static int SCROLLBAR = 23;
  158.  
  159.     /**
  160.      * The array index for the info background color.
  161.      */
  162.     public final static int INFO = 24;
  163.  
  164.     /**
  165.      * The array index for the info text color.
  166.      */
  167.     public final static int INFO_TEXT = 25;
  168.  
  169.     /**
  170.      * The number of system colors in the array.
  171.      */
  172.     public final static int NUM_COLORS = 26;
  173.     
  174.    /**
  175.      * The color of the desktop background.
  176.      */
  177.     public final static SystemColor desktop = new SystemColor((byte)DESKTOP);
  178.  
  179.     /**
  180.      * The background color for captions in window borders.
  181.      */
  182.     public final static SystemColor activeCaption = new SystemColor((byte)ACTIVE_CAPTION);
  183.  
  184.     /**
  185.      * The text color for captions in window borders.
  186.      */
  187.     public final static SystemColor activeCaptionText = new SystemColor((byte)ACTIVE_CAPTION_TEXT);
  188.  
  189.     /**
  190.      * The border color for captions in window borders.
  191.      */
  192.     public final static SystemColor activeCaptionBorder = new SystemColor((byte)ACTIVE_CAPTION_BORDER);
  193.  
  194.     /**
  195.      * The background color for inactive captions in window borders.
  196.      */
  197.     public final static SystemColor inactiveCaption = new SystemColor((byte)INACTIVE_CAPTION);
  198.  
  199.     /**
  200.      * The text color for inactive captions in window borders.
  201.      */
  202.     public final static SystemColor inactiveCaptionText = new SystemColor((byte)INACTIVE_CAPTION_TEXT);
  203.  
  204.     /**
  205.      * The border color for inactive captios in window borders.
  206.      */
  207.     public final static SystemColor inactiveCaptionBorder = new SystemColor((byte)INACTIVE_CAPTION_BORDER);
  208.  
  209.     /**
  210.      * The background color for windows.
  211.      */
  212.     public final static SystemColor window = new SystemColor((byte)WINDOW);
  213.  
  214.     /**
  215.      * The border color for windows.
  216.      */
  217.     public final static SystemColor windowBorder = new SystemColor((byte)WINDOW_BORDER);
  218.  
  219.     /**
  220.      * The text color for windows.
  221.      */
  222.     public final static SystemColor windowText = new SystemColor((byte)WINDOW_TEXT);
  223.  
  224.     /**
  225.      * The background color for menus.
  226.      */
  227.     public final static SystemColor menu = new SystemColor((byte)MENU);
  228.  
  229.     /**
  230.      * The text color for menus.
  231.      */
  232.     public final static SystemColor menuText = new SystemColor((byte)MENU_TEXT);
  233.  
  234.     /**
  235.      * The background color for text components.
  236.      */
  237.     public final static SystemColor text = new SystemColor((byte)TEXT);
  238.  
  239.     /**
  240.      * The text color for text components.
  241.      */
  242.     public final static SystemColor textText = new SystemColor((byte)TEXT_TEXT);
  243.  
  244.     /**
  245.      * The background color for highlighted text.
  246.      */
  247.     public final static SystemColor textHighlight = new SystemColor((byte)TEXT_HIGHLIGHT);
  248.  
  249.     /**
  250.      * The text color for highlighted text.
  251.      */
  252.     public final static SystemColor textHighlightText = new SystemColor((byte)TEXT_HIGHLIGHT_TEXT);
  253.  
  254.     /**
  255.      * The text color for inactive text.
  256.      */
  257.     public final static SystemColor textInactiveText = new SystemColor((byte)TEXT_INACTIVE_TEXT);
  258.  
  259.     /**
  260.      * The background color for control objects.
  261.      */
  262.     public final static SystemColor control = new SystemColor((byte)CONTROL);
  263.  
  264.     /**
  265.      * The text color for control objects.
  266.      */
  267.     public final static SystemColor controlText = new SystemColor((byte)CONTROL_TEXT);
  268.  
  269.     /**
  270.      * The regular highlight color for control objects.
  271.      */
  272.     public final static SystemColor controlHighlight = new SystemColor((byte)CONTROL_HIGHLIGHT);
  273.  
  274.     /**
  275.      * The light highlight color for control objects.
  276.      */
  277.     public final static SystemColor controlLtHighlight = new SystemColor((byte)CONTROL_LT_HIGHLIGHT);
  278.  
  279.     /**
  280.      * The regular shadow color for control objects.
  281.      */
  282.     public final static SystemColor controlShadow = new SystemColor((byte)CONTROL_SHADOW);
  283.  
  284.     /**
  285.      * The dark shadow color for control objects.
  286.      */
  287.     public final static SystemColor controlDkShadow = new SystemColor((byte)CONTROL_DK_SHADOW);
  288.  
  289.     /**
  290.      * The background color for scrollbars.
  291.      */
  292.     public final static SystemColor scrollbar = new SystemColor((byte)SCROLLBAR);
  293.  
  294.     /**
  295.      * The background color for info(help) text.
  296.      */
  297.     public final static SystemColor info = new SystemColor((byte)INFO);
  298.  
  299.     /**
  300.      * The text color for info(help) text.
  301.      */
  302.     public final static SystemColor infoText = new SystemColor((byte)INFO_TEXT);
  303.  
  304.     /*
  305.      * System colors with default initial values, overwritten by toolkit if 
  306.      * system values differ and are available.
  307.      */
  308.     private static int[] systemColors = {
  309.         0xFF005C5C,  // desktop = new Color(0,92,92);
  310.         0xFF000080,  // activeCaption = new Color(0,0,128);
  311.         0xFFFFFFFF,  // activeCaptionText = Color.white;
  312.         0xFFC0C0C0,  // activeCaptionBorder = Color.lightGray;
  313.         0xFF808080,  // inactiveCaption = Color.gray;
  314.         0xFFC0C0C0,  // inactiveCaptionText = Color.lightGray;
  315.         0xFFC0C0C0,  // inactiveCaptionBorder = Color.lightGray;
  316.         0xFFFFFFFF,  // window = Color.white;
  317.         0xFF000000,  // windowBorder = Color.black;
  318.         0xFF000000,  // windowText = Color.black;
  319.         0xFFC0C0C0,  // menu = Color.lightGray;
  320.         0xFF000000,  // menuText = Color.black;
  321.         0xFFC0C0C0,  // text = Color.lightGray;
  322.         0xFF000000,  // textText = Color.black;
  323.         0xFF000080,  // textHighlight = new Color(0,0,128);
  324.         0xFFFFFFFF,  // textHighlightText = Color.white;
  325.         0xFF808080,  // textInactiveText = Color.gray;
  326.         0xFFC0C0C0,  // control = Color.lightGray;
  327.         0xFF000000,  // controlText = Color.black;
  328.         0xFFFFFFFF,  // controlHighlight = Color.white;
  329.         0xFFE0E0E0,  // controlLtHighlight = new Color(224,224,224);
  330.         0xFF808080,  // controlShadow = Color.gray;
  331.         0xFF000000,  // controlDkShadow = Color.black;
  332.         0xFFE0E0E0,  // scrollbar = new Color(224,224,224);
  333.         0xFFE0E000,  // info = new Color(224,224,0);
  334.         0xFF000000,  // infoText = Color.black;
  335.     };
  336.  
  337.     /*
  338.      * JDK 1.1 serialVersionUID 
  339.      */
  340.     private static final long serialVersionUID = 4503142729533789064L;
  341.  
  342.     static {
  343.       updateSystemColors();
  344.     }
  345.  
  346.     /**
  347.      * called from <init> & toolkit to update the above systemColors cache
  348.      */
  349.     private static void updateSystemColors() {
  350.       Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
  351.     }
  352.  
  353.     /**
  354.      * Create a symbolic color that represents an indexed entry into system
  355.      * color cache. Used by above static system colors.
  356.      */
  357.     private SystemColor(byte index) {
  358.         super(0, 0, 0);
  359.     value = index;
  360.     }
  361.  
  362.     /**
  363.      * Gets the "current" RGB value representing the symbolic color.
  364.      * (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).
  365.      * @see java.awt.image.ColorModel#getRGBdefault
  366.      * @see java.awt.Color#getBlue(int)
  367.      * @see java.awt.Color#getGreen(int)
  368.      * @see java.awt.Color#getRed(int)
  369.      */
  370.     public int getRGB() {
  371.     return systemColors[value];
  372.     }
  373.  
  374.     /**
  375.      * Returns the String representation of this Color's values.
  376.      */
  377.     public String toString() {
  378.         return getClass().getName() + "[i=" + (value) + "]";
  379.     }
  380.  
  381. }
  382.