KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tools > admin > ChangePasswordDialog


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: ChangePasswordDialog.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44  */

45 package org.exolab.jms.tools.admin;
46
47 import java.awt.BorderLayout JavaDoc;
48 import java.awt.FlowLayout JavaDoc;
49 import java.awt.event.ActionEvent JavaDoc;
50 import java.awt.event.ActionListener JavaDoc;
51 import java.awt.event.KeyEvent JavaDoc;
52 import java.awt.event.WindowAdapter JavaDoc;
53 import java.awt.event.WindowEvent JavaDoc;
54
55 import javax.swing.BorderFactory JavaDoc;
56 import javax.swing.JButton JavaDoc;
57 import javax.swing.JFrame JavaDoc;
58 import javax.swing.JLabel JavaDoc;
59 import javax.swing.JOptionPane JavaDoc;
60 import javax.swing.JPanel JavaDoc;
61 import javax.swing.JPasswordField JavaDoc;
62 import javax.swing.JSeparator JavaDoc;
63 import javax.swing.JTextField JavaDoc;
64 import javax.swing.KeyStroke JavaDoc;
65 import javax.swing.SwingConstants JavaDoc;
66 import javax.swing.SwingUtilities JavaDoc;
67 import javax.swing.border.Border JavaDoc;
68 import javax.swing.text.Keymap JavaDoc;
69
70
71 /**
72  * A simple dialog to collect information for change password
73  *
74  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
75  * @author <a HREF="mailto:knut@lerpold.no">Knut Lerpold</a>
76  * @see AdminMgr
77  */

78 public class ChangePasswordDialog extends BaseDialog {
79
80     // All the gui objects for this dialog
81
private JPanel JavaDoc jPanel1;
82     private JButton JavaDoc okButton;
83     private JButton JavaDoc cancelButton;
84     private JPanel JavaDoc jPanel2;
85     private JSeparator JavaDoc jSeparator2;
86     private JLabel JavaDoc jLabel1;
87     private JPanel JavaDoc jPanel3;
88     private JPanel JavaDoc jPanel4;
89     private JPanel JavaDoc jPanel5;
90     private JLabel JavaDoc jLabel2;
91     private JLabel JavaDoc jLabel3;
92     private JPasswordField JavaDoc jPasswordField1;
93     private JPasswordField JavaDoc jPasswordField2;
94
95
96     protected String JavaDoc password;
97     protected String JavaDoc confirmedPassword;
98
99     // The one and only instance of this object.
100
static private ChangePasswordDialog instance_;
101
102
103     /**
104      * Creates new ChangePasswordDialog form
105      *
106      * @param parent The parent form.
107      */

108     public ChangePasswordDialog(JFrame JavaDoc parent) {
109         super(parent);
110     }
111
112     /**
113      * Create all the gui components that comprise this form, and setup all
114      * action handlers.
115      */

116     protected void initComponents() {
117         jPanel1 = new JPanel JavaDoc();
118         okButton = new JButton JavaDoc();
119         cancelButton = new JButton JavaDoc();
120         jPanel2 = new JPanel JavaDoc();
121         jPanel3 = new JPanel JavaDoc();
122         jPanel4 = new JPanel JavaDoc();
123         jPanel5 = new JPanel JavaDoc();
124         jLabel2 = new JLabel JavaDoc();
125         jLabel2.setText("Enter password");
126         jLabel3 = new JLabel JavaDoc();
127         jLabel3.setText("Confirm password");
128         jPasswordField1 = new JPasswordField JavaDoc();
129         jPasswordField2 = new JPasswordField JavaDoc();
130
131
132         jLabel1 = new JLabel JavaDoc();
133         jLabel1.setText("Username");
134         displayText = new JTextField JavaDoc();
135         jSeparator2 = new JSeparator JavaDoc();
136         setTitle("Change password");
137         setModal(true);
138         setResizable(true);
139         addWindowListener(new WindowAdapter JavaDoc() {
140
141             public void windowClosing(WindowEvent JavaDoc evt) {
142                 closeDialog(evt);
143             }
144         }
145         );
146
147         jPanel1.setLayout(new FlowLayout JavaDoc(1, 50, 10));
148         okButton.setToolTipText("Press to confirm Action");
149         okButton.setText("OK");
150         getRootPane().setDefaultButton(okButton);
151         jPanel1.add(okButton);
152         cancelButton.setToolTipText("Press to abort Action");
153         cancelButton.setText("Cancel");
154         jPanel1.add(cancelButton);
155         getContentPane().add(jPanel1, BorderLayout.SOUTH);
156
157         jPanel2.setLayout(new BorderLayout JavaDoc(0, 15));
158         jPanel2.add(jPanel3, BorderLayout.NORTH);
159         jPanel2.add(jPanel4, BorderLayout.CENTER);
160         jPanel2.add(jPanel5, BorderLayout.SOUTH);
161         getContentPane().add(jPanel2, BorderLayout.CENTER);
162
163         //Username
164
jPanel3.setLayout(new BorderLayout JavaDoc(0, 15));
165         Border JavaDoc loweredbevel = BorderFactory.createLoweredBevelBorder();
166         displayText.setBorder(loweredbevel);
167         displayText.setEditable(false);
168         displayText.setEnabled(false);
169         displayText.setHorizontalAlignment(SwingConstants.LEFT);
170         jPanel3.add(jLabel1, BorderLayout.NORTH);
171         jPanel3.add(displayText, BorderLayout.CENTER);
172         jPanel3.add(jSeparator2, BorderLayout.SOUTH);
173         //getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);
174

175         //Password
176
jPanel4.setLayout(new BorderLayout JavaDoc(0, 15));
177         jPasswordField1.setBorder(loweredbevel);
178         jPasswordField1.setEditable(true);
179         jPasswordField1.setText("");
180         jPasswordField1.setHorizontalAlignment(SwingConstants.LEFT);
181         jPanel4.add(jLabel2, BorderLayout.NORTH);
182         jPanel4.add(jPasswordField1, BorderLayout.CENTER);
183         jPanel4.add(jSeparator2, BorderLayout.SOUTH);
184
185         //Confirm password
186
jPanel5.setLayout(new BorderLayout JavaDoc(0, 15));
187         jPasswordField2.setBorder(loweredbevel);
188         jPasswordField2.setEditable(true);
189         jPasswordField2.setText("");
190         jPasswordField2.setHorizontalAlignment(SwingConstants.LEFT);
191         jPanel5.add(jLabel3, BorderLayout.NORTH);
192         jPanel5.add(jPasswordField2, BorderLayout.CENTER);
193         jPanel5.add(jSeparator2, BorderLayout.SOUTH);
194
195         okButton.addActionListener(new ActionListener JavaDoc() {
196
197             public void actionPerformed(ActionEvent JavaDoc evt) {
198                 confirm();
199             }
200         }
201         );
202
203         cancelButton.addActionListener(new ActionListener JavaDoc() {
204
205             public void actionPerformed(ActionEvent JavaDoc evt) {
206                 cancel();
207             }
208         }
209         );
210
211         // Have default button get the keypress event.
212
// This is broken with jdk1.3rc1
213
KeyStroke JavaDoc enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
214         Keymap JavaDoc km = displayText.getKeymap();
215         km.removeKeyStrokeBinding(enter);
216     }
217
218     /**
219      * Display the create changepassword dialog box
220      */

221     public void displayChangePassword(String JavaDoc username) {
222         clearPasswords();
223         displayText.setText(username);
224
225         setLocationRelativeTo(getParent());
226         status_ = CANCELED;
227         setVisible(true);
228
229         SwingUtilities.invokeLater(new Runnable JavaDoc() {
230
231             public void run() {
232                 cancelButton.requestFocus();
233             }
234         });
235     }
236
237     /**
238      * Get the one and only instance of this dialog. The dialog must first
239      * have been created with the create call below.
240      *
241      * @return ChangePasswordDialog the one and only instance
242      *
243      */

244     public static ChangePasswordDialog instance() {
245         return instance_;
246     }
247
248     /**
249      * Create the one and only instance of the ChangePassword Dialog.
250      *
251      * @param parent the parent of this dialog
252      * @return ChangePasswordDialog the one and only instance
253      *
254      */

255     public static ChangePasswordDialog create(JFrame JavaDoc parent) {
256         if (instance_ == null) {
257             instance_ = new ChangePasswordDialog(parent);
258         }
259         return instance_;
260     }
261
262     /**
263      * Returns the password
264      *
265      * @return the password
266      */

267     public String JavaDoc getPassword() {
268         return password;
269     }
270
271     /**
272      * Override confirm to be able to check password
273      *
274      */

275     protected void confirm() {
276         password = String.valueOf(jPasswordField1.getPassword());
277         confirmedPassword = String.valueOf(jPasswordField2.getPassword());
278
279         if (password == null || password.equals("")) {
280             clearPasswords();
281             JOptionPane.showMessageDialog
282                 (this, "A password must be suplied", "Create Error",
283                     JOptionPane.ERROR_MESSAGE);
284         } else if (confirmedPassword == null || confirmedPassword.equals("")) {
285             clearPasswords();
286             JOptionPane.showMessageDialog
287                 (this, "A confirmed password must be suplied", "Create Error",
288                     JOptionPane.ERROR_MESSAGE);
289         } else if (!password.equals(confirmedPassword)) {
290             clearPasswords();
291             JOptionPane.showMessageDialog
292                 (this, "Confirmed password don't match password", "Create Error",
293                     JOptionPane.ERROR_MESSAGE);
294         } else {
295             JOptionPane.showMessageDialog
296                 (this, "Password has changed", "Info",
297                     JOptionPane.INFORMATION_MESSAGE);
298             status_ = CONFIRMED;
299             setVisible(false);
300             dispose();
301         }
302     }
303
304     private void clearPasswords() {
305         jPasswordField1.setText("");
306         jPasswordField2.setText("");
307     }
308
309 }
310
311
Popular Tags