home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / FSCROLL.EXE / SRC / FunScrollColorSupport.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  8.5 KB  |  214 lines

  1. /*
  2.  * Copyright (c) 1995 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. import java.awt.Color;
  10. import java.util.Hashtable;
  11.  
  12. /**
  13.  * FunScroll Color Support
  14.  *
  15.  * @version 1.1 96/06/23
  16.  * @author  Jan Andersson (janne@torpa.se)
  17.  */
  18. public class FunScrollColorSupport {
  19.    static Hashtable colors;
  20.  
  21.    /**
  22.     * Returns a darker version of color.
  23.     */
  24.    static Color darker(int r, int g, int b, double factor) {
  25.       return new Color(Math.max((int)(r * (1 - factor)), 0),
  26.                Math.max((int)(g * (1 - factor)), 0),
  27.                Math.max((int)(b * (1 - factor)), 0));
  28.    }
  29.  
  30.    /**
  31.     * Returns a darker version of color.
  32.     */
  33.    static Color darker(Color c, double factor) {
  34.       int r, g, b;
  35.       r = c.getRed();
  36.       g = c.getGreen();
  37.       b = c.getBlue();
  38.       return darker(r, g, b, factor);
  39.    }
  40.  
  41.    /**
  42.     * Returns a brighter version of color.
  43.     */
  44.    static Color brighter(int r, int g, int b, double factor) {
  45.       int r2, g2, b2;
  46.       r2 = r + (int)((255 - r) * factor);
  47.       g2 = g + (int)((255 - g) * factor);
  48.       b2 = b + (int)((255 - b) * factor);
  49.       return new Color(r2, g2, b2);
  50.    }
  51.    
  52.    /**
  53.     * Returns a brighter version of color.
  54.     */
  55.    static Color brighter(Color c, double factor) {
  56.       int r, g, b;
  57.       r = c.getRed();
  58.       g = c.getGreen();
  59.       b = c.getBlue();
  60.       return brighter(r, g, b, factor);
  61.    }
  62.  
  63.    /**
  64.     * lookup rgb string representing color name
  65.     */
  66.    public static String lookup(String name) {
  67.       if(colors == null)
  68.      createHashTable();
  69.       String nameLowerCase = name.toLowerCase();
  70.       return (String)colors.get(nameLowerCase);
  71.    }
  72.  
  73.    /**
  74.     * Create hash table
  75.     */
  76.    public static void createHashTable() {
  77.       colors = new Hashtable(650);
  78.       colors.put("aliceblue",         "f0f8ff");
  79.       colors.put("antiquewhite",      "faebd7");
  80.       colors.put("aquamarine",        "7fffd4");
  81.       colors.put("azure",             "f0ffff");
  82.       colors.put("beige",             "f5f5dc");
  83.       colors.put("bisque",            "ffe4c4");
  84.       colors.put("black",             "000000");
  85.       colors.put("blanchedalmond",    "ffebcd");
  86.       colors.put("blue",              "0000ff");
  87.       colors.put("blueviolet",        "8a2be2");
  88.       colors.put("brown",             "a52a2a");
  89.       colors.put("burlywood",         "deb887");
  90.       colors.put("cadetblue",         "5f9ea0");
  91.       colors.put("chartreuse",        "7fff00");
  92.       colors.put("chocolate",         "d2691e");
  93.       colors.put("coral",             "ff7f50");
  94.       colors.put("cornflowerblue",    "6495ed");
  95.       colors.put("cornsilk",          "fff8dc");
  96.       colors.put("cyan",              "00ffff");
  97.       colors.put("darkgoldenrod",     "b8860b");
  98.       colors.put("darkgreen",         "006400");
  99.       colors.put("darkkhaki",         "bdb76b");
  100.       colors.put("darkolivegreen",    "556b2f");
  101.       colors.put("darkorange",        "ff8c00");
  102.       colors.put("darkorchid",        "9932cc");
  103.       colors.put("darksalmon",        "e9967a");
  104.       colors.put("darkseagreen",      "8fbc8f");
  105.       colors.put("darkslateblue",     "483d8b");
  106.       colors.put("darkslategray",     "2f4f4f");
  107.       colors.put("darkslategrey",     "2f4f4f");
  108.       colors.put("darkturquoise",     "00ced1");
  109.       colors.put("darkviolet",        "9400d3");
  110.       colors.put("deeppink",          "ff1493");
  111.       colors.put("deepskyblue",       "00bfff");
  112.       colors.put("dimgray",           "696969");
  113.       colors.put("dimgrey",           "696969");
  114.       colors.put("dodgerblue",        "1e90ff");
  115.       colors.put("firebrick",         "b22222");
  116.       colors.put("floralwhite",       "fffaf0");
  117.       colors.put("forestgreen",       "228b22");
  118.       colors.put("green",             "00ff00");
  119.       colors.put("gainsboro",         "dcdcdc");
  120.       colors.put("ghostwhite",        "f8f8ff");
  121.       colors.put("gold",              "ffd700");
  122.       colors.put("goldenrod",         "daa520");
  123.       colors.put("gray",              "bebebe");
  124.       colors.put("honeydew",          "f0fff0");
  125.       colors.put("hotpink",           "ff69b4");
  126.       colors.put("indianred",         "cd5c5c");
  127.       colors.put("ivory",             "fffff0");
  128.       colors.put("khaki",             "f0e68c");
  129.       colors.put("lavender",          "e6e6fa");
  130.       colors.put("lavenderblush",     "fff0f5");
  131.       colors.put("lawngreen",         "7cfc00");
  132.       colors.put("lemonchiffon",      "fffacd");
  133.       colors.put("lightblue",         "add8e6");
  134.       colors.put("lightcoral",        "f08080");
  135.       colors.put("lightcyan",         "e0ffff");
  136.       colors.put("lightgoldenrod",    "eedd82");
  137.       colors.put("lightgoldenrodyellow","fafad2");
  138.       colors.put("lightgray",         "d3d3d3");
  139.       colors.put("lightgrey",         "d3d3d3");
  140.       colors.put("lightpink",         "ffb6c1");
  141.       colors.put("lightsalmon",       "ffa07a");
  142.       colors.put("lightseagreen",     "20b2aa");
  143.       colors.put("lightskyblue",      "87cefa");
  144.       colors.put("lightslateblue",    "8470ff");
  145.       colors.put("lightslategray",    "778899");
  146.       colors.put("lightslategrey",    "778899");
  147.       colors.put("lightsteelblue",    "b0c4de");
  148.       colors.put("lightyellow",       "ffffe0");
  149.       colors.put("limegreen",         "32cd32");
  150.       colors.put("linen",             "faf0e6");
  151.       colors.put("magenta",           "ff00ff");
  152.       colors.put("maroon",            "b03060");
  153.       colors.put("mediumaquamarine",  "66cdaa");
  154.       colors.put("mediumblue",        "0000cd");
  155.       colors.put("mediumorchid",      "ba55d3");
  156.       colors.put("mediumpurple",      "9370db");
  157.       colors.put("mediumseagreen",    "3cb371");
  158.       colors.put("mediumslateblue",   "7b68ee");
  159.       colors.put("mediumspringgreen", "00fa9a");
  160.       colors.put("mediumturquoise",   "48d1cc");
  161.       colors.put("mediumvioletred",   "c71585");
  162.       colors.put("midnightblue",      "191970");
  163.       colors.put("mintcream",         "f5fffa");
  164.       colors.put("mistyrose",         "ffe4e1");
  165.       colors.put("moccasin",          "ffe4b5");
  166.       colors.put("navajowhite",       "ffdead");
  167.       colors.put("navy",              "000080");
  168.       colors.put("navyblue",          "000080");
  169.       colors.put("oldlace",           "fdf5e6");
  170.       colors.put("olivedrab",         "6b8e23");
  171.       colors.put("orange",            "ffa500");
  172.       colors.put("orangered",         "ff4500");
  173.       colors.put("orchid",            "da70d6");
  174.       colors.put("palegoldenrod",     "eee8aa");
  175.       colors.put("palegreen",         "98fb98");
  176.       colors.put("paleturquoise",     "afeeee");
  177.       colors.put("palevioletred",     "db7093");
  178.       colors.put("papayawhip",        "ffefd5");
  179.       colors.put("peachpuff",         "ffdab9");
  180.       colors.put("peru",              "cd853f");
  181.       colors.put("pink",              "ffc0cb");
  182.       colors.put("plum",              "dda0dd");
  183.       colors.put("powderblue",        "b0e0e6");
  184.       colors.put("purple",            "a020f0");
  185.       colors.put("red",               "ff0000");
  186.       colors.put("rosybrown",         "bc8f8f");
  187.       colors.put("royalblue",         "4169e1");
  188.       colors.put("saddlebrown",       "8b4513");
  189.       colors.put("salmon",            "fa8072");
  190.       colors.put("sandybrown",        "f4a460");
  191.       colors.put("seagreen",          "2e8b57");
  192.       colors.put("seashell",          "fff5ee");
  193.       colors.put("sienna",            "a0522d");
  194.       colors.put("skyblue",           "87ceeb");
  195.       colors.put("slateblue",         "6a5acd");
  196.       colors.put("slategray",         "708090");
  197.       colors.put("slategrey",         "708090");
  198.       colors.put("snow",              "fffafa");
  199.       colors.put("springgreen",       "00ff7f");
  200.       colors.put("steelblue",         "4682b4");
  201.       colors.put("tan",               "d2b48c");
  202.       colors.put("thistle",           "d8bfd8");
  203.       colors.put("tomato",            "ff6347");
  204.       colors.put("turquoise",         "40e0d0");
  205.       colors.put("violet",            "ee82ee");
  206.       colors.put("violetred",         "d02090");
  207.       colors.put("wheat",             "f5deb3");
  208.       colors.put("white",             "ffffff");
  209.       colors.put("whitesmoke",        "f5f5f5");
  210.       colors.put("yellow",            "ffff00");
  211.       colors.put("yellowgreen",       "9acd32");
  212.    }
  213. }
  214.