MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / ProxySettings

Class ProxySettings

ij/src/main/java/ij/plugin/ProxySettings.java:13–81  ·  view source on GitHub ↗

This plugin implements the Plugins/Utilities/Proxy Settings command. It sets the JVM proxy properties to allow the Help/Update ImageJ command and File/Open Samples menu to work on networks behind a proxy server. @author Dimiter Prodanov

Source from the content-addressed store, hash-verified

11* @author Dimiter Prodanov
12*/
13public class ProxySettings implements PlugIn {
14 private Properties props = System.getProperties();
15 private String proxyhost = Prefs.get("proxy.server", "");
16 private int proxyport = (int)Prefs.get("proxy.port", 8080);
17
18 public void run(String arg) {
19 if (IJ.getApplet()!=null) return;
20 String host = System.getProperty("http.proxyHost");
21 if (host!=null) proxyhost = host;
22 String port = System.getProperty("http.proxyPort");
23 if (port!=null) {
24 double portNumber = Tools.parseDouble(port);
25 if (!Double.isNaN(portNumber))
26 proxyport = (int)portNumber;
27 }
28 if (!showDialog()) return;
29 if (!proxyhost.equals(""))
30 props.put("proxySet", "true");
31 else
32 props.put("proxySet", "false");
33 props.put("http.proxyHost", proxyhost);
34 props.put("http.proxyPort", ""+proxyport);
35 Prefs.set("proxy.server", proxyhost);
36 Prefs.set("proxy.port", proxyport);
37 String httpsHost = System.getProperty("https.proxyHost");
38 if (httpsHost == null) {
39 httpsHost = proxyhost;
40 }
41 int httpsPort = proxyport;
42 String httpsSystemPort = System.getProperty("https.proxyPort");
43 if (httpsSystemPort != null) {
44 double portNumber = Tools.parseDouble(httpsSystemPort);
45 if (!Double.isNaN(portNumber))
46 httpsPort = (int)portNumber;
47 }
48 props.put("https.proxyHost", httpsHost);
49 props.put("https.proxyPort", ""+httpsPort);
50 try {
51 System.setProperty("java.net.useSystemProxies", Prefs.useSystemProxies?"true":"false");
52 } catch(Exception e) {}
53 if (IJ.debugMode)
54 logProperties();
55 }
56
57 public void logProperties() {
58 IJ.log("proxy set: "+ System.getProperty("proxySet"));
59 IJ.log("http proxy host: "+ System.getProperty("http.proxyHost"));
60 IJ.log("http proxy port: "+System.getProperty("http.proxyPort"));
61 IJ.log("https proxy host: "+ System.getProperty("https.proxyHost"));
62 IJ.log("https proxy port: "+System.getProperty("https.proxyPort"));
63 IJ.log("java.net.useSystemProxies: "+System.getProperty("java.net.useSystemProxies"));
64 }
65
66 boolean showDialog() {
67 GenericDialog gd=new GenericDialog("Proxy Settings");
68 gd.addStringField("Proxy server:", proxyhost, 15);
69 gd.addNumericField("Port:", proxyport , 0);
70 gd.addCheckbox("Or, use system proxy settings", Prefs.useSystemProxies);

Callers

nothing calls this directly

Calls 2

getMethod · 0.95
getPropertiesMethod · 0.45

Tested by

no test coverage detected