Show PasswordDialog.java syntax highlighted
/**
* Copyright (c) 2003
* Helsinki Institute of Physics
* see LICENSE file for details
*
* PasswordDialog.java
*/
package fi.hip.gb.client.ui.myproxy;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import org.globus.tools.ui.util.JJPanel;
import fi.hip.gb.client.ui.Utils;
/**
* Dialog which asks password. When user click ok the
* {@link MyProxyGUI#putProxy(String) } is called.
*
* @author Juho Karppinen
* @version $Id: PasswordDialog.java 102 2004-11-12 14:31:37Z jkarppin $
*/
public class PasswordDialog extends JDialog implements ActionListener {
/**
* Shows password dialog
* @param gui parent gui, called when user has entered password
*/
public PasswordDialog(MyProxyGUI gui) {
super(gui, "Enter Password", true);
_gui = gui;
setSize(450, 125);
Container contentPane = getContentPane();
JJPanel gridPanel = new JJPanel();
gridPanel.setInsets(2, 2, 2, 2);
gridPanel.setAnchor(GridBagConstraints.EAST);
gridPanel.setBorder(BorderFactory.createEtchedBorder());
gridPanel.add(new JLabel("Enter Certificate Password: "), 0, 0, 1, 1);
gridPanel.setAnchor(GridBagConstraints.WEST);
gridPanel.gbc.weightx = 1;
gridPanel.setFill(GridBagConstraints.HORIZONTAL);
gridPanel.add(_tfPasswd, 1, 0, 1, 1);
contentPane.add(gridPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
_okButton = new JButton("OK");
_okButton.addActionListener(this);
_okButton.setDefaultCapable(true);
_okButton.setMnemonic(KeyEvent.VK_O);
getRootPane().setDefaultButton(_okButton);
_cancelButton = new JButton("Cancel");
_cancelButton.setMnemonic(KeyEvent.VK_C);
_cancelButton.addActionListener(this);
buttonPanel.add(_okButton);
buttonPanel.add(_cancelButton);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
Utils.center(this);
setVisible(true);
}
/**
* Validate ui fields
* @return true if all fields are correctly set up
*/
private boolean validateSettings() {
char[] pwd = _tfPasswd.getPassword();
if(pwd.length > 0)
return true;
JOptionPane.showMessageDialog(
this,
"Please enter your password.",
"Need More Information",
JOptionPane.WARNING_MESSAGE);
return false;
}
/**
* Handles button events for saving and exiting
*
* @param evt an ActionEvent
*/
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == _cancelButton) {
_gui.putProxy(null);
setVisible(false);
} else if (validateSettings()) {
_gui.putProxy(new String(_tfPasswd.getPassword()));
setVisible(false);
}
}
private MyProxyGUI _gui;
private JPasswordField _tfPasswd = new JPasswordField(10);
private JButton _okButton;
private JButton _cancelButton;
}
See more files for this project here