KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > SystemColors


1 package thinlet.drafts;
2
3 import java.awt.*;
4 import java.awt.image.*;
5 import java.util.*;
6 import thinlet.*;
7
8 /**
9  *
10  */

11 public class SystemColors {
12
13     private static final Color[] colors = { Color.white,
14         Color.lightGray, Color.gray, Color.darkGray, Color.black,
15         Color.red, Color.pink, Color.orange, Color.yellow,
16         Color.green, Color.magenta, Color.cyan, Color.blue };
17     private static final String JavaDoc[] colornames = { "white",
18         "light gray", "gray", "dark gray", "black",
19         "red", "pink", "orange", "yellow",
20         "green", "magenta", "cyan", "blue" };
21     
22     private static final SystemColor[] systemcolors = { SystemColor.desktop,
23         SystemColor.activeCaption, SystemColor.activeCaptionText, SystemColor.activeCaptionBorder,
24         SystemColor.inactiveCaption, SystemColor.inactiveCaptionText, SystemColor.inactiveCaptionBorder,
25         SystemColor.window, SystemColor.windowBorder, SystemColor.windowText,
26         SystemColor.menu, SystemColor.menuText,
27         SystemColor.text, SystemColor.textText,
28         SystemColor.textHighlight, SystemColor.textHighlightText, SystemColor.textInactiveText,
29         SystemColor.control, SystemColor.controlText, SystemColor.controlHighlight,
30         SystemColor.controlLtHighlight, SystemColor.controlShadow, SystemColor.controlDkShadow,
31         SystemColor.scrollbar, SystemColor.info, SystemColor.infoText };
32     private static final String JavaDoc[] systemcolornames = { "desktop",
33         "active caption", "active caption text", "active caption border",
34         "inactive caption", "inactive caption text", "inactive caption border",
35         "window", "window border", "window text",
36         "menu", "menu text",
37         "text", "text text",
38         "text highlight", "text highlight text", "text inactive text",
39         "control", "control text", "control highlight",
40         "control light highlight", "control shadow", "control dark shadow",
41         "scrollbar", "info", "info text" };
42     
43     /**
44      *
45      */

46     public void loadColors(Thinlet thinlet, Object JavaDoc combobox) {
47         for (int i = 0; i < colors.length; i++) {
48             Object JavaDoc choice = Thinlet.create("choice");
49             Image icon = createIcon(thinlet, colors[i]);
50             thinlet.setIcon(choice, "icon", icon);
51             thinlet.setString(choice, "text", colornames[i] + " (0x" +
52                 Integer.toHexString(colors[i].getRGB()).substring(2) + ")");
53             thinlet.add(combobox, choice);
54         }
55     }
56     
57     /**
58      *
59      */

60     public void loadSystemColors(Thinlet thinlet, Object JavaDoc list) {
61         Hashtable iconcache = new Hashtable();
62         for (int i = 0; i < systemcolors.length; i++) {
63             Object JavaDoc item = Thinlet.create("item");
64             Image icon = (Image) iconcache.get(systemcolors[i]);
65             if (icon == null) {
66                 icon = createIcon(thinlet, systemcolors[i]);
67                 iconcache.put(systemcolors[i], icon);
68             }
69             thinlet.setIcon(item, "icon", icon);
70             thinlet.setString(item, "text", systemcolornames[i] + " (0x" +
71                 Integer.toHexString(0xff000000 | systemcolors[i].getRGB()).substring(2) + ")");
72             thinlet.add(list, item);
73         }
74     }
75     
76     /**
77      *
78      */

79     private static Image createIcon(Component component, Color color) {
80         int rgb = color.getRGB();
81         int[] pix = new int[12 * 12];
82         for (int x = 0; x < 12; x++) {
83             for (int y = 0; y < 12; y++) {
84                 pix[x + y * 12] = ((x > 0) && (x < 11) &&
85                     (y > 0) && (y < 11)) ? rgb : 0xff666666;
86             }
87         }
88         return component.createImage(
89             new MemoryImageSource(12, 12, pix, 0, 12));
90     }
91 }
Popular Tags