KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > dialogs > AddNewUserDialog


1 package SnowMailClient.view.dialogs;
2
3 import snow.utils.gui.Icons;
4 import SnowMailClient.model.accounts.*;
5 import SnowMailClient.crypto.Utilities;
6 import snow.Language.Language;
7
8 import java.awt.*;
9 import java.awt.event.*;
10 import javax.swing.*;
11 import javax.swing.border.*;
12
13
14 public class AddNewUserDialog extends JDialog {
15
16     public boolean addNewUserOnExit = false;
17
18     private final JTextField name = new JTextField();
19     private final JTextField pass = new JTextField("password");
20     private final JTextField confirmPass = new JTextField();
21
22     public AddNewUserDialog(JDialog owner, String JavaDoc servername)
23     {
24        super(owner, "Create a new user on "+servername, true);
25
26        getContentPane().setLayout(new BorderLayout());
27
28        JPanel cpanel = new JPanel(new GridLayout(3,2));
29        getContentPane().add(cpanel, BorderLayout.CENTER);
30        cpanel.setBorder(new EmptyBorder(5,5,5,5));
31
32        cpanel.add(new JLabel("User name "));
33        cpanel.add(name);
34        cpanel.add(new JLabel("Password (press ENTER to hash) "));
35        cpanel.add(pass);
36        cpanel.add(new JLabel("Confirm (press ENTER to hash)"));
37        cpanel.add(confirmPass);
38
39        JPanel contrlpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
40        getContentPane().add(contrlpanel, BorderLayout.SOUTH);
41
42        JButton cancel = new JButton(Language.translate("Cancel"));
43        contrlpanel.add(cancel);
44        cancel.addActionListener(new ActionListener( ){
45        public void actionPerformed(ActionEvent e)
46         {
47            dispose();
48         }
49        });
50        JButton changePass = new JButton(Language.translate("Add it"), Icons.PlusIcon.shared10);
51        changePass.setBackground(Color.orange);
52        contrlpanel.add(changePass);
53        final JDialog ref = this;
54        changePass.addActionListener(new ActionListener( ){
55        public void actionPerformed(ActionEvent e)
56         {
57            // test
58
if(!pass.getText().equals( confirmPass.getText()))
59            {
60                JOptionPane.showMessageDialog(ref, "ERROR : Bad password confirmation");
61            }
62            else if(name.getText().trim().length()<1)
63            {
64                JOptionPane.showMessageDialog(ref, "ERROR : Bad username, should have at least one character !");
65            }
66            else
67            {
68              addNewUserOnExit = true;
69              dispose();
70            }
71         }
72        });
73        pass.addActionListener(new ActionListener(){
74           public void actionPerformed(ActionEvent e)
75           {
76               String JavaDoc passw = pass.getText();
77               if(!Utilities.isValidHashPasswordFormat(passw))
78               {
79                   pass.setText( Utilities.hashPassword(passw) );
80               }
81           }
82        });
83        confirmPass.addActionListener(new ActionListener(){
84           public void actionPerformed(ActionEvent e)
85           {
86               String JavaDoc pass = confirmPass.getText();
87               if(!Utilities.isValidHashPasswordFormat(pass))
88               {
89                   confirmPass.setText( Utilities.hashPassword(pass) );
90               }
91           }
92        });
93     }
94
95     public final String JavaDoc getUserName()
96     {
97       return name.getText();
98     }
99
100     public final String JavaDoc getPassword()
101     {
102       return confirmPass.getText();
103     }
104
105 }
Popular Tags