JAL-629 Much better way of dealing with list of filenames/URLs without an --open...
[jalview.git] / src / jalview / util / BrowserLauncher.java
index cddbecb..f9fa80d 100644 (file)
@@ -1,43 +1,51 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.util;
 
-import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
-import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
+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 jalview.bin.Cache;
 import jalview.bin.Console;
 
-public class BrowserLauncher extends edu.stanford.ejalbert.BrowserLauncher
+public class BrowserLauncher
 {
   private static BrowserLauncher INSTANCE = null;
 
-  // get singleton BrowserLauncher instance
+  private static String preferredBrowser = null;
+
   public static BrowserLauncher getInstance()
   {
-    if (INSTANCE == null)
+    if (INSTANCE != null)
     {
-      try
-      {
-        INSTANCE = new BrowserLauncher();
-      } catch (BrowserLaunchingInitializingException e)
-      {
-        Console.warn(MessageManager.formatMessage(
-                "exception.browser_unable_to_launch", e.getMessage()));
-      } catch (UnsupportedOperatingSystemException e)
-      {
-        Console.warn(MessageManager.formatMessage("exception."));
-        Console.debug(e.getMessage());
-      }
+      return INSTANCE;
     }
+    INSTANCE = new BrowserLauncher();
     return INSTANCE;
   }
 
-  public BrowserLauncher() throws BrowserLaunchingInitializingException,
-          UnsupportedOperatingSystemException
-  {
-    super();
-  }
-
-  private static String preferredBrowser = null;
-
   public static void openURL(String url)
   {
     if (Platform.isJS())
@@ -52,28 +60,61 @@ public class BrowserLauncher extends edu.stanford.ejalbert.BrowserLauncher
      * @j2sIgnore
      */
     {
-      BrowserLauncher bl = getInstance();
-      if (bl != null)
+      Desktop d = Desktop.getDesktop();
+      if (d != null && d.isSupported(Desktop.Action.BROWSE))
       {
-        if (Platform.isMac() || preferredBrowser == null)
+        try
         {
-          bl.openURLinBrowser(url);
-        }
-        else
+          d.browse(new URI(url));
+        } catch (IOException e)
+        {
+          Console.warn(MessageManager.formatMessage(
+                  "exception.browser_unable_to_launch", url));
+          Console.warn(e.getMessage());
+          Console.debug(Cache.getStackTraceString(e));
+        } catch (URISyntaxException e1)
         {
-          bl.openURLinBrowser(preferredBrowser, url);
+          Console.warn(MessageManager.formatMessage(
+                  "exception.browser_unable_to_launch", url));
+          Console.warn(e1.getMessage());
+          Console.debug(Cache.getStackTraceString(e1));
         }
       }
       else
       {
-        Console.warn("Could not open URL '" + url + "'");
+        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<String> getBrowserList()
+  {
+    return new ArrayList<String>();
+  }
+
+  public static String getBrowserSystemProperty()
+  {
+    // return IBrowserLaunching.BROWSER_SYSTEM_PROPERTY;
+    return "jalview.default.browser";
+  }
+
 }
\ No newline at end of file