1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.util;
21
22 import java.awt.Toolkit;
23 import javax.swing.*;
24
25 public class SystemHelper
26 {
27
28
29
30
31
32 /***
33 * True, if is system is Apple Mac OS X; false, otherwise.
34 */
35 public static final boolean isMacOSX;
36
37 /***
38 * True, if system is Microsoft Windows; false, otherwise.
39 */
40 public static final boolean isWindowsOS;
41
42 /***
43 * True, if JDK version is smaller than 1.4.
44 */
45 public static final boolean isJDK13orSmaller;
46
47 /***
48 * True, if ziga.dll was loaded; false, otherwise. ziga.dll contains
49 * support for the Windows system tray and native launch support.
50 */
51 public static boolean isZigaDllLoaded;
52
53
54
55 static {
56 String ver = System.getProperty("java.version", "");
57 isJDK13orSmaller = (VersionParser.compare(ver, "1.4.0") < 0);
58
59 String os = System.getProperty("os.name").toLowerCase();
60 isWindowsOS = (os.indexOf("windows") != -1);
61 isMacOSX = (os.indexOf("mac os x") != -1);
62
63 isZigaDllLoaded = false;
64 if (isWindowsOS) {
65 try {
66 System.loadLibrary("ziga");
67 isZigaDllLoaded = true;
68 } catch (UnsatisfiedLinkError e) {
69
70 }
71 }
72 }
73
74
75
76
77
78 /***
79 * This method should be invoked at an early stage.
80 */
81 public static void init()
82 {
83
84 }
85
86 /***
87 * Returns the default launcher for the current operating system.
88 */
89 public static String getNativeLauncherType()
90 {
91 if (isWindowsOS && isZigaDllLoaded) {
92 return "ziga.dll";
93 }
94 else if (isMacOSX) {
95 return "open";
96 }
97
98 return "other";
99 }
100
101 /***
102 * Returns true, if operating system is Mac OS X and a version below
103 * Jaguar (10.2).
104 */
105 public static boolean hasMacOSXModalDialogBug()
106 {
107 if (isMacOSX) {
108 String ver = System.getProperty("os.version", "");
109 return VersionParser.compare(ver, "10.2.0") < 0;
110 }
111
112 return false;
113 }
114
115 /***
116 * Disable tooltips on Mac OS X and JDK 1.3.*.
117 *
118 * @see <a href="http://developer.apple.com/qa/qa2001/qa1153.html">Apple</a>
119 */
120 public static boolean hasMacOSXToolTipsBug()
121 {
122 return (isMacOSX) ? isJDK13orSmaller : false;
123 }
124
125 public static KeyStroke getMenuShortcut(int keyCode)
126 {
127 int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
128 return KeyStroke.getKeyStroke(keyCode, mask);
129 }
130
131 }