JAL-3103 Remove BrowserLauncher2 and use Desktop.browse(url) with wrapper methods
[jalview.git] / src / jalview / gui / Preferences.java
index a64534b..fe0aea1 100755 (executable)
@@ -51,9 +51,11 @@ 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;
+import jalview.bin.Console;
 import jalview.bin.MemorySetting;
 import jalview.ext.pymol.PymolManager;
 import jalview.gui.Help.HelpId;
@@ -72,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;
@@ -147,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;
@@ -432,7 +435,7 @@ public class Preferences extends GPreferences
       }
     } catch (IllegalArgumentException e)
     {
-      Cache.error("Unknown structure viewer type: " + viewerType
+      Console.error("Unknown structure viewer type: " + viewerType
               + ", defaulting to Jmol");
       type = ViewerType.JMOL;
     }
@@ -446,26 +449,27 @@ public class Preferences extends GPreferences
         if (validateViewerPath())
         {
           String path = structureViewerPath.getText();
-          try {
-          ViewerType type = ViewerType.valueOf(viewerType);
-          switch (type)
+          try
           {
-          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;
+            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)
+          {
+            Console.error("Failed to set path - unknown viewer type", x);
           }
-        } catch (IllegalArgumentException x)
-        {
-          Cache.error("Failed to set path - unknown viewer type",x);
-        }
         }
       }
     });
@@ -620,7 +624,7 @@ public class Preferences extends GPreferences
       proxyType.setSelected(customProxy.getModel(), true);
       break;
     default:
-      Cache.warn(
+      Console.warn(
               "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
                       + proxyTypeString);
     }
@@ -637,7 +641,11 @@ public class Preferences extends GPreferences
     setCustomProxyEnabled();
     applyProxyButtonEnabled(false);
 
-    defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
+    String browserPref = Cache.getDefault("DEFAULT_BROWSER", "");
+    if (browserPref != null)
+    {
+      defaultBrowser.getModel().setSelectedItem(browserPref);
+    }
 
     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
     // note antisense here: default is true
@@ -885,9 +893,9 @@ public class Preferences extends GPreferences
      */
     // Proxy settings set first (to catch web services)
 
-    Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
-
-    jalview.util.BrowserLauncher.resetBrowser();
+    Cache.setOrRemove("DEFAULT_BROWSER",
+            (String) defaultBrowser.getSelectedItem());
+    BrowserLauncher.resetBrowser(true);
 
     // save user-defined and selected links
     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
@@ -1051,8 +1059,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
    */
@@ -1106,7 +1114,7 @@ public class Preferences extends GPreferences
    * DOCUMENT ME!
    * 
    * @param e
-   *            DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   @Override
   public void cancel_actionPerformed(ActionEvent e)
@@ -1128,7 +1136,7 @@ public class Preferences extends GPreferences
    * DOCUMENT ME!
    * 
    * @param e
-   *            DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   @Override
   public void annotations_actionPerformed(ActionEvent e)
@@ -1189,7 +1197,7 @@ public class Preferences extends GPreferences
     if (index == -1)
     {
       // button no longer enabled if row is not selected
-      Cache.debug("Edit with no row selected in linkUrlTable");
+      Console.debug("Edit with no row selected in linkUrlTable");
       return;
     }
 
@@ -1241,7 +1249,7 @@ public class Preferences extends GPreferences
     if (index == -1)
     {
       // button no longer enabled if row is not selected
-      Cache.debug("Delete with no row selected in linkUrlTable");
+      Console.debug("Delete with no row selected in linkUrlTable");
       return;
     }
     else
@@ -1272,7 +1280,8 @@ public class Preferences extends GPreferences
 
       if (value == JFileChooser.APPROVE_OPTION)
       {
-        defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
+        defaultBrowser.getModel().setSelectedItem(
+                chooser.getSelectedFile().getAbsolutePath());
       }
     }
   }
@@ -1391,8 +1400,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()
@@ -1413,8 +1422,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)