1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.bric.multislider;
21
22 import java.security.AccessControlException;
23
24
25
26
27
28
29
30 public class Jvm
31 {
32
33
34
35
36
37 public static void printProfile()
38 {
39 System.out.println(getProfile());
40 }
41
42
43
44
45
46
47 public static String getProfile()
48 {
49 StringBuffer sb = new StringBuffer();
50 sb.append("OS = " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + "), "
51 + System.getProperty("os.arch") + "\n");
52 sb.append("Java Version = " + System.getProperty("java.version") + "\n");
53 return sb.toString();
54 }
55
56
57
58
59 public static final float javaVersion = Jvm.getMajorJavaVersion(true);
60
61 private static final String osName = getOSName();
62
63 private static String getOSName()
64 {
65 try
66 {
67 String s = (System.getProperty("os.name").toLowerCase());
68 return s;
69 }
70 catch (AccessControlException e)
71 {
72 e.printStackTrace();
73 return "unknown";
74 }
75 }
76
77
78 public static final boolean isMac = (osName.indexOf("mac") != -1);
79
80
81 public static final boolean isLinux = (osName.indexOf("linux") != -1);
82
83
84 public static final boolean isWindows = (osName.indexOf("windows") != -1);
85
86
87 public static final boolean isVista = (osName.indexOf("vista") != -1);
88
89
90 public static final boolean isWindows7 = isWindows && (osName.indexOf("7") != -1);
91
92
93 public static final boolean isWindowsXP = isWindows && (osName.indexOf("xp") != -1);
94
95
96 public static final boolean isVistaOrWindows7 = isVista || isWindows7;
97
98
99
100
101
102 public static final boolean usingQuartz = isUsingQuartz();
103
104 private static boolean isUsingQuartz()
105 {
106 try
107 {
108 return isMac
109 && ((javaVersion > 0 && javaVersion < 1.4f) || (System.getProperty("apple.awt.graphics.UseQuartz") != null
110 && System.getProperty("apple.awt.graphics.UseQuartz").toString().equals("true")));
111 }
112 catch (AccessControlException e)
113 {
114 e.printStackTrace();
115 return false;
116 }
117 }
118
119
120
121
122
123
124
125
126
127
128 public static float getMajorJavaVersion() throws AccessControlException
129 {
130 String majorVersion = null;
131 try
132 {
133 System.getProperty("java.major.version");
134 }
135 catch (java.security.AccessControlException e)
136 {
137 return -1;
138 }
139 if (majorVersion == null)
140 {
141 String s = System.getProperty("java.version");
142 float f = -1;
143 int i = s.length();
144 while (f < 0 && i > 0)
145 {
146 try
147 {
148 f = Float.parseFloat(s.substring(0, i));
149 }
150 catch (Exception e)
151 {
152 }
153 i--;
154 }
155 majorVersion = Float.toString(f);
156 System.setProperty("java.major.version", majorVersion);
157 }
158 return Float.parseFloat(majorVersion);
159 }
160
161
162
163
164
165 public static float getMajorJavaVersion(boolean catchSecurityException)
166 {
167 try
168 {
169 return getMajorJavaVersion();
170 }
171 catch (RuntimeException t)
172 {
173 if (catchSecurityException)
174 {
175 System.err.println(
176 "this exception was ignored without incident, but it means we can't determine the major java version:");
177 t.printStackTrace();
178 return -1;
179 }
180 throw t;
181 }
182 }
183 }