mev-4.0.01/source/org/tigr/microarray/mev/cluster/clusterUtil/submit/PasswordDialog.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2004, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * PasswordDialog.java
2 26 Feb 07 jari 7  *
2 26 Feb 07 jari 8  * Created on July 16, 2004, 2:49 PM
2 26 Feb 07 jari 9  */
2 26 Feb 07 jari 10
2 26 Feb 07 jari 11 package org.tigr.microarray.mev.cluster.clusterUtil.submit;
2 26 Feb 07 jari 12
2 26 Feb 07 jari 13 import java.awt.Dimension;
2 26 Feb 07 jari 14 import java.awt.GridBagConstraints;
2 26 Feb 07 jari 15 import java.awt.GridBagLayout;
2 26 Feb 07 jari 16 import java.awt.Insets;
2 26 Feb 07 jari 17 import java.awt.Toolkit;
2 26 Feb 07 jari 18
2 26 Feb 07 jari 19 import javax.swing.JFrame;
2 26 Feb 07 jari 20 import javax.swing.JLabel;
2 26 Feb 07 jari 21 import javax.swing.JOptionPane;
2 26 Feb 07 jari 22 import javax.swing.JPasswordField;
2 26 Feb 07 jari 23 import javax.swing.JTextField;
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog;
2 26 Feb 07 jari 26 import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel;
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28 /** Collects user and password information.
2 26 Feb 07 jari 29  * @author braisted
2 26 Feb 07 jari 30  */
2 26 Feb 07 jari 31 public class PasswordDialog extends AlgorithmDialog {
2 26 Feb 07 jari 32     
2 26 Feb 07 jari 33     private JTextField userField;
2 26 Feb 07 jari 34     private JPasswordField passField;
2 26 Feb 07 jari 35     protected int result = JOptionPane.CANCEL_OPTION;
2 26 Feb 07 jari 36     
2 26 Feb 07 jari 37     /** Creates a new instance of PasswordDialog
2 26 Feb 07 jari 38      * @param title Dialog title
2 26 Feb 07 jari 39      * @param userFieldLabel label for user field
2 26 Feb 07 jari 40      * @param user optional user name, can be null
2 26 Feb 07 jari 41      * @param password optional password, can be null
2 26 Feb 07 jari 42      */
2 26 Feb 07 jari 43     public PasswordDialog(String title, String userFieldLabel, String user, String password) {
2 26 Feb 07 jari 44         super(new JFrame(), title, true);
2 26 Feb 07 jari 45         JLabel userLabel = new JLabel(userFieldLabel);
2 26 Feb 07 jari 46         userLabel.setHorizontalAlignment(JLabel.RIGHT);
2 26 Feb 07 jari 47         userField = new JTextField(20);        
2 26 Feb 07 jari 48         if(user != null)
2 26 Feb 07 jari 49             userField.setText(user);
2 26 Feb 07 jari 50         
2 26 Feb 07 jari 51         JLabel passLabel = new JLabel("Password:");
2 26 Feb 07 jari 52         passLabel.setHorizontalAlignment(JLabel.RIGHT);
2 26 Feb 07 jari 53         passField = new JPasswordField(20);
2 26 Feb 07 jari 54         if(password != null) {
2 26 Feb 07 jari 55             passField.setText(password);
2 26 Feb 07 jari 56             
2 26 Feb 07 jari 57         }
2 26 Feb 07 jari 58         ParameterPanel panel = new ParameterPanel("User Login Information");
2 26 Feb 07 jari 59         panel.setLayout(new GridBagLayout());
2 26 Feb 07 jari 60         
2 26 Feb 07 jari 61         panel.add(userLabel, new GridBagConstraints(0,0,1,1,0.0,0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(10,20,0,0), 0,0));
2 26 Feb 07 jari 62         panel.add(userField, new GridBagConstraints(1,0,1,1,0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,10,0,0), 0,0));
2 26 Feb 07 jari 63         panel.add(passLabel, new GridBagConstraints(0,1,1,1,0.0,0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(15,20,10,0), 0,0));
2 26 Feb 07 jari 64         panel.add(passField, new GridBagConstraints(1,1,1,1,0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(15,10,10,0), 0,0));
2 26 Feb 07 jari 65         
2 26 Feb 07 jari 66         addContent(panel);        
2 26 Feb 07 jari 67         if(password != null) {
2 26 Feb 07 jari 68          passField.selectAll();
2 26 Feb 07 jari 69             passField.grabFocus();   
2 26 Feb 07 jari 70         }
2 26 Feb 07 jari 71         pack();
2 26 Feb 07 jari 72     }
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     /** Returns the password
2 26 Feb 07 jari 75      * @return  */
2 26 Feb 07 jari 76     public String getPassword() {
2 26 Feb 07 jari 77         return new String(passField.getPassword());
2 26 Feb 07 jari 78     }
2 26 Feb 07 jari 79     
2 26 Feb 07 jari 80     /** Returns the user name
2 26 Feb 07 jari 81      * @return
2 26 Feb 07 jari 82      */    
2 26 Feb 07 jari 83     public String getUserName() {
2 26 Feb 07 jari 84         return userField.getText().trim();
2 26 Feb 07 jari 85     }
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     protected void resetControls() {
2 26 Feb 07 jari 88         this.userField.setText("");
2 26 Feb 07 jari 89         this.passField.setText("");
2 26 Feb 07 jari 90         this.userField.grabFocus();
2 26 Feb 07 jari 91     }
2 26 Feb 07 jari 92         /**
2 26 Feb 07 jari 93      * Shows the dialog.
2 26 Feb 07 jari 94      */
2 26 Feb 07 jari 95     public int showModal() {
2 26 Feb 07 jari 96         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2 26 Feb 07 jari 97         setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2);
2 26 Feb 07 jari 98         show();
2 26 Feb 07 jari 99         return result;
2 26 Feb 07 jari 100     }
2 26 Feb 07 jari 101     
2 26 Feb 07 jari 102     public static void main(String [] args) {
2 26 Feb 07 jari 103         PasswordDialog d = new PasswordDialog("LOLA User Login", "Email:", "braisted@tigr.org", "password");
2 26 Feb 07 jari 104         d.showModal();
2 26 Feb 07 jari 105         System.out.println("password ="+new String(d.getPassword()));
2 26 Feb 07 jari 106         
2 26 Feb 07 jari 107     }
2 26 Feb 07 jari 108 }