Line | |
---|
1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.net.MalformedURLException;
|
---|
8 | import java.net.URL;
|
---|
9 |
|
---|
10 | import javax.swing.JApplet;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Helper to open platform web browser on different platforms
|
---|
16 | *
|
---|
17 | * This now delegates the real work to a platform specific class.
|
---|
18 | *
|
---|
19 | * @author Imi
|
---|
20 | */
|
---|
21 | public class OpenBrowser {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * @return <code>null</code> for success or a string in case of an error.
|
---|
25 | * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched,
|
---|
26 | * {@see Main#platform}
|
---|
27 | */
|
---|
28 | public static String displayUrl(String url) throws IllegalStateException {
|
---|
29 | if (Main.applet) {
|
---|
30 | try {
|
---|
31 | JApplet applet = (JApplet) Main.parent;
|
---|
32 | applet.getAppletContext().showDocument(new URL(url));
|
---|
33 | return null;
|
---|
34 | } catch (MalformedURLException mue) {
|
---|
35 | return mue.getMessage();
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | if (Main.platform == null)
|
---|
40 | throw new IllegalStateException(tr("Failed to open URL. There is currently no platform set. Please set a platform first."));
|
---|
41 | try {
|
---|
42 | Main.platform.openUrl(url);
|
---|
43 | } catch (IOException e) {
|
---|
44 | return e.getMessage();
|
---|
45 | }
|
---|
46 | return null;
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.