KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > CreateUserDialog


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): Alexander Fedorowicz
20  * Contributor(s):
21  */

22 package org.objectweb.joram.client.tools.admin;
23
24 import javax.swing.*;
25 import java.awt.*;
26 import java.awt.event.*;
27
28
29 public class CreateUserDialog extends JDialog {
30   private static CreateUserDialog dialog;
31   private static JLabel nameLabel;
32   private static JLabel passwdLabel;
33   private static JLabel passwd2Label;
34
35   private Frame parent = null;
36   private String JavaDoc name = "";
37   private String JavaDoc passwd = "";
38   private String JavaDoc passwd2 = "";
39
40   private JTextField nameField = null;
41   private JPasswordField passwdField = null;
42   private JPasswordField passwd2Field = null;
43   private JButton submitButton = null;
44   private boolean actionCancelled = false;
45
46   /**
47    * Set up the dialog. The first argument can be null,
48    * but it really should be a component in the dialog's
49    * controlling frame.
50    */

51   public static CreateUserDialog initialize(Frame parent) {
52     // These JLabel objects are required by the constructor
53
nameLabel = new JLabel("User name: ");
54     passwdLabel = new JLabel("Password: ");
55     passwd2Label = new JLabel("Password again: ");
56
57     dialog = new CreateUserDialog(parent);
58     
59     return dialog;
60   }
61
62   /**
63    * Show the initialized dialog. The first argument should
64    * be null if you want the dialog to come up in the center
65    * of the screen. Otherwise, the argument should be the
66    * component on top of which the dialog should appear.
67    */

68   public static CreateUserDialog showDialog() {
69     return showDialog("", false);
70   }
71
72   public static CreateUserDialog showDialog(String JavaDoc name, boolean passwdOnly) {
73     dialog.nameField.setText(name);
74     dialog.passwdField.setText("");
75     dialog.passwd2Field.setText("");
76     
77     if (passwdOnly) {
78       dialog.setTitle("Change Password");
79       dialog.nameField.setEditable(false);
80       dialog.submitButton.setText("Apply");
81     }
82     else {
83       dialog.setTitle("Create User");
84       dialog.nameField.setEditable(true);
85       dialog.submitButton.setText("Create");
86     }
87     
88     dialog.setActionCancelled(false);
89     dialog.setLocationRelativeTo(dialog.parent);
90     dialog.setVisible(true);
91     return dialog;
92   }
93
94
95   private CreateUserDialog(Frame frame)
96   {
97     super(frame, true);
98
99     parent = frame;
100
101     // Buttons
102
submitButton = new JButton("Create");
103     JButton cancelButton = new JButton("Cancel");
104     cancelButton.addActionListener(new ActionListener() {
105       public void actionPerformed(ActionEvent e) {
106         CreateUserDialog.dialog.setVisible(false);
107         CreateUserDialog.dialog.setActionCancelled(true);
108       }
109     });
110
111     submitButton.addActionListener(new ActionListener() {
112       public void actionPerformed(ActionEvent e) {
113         CreateUserDialog.dialog.setVisible(false);
114         name = nameField.getText();
115         passwd = new String JavaDoc(passwdField.getPassword());
116         passwd2 = new String JavaDoc(passwd2Field.getPassword());
117       }
118     });
119     getRootPane().setDefaultButton(submitButton);
120
121     // Main part of the dialog
122
nameField = new JTextField(name, 20);
123     passwdField = new JPasswordField(passwd, 20);
124     passwd2Field = new JPasswordField(passwd2, 20);
125     JLabel[] labels = {nameLabel, passwdLabel, passwd2Label};
126     JTextField[] textFields = {nameField, passwdField, passwd2Field};
127     JPanel form = new InputFormPanel(labels, textFields);
128     form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
129     
130     //Lay out the buttons from left to right.
131
JPanel buttonPane = new JPanel();
132     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
133     buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
134     buttonPane.add(Box.createHorizontalGlue());
135     buttonPane.add(submitButton);
136     buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
137     buttonPane.add(cancelButton);
138
139     //Put everything together, using the content pane's BorderLayout.
140
Container contentPane = getContentPane();
141     contentPane.add(form, BorderLayout.CENTER);
142     contentPane.add(buttonPane, BorderLayout.SOUTH);
143
144     pack();
145   }
146
147   public boolean getActionCancelled() { return actionCancelled; }
148     
149   public void setActionCancelled(boolean cancelled)
150   {
151     actionCancelled = cancelled;
152   }
153   
154   public String JavaDoc getUserName() { return name; }
155   
156   public void setUserName(String JavaDoc name)
157   {
158     this.name = name;
159   }
160   
161   public String JavaDoc getPassword() { return passwd; }
162
163   public String JavaDoc getConfirmationPassword() { return passwd2; }
164   
165   public void setPassword(String JavaDoc passwd)
166   {
167     this.passwd = passwd;
168     this.passwd2 = passwd;
169   }
170 }
171
Popular Tags