From ffb81b30278acc20fdaffa1ceb1cc5df699d8f74 Mon Sep 17 00:00:00 2001 From: tcarver <tjc> Date: Tue, 5 Feb 2013 10:16:23 +0000 Subject: [PATCH] fix for Java 7 on Mac OSX --- .../sanger/artemis/editor/BrowserControl.java | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/uk/ac/sanger/artemis/editor/BrowserControl.java b/uk/ac/sanger/artemis/editor/BrowserControl.java index 9bf8f6596..54ccde9a5 100644 --- a/uk/ac/sanger/artemis/editor/BrowserControl.java +++ b/uk/ac/sanger/artemis/editor/BrowserControl.java @@ -40,22 +40,16 @@ import java.io.IOException; public class BrowserControl { - // The default system browser under windows. private static final String WIN_PATH = "rundll32"; // The flag to display a url. private static final String WIN_FLAG = "url.dll,FileProtocolHandler"; - // The default browser under unix. - private static final String UNIX_PATH = "netscape"; - // The flag to display a url. private static final String UNIX_FLAG = "-remote openURL"; - private static final String MAC_PATH = "/usr/bin/open"; /** * Display a file in the system browser. If you want to display a * file, you must include the absolute path name. - * * @param url the file's url (the url must start with either "http://" * or "file://"). */ @@ -77,7 +71,6 @@ public class BrowserControl } else { - String[] browsers = { "x-www-browser", "mozilla", "firefox", "opera", "konqueror", @@ -88,19 +81,26 @@ public class BrowserControl { ExternalApplication exApp = new ExternalApplication( new String[] {"which", browsers[count]}, null, null); - - //String stderr = exApp.getProcessStderr(); String stdout = exApp.getProcessStdout(); if(stdout != null && stdout.startsWith("/")) browser = browsers[count]; } if(browser == null) - System.err.println("Could not find web browser"); + { + try + { + java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); + } + catch(Exception e) + { + System.err.println("Could not find web browser"); + } + } else { if(browser.equals("netscape") || browser.equals("mozilla")) - handleNetscapeAndMozilla(url, browser); + handleNetscapeAndMozilla(url, browser); else Runtime.getRuntime().exec(new String[] {browser, url}); } @@ -114,35 +114,33 @@ public class BrowserControl } } - private static void handleNetscapeAndMozilla(final String url, final String browser) throws IOException { - String cmd = browser + " " + UNIX_FLAG + "(" + url + ")"; - Process p = Runtime.getRuntime().exec(cmd); - try - { - // wait for exit code -- if it's 0, command worked, - // otherwise we need to start the browser up. - int exitCode = p.waitFor(); + String cmd = browser + " " + UNIX_FLAG + "(" + url + ")"; + Process p = Runtime.getRuntime().exec(cmd); + try + { + // wait for exit code -- if it's 0, command worked, + // otherwise we need to start the browser up. + int exitCode = p.waitFor(); if (exitCode != 0) { - // Command failed, start up the browser - cmd = browser + " " + url; - p = Runtime.getRuntime().exec(cmd); - } - } - catch (InterruptedException x) - { - System.err.println("Error bringing up browser, cmd='" + cmd + "'"); - System.err.println("Caught: " + x); + // Command failed, start up the browser + cmd = browser + " " + url; + p = Runtime.getRuntime().exec(cmd); } + } + catch (InterruptedException x) + { + System.err.println("Error bringing up browser, cmd='" + cmd + "'"); + System.err.println("Caught: " + x); + } } /** * Try to determine whether this application is running under Windows * or some other platform by examing the "os.name" property. - * * @return true if this application is running under a Windows OS */ public static boolean isWindowsPlatform() @@ -156,7 +154,8 @@ public class BrowserControl private static boolean isMac() { - return System.getProperty("mrj.version") != null; + return System.getProperty("mrj.version") != null || + System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0; } /** -- GitLab