JAL-3103 Switched to (a wrapper around) BrowserLauncher2
[jalview.git] / src / jalview / gui / Preferences.java
index b9f30e3..7a4dbc0 100755 (executable)
@@ -51,6 +51,7 @@ import javax.swing.table.TableColumn;
 import javax.swing.table.TableModel;
 import javax.swing.table.TableRowSorter;
 
+import edu.stanford.ejalbert.launching.IBrowserLaunching;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
@@ -73,6 +74,7 @@ import jalview.urls.UrlLinkTableModel;
 import jalview.urls.api.UrlProviderFactoryI;
 import jalview.urls.api.UrlProviderI;
 import jalview.urls.desktop.DesktopUrlProviderFactory;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.util.UrlConstants;
@@ -148,10 +150,10 @@ public class Preferences extends GPreferences
 
   /**
    * Holds name and link separated with | character. Sequence IDS and Sequences
-   * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and $SEQUENCES$
-   * or $SEQUENCES=/.possible | chars ./=$ and separation character for first and
-   * second token specified after a pipe character at end |,|. (TODO: proper
-   * escape for using | to separate ids or sequences
+   * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
+   * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
+   * for first and second token specified after a pipe character at end |,|.
+   * (TODO: proper escape for using | to separate ids or sequences
    */
 
   public static List<String> groupURLLinks;
@@ -447,26 +449,27 @@ public class Preferences extends GPreferences
         if (validateViewerPath())
         {
           String path = structureViewerPath.getText();
-          try {
-          ViewerType type = ViewerType.valueOf(viewerType);
-          switch (type)
+          try
+          {
+            ViewerType type = ViewerType.valueOf(viewerType);
+            switch (type)
+            {
+            case JMOL:
+              break;
+            case CHIMERA:
+              Cache.setProperty(CHIMERA_PATH, path);
+              break;
+            case CHIMERAX:
+              Cache.setProperty(CHIMERAX_PATH, path);
+              break;
+            case PYMOL:
+              Cache.setProperty(PYMOL_PATH, path);
+              break;
+            }
+          } catch (IllegalArgumentException x)
           {
-          case JMOL:
-            break;
-          case CHIMERA:
-            Cache.setProperty(CHIMERA_PATH, path);
-            break;
-          case CHIMERAX:
-            Cache.setProperty(CHIMERAX_PATH, path);
-            break;
-          case PYMOL:
-            Cache.setProperty(PYMOL_PATH, path);
-            break;
+            Console.error("Failed to set path - unknown viewer type", x);
           }
-        } catch (IllegalArgumentException x)
-        {
-          Console.error("Failed to set path - unknown viewer type",x);
-        }
         }
       }
     });
@@ -887,8 +890,16 @@ public class Preferences extends GPreferences
     // Proxy settings set first (to catch web services)
 
     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
-
-    jalview.util.BrowserLauncher.resetBrowser();
+    if (Cache.getProperty("DEFAULT_BROWSER") != null)
+    {
+      System.setProperty(IBrowserLaunching.BROWSER_SYSTEM_PROPERTY,
+              Cache.getProperty("DEFAULT_BROWSER"));
+    }
+    else
+    {
+      System.clearProperty(IBrowserLaunching.BROWSER_SYSTEM_PROPERTY);
+    }
+    BrowserLauncher.resetBrowser();
 
     // save user-defined and selected links
     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
@@ -1052,8 +1063,8 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * Do any necessary validation before saving settings. Return focus to the first
-   * tab which fails validation.
+   * Do any necessary validation before saving settings. Return focus to the
+   * first tab which fails validation.
    * 
    * @return
    */
@@ -1107,7 +1118,7 @@ public class Preferences extends GPreferences
    * DOCUMENT ME!
    * 
    * @param e
-   *            DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   @Override
   public void cancel_actionPerformed(ActionEvent e)
@@ -1129,7 +1140,7 @@ public class Preferences extends GPreferences
    * DOCUMENT ME!
    * 
    * @param e
-   *            DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   @Override
   public void annotations_actionPerformed(ActionEvent e)
@@ -1392,8 +1403,8 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * Returns true if structure viewer path is to a valid executable, else shows an
-   * error dialog. Does nothing if the path is empty, as is the case for Jmol
+   * Returns true if structure viewer path is to a valid executable, else shows
+   * an error dialog. Does nothing if the path is empty, as is the case for Jmol
    * (built in to Jalview) or when Jalview is left to try default paths.
    */
   private boolean validateViewerPath()
@@ -1414,8 +1425,8 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * If Chimera or ChimeraX or Pymol is selected, check it can be found on default
-   * or user-specified path, if not show a warning/help dialog
+   * If Chimera or ChimeraX or Pymol is selected, check it can be found on
+   * default or user-specified path, if not show a warning/help dialog
    */
   @Override
   protected void structureViewer_actionPerformed(String selectedItem)