KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > DesktopProperties


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 DesktopProperties {
12     
13     /**
14      *
15      */

16     public void loadProperties(Thinlet thinlet,
17             Object JavaDoc colortable, Object JavaDoc geometrytable, Object JavaDoc fonttable, Object JavaDoc audiolist) {
18         String JavaDoc[] keys = (String JavaDoc[]) Utilities.getUtilities().getDesktopProperty("win.propNames");
19         if (keys != null) {
20             Hashtable iconcache = new Hashtable();
21             for (int i = 0; i < keys.length; i++) {
22                 Object JavaDoc value = Utilities.getUtilities().getDesktopProperty(keys[i]);
23                 if (value instanceof Color) { // Color Properties
24
Image icon = (Image) iconcache.get(value);
25                     int rgb = ((Color) value).getRGB();
26                     if (icon == null) {
27                         int[] pix = new int[12 * 12];
28                         for (int x = 0; x < 12; x++) {
29                             for (int y = 0; y < 12; y++) {
30                                 pix[x + y * 12] = ((x > 0) && (x < 11) &&
31                                     (y > 0) && (y < 11)) ? rgb : 0xff666666;
32                             }
33                         }
34                         icon = thinlet.createImage(
35                             new MemoryImageSource(12, 12, pix, 0, 12));
36                         iconcache.put(value, icon);
37                     }
38                     addRow(thinlet, colortable, keys[i],
39                         icon, "0x" + Integer.toHexString(rgb).substring(2));
40                 }
41                 else if (value instanceof Integer JavaDoc) { // Geometry or Input Properties
42
addRow(thinlet, geometrytable, keys[i], null, value.toString());
43                 }
44                 else if (value instanceof Font) { // Font Properties
45
Font font = (Font) value;
46                     StringBuffer JavaDoc text = new StringBuffer JavaDoc(font.getName());
47                     if (font.isBold()) { text.append(" bold"); }
48                     if (font.isItalic()) { text.append(" italic"); }
49                     text.append(' '); text.append(font.getSize());
50                     addRow(thinlet, fonttable, keys[i], null, text.toString());
51                 }
52                 else if (value instanceof Boolean JavaDoc) { // Visual Effect Properties
53
addRow(thinlet, geometrytable, keys[i], null, value.toString());
54                 }
55                 else if (value instanceof Runnable JavaDoc) { // Audio-feedback Properties
56
Object JavaDoc item = Thinlet.create("item");
57                     thinlet.setString(item, "text", keys[i]);
58                     thinlet.putProperty(item, "runnable", value);
59                     thinlet.add(audiolist, item);
60                 }
61 // else System.out.println(keys[i] + ": " + value +
62
// " (" + value.getClass().getName() + ")");
63
}
64         }
65     }
66     
67     /**
68      *
69      */

70     private void addRow(Thinlet thinlet, Object JavaDoc table, String JavaDoc key, Image icon, String JavaDoc value) {
71         Object JavaDoc row = Thinlet.create("row");
72         Object JavaDoc keycell = Thinlet.create("cell");
73         thinlet.setString(keycell, "text", key);
74         thinlet.add(row, keycell);
75         Object JavaDoc valuecell = Thinlet.create("cell");
76         if (icon != null) { thinlet.setIcon(valuecell, "icon", icon); }
77         thinlet.setString(valuecell, "text", value);
78         thinlet.add(row, valuecell);
79         thinlet.add(table, row);
80     }
81     
82     /**
83      *
84      */

85     public void rowSelected(Thinlet thinlet, Object JavaDoc audiolist, Object JavaDoc playbutton) {
86         thinlet.setBoolean(playbutton, "enabled", thinlet.getSelectedIndex(audiolist) != -1);
87     }
88     
89     /**
90      *
91      */

92     public void play(Thinlet thinlet, Object JavaDoc audiolist) {
93         Object JavaDoc item = thinlet.getSelectedItem(audiolist);
94         Runnable JavaDoc runnable = (Runnable JavaDoc) thinlet.getProperty(item, "runnable");
95         runnable.run();
96     }
97 }
Popular Tags