X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FBrowserLauncher.java;h=f9fa80d11e70ad4c4454b2afe51d53116c44ab4f;hb=a9177efb4097815d9a8031aa22700c61a7d6260a;hp=304fc591e6054f1d30d570b27f6eda8d2361f444;hpb=892a62261b740199fbc664c012107ae4392b7521;p=jalview.git
diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java
index 304fc59..f9fa80d 100644
--- a/src/jalview/util/BrowserLauncher.java
+++ b/src/jalview/util/BrowserLauncher.java
@@ -1,17 +1,52 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.util;
+import java.awt.Desktop;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
-import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
-import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
import jalview.bin.Cache;
import jalview.bin.Console;
public class BrowserLauncher
{
+ private static BrowserLauncher INSTANCE = null;
+
private static String preferredBrowser = null;
- public static void openURL(String url) throws IOException
+ public static BrowserLauncher getInstance()
+ {
+ if (INSTANCE != null)
+ {
+ return INSTANCE;
+ }
+ INSTANCE = new BrowserLauncher();
+ return INSTANCE;
+ }
+
+ public static void openURL(String url)
{
if (Platform.isJS())
{
@@ -25,38 +60,61 @@ public class BrowserLauncher
* @j2sIgnore
*/
{
- edu.stanford.ejalbert.BrowserLauncher bl = null;
- try
- {
- bl = new edu.stanford.ejalbert.BrowserLauncher();
- } catch (BrowserLaunchingInitializingException e)
+ Desktop d = Desktop.getDesktop();
+ if (d != null && d.isSupported(Desktop.Action.BROWSE))
{
- Console.warn(MessageManager.formatMessage(
- "exception.browser_unable_to_launch", e.getMessage()));
- } catch (UnsupportedOperatingSystemException e)
- {
- Console.warn(MessageManager.formatMessage("exception."));
- Console.debug(e.getMessage());
- }
- if (bl != null)
- {
- if (Platform.isMac() || preferredBrowser == null)
+ try
{
- bl.openURLinBrowser(url);
- }
- else
+ d.browse(new URI(url));
+ } catch (IOException e)
{
- System.err.println(
- "**** OPENURL (" + preferredBrowser + ", " + url + ")");
- bl.openURLinBrowser(preferredBrowser, url);
+ Console.warn(MessageManager.formatMessage(
+ "exception.browser_unable_to_launch", url));
+ Console.warn(e.getMessage());
+ Console.debug(Cache.getStackTraceString(e));
+ } catch (URISyntaxException e1)
+ {
+ Console.warn(MessageManager.formatMessage(
+ "exception.browser_unable_to_launch", url));
+ Console.warn(e1.getMessage());
+ Console.debug(Cache.getStackTraceString(e1));
}
}
+ else
+ {
+ Console.warn(MessageManager
+ .formatMessage("exception.browser_os_not_supported", url));
+ }
}
}
public static void resetBrowser()
{
+ resetBrowser(false);
+ }
+
+ public static void resetBrowser(boolean removeIfNull)
+ {
String defaultBrowser = Cache.getProperty("DEFAULT_BROWSER");
preferredBrowser = defaultBrowser;
+ // System.setProperty(getBrowserSystemProperty(),
+ // Cache.getProperty("DEFAULT_BROWSER"));
+ if (defaultBrowser == null && removeIfNull)
+ {
+ // System.clearProperty(getBrowserSystemProperty());
+ }
+
}
+
+ public static List getBrowserList()
+ {
+ return new ArrayList();
+ }
+
+ public static String getBrowserSystemProperty()
+ {
+ // return IBrowserLaunching.BROWSER_SYSTEM_PROPERTY;
+ return "jalview.default.browser";
+ }
+
}
\ No newline at end of file