1 package thinlet.drafts; 2 3 import java.applet.*; 4 import java.awt.*; 5 import java.util.*; 6 import thinlet.*; 7 8 11 public class SystemProperties { 12 13 private static final String [] KEYS = { "java.version", "java.vendor", 14 "java.vendor.url", "java.home", "java.vm.specification.version", 15 "java.vm.specification.vendor", "java.vm.specification.name", 16 "java.vm.version", "java.vm.vendor", "java.vm.name", "java.specification.version", 17 "java.specification.vendor", "java.specification.name", "java.class.version", 18 "java.class.path", "java.library.path", "java.io.tmpdir", "java.compiler", 19 "java.ext.dirs", "os.name", "os.arch", "os.version", "file.separator", 20 "path.separator", "line.separator", "user.name", "user.home", "user.dir" }; 21 22 25 public void loadProperties(Thinlet thinlet, Object table) { 26 try { 27 Properties properties = System.getProperties(); 28 for (Enumeration keys = properties.propertyNames(); keys.hasMoreElements();) { 29 String key = (String ) keys.nextElement(); 30 addRow(thinlet, table, key, properties.getProperty(key)); 31 } 32 } catch (SecurityException exc) { for (int i = 0; i < KEYS.length; i++) { 34 try { 35 addRow(thinlet, table, KEYS[i], System.getProperty(KEYS[i])); 36 } catch (SecurityException sexc) {} 37 } 38 } 39 } 40 41 44 private void addRow(Thinlet thinlet, Object table, String key, String value) { 45 Object row = Thinlet.create("row"); 46 Object keycell = Thinlet.create("cell"); 47 thinlet.setString(keycell, "text", key); 48 thinlet.add(row, keycell); 49 Object valuecell = Thinlet.create("cell"); 50 thinlet.setString(valuecell, "text", value); 51 thinlet.add(row, valuecell); 52 thinlet.add(table, row); 53 } 54 55 58 public void updateMeter(Thinlet thinlet, Object free, Object total, Object meter) { 59 Runtime runtime = Runtime.getRuntime(); 60 long fm = runtime.freeMemory(); 61 long tm = runtime.totalMemory(); 62 thinlet.setString(free, "text", String.valueOf(fm)); 63 thinlet.setString(total, "text", String.valueOf(tm)); 64 thinlet.setInteger(meter, "value", (int) ((tm - fm) * 100L / tm)); 65 } 66 67 70 public void collectGarbage(Thinlet thinlet, Object free, Object total, Object meter) { 71 Runtime.getRuntime().gc(); 72 updateMeter(thinlet, free, total, meter); 73 } 74 75 78 public void loadApplet(Thinlet thinlet, Object codebase, Object docbase, Object locale) { 79 for (Component comp = thinlet.getParent(); comp != null; comp = comp.getParent()) { 80 if (comp instanceof Applet) { 81 Applet applet = (Applet) comp; 82 thinlet.setString(codebase, "text", applet.getCodeBase().toString()); 83 thinlet.setString(docbase, "text", applet.getDocumentBase().toString()); 84 thinlet.setString(locale, "text", applet.getLocale().toString()); 85 break; 86 } 87 } 88 } 89 } | Popular Tags |