View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
29  
30      //--- Data field(s) ---
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      // --- Initializer ---
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  				//logger.warn("could not load ziga.dll", e);
70  			}
71  		}
72      }
73  
74      //--- Constructor(s) ---
75  
76      //--- Method(s) ---
77  
78      /***
79       * This method should be invoked at an early stage.
80       */
81      public static void init()
82      {
83  		// dummy method, see static block above
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 }