JAL-4193 JAL-4194 sessionProperties layer in Cache, CLI arg Opts to deal with -Pkey...
[jalview.git] / src / jalview / gui / Preferences.java
index 17f6af6..c4f32c3 100755 (executable)
@@ -27,7 +27,6 @@ import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
@@ -35,7 +34,6 @@ import java.util.concurrent.CompletableFuture;
 
 import javax.help.HelpSetException;
 import javax.swing.JComboBox;
-import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JPanel;
 import javax.swing.ListSelectionModel;
@@ -51,7 +49,7 @@ import javax.swing.table.TableColumn;
 import javax.swing.table.TableModel;
 import javax.swing.table.TableRowSorter;
 
-import edu.stanford.ejalbert.launching.IBrowserLaunching;
+//import edu.stanford.ejalbert.launching.IBrowserLaunching;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
@@ -74,7 +72,6 @@ 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;
@@ -159,6 +156,9 @@ public class Preferences extends GPreferences
   public static List<String> groupURLLinks;
   static
   {
+    // don't populate with session properties
+    Cache.disableSessionProperties();
+
     // get links selected to be in the menu (SEQUENCE_LINKS)
     // and links entered by the user but not selected (STORED_LINKS)
     String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
@@ -183,6 +183,9 @@ public class Preferences extends GPreferences
      */
 
     groupURLLinks = new ArrayList<>();
+
+    // reenable
+    Cache.enableSessionProperties();
   }
 
   JInternalFrame frame;
@@ -191,7 +194,7 @@ public class Preferences extends GPreferences
 
   private OptionsParam promptEachTimeOpt = new OptionsParam(
           MessageManager.getString("label.prompt_each_time"),
-          "Prompt each time");
+          LineartOptions.PROMPT_EACH_TIME);
 
   private OptionsParam lineArtOpt = new OptionsParam(
           MessageManager.getString("label.lineart"), "Lineart");
@@ -251,7 +254,11 @@ public class Preferences extends GPreferences
   private Preferences()
   {
     super();
+    // don't populate with session properties
+    Cache.disableSessionProperties();
+
     frame = new JInternalFrame();
+    frame.setFrameIcon(null);
     frame.setContentPane(this);
     if (!Platform.isJS())
     /**
@@ -388,9 +395,9 @@ public class Preferences extends GPreferences
      * Set overview panel defaults
      */
     gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
-            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
+            OverviewCanvas.OVERVIEW_DEFAULT_GAP));
     hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR,
-            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
+            OverviewCanvas.OVERVIEW_DEFAULT_HIDDEN));
     useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
     gapLabel.setEnabled(!useLegacyGap.isSelected());
     gapColour.setEnabled(!useLegacyGap.isSelected());
@@ -641,12 +648,6 @@ public class Preferences extends GPreferences
     setCustomProxyEnabled();
     applyProxyButtonEnabled(false);
 
-    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
     questionnaire
@@ -697,6 +698,8 @@ public class Preferences extends GPreferences
      * Set Startup tab defaults
      */
 
+    // re-enable
+    Cache.enableSessionProperties();
   }
 
   /**
@@ -709,6 +712,8 @@ public class Preferences extends GPreferences
   protected void setupOutputCombo(JComboBox<Object> comboBox,
           String propertyKey)
   {
+    Cache.disableSessionProperties();
+
     comboBox.addItem(promptEachTimeOpt);
     comboBox.addItem(lineArtOpt);
     comboBox.addItem(textOpt);
@@ -730,6 +735,8 @@ public class Preferences extends GPreferences
     {
       comboBox.setSelectedItem(promptEachTimeOpt);
     }
+
+    Cache.enableSessionProperties();
   }
 
   /**
@@ -741,6 +748,8 @@ public class Preferences extends GPreferences
   @Override
   public void ok_actionPerformed(ActionEvent e)
   {
+    Cache.disableSessionProperties();
+
     if (!validateSettings())
     {
       return;
@@ -754,6 +763,7 @@ public class Preferences extends GPreferences
     /*
      * Save Visual settings
      */
+
     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
             Boolean.toString(seqLimit.isSelected()));
     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
@@ -893,19 +903,6 @@ public class Preferences extends GPreferences
      */
     // Proxy settings set first (to catch web services)
 
-    Cache.setOrRemove("DEFAULT_BROWSER",
-            (String) defaultBrowser.getSelectedItem());
-    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);
     if (menuLinks.isEmpty())
@@ -1041,10 +1038,14 @@ public class Preferences extends GPreferences
     } catch (Exception ex)
     {
     }
+
+    Cache.enableSessionProperties();
   }
 
   public void saveProxySettings()
   {
+    Cache.disableSessionProperties();
+
     String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
             : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
                     : Cache.PROXYTYPE_SYSTEM;
@@ -1065,6 +1066,8 @@ public class Preferences extends GPreferences
       wsPrefs.update++;
     }
     previousProxyType = newProxyType;
+
+    Cache.enableSessionProperties();
   }
 
   /**
@@ -1096,6 +1099,8 @@ public class Preferences extends GPreferences
   @Override
   public void startupFileTextfield_mouseClicked()
   {
+    Cache.disableSessionProperties();
+
     // TODO: JAL-3048 not needed for Jalview-JS
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser
@@ -1117,6 +1122,8 @@ public class Preferences extends GPreferences
       startupFileTextfield
               .setText(chooser.getSelectedFile().getAbsolutePath());
     }
+
+    Cache.enableSessionProperties();
   }
 
   /**
@@ -1270,31 +1277,6 @@ public class Preferences extends GPreferences
     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
   }
 
-  @Override
-  public void defaultBrowser_mouseClicked(MouseEvent e)
-  {
-    // TODO: JAL-3048 not needed for j2s
-    if (!Platform.isJS()) // BH 2019
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     */
-    {
-      JFileChooser chooser = new JFileChooser(".");
-      chooser.setDialogTitle(
-              MessageManager.getString("label.select_default_browser"));
-
-      int value = chooser.showOpenDialog(this);
-
-      if (value == JFileChooser.APPROVE_OPTION)
-      {
-        defaultBrowser.getModel().setSelectedItem(
-                chooser.getSelectedFile().getAbsolutePath());
-      }
-    }
-  }
-
   /*
    * (non-Javadoc)
    * 
@@ -1353,13 +1335,11 @@ public class Preferences extends GPreferences
     boolean enabled = useLegacyGap.isSelected();
     if (enabled)
     {
-      gapColour.setBackground(
-              jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
+      gapColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_LEGACY_GAP);
     }
     else
     {
-      gapColour.setBackground(
-              jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
+      gapColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_GAP);
     }
     gapColour.setEnabled(!enabled);
     gapLabel.setEnabled(!enabled);
@@ -1371,8 +1351,7 @@ public class Preferences extends GPreferences
     useLegacyGap.setSelected(false);
     useLegacyGaps_actionPerformed(null);
     showHiddenAtStart.setSelected(false);
-    hiddenColour.setBackground(
-            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
+    hiddenColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_HIDDEN);
   }
 
   @Override
@@ -1454,6 +1433,7 @@ public class Preferences extends GPreferences
      */
     String viewerPath = "";
     List<String> paths = null;
+    Cache.disableSessionProperties();
     try
     {
       ViewerType viewerType = ViewerType.valueOf(selectedItem);
@@ -1479,6 +1459,7 @@ public class Preferences extends GPreferences
     {
       // only valid entries should be in the drop-down
     }
+    Cache.enableSessionProperties();
     structureViewerPath.setText(viewerPath);
 
     paths.add(0, structureViewerPath.getText());