author | Markus Bröker <mbroeker@largo.homelinux.org> |
Sun, 10 May 2009 16:04:42 +0200 | |
changeset 7 | 93fe1f21e0d8 |
parent 0 | e0dbaef72362 |
child 13 | f83884cc7d2f |
permissions | -rw-r--r-- |
0
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
1 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
2 |
* $Id: BrowserLaunch.java 125 2008-04-22 08:06:08Z mbroeker $ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
3 |
* $URL: http://localhost/svn/eclipse/Schachspiel/trunk/org/homelinux/largo/utils/BrowserLaunch.java $ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
4 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
5 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
6 |
package org.homelinux.largo.utils; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
7 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
8 |
import java.lang.reflect.Method; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
9 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
10 |
import javax.swing.JOptionPane; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
11 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
12 |
* Cross-Platform Browserlaunch |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
13 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
14 |
public class BrowserLaunch { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
15 |
private static final String errMsg = "Error attempting to launch web browser"; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
16 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
17 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
18 |
* This method opens the URL in a native platform browser |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
19 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
20 |
public void openURL(String url) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
21 |
String osName = System.getProperty("os.name"); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
22 |
try { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
23 |
if (osName.startsWith("Mac OS")) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
24 |
Class<?> fileMgr = Class.forName("com.apple.eio.FileManager"); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
25 |
Method openURL = fileMgr.getDeclaredMethod("openURL", |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
26 |
new Class[] { String.class }); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
27 |
openURL.invoke(null, new Object[] { url }); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
28 |
} else if (osName.startsWith("Windows")) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
29 |
Runtime.getRuntime().exec( |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
30 |
"rundll32 url.dll,FileProtocolHandler " + url); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
31 |
else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
32 |
String[] browsers = { "firefox", "opera", "konqueror", |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
33 |
"epiphany", "mozilla", "netscape" }; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
34 |
String browser = null; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
35 |
for (int count = 0; count < browsers.length && browser == null; count++) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
36 |
if (Runtime.getRuntime().exec( |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
37 |
new String[] { "which", browsers[count] }) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
38 |
.waitFor() == 0) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
39 |
browser = browsers[count]; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
40 |
if (browser == null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
41 |
throw new Exception("Could not find web browser"); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
42 |
else |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
43 |
Runtime.getRuntime().exec(new String[] { browser, url }); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
44 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
45 |
} catch (Exception e) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
46 |
JOptionPane.showMessageDialog(null, errMsg + ":\n" |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
47 |
+ e.getLocalizedMessage()); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
48 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
49 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
50 |
}; |