home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / desvs7nu / src / xcolornames.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.6 KB  |  73 lines

  1. /*
  2.  * Copyright (c) 1996 by Jan Andersson, Torpa Konsult AB.
  3.  *
  4.  * Permission to use, copy, and distribute this software for
  5.  * NON-COMMERCIAL purposes and without fee is hereby granted
  6.  * provided that this copyright notice appears in all copies.
  7.  *
  8.  */
  9.  
  10. import java.util.Hashtable;
  11.  
  12. /**
  13.  * Simple class to convert from X11 symbolic color names to RGB
  14.  * value.
  15.  *
  16.  * Note: Not even close to support all X11 color names.
  17.  *
  18.  * @version    1.1 96/02/20
  19.  * @author     Jan Andersson, Torpa Konsult AB. (janne@torpa.se)
  20.  */
  21. public class XColorNames {
  22.    public static final int NOT_FOUND = Integer.MIN_VALUE;
  23.    static Hashtable table;
  24.    static {
  25.       table = new Hashtable(100);
  26.       // Color table, from Anthony Thyssen's Icon Library
  27.       table.put("black", new Integer(0x000000));
  28.       table.put("dark slate gray", new Integer(0x2F4F4F));
  29.       table.put("slate gray", new Integer(0x708090));
  30.       table.put("gray", new Integer(0xBEBEBE));
  31.       table.put("gainsboro", new Integer(0xDCDCDC));
  32.       table.put("white", new Integer(0xFFFFFF));
  33.       table.put("purple", new Integer(0xA020F0));
  34.       table.put("magenta", new Integer(0xFF00FF));
  35.       table.put("violet", new Integer(0xEE82EE));
  36.       table.put("firebrick", new Integer(0xB22222));
  37.       table.put("red", new Integer(0xFF0000));
  38.       table.put("tomato", new Integer(0xFF6347));
  39.       table.put("orange", new Integer(0xFFA500));
  40.       table.put("gold", new Integer(0xFFD700));
  41.       table.put("yellow", new Integer(0xFFFF00));
  42.       table.put("sienna", new Integer(0xA0522D));
  43.       table.put("peru", new Integer(0xCD853F));
  44.       table.put("tan", new Integer(0xD2B4C8));
  45.       table.put("wheat", new Integer(0xF5DeB3));
  46.       table.put("lemon chiffon", new Integer(0xFFFACD));
  47.       table.put("sea green", new Integer(0x2E8B57));
  48.       table.put("lime green", new Integer(0x32CD32));
  49.       table.put("green", new Integer(0x00FF00));
  50.       table.put("pale green", new Integer(0x98FB98));
  51.       table.put("navy", new Integer(0x000080));
  52.       table.put("blue", new Integer(0x0000FF));
  53.       table.put("dodger blue", new Integer(0x1E90FF));
  54.       table.put("sky blue", new Integer(0x87CEEB));
  55.       table.put("lavender", new Integer(0xE6E6FA));
  56.       table.put("tan", new Integer(0xD2B48C));
  57.       table.put("cyan", new Integer(0x00FFFF));
  58.    }
  59.  
  60.    /**
  61.     * Get RGB value for symbolic color name
  62.     * @param colorName name of color to look up.
  63.     * @returns RGB value or null if color unknown
  64.     */
  65.    public static int getRgb(String name) {
  66.       Object tmp = table.get(name);
  67.       if (tmp == null)
  68.      return NOT_FOUND;
  69.       return ((Integer)tmp).intValue();
  70.    }
  71.    
  72. }
  73.