1   /*  UserPasswordDialog.java
2    *
3    *  Copyright (c) 1998-2005, The University of Sheffield.
4    *
5    *  This file is part of GATE (see http://gate.ac.uk/), and is free
6    *  software, licenced under the GNU Library General Public License,
7    *  Version 2, June 1991 (in the distribution as file licence.html,
8    *  and also available at http://gate.ac.uk/gate/licence.html).
9    *
10   *  Kalina Bontcheva,  03/October/2001
11   *
12   *  $Id: UserPasswordDialog.java,v 1.4 2005/01/11 13:51:35 ian Exp $
13   *
14   */
15  
16  package gate.gui;
17  
18  import java.awt.Component;
19  
20  import javax.swing.*;
21  
22  
23  public class UserPasswordDialog {
24  
25    String userName = "";
26    String userPass = "";
27  
28    public UserPasswordDialog() {
29    }
30  
31    public boolean showPasswordDialog(String message, Component parent) {
32  
33      JPanel listPanel = new JPanel();
34      listPanel.setLayout(new BoxLayout(listPanel,BoxLayout.X_AXIS));
35  
36      JPanel panel1 = new JPanel();
37      panel1.setLayout(new BoxLayout(panel1,BoxLayout.Y_AXIS));
38      panel1.add(new JLabel("User name: "));
39      panel1.add(new JLabel("Password: "));
40  
41      JPanel panel2 = new JPanel();
42      panel2.setLayout(new BoxLayout(panel2,BoxLayout.Y_AXIS));
43      JTextField usrField = new JTextField(30);
44      panel2.add(usrField);
45      JPasswordField pwdField = new JPasswordField(30);
46      panel2.add(pwdField);
47  
48      listPanel.add(panel1);
49      listPanel.add(Box.createHorizontalStrut(30));
50      listPanel.add(panel2);
51  
52      if(OkCancelDialog.showDialog( parent,
53                                    listPanel,
54                                    message)){
55        userName = usrField.getText();
56        userPass = new String(pwdField.getPassword());
57        return true;
58      }
59  
60      return false;
61    }
62  
63    public String getUserName() {
64      return userName;
65    }
66  
67    public String getPassword() {
68      return userPass;
69    }
70  
71  }