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