Show MyProxyOptions.java syntax highlighted
/**
* Copyright (c) 2003
* Helsinki Institute of Physics
* see LICENSE file for details
*
* MyProxyOptions.java
*/
package fi.hip.gb.client.ui.myproxy;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.globus.tools.ui.util.JJPanel;
import fi.hip.gb.client.ui.Utils;
import fi.hip.gb.core.Config;
import fi.hip.gb.core.plugin.ConfigPlugin;
/**
* Myproxy properties dialog.
*
* @author Juho Karppinen
* @version $Id: MyProxyOptions.java 552 2005-09-26 16:53:58Z jkarppin $
*/
public class MyProxyOptions extends JJPanel implements ConfigPlugin {
private JTextField tfLocalLifetime = new JTextField(5);
private JTextField tfRemoteLifetime = new JTextField(5);
private JTextField tfMyproxyServer = new JTextField(30);
private JTextField tfMyproxyDn = new JTextField(30);
private JTextField tfMyproxyPort = new JTextField(6);
private int localScale = 60;
private int remoteScale = 60;
/**
* Initialize options panel for chaning and viewing myproxy
* settings.
*/
public MyProxyOptions() {
load();
// add basic editing features
Utils.addPopupMenu(this.tfMyproxyServer);
Utils.addPopupMenu(this.tfMyproxyDn);
Utils.addPopupMenu(this.tfMyproxyPort);
Utils.addPopupMenu(this.tfLocalLifetime);
Utils.addPopupMenu(this.tfRemoteLifetime);
this.setBorder(BorderFactory.createEtchedBorder());
this.setAnchor(GridBagConstraints.EAST);
this.add(new JLabel("Myproxy Server: "), 0, 0, 1, 1);
this.add(new JLabel("Myproxy Server DN:"), 0, 1, 1, 1);
this.add(new JLabel("Myproxy Port:"), 0, 2, 1, 1);
this.add(new JLabel("Local Proxy Lifetime: "), 0, 3, 1, 1);
this.add(new JLabel("Proxy Lifetime on Server: "), 0, 4, 1, 1);
this.setAnchor(GridBagConstraints.WEST);
this.add(this.tfMyproxyServer, 1, 0, 1, 1);
this.add(this.tfMyproxyDn, 1, 1, 1, 1);
this.add(this.tfMyproxyPort, 1, 2, 1, 1);
String[] lifetimeScales = { "minutes", "hours", "days" };
JPanel localLifetimePanel =
new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
final JComboBox cbLocalLifetime = new JComboBox(lifetimeScales);
cbLocalLifetime.setSelectedIndex(1);
cbLocalLifetime.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
MyProxyOptions.this.localScale =
changeScale((String)cbLocalLifetime.getSelectedItem(),
MyProxyOptions.this.localScale,
MyProxyOptions.this.tfLocalLifetime);
}
});
localLifetimePanel.add(this.tfLocalLifetime);
localLifetimePanel.add(cbLocalLifetime);
this.add(localLifetimePanel, 1, 3, 1, 1);
JPanel portalLifetimePanel =
new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
final JComboBox cbRemoteLifetime = new JComboBox(lifetimeScales);
cbRemoteLifetime.setSelectedIndex(1);
cbRemoteLifetime.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
MyProxyOptions.this.remoteScale =
changeScale((String)cbRemoteLifetime.getSelectedItem(),
MyProxyOptions.this.remoteScale,
MyProxyOptions.this.tfRemoteLifetime);
}
});
portalLifetimePanel.add(this.tfRemoteLifetime);
portalLifetimePanel.add(cbRemoteLifetime);
this.add(portalLifetimePanel, 1, 4, 1, 1);
this.tfMyproxyServer.setToolTipText("Myproxy server address");
this.tfMyproxyDn.setToolTipText("Normally needed only if myproxy server "
+ "doesn't have valid host certificates");
this.tfMyproxyPort.setToolTipText("Default port is 7512");
this.tfLocalLifetime.setToolTipText("Lifetime of downloaded proxy on local computer");
this.tfRemoteLifetime.setToolTipText("Lifetime of uploaded proxy on myproxy server");
}
/**
* Change scale of proxy lifetime
* @param newScaleName name of new scale, minutes, hours or days
* @param oldScale old scaling to minutes
* @param tf field containing the value
* @return new scaling to minutes
*/
private int changeScale(String newScaleName, int oldScale, JTextField tf) {
int newScale = 1;
if(newScaleName.equals("minutes"))
newScale = 1;
else if(newScaleName.equals("hours"))
newScale = 60;
else if(newScaleName.equals("days"))
newScale = 60*24;
float oldValue = Float.parseFloat(tf.getText());
tf.setText(Float.toString(oldValue * oldScale / newScale));
return newScale;
}
/*
* @see fi.hip.gb.core.plugin.ConfigPlugin#init()
*/
public JComponent init() {
return this;
}
/*
* @see fi.hip.gb.core.plugin.ConfigPlugin#load()
*/
public void load() {
Config config = Config.getInstance();
this.tfMyproxyServer.setText("" + config.getMyProxyServer());
this.tfMyproxyDn.setText("" + config.getMyProxyDn());
this.tfMyproxyPort.setText("" + config.getMyProxyPort());
this.tfLocalLifetime.setText("" + config.getMyProxyLocalLifetime() / this.localScale);
this.tfRemoteLifetime.setText("" + config.getMyProxyRemoteLifetime() / this.remoteScale);
}
/*
* @see fi.hip.gb.core.plugin.ConfigPlugin#save()
*/
public void save() throws IOException {
Config config = Config.getInstance();
config.setMyProxyServer(this.tfMyproxyServer.getText());
config.setMyProxyDn(this.tfMyproxyDn.getText());
config.setMyProxyPort(Integer.parseInt(this.tfMyproxyPort.getText()));
config.setMyProxyLocalLifetime((int)(Float.parseFloat(this.tfLocalLifetime.getText()) * this.localScale));
config.setMyProxyRemoteLifetime((int)(Float.parseFloat(this.tfRemoteLifetime.getText()) * this.remoteScale));
}
/*
* @see fi.hip.gb.core.plugin.ConfigPlugin#validate()
*/
public void validateSettings() throws IOException {
String errorMessage = null;
if (this.tfMyproxyServer.getText().trim().equals(""))
errorMessage = "Please enter the hostname of the myproxy server";
else if (this.tfMyproxyPort.getText().trim().equals(""))
errorMessage = "Please enter the port number of the myproxy server";
else if (this.tfLocalLifetime.getText().trim().equals(""))
errorMessage = "Please enter the lifetime of the local proxy";
else if (this.tfRemoteLifetime.getText().trim().equals(""))
errorMessage = "Please enter the maximum allowed lifetime of the proxy on the myproxy server";
if(errorMessage != null) {
throw new IOException("Error while validating MyProxy settings."
+ errorMessage);
}
}
/*
* @see fi.hip.gb.core.plugin.ConfigPlugin#stop()
*/
public void stop() {
}
}
See more files for this project here