mev-4.0.01/source/org/tigr/microarray/mev/DatabaseLoginDialog.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, 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  * $RCSfile: DatabaseLoginDialog.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.4 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 20:59:41 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Font;
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.event.ActionEvent;
2 26 Feb 07 jari 18 import java.awt.event.ActionListener;
2 26 Feb 07 jari 19 import java.awt.event.KeyEvent;
2 26 Feb 07 jari 20 import java.awt.event.KeyListener;
2 26 Feb 07 jari 21 import java.util.Hashtable;
2 26 Feb 07 jari 22
2 26 Feb 07 jari 23 import javax.swing.JButton;
2 26 Feb 07 jari 24 import javax.swing.JFrame;
2 26 Feb 07 jari 25 import javax.swing.JLabel;
2 26 Feb 07 jari 26 import javax.swing.JPasswordField;
2 26 Feb 07 jari 27 import javax.swing.JTextField;
2 26 Feb 07 jari 28
2 26 Feb 07 jari 29 import org.tigr.util.awt.ActionInfoDialog;
2 26 Feb 07 jari 30 import org.tigr.util.awt.ActionInfoEvent;
2 26 Feb 07 jari 31 import org.tigr.util.awt.GBA;
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33 public class DatabaseLoginDialog extends ActionInfoDialog {
2 26 Feb 07 jari 34     private JFrame parent;
2 26 Feb 07 jari 35     JLabel usernameLabel, passwordLabel;
2 26 Feb 07 jari 36     JTextField usernameTextField;
2 26 Feb 07 jari 37     JPasswordField passwordField;
2 26 Feb 07 jari 38     JButton okButton, cancelButton;
2 26 Feb 07 jari 39     Font databaseLoginDialogFont;
2 26 Feb 07 jari 40     GBA gba;
2 26 Feb 07 jari 41     
2 26 Feb 07 jari 42     public DatabaseLoginDialog(JFrame parent) {
2 26 Feb 07 jari 43   super(parent, true);
2 26 Feb 07 jari 44   try {
2 26 Feb 07 jari 45       this.parent = parent;
2 26 Feb 07 jari 46       gba = new GBA();
2 26 Feb 07 jari 47       
2 26 Feb 07 jari 48       usernameLabel = new JLabel("Username: ");
2 26 Feb 07 jari 49       
2 26 Feb 07 jari 50       usernameTextField = new JTextField(10);
2 26 Feb 07 jari 51       usernameTextField.addKeyListener(new EventListener());
2 26 Feb 07 jari 52       
2 26 Feb 07 jari 53       passwordLabel = new JLabel("Password: ");
2 26 Feb 07 jari 54       
2 26 Feb 07 jari 55       passwordField = new JPasswordField(10);
2 26 Feb 07 jari 56       passwordField.setEchoChar('*');
2 26 Feb 07 jari 57       passwordField.addKeyListener(new EventListener());
2 26 Feb 07 jari 58       
2 26 Feb 07 jari 59       okButton = new JButton("Login");
2 26 Feb 07 jari 60       okButton.addActionListener(new EventListener());
2 26 Feb 07 jari 61       
2 26 Feb 07 jari 62       cancelButton = new JButton("Cancel");
2 26 Feb 07 jari 63       cancelButton.addActionListener(new EventListener());
2 26 Feb 07 jari 64       
2 26 Feb 07 jari 65       contentPane.setLayout(new GridBagLayout());
2 26 Feb 07 jari 66       gba.add(contentPane, usernameLabel, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 67       gba.add(contentPane, usernameTextField, 1, 0, 1, 1, 1, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 68       gba.add(contentPane, passwordLabel, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 69       gba.add(contentPane, passwordField, 1, 1, 2, 1, 1, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 70       gba.add(contentPane, cancelButton, 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 71       gba.add(contentPane, okButton, 1, 2, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0);
2 26 Feb 07 jari 72       
2 26 Feb 07 jari 73       pack();
2 26 Feb 07 jari 74       setResizable(false);
2 26 Feb 07 jari 75       setTitle("Database Login");
2 26 Feb 07 jari 76       usernameTextField.grabFocus();
2 26 Feb 07 jari 77       setLocation(150, 150);
2 26 Feb 07 jari 78   } catch (Exception e) {
2 26 Feb 07 jari 79       System.out.println("Exception (DatabaseLoginDialog.const()): " + e);
2 26 Feb 07 jari 80   }
2 26 Feb 07 jari 81     }
2 26 Feb 07 jari 82     
2 26 Feb 07 jari 83     class EventListener implements ActionListener, KeyListener {
2 26 Feb 07 jari 84   public void actionPerformed(ActionEvent event) {
2 26 Feb 07 jari 85       if (event.getSource() == okButton) {
2 26 Feb 07 jari 86     String username = usernameTextField.getText();
2 26 Feb 07 jari 87     String password = new String(passwordField.getPassword());
2 26 Feb 07 jari 88     hide();
2 26 Feb 07 jari 89     
2 26 Feb 07 jari 90     Hashtable hash = new Hashtable();
2 26 Feb 07 jari 91     hash.put(new String("username"), username);
2 26 Feb 07 jari 92     hash.put(new String("password"), password);
2 26 Feb 07 jari 93     fireEvent(new ActionInfoEvent(this, hash));
2 26 Feb 07 jari 94     
2 26 Feb 07 jari 95     dispose();
2 26 Feb 07 jari 96       } else if (event.getSource() == cancelButton) dispose();
2 26 Feb 07 jari 97   }
2 26 Feb 07 jari 98   
2 26 Feb 07 jari 99   public void keyPressed(KeyEvent event) {
2 26 Feb 07 jari 100       if (event.getKeyCode() == KeyEvent.VK_ENTER) {
2 26 Feb 07 jari 101     String username = usernameTextField.getText();
2 26 Feb 07 jari 102     String password = new String(passwordField.getPassword());
2 26 Feb 07 jari 103     hide();
2 26 Feb 07 jari 104     
2 26 Feb 07 jari 105     Hashtable hash = new Hashtable();
2 26 Feb 07 jari 106     hash.put(new String("username"), username);
2 26 Feb 07 jari 107     hash.put(new String("password"), password);
2 26 Feb 07 jari 108     fireEvent(new ActionInfoEvent(this, hash));
2 26 Feb 07 jari 109     
2 26 Feb 07 jari 110     dispose();
2 26 Feb 07 jari 111       }
2 26 Feb 07 jari 112   }
2 26 Feb 07 jari 113   
2 26 Feb 07 jari 114   public void keyReleased(KeyEvent event) {;}
2 26 Feb 07 jari 115   public void keyTyped(KeyEvent event) {;}
2 26 Feb 07 jari 116     }
2 26 Feb 07 jari 117 }