source: josm/src/org/openstreetmap/josm/tools/OpenBrowser.java@ 149

Last change on this file since 149 was 149, checked in by imi, 18 years ago
  • added dynamic loading of plugins
  • removed mappaint (now seperate plugin)
  • fixed UrlLabel for Linux and Mac (untested)
File size: 1.3 KB
Line 
1package org.openstreetmap.josm.tools;
2
3import java.io.IOException;
4
5/**
6 * Helper to open platform web browser on different platforms
7 * @author Imi
8 */
9public class OpenBrowser {
10
11 /**
12 * @return <code>null</code> for success or a string in case of an error.
13 */
14 public static String displayUrl(String url) {
15 String os = System.getProperty("os.name");
16 if (os == null)
17 return "unknown operating system";
18 try {
19 if (os != null && os.startsWith("Windows"))
20 windows(url);
21 else if (os.equals("Linux") || os.equals("Solaris") || os.equals("SunOS") || os.equals("AIX") || os.equals("FreeBSD"))
22 linux(url);
23 else if (os.equals("Mac OS") || os.equals("Mac OS X"))
24 mac(url);
25 else
26 return "unknown operating system";
27 } catch (IOException e) {
28 return e.getMessage();
29 }
30 return null;
31 }
32
33 private static void windows(String url) throws IOException {
34 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
35 }
36
37 private static void linux(String url) throws IOException {
38 try {
39 Runtime.getRuntime().exec("gnome-open " + url);
40 } catch (IOException e) {
41 Runtime.getRuntime().exec("kfmclient openURL " + url);
42 }
43 }
44
45 private static void mac(String url) throws IOException {
46 Runtime.getRuntime().exec("open " + url);
47 }
48}
Note: See TracBrowser for help on using the repository browser.