Source Code Cross Referenced for SystemInfo.java in  » Swing-Library » jide-common » com » jidesoft » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jide common » com.jidesoft.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)SystemInfo.java
003:         *
004:         * Copyright 2002 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.utils;
007:
008:        import java.util.Locale;
009:
010:        /**
011:         * A utility class can detect OS system information.
012:         */
013:        final public class SystemInfo {
014:
015:            /**
016:             * Variable for whether or not we're on Windows.
017:             */
018:            private static boolean _isWindows = false;
019:
020:            /**
021:             * Variable for whether or not we're on Windows NT or 2000.
022:             */
023:            private static boolean _isWindowsNTor2000 = false;
024:
025:            /**
026:             * Variable for whether or not we're on Windows XP.
027:             */
028:            private static boolean _isWindowsXP = false;
029:
030:            /**
031:             * Variable for whether or not we're on Windows 2003.
032:             */
033:            private static boolean _isWindows2003 = false;
034:
035:            /**
036:             * Flag which indicates that the Win98/Win2k/WinME features
037:             * should be disabled.
038:             */
039:            private static boolean _isClassicWindows = false;
040:
041:            /**
042:             * Variable for whether or not we're on Windows 95.
043:             */
044:            private static boolean _isWindows95 = false;
045:
046:            /**
047:             * Variable for whether or not we're on Windows 98.
048:             */
049:            private static boolean _isWindows98 = false;
050:
051:            /**
052:             * Variable for whether or not the operating system allows the
053:             * application to be reduced to the system tray.
054:             */
055:            private static boolean _supportsTray = false;
056:
057:            /**
058:             * Variable for whether or not we're on Mac 9.1 or below.
059:             */
060:            private static boolean _isMacClassic = false;
061:
062:            /**
063:             * Variable for whether or not we're on MacOSX.
064:             */
065:            private static boolean _isMacOSX = false;
066:
067:            /**
068:             * Variable for whether or not we're on Linux.
069:             */
070:            private static boolean _isLinux = false;
071:
072:            /**
073:             * Variable for whether or not we're on Solaris.
074:             */
075:            private static boolean _isSolaris = false;
076:
077:            /**
078:             * Make sure the constructor can never be called.
079:             */
080:            private SystemInfo() {
081:            }
082:
083:            /**
084:             * Initialize the settings statically.
085:             */
086:            static {
087:                // get the operating system
088:                String os = SecurityUtils.getProperty("os.name", "Windows XP");
089:
090:                // set the operating system variables
091:                _isWindows = os.indexOf("Windows") != -1;
092:                try {
093:                    String osVersion = SecurityUtils.getProperty("os.version",
094:                            "5.0");
095:                    Float version = Float.valueOf(osVersion);
096:                    _isClassicWindows = version <= 4.0;
097:                } catch (NumberFormatException ex) {
098:                    _isClassicWindows = false;
099:                }
100:                if (os.indexOf("Windows XP") != -1
101:                        || os.indexOf("Windows NT") != -1
102:                        || os.indexOf("Windows 2000") != -1) {
103:                    _isWindowsNTor2000 = true;
104:                }
105:                if (os.indexOf("Windows XP") != -1) {
106:                    _isWindowsXP = true;
107:                }
108:                if (os.indexOf("Windows 2003") != -1) {
109:                    _isWindows2003 = true;
110:                    _isWindowsXP = true;
111:                }
112:                if (os.indexOf("Windows 95") != -1) {
113:                    _isWindows95 = true;
114:                }
115:                if (os.indexOf("Windows 98") != -1) {
116:                    _isWindows98 = true;
117:                }
118:                if (_isWindows)
119:                    _supportsTray = true;
120:                _isSolaris = (os.indexOf("Solaris") != -1)
121:                        || (os.indexOf("SunOS") != -1);
122:                _isLinux = os.indexOf("Linux") != -1;
123:                if (os.startsWith("Mac OS")) {
124:                    if (os.endsWith("X")) {
125:                        _isMacOSX = true;
126:                    } else {
127:                        _isMacClassic = true;
128:                    }
129:                }
130:            }
131:
132:            /**
133:             * Returns the version of java we're using.
134:             *
135:             * @return the java verison.
136:             */
137:            public static String getJavaVersion() {
138:                return SecurityUtils.getProperty("java.version", "1.4.2");
139:            }
140:
141:            /**
142:             * Returns the vendor for java we're using.
143:             *
144:             * @return the java vendor.
145:             */
146:            public static String getJavaVendor() {
147:                return SecurityUtils.getProperty("java.vendor", "");
148:            }
149:
150:            /**
151:             * Returns the verion of the java classwe're using.
152:             *
153:             * @return the java class verison.
154:             */
155:            public static String getJavaClassVerion() {
156:                return SecurityUtils.getProperty("java.class.version", "");
157:            }
158:
159:            /**
160:             * Returns the operating system.
161:             *
162:             * @return the os name.
163:             */
164:            public static String getOS() {
165:                return SecurityUtils.getProperty("os.name", "Windows XP");
166:            }
167:
168:            /**
169:             * Returns the operating system version.
170:             *
171:             * @return the os version.
172:             */
173:            public static String getOSVersion() {
174:                return SecurityUtils.getProperty("os.version", "");
175:            }
176:
177:            /**
178:             * Returns the operating system architecture.
179:             *
180:             * @return the os architecture.
181:             */
182:            public static String getOSArchitecture() {
183:                return SecurityUtils.getProperty("os.arch", "");
184:            }
185:
186:            /**
187:             * Returns the user's home directory.
188:             *
189:             * @return the user home .
190:             */
191:            public static String getCurrentDirectory() {
192:                return SecurityUtils.getProperty("user.dir", "");
193:            }
194:
195:            /**
196:             * Returns true if this is Windows NT or Windows 2000 and
197:             * hence can support a system tray feature.
198:             *
199:             * @return true of system tray is supported.
200:             */
201:            public static boolean supportsTray() {
202:                return _supportsTray;
203:            }
204:
205:            /**
206:             * Set supportTray to false in case dll is missing.
207:             *
208:             * @param support true or false.
209:             */
210:            public static void setSupportsTray(boolean support) {
211:                _supportsTray = support;
212:            }
213:
214:            /**
215:             * Returns whether or not the os is some version of Windows.
216:             *
217:             * @return <tt>true</tt> if the application is running on some Windows
218:             *         version, <tt>false</tt> otherwise.
219:             */
220:            public static boolean isWindows() {
221:                return _isWindows;
222:            }
223:
224:            /**
225:             * Gets the state of the flag which indicates if the old Windows
226:             * look and feel should be rendered. This flag is used by the
227:             * component UI delegates as a hint to determine which style the component
228:             * should be rendered.
229:             *
230:             * @return true if Windows 95 and Windows NT 4 look and feel should
231:             *         be rendered.
232:             */
233:            public static boolean isClassicWindows() {
234:                return _isClassicWindows;
235:            }
236:
237:            /**
238:             * Returns whether or not the os is some version of Windows NT.
239:             *
240:             * @return <tt>true</tt> if the application is running on Windows NT
241:             *         or 2000, <tt>false</tt> otherwise.
242:             */
243:            public static boolean isWindowsNTor2000() {
244:                return _isWindowsNTor2000;
245:            }
246:
247:            /**
248:             * Returns whether or not the os is some version of Windows XP.
249:             *
250:             * @return <tt>true</tt> if the application is running on Windows XP,
251:             *         <tt>false</tt> otherwise.
252:             */
253:            public static boolean isWindowsXP() {
254:                return _isWindowsXP;
255:            }
256:
257:            /**
258:             * Returns whether or not the os is some version of Windows 95.
259:             *
260:             * @return <tt>true</tt> if the application is running on Windows XP,
261:             *         <tt>false</tt> otherwise.
262:             */
263:            public static boolean isWindows95() {
264:                return _isWindows95;
265:            }
266:
267:            /**
268:             * Returns whether or not the os is some version of Windows 98.
269:             *
270:             * @return <tt>true</tt> if the application is running on Windows XP,
271:             *         <tt>false</tt> otherwise.
272:             */
273:            public static boolean isWindows98() {
274:                return _isWindows98;
275:            }
276:
277:            /**
278:             * Returns whether or not the os is some version of Windows 2003.
279:             *
280:             * @return <tt>true</tt> if the application is running on Windows 2003,
281:             *         <tt>false</tt> otherwise.
282:             */
283:            public static boolean isWindows2003() {
284:                return _isWindows2003;
285:            }
286:
287:            /**
288:             * Returns whether or not the os is Mac 9.1 or earlier.
289:             *
290:             * @return <tt>true</tt> if the application is running on a Mac version
291:             *         prior to OSX, <tt>false</tt> otherwise.
292:             */
293:            public static boolean isMacClassic() {
294:                return _isMacClassic;
295:            }
296:
297:            /**
298:             * Returns whether or not the os is Mac OSX.
299:             *
300:             * @return <tt>true</tt> if the application is running on Mac OSX,
301:             *         <tt>false</tt> otherwise.
302:             */
303:            public static boolean isMacOSX() {
304:                return _isMacOSX;
305:            }
306:
307:            /**
308:             * Returns whether or not the os is any Mac os.
309:             *
310:             * @return <tt>true</tt> if the application is running on Mac OSX
311:             *         or any previous mac version, <tt>false</tt> otherwise.
312:             */
313:            public static boolean isAnyMac() {
314:                return _isMacClassic || _isMacOSX;
315:            }
316:
317:            /**
318:             * Returns whether or not the os is Solaris.
319:             *
320:             * @return <tt>true</tt> if the application is running on Solaris,
321:             *         <tt>false</tt> otherwise.
322:             */
323:            public static boolean isSolaris() {
324:                return _isSolaris;
325:            }
326:
327:            /**
328:             * Returns whether or not the os is Linux.
329:             *
330:             * @return <tt>true</tt> if the application is running on Linux,
331:             *         <tt>false</tt> otherwise.
332:             */
333:            public static boolean isLinux() {
334:                return _isLinux;
335:            }
336:
337:            /**
338:             * Returns whether or not the os is some version of
339:             * Unix, defined here as only Solaris or Linux.
340:             *
341:             * @return <tt>true</tt> if the application is running on a type of UNIX such as Linux or Solaris,
342:             *         <tt>false</tt> otherwise.
343:             */
344:            public static boolean isUnix() {
345:                return _isLinux || _isSolaris;
346:            }
347:
348:            /**
349:             * Returns whether or no the JDK version is 1.3 and above.
350:             *
351:             * @return <tt>true</tt> if the application is running on JDK 1.3 and above,
352:             *         <tt>false</tt> otherwise.
353:             */
354:            public static boolean isJdk13Above() {
355:                String s = getJavaVersion();
356:                String sub = s.substring(0, 3);
357:                try {
358:                    double version = Double.parseDouble(sub);
359:                    return version >= 1.3;
360:                } catch (NumberFormatException e) {
361:                    // ignore
362:                }
363:                return false;
364:            }
365:
366:            /**
367:             * Returns whether or no the JDK version is 1.4.2 and above.
368:             *
369:             * @return <tt>true</tt> if the application is running on JDK 1.4.2 and above,
370:             *         <tt>false</tt> otherwise.
371:             */
372:            public static boolean isJdk142Above() {
373:                String s = getJavaVersion();
374:                String sub = s.substring(0, 5);
375:
376:                return sub.compareTo("1.4.2") >= 0;
377:
378:            }
379:
380:            /**
381:             * Returns whether or no the JDK version is 1.4 and above.
382:             *
383:             * @return <tt>true</tt> if the application is running on JDK 1.4 and above,
384:             *         <tt>false</tt> otherwise.
385:             */
386:            public static boolean isJdk14Above() {
387:                String s = getJavaVersion();
388:                String sub = s.substring(0, 3);
389:                try {
390:                    double version = Double.parseDouble(sub);
391:                    return version >= 1.4;
392:                } catch (NumberFormatException e) {
393:                    // ignore
394:                }
395:                return false;
396:            }
397:
398:            /**
399:             * Returns whether or no the JDK version is 1.5 and above.
400:             *
401:             * @return <tt>true</tt> if the application is running on JDK 1.5 and above,
402:             *         <tt>false</tt> otherwise.
403:             */
404:            public static boolean isJdk15Above() {
405:                String s = getJavaVersion();
406:                String sub = s.substring(0, 3);
407:                try {
408:                    double version = Double.parseDouble(sub);
409:                    return version >= 1.5;
410:                } catch (NumberFormatException e) {
411:                    // ignore
412:                }
413:                return false;
414:            }
415:
416:            /**
417:             * Returns whether or no the JDK version is 6 and above.
418:             *
419:             * @return <tt>true</tt> if the application is running on JDK 6 and above,
420:             *         <tt>false</tt> otherwise.
421:             * @deprecated use {@link #isJdk6Above()}. Nothing is wrong with this method. It's just
422:             *             Sun starts to call JDK1.6 as JDK6 now.
423:             */
424:            public static boolean isJdk16Above() {
425:                return isJdk6Above();
426:            }
427:
428:            /**
429:             * Returns whether or no the JDK version is 6 and above.
430:             *
431:             * @return <tt>true</tt> if the application is running on JDK 6 and above,
432:             *         <tt>false</tt> otherwise.
433:             */
434:            public static boolean isJdk6Above() {
435:                String s = getJavaVersion();
436:                String sub = s.substring(0, 3);
437:                try {
438:                    double version = Double.parseDouble(sub);
439:                    return version >= 1.6;
440:                } catch (NumberFormatException e) {
441:                    // ignore
442:                }
443:                return false;
444:            }
445:
446:            /**
447:             * Returns whether or no the JDK version is 1.7 and above.
448:             *
449:             * @return <tt>true</tt> if the application is running on JDK 1.7 and above,
450:             *         <tt>false</tt> otherwise.
451:             */
452:            public static boolean isJdk7Above() {
453:                String s = getJavaVersion();
454:                String sub = s.substring(0, 3);
455:                try {
456:                    double version = Double.parseDouble(sub);
457:                    return version >= 1.7;
458:                } catch (NumberFormatException e) {
459:                    // ignore
460:                }
461:                return false;
462:            }
463:
464:            /**
465:             * Returns whether the default locale is one of the three language - Chinese, Japanese or Korean - also known as CJK.
466:             *
467:             * @return true if the default locale is in CJK.
468:             */
469:            public static boolean isCJKLocale() {
470:                return isCJKLocale(Locale.getDefault());
471:            }
472:
473:            /**
474:             * Returns whether the locale is one of the three language - Chinese, Japanese or Korean - also known as CJK.
475:             *
476:             * @param locale the locale to be checked.
477:             * @return true if the default locale is in CJK.
478:             */
479:            public static boolean isCJKLocale(Locale locale) {
480:                return locale.equals(Locale.CHINA)
481:                        || locale.equals(Locale.CHINESE)
482:                        || locale.equals(new Locale("zh", "HK"))
483:                        || locale.equals(Locale.TAIWAN)
484:                        || locale.equals(Locale.JAPAN)
485:                        || locale.equals(Locale.JAPANESE)
486:                        || locale.equals(Locale.KOREA)
487:                        || locale.equals(Locale.KOREAN);
488:            }
489:
490:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.