JAL-3633 Remember system set proxy properties. Add options in Preferences for No...
[jalview.git] / src / jalview / gui / Preferences.java
index 1f61bae..e27905c 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.bin.Cache;
-import jalview.gui.Help.HelpId;
-import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.BackupFiles;
-import jalview.io.BackupFilesPresetEntry;
-import jalview.io.FileFormatI;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.jbgui.GPreferences;
-import jalview.jbgui.GSequenceLink;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemes;
-import jalview.schemes.ResidueColourScheme;
-import jalview.urls.UrlLinkTableModel;
-import jalview.urls.api.UrlProviderFactoryI;
-import jalview.urls.api.UrlProviderI;
-import jalview.urls.desktop.DesktopUrlProviderFactory;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-import jalview.util.UrlConstants;
-import jalview.ws.sifts.SiftsSettings;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -74,6 +51,28 @@ import javax.swing.table.TableModel;
 import javax.swing.table.TableRowSorter;
 
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.bin.Cache;
+import jalview.gui.Help.HelpId;
+import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.BackupFiles;
+import jalview.io.BackupFilesPresetEntry;
+import jalview.io.FileFormatI;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.jbgui.GPreferences;
+import jalview.jbgui.GSequenceLink;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
+import jalview.urls.UrlLinkTableModel;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.UrlConstants;
+import jalview.ws.sifts.SiftsSettings;
 
 /**
  * DOCUMENT ME!
@@ -317,12 +316,10 @@ public class Preferences extends GPreferences
     /*
      * Set overview panel defaults
      */
-    gapColour.setBackground(
-            Cache.getDefaultColour(GAP_COLOUR,
-                    jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
-    hiddenColour.setBackground(
-            Cache.getDefaultColour(HIDDEN_COLOUR,
-                    jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
+    gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
+            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
+    hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR,
+            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
     useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
     gapLabel.setEnabled(!useLegacyGap.isSelected());
     gapColour.setEnabled(!useLegacyGap.isSelected());
@@ -487,10 +484,27 @@ public class Preferences extends GPreferences
       }
     }
 
-    useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
-    useProxy_actionPerformed(); // make sure useProxy is correctly initialised
-    proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
-    proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
+    String proxyTypeString = Cache.getDefault("USE_PROXY", "false");
+    switch (proxyTypeString)
+    {
+    case "none":
+      proxyType.setSelected(noProxy.getModel(), true);
+      break;
+    case "false":
+      proxyType.setSelected(systemProxy.getModel(), true);
+      break;
+    case "true":
+      proxyType.setSelected(customProxy.getModel(), true);
+      break;
+    default:
+      String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
+              + proxyTypeString;
+      Cache.log.warn(message);
+    }
+    proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", ""));
+    proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", ""));
+    proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", ""));
+    proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", ""));
 
     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
 
@@ -548,8 +562,7 @@ public class Preferences extends GPreferences
 
     annotations_actionPerformed(null); // update the display of the annotation
                                        // settings
-    
-    
+
     /*
      * Set Backups tab defaults
      */
@@ -727,22 +740,35 @@ public class Preferences extends GPreferences
             sequenceUrlLinks.getPrimaryUrlId());
 
     Cache.applicationProperties.setProperty("USE_PROXY",
-            Boolean.toString(useProxy.isSelected()));
+            customProxy.isSelected() ? "true"
+                    : noProxy.isSelected() ? "none" : "false");
 
-    Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
+    Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
 
-    Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
+    Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
 
-    if (useProxy.isSelected())
+    Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
+
+    Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
+
+    if (noProxy.isSelected())
     {
-      System.setProperty("http.proxyHost", proxyServerTB.getText());
-      System.setProperty("http.proxyPort", proxyPortTB.getText());
+      Cache.log.warn("Setting no proxy settings");
+      Cache.setProxyProperties(null, null, null, null);
     }
-    else
+    else if (customProxy.isSelected())
     {
-      System.setProperty("http.proxyHost", "");
-      System.setProperty("http.proxyPort", "");
+      Cache.log.warn("Setting custom proxy settings");
+      Cache.setProxyProperties(proxyServerHttpTB.getText(),
+              proxyPortHttpTB.getText(), proxyServerHttpsTB.getText(),
+              proxyPortHttpsTB.getText());
     }
+    else // systemProxy should be selected and is sensible default
+    {
+      Cache.log.warn("Setting system proxy settings");
+      Cache.resetProxyProperties();
+    }
+
     Cache.setProperty("VERSION_CHECK",
             Boolean.toString(versioncheck.isSelected()));
     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
@@ -809,16 +835,16 @@ public class Preferences extends GPreferences
     Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
             Boolean.toString(enableBackupFiles.isSelected()));
     int preset = getComboIntStringKey(backupfilesPresetsCombo);
-    Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
+    Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET",
+            Integer.toString(preset));
 
     if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
     {
       BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
       BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
               BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
-      Cache.applicationProperties
-              .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
-                      customBFPE.toString());
+      Cache.applicationProperties.setProperty(
+              BackupFilesPresetEntry.CUSTOMCONFIG, customBFPE.toString());
     }
 
     BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
@@ -1349,4 +1375,5 @@ public class Preferences extends GPreferences
       }
     }
   }
+
 }