KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > SystemProperties


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

11 public class SystemProperties {
12     
13     private static final String JavaDoc[] 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     /**
23      *
24      */

25     public void loadProperties(Thinlet thinlet, Object JavaDoc table) {
26         try {
27             Properties properties = System.getProperties();
28             for (Enumeration keys = properties.propertyNames(); keys.hasMoreElements();) {
29                 String JavaDoc key = (String JavaDoc) keys.nextElement();
30                 addRow(thinlet, table, key, properties.getProperty(key));
31             }
32         } catch (SecurityException JavaDoc exc) { // inside applet
33
for (int i = 0; i < KEYS.length; i++) {
34                 try {
35                     addRow(thinlet, table, KEYS[i], System.getProperty(KEYS[i]));
36                 } catch (SecurityException JavaDoc sexc) {}
37             }
38         }
39     }
40     
41     /**
42      *
43      */

44     private void addRow(Thinlet thinlet, Object JavaDoc table, String JavaDoc key, String JavaDoc value) {
45         Object JavaDoc row = Thinlet.create("row");
46         Object JavaDoc keycell = Thinlet.create("cell");
47         thinlet.setString(keycell, "text", key);
48         thinlet.add(row, keycell);
49         Object JavaDoc valuecell = Thinlet.create("cell");
50         thinlet.setString(valuecell, "text", value);
51         thinlet.add(row, valuecell);
52         thinlet.add(table, row);
53     }
54     
55     /**
56      *
57      */

58     public void updateMeter(Thinlet thinlet, Object JavaDoc free, Object JavaDoc total, Object JavaDoc meter) {
59         Runtime JavaDoc 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     /**
68      *
69      */

70     public void collectGarbage(Thinlet thinlet, Object JavaDoc free, Object JavaDoc total, Object JavaDoc meter) {
71         Runtime.getRuntime().gc();
72         updateMeter(thinlet, free, total, meter);
73     }
74     
75     /**
76      *
77      */

78     public void loadApplet(Thinlet thinlet, Object JavaDoc codebase, Object JavaDoc docbase, Object JavaDoc 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