001: package thinlet.drafts;
002:
003: import java.awt.*;
004: import java.awt.image.*;
005: import java.util.*;
006: import thinlet.*;
007:
008: /**
009: *
010: */
011: public class SystemColors {
012:
013: private static final Color[] colors = { Color.white,
014: Color.lightGray, Color.gray, Color.darkGray, Color.black,
015: Color.red, Color.pink, Color.orange, Color.yellow,
016: Color.green, Color.magenta, Color.cyan, Color.blue };
017: private static final String[] colornames = { "white", "light gray",
018: "gray", "dark gray", "black", "red", "pink", "orange",
019: "yellow", "green", "magenta", "cyan", "blue" };
020:
021: private static final SystemColor[] systemcolors = {
022: SystemColor.desktop, SystemColor.activeCaption,
023: SystemColor.activeCaptionText,
024: SystemColor.activeCaptionBorder,
025: SystemColor.inactiveCaption,
026: SystemColor.inactiveCaptionText,
027: SystemColor.inactiveCaptionBorder, SystemColor.window,
028: SystemColor.windowBorder, SystemColor.windowText,
029: SystemColor.menu, SystemColor.menuText, SystemColor.text,
030: SystemColor.textText, SystemColor.textHighlight,
031: SystemColor.textHighlightText,
032: SystemColor.textInactiveText, SystemColor.control,
033: SystemColor.controlText, SystemColor.controlHighlight,
034: SystemColor.controlLtHighlight, SystemColor.controlShadow,
035: SystemColor.controlDkShadow, SystemColor.scrollbar,
036: SystemColor.info, SystemColor.infoText };
037: private static final String[] systemcolornames = { "desktop",
038: "active caption", "active caption text",
039: "active caption border", "inactive caption",
040: "inactive caption text", "inactive caption border",
041: "window", "window border", "window text", "menu",
042: "menu text", "text", "text text", "text highlight",
043: "text highlight text", "text inactive text", "control",
044: "control text", "control highlight",
045: "control light highlight", "control shadow",
046: "control dark shadow", "scrollbar", "info", "info text" };
047:
048: /**
049: *
050: */
051: public void loadColors(Thinlet thinlet, Object combobox) {
052: for (int i = 0; i < colors.length; i++) {
053: Object choice = thinlet.create("choice");
054: Image icon = createIcon(thinlet, colors[i]);
055: thinlet.setIcon(choice, "icon", icon);
056: thinlet.setString(choice, "text", colornames[i]
057: + " (0x"
058: + Integer.toHexString(colors[i].getRGB())
059: .substring(2) + ")");
060: thinlet.add(combobox, choice);
061: }
062: }
063:
064: /**
065: *
066: */
067: public void loadSystemColors(Thinlet thinlet, Object list) {
068: Hashtable iconcache = new Hashtable();
069: for (int i = 0; i < systemcolors.length; i++) {
070: Object item = thinlet.create("item");
071: Image icon = (Image) iconcache.get(systemcolors[i]);
072: if (icon == null) {
073: icon = createIcon(thinlet, systemcolors[i]);
074: iconcache.put(systemcolors[i], icon);
075: }
076: thinlet.setIcon(item, "icon", icon);
077: thinlet.setString(item, "text", systemcolornames[i]
078: + " (0x"
079: + Integer.toHexString(
080: 0xff000000 | systemcolors[i].getRGB())
081: .substring(2) + ")");
082: thinlet.add(list, item);
083: }
084: }
085:
086: /**
087: *
088: */
089: private static Image createIcon(Component component, Color color) {
090: int rgb = color.getRGB();
091: int[] pix = new int[12 * 12];
092: for (int x = 0; x < 12; x++) {
093: for (int y = 0; y < 12; y++) {
094: pix[x + y * 12] = ((x > 0) && (x < 11) && (y > 0) && (y < 11)) ? rgb
095: : 0xff666666;
096: }
097: }
098: return component.createImage(new MemoryImageSource(12, 12, pix,
099: 0, 12));
100: }
101: }
|