import java.util.*; import ij.*; import ij.gui.*; import ij.plugin.*; /** Configures the network parameters of the JVM within ImageJ: * - proxy port * - proxy host * - proxy username * - proxy password * * ToDo: implement a password dialog in ImageJ * * @version 1.0 * @date 12 May 2008 * * * @author Dimiter Prodanov * IMEC * * "read the source, meditate, get rich, buy a Ferari" * */ public class NetSetup_ implements PlugIn { private static Properties props = System.getProperties(); private String proxyhost = ""; private int proxyport = 8080; private String proxyuser = ""; private String proxypass = ""; private boolean debug = true; private boolean authenticate; private final static String version="1.0"; /* (non-Javadoc) * @see ij.plugin.PlugIn#run(java.lang.String) */ public void run(String arg) { //System.getProperties().put("http.proxyHost", "someProxyURL"); //IJ.log("http.proxyHost: "+props.getProperty("http.proxyHost")); if (showDialog()){ props.put("proxySet", "true"); props.put("http.proxyHost", proxyhost); props.put("http.proxyPort", new Integer(proxyport).toString()); props.put("http.proxyUser", proxyuser); props.put("http.proxyPassword", proxypass); } if (debug) { IJ.log("proxy set: "+ System.getProperty("proxySet")); IJ.log("proxy host: "+ System.getProperty("http.proxyHost")); IJ.log("proxy port: "+System.getProperty("http.proxyPort")); IJ.log("proxy username: "+ System.getProperty("http.proxyUser")); IJ.log("proxy password: "+ System.getProperty("http.proxyPassword")); } } boolean showDialog() { GenericDialog gd=new GenericDialog("Proxy Setup"); gd.addStringField("Proxy Server:", proxyhost); gd.addNumericField("Port:", proxyport , 0); gd.addCheckbox(" Authenticate", authenticate); gd.showDialog(); if (gd.wasCanceled()) return false; proxyhost = gd.getNextString(); proxyport = (int)gd.getNextNumber(); authenticate = gd.getNextBoolean(); if (authenticate) { GenericDialog gd2=new GenericDialog("Authentication"); gd2.addStringField("Username:", proxyuser, 15); gd2.addStringField("Password:", proxypass, 15); gd2.showDialog(); if (!gd. wasCanceled()) { proxyuser=gd2.getNextString(); proxypass=gd2.getNextString(); } } return true; } }