Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
JavaProperties.java
1 package ij.plugin;
2 import ij.*;
3 import ij.text.*;
4 import java.awt.*;
5 import java.util.*;
6 import java.applet.Applet;
7 
9 public class JavaProperties implements PlugIn {
10 
11  StringBuffer sb = new StringBuffer();
12 
13  public void run(String arg) {
14  sb.append("\n");
15  sb.append("Java properties applets can read:\n");
16  show("java.version");
17  show("java.vendor");
18  if (IJ.isMacintosh()) show("mrj.version");
19  show("os.name");
20  show("os.version");
21  show("os.arch");
22  show("file.separator");
23  show("path.separator");
24 
25  String s = System.getProperty("line.separator");
26  char ch1, ch2;
27  String str1, str2="";
28  ch1 = s.charAt(0);
29  if (ch1=='\r')
30  str1 = "<cr>";
31  else
32  str1 = "<lf>";
33  if (s.length()==2) {
34  ch2 = s.charAt(1);
35  if (ch2=='\r')
36  str2 = "<cr>";
37  else
38  str2 = "<lf>";
39  }
40  sb.append(" line.separator: " + str1 + str2+"\n");
41 
42  Applet applet = IJ.getApplet();
43  if (applet!=null) {
44  sb.append("\n");
45  sb.append(" code base: "+applet.getCodeBase()+"\n");
46  sb.append(" document base: "+applet.getDocumentBase()+"\n");
47  sb.append(" sample images dir: "+Prefs.getImagesURL()+"\n");
48  TextWindow tw = new TextWindow("Properties", new String(sb), 400, 400);
49  return;
50  }
51  sb.append("\n");
52  sb.append("Java properties only applications can read:\n");
53  show("user.name");
54  show("user.home");
55  show("user.dir");
56  show("user.country");
57  show("file.encoding");
58  show("java.home");
59  show("java.compiler");
60  show("java.class.path");
61  show("java.ext.dirs");
62  show("java.io.tmpdir");
63 
64  sb.append("\n");
65  sb.append("Other properties:\n");
66  String userDir = System.getProperty("user.dir");
67  String userHome = System.getProperty("user.home");
68  String osName = System.getProperty("os.name");
69  String prefsDir = osName.indexOf("Windows",0)>-1?userDir:userHome;
70  if (IJ.isMacOSX()) prefsDir = prefsDir + "/Library/Preferences";
71  sb.append(" version: "+IJ.getInstance().VERSION+"\n");
72  sb.append(" java 2: "+IJ.isJava2()+"\n");
73  sb.append(" java 1.4: "+IJ.isJava14()+"\n");
74  sb.append(" prefs dir: "+prefsDir+"\n");
75  sb.append(" plugins dir: "+Menus.getPlugInsPath()+"\n");
76  sb.append(" sample images dir: "+Prefs.getImagesURL()+"\n");
77  Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
78  sb.append(" screen size: " + d.width + "x" + d.height+"\n");
79  sb.append(" memory in use: "+IJ.freeMemory()+"\n");
80  if (IJ.altKeyDown())
81  doFullDump();
82  TextWindow tw = new TextWindow("Properties", new String(sb), 300, 400);
83  }
84 
85  void show(String property) {
86  String p = System.getProperty(property);
87  if (p!=null)
88  sb.append(" " + property + ": " + p+"\n");
89  }
90 
91  void doFullDump() {
92  sb.append("\n");
93  sb.append("All Properties:\n");
94  Properties props = System.getProperties();
95  for (Enumeration en=props.keys(); en.hasMoreElements();) {
96  String key = (String)en.nextElement();
97  sb.append(" "+key+": "+(String)props.get(key)+"\n");
98  }
99  }
100 
101 }