JAL-3633 Remember system set proxy properties. Add options in Preferences for No...
[jalview.git] / src / jalview / gui / Preferences.java
index c61c70e..f337898 100755 (executable)
@@ -536,10 +536,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", ""));
 
@@ -812,22 +829,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", proxyServerHttpTB.getText());
 
-    Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
+    Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
 
-    Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
+    Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
 
-    if (useProxy.isSelected())
+    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())