home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / hotjava / classsrc / awt / color~1.jav < prev    next >
Encoding:
Text File  |  1995-08-11  |  3.3 KB  |  128 lines

  1. /*
  2.  * @(#)Color.java    1.12 95/05/12 Sami Shaio
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package awt;
  20.  
  21. import java.io.*;
  22. import java.lang.*;
  23.  
  24. /**
  25.  * A class to encapsulate RGB Colors.
  26.  *
  27.  * @version 1.12 12 May 1995
  28.  * @author Sami Shaio
  29.  */
  30. public class Color {
  31.     private int pData;
  32.  
  33.     public int r;
  34.     public int g;
  35.     public int b;
  36.  
  37.     public static Color white;
  38.     public static Color lightGray;
  39.     public static Color gray;
  40.     public static Color darkGray;
  41.     public static Color black;
  42.     
  43.     public static Color red;
  44.     public static Color pink;
  45.     public static Color orange;
  46.     public static Color yellow;
  47.     public static Color green;
  48.     public static Color magenta;
  49.     public static Color blue;
  50.     public static Color cyan;
  51.  
  52.     public static Color menuFore;
  53.     public static Color menuBack;
  54.     public static Color menuHighlight;
  55.     public static Color menuBright;
  56.     public static Color menuDim;
  57.  
  58.     public static Color editableText;
  59.     public static Color readOnlyText;
  60.  
  61.     
  62.     /**
  63.      * Creates a color with the given RGB values. The actual color
  64.      * will depend on the server ws finding the best match given the
  65.      * color space available.
  66.      */
  67.     public Color(WServer ws, int R, int G, int B) {
  68.     r = R;
  69.     g = G;
  70.     b = B;
  71.     pData = 0;
  72.     if (ws != null) {
  73.         ws.colorCreate(this);
  74.     }
  75.     }
  76.  
  77.     public Color(int R, int G, int B) {
  78.     this(null, R, G, B);
  79.     }
  80.     
  81.     static void initColors(WServer ws) {
  82.     white        = new Color(ws, 255, 255, 255);
  83.     lightGray     = new Color(ws, 192, 192, 192);
  84.     gray         = new Color(ws, 128, 128, 128);
  85.     darkGray     = new Color(ws, 64, 64, 64);
  86.     black         = new Color(ws, 0, 0, 0);
  87.     
  88.     red         = new Color(ws, 255, 0, 0);
  89.     pink         = new Color(ws, 255, 175, 175);
  90.     orange         = new Color(ws, 255, 200, 0);
  91.     yellow         = new Color(ws, 255, 255, 0);
  92.     green         = new Color(ws, 0, 255, 0);
  93.     magenta     = new Color(ws, 255, 0, 255);
  94.     cyan        = new Color(ws, 0, 255, 255);
  95.     blue         = new Color(ws, 0, 0, 255);
  96.  
  97.     menuFore = Color.black;
  98.     menuBack = new Color(ws, 204, 204, 204);
  99.     menuHighlight = new Color(ws, 183, 183, 183);
  100.     menuBright = new Color(ws, 255, 255, 255);
  101.     menuDim = new Color(ws, 102, 102, 102);
  102.  
  103.     editableText = new Color(ws, 245, 245, 245);
  104.     readOnlyText = new Color(ws, 192, 192, 192);
  105.     }
  106.  
  107.     /**
  108.      * Compare against another color
  109.      */
  110.     public boolean equal(Color col) {
  111.     return (r == col.r) && (g == col.g) && (b == col.b);
  112.     }
  113.  
  114.     /**
  115.      * Convert to a String
  116.      */
  117.     public String toString() {
  118.     return "rgb(" + r + "," + g + "," + b + ")";
  119.     }
  120.  
  121.     /**
  122.      * Print
  123.      */
  124.     public void print() {
  125.     System.out.println(toString());
  126.     }
  127. }
  128.