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

Last change on this file since 2748 was 2748, checked in by Gubaer, 14 years ago

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.net.MalformedURLException;
8import java.net.URL;
9
10import javax.swing.JApplet;
11
12import 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 */
21public 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.