1 package thinlet.drafts; 2 3 import java.awt.*; 4 import java.awt.image.*; 5 import java.util.*; 6 import thinlet.*; 7 8 11 public class DesktopProperties { 12 13 16 public void loadProperties(Thinlet thinlet, 17 Object colortable, Object geometrytable, Object fonttable, Object audiolist) { 18 String [] keys = (String []) 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 value = Utilities.getUtilities().getDesktopProperty(keys[i]); 23 if (value instanceof Color) { 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 ) { addRow(thinlet, geometrytable, keys[i], null, value.toString()); 43 } 44 else if (value instanceof Font) { Font font = (Font) value; 46 StringBuffer text = new StringBuffer (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 ) { addRow(thinlet, geometrytable, keys[i], null, value.toString()); 54 } 55 else if (value instanceof Runnable ) { Object item = Thinlet.create("item"); 57 thinlet.setString(item, "text", keys[i]); 58 thinlet.putProperty(item, "runnable", value); 59 thinlet.add(audiolist, item); 60 } 61 } 64 } 65 } 66 67 70 private void addRow(Thinlet thinlet, Object table, String key, Image icon, String value) { 71 Object row = Thinlet.create("row"); 72 Object keycell = Thinlet.create("cell"); 73 thinlet.setString(keycell, "text", key); 74 thinlet.add(row, keycell); 75 Object 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 85 public void rowSelected(Thinlet thinlet, Object audiolist, Object playbutton) { 86 thinlet.setBoolean(playbutton, "enabled", thinlet.getSelectedIndex(audiolist) != -1); 87 } 88 89 92 public void play(Thinlet thinlet, Object audiolist) { 93 Object item = thinlet.getSelectedItem(audiolist); 94 Runnable runnable = (Runnable ) thinlet.getProperty(item, "runnable"); 95 runnable.run(); 96 } 97 } | Popular Tags |