KickJava   Java API By Example, From Geeks To Geeks.

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


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: CreateLogonDialog.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44  */

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

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

106     public CreateLogonDialog(JFrame JavaDoc parent) {
107         super(parent);
108     }
109
110     /**
111      * Display the create queue dialog box
112      */

113     public void displayCreateLogon() {
114         clearPasswords();
115         displayText.setText("");
116
117         setLocationRelativeTo(getParent());
118         status_ = CANCELED;
119         setVisible(true);
120
121         SwingUtilities.invokeLater(new Runnable JavaDoc() {
122
123             public void run() {
124                 cancelButton.requestFocus();
125             }
126         }
127         );
128     }
129
130     /**
131      * Get the one and only instance of this dialog. The dialog must first
132      * have been created with the create call below.
133      *
134      * @return LogonDialog the one and only instance
135      *
136      */

137     public static CreateLogonDialog instance() {
138         return instance_;
139     }
140
141     /**
142      * Create the one and only instance of the Logon Dialog.
143      *
144      * @param parent the parent of this dialog
145      * @return QueueDialog the one and only instance
146      *
147      */

148     public static CreateLogonDialog create(JFrame JavaDoc parent) {
149         if (instance_ == null) {
150             instance_ = new CreateLogonDialog(parent);
151         }
152         return instance_;
153     }
154
155     /**
156      * Returns the password
157      *
158      * @return the password
159      */

160     public String JavaDoc getPassword() {
161         return password;
162     }
163
164     /**
165      * Create all the gui components that comprise this form, and setup all
166      * action handlers.
167      */

168     protected void initComponents() {
169         jPanel1 = new JPanel JavaDoc();
170         okButton = new JButton JavaDoc();
171         cancelButton = new JButton JavaDoc();
172         jPanel2 = new JPanel JavaDoc();
173         jPanel3 = new JPanel JavaDoc();
174         jPanel4 = new JPanel JavaDoc();
175         jLabel2 = new JLabel JavaDoc();
176         jLabel2.setText("Enter password");
177         jPasswordField1 = new JPasswordField JavaDoc();
178
179
180         jLabel1 = new JLabel JavaDoc();
181         jLabel1.setText("Enter the user name");
182         displayText = new JTextField JavaDoc();
183         jSeparator2 = new JSeparator JavaDoc();
184         setTitle("Logon");
185         setModal(true);
186         setResizable(true);
187         addWindowListener(new WindowAdapter JavaDoc() {
188
189             public void windowClosing(WindowEvent JavaDoc evt) {
190                 closeDialog(evt);
191             }
192         }
193         );
194
195         jPanel1.setLayout(new FlowLayout JavaDoc(1, 50, 10));
196         okButton.setToolTipText("Press to confirm Action");
197         okButton.setText("OK");
198         getRootPane().setDefaultButton(okButton);
199         jPanel1.add(okButton);
200         cancelButton.setToolTipText("Press to abort Action");
201         cancelButton.setText("Cancel");
202         jPanel1.add(cancelButton);
203         getContentPane().add(jPanel1, BorderLayout.SOUTH);
204
205         jPanel2.setLayout(new BorderLayout JavaDoc(0, 15));
206         jPanel2.add(jPanel3, BorderLayout.NORTH);
207         jPanel2.add(jPanel4, BorderLayout.CENTER);
208         getContentPane().add(jPanel2, BorderLayout.CENTER);
209
210         //Username
211
jPanel3.setLayout(new BorderLayout JavaDoc(0, 15));
212         Border JavaDoc loweredbevel = BorderFactory.createLoweredBevelBorder();
213         displayText.setBorder(loweredbevel);
214         displayText.setEditable(true);
215         displayText.setText("");
216         displayText.setHorizontalAlignment(SwingConstants.LEFT);
217         jPanel3.add(jLabel1, BorderLayout.NORTH);
218         jPanel3.add(displayText, BorderLayout.CENTER);
219         jPanel3.add(jSeparator2, BorderLayout.SOUTH);
220
221         //Password
222
jPanel4.setLayout(new BorderLayout JavaDoc(0, 15));
223         jPasswordField1.setBorder(loweredbevel);
224         jPasswordField1.setEditable(true);
225         jPasswordField1.setText("");
226         jPasswordField1.setHorizontalAlignment(SwingConstants.LEFT);
227         jPanel4.add(jLabel2, BorderLayout.NORTH);
228         jPanel4.add(jPasswordField1, BorderLayout.CENTER);
229         jPanel4.add(jSeparator2, BorderLayout.SOUTH);
230
231         okButton.addActionListener(new ActionListener JavaDoc() {
232
233             public void actionPerformed(ActionEvent JavaDoc evt) {
234                 confirm();
235             }
236         }
237         );
238
239         cancelButton.addActionListener(new ActionListener JavaDoc() {
240
241             public void actionPerformed(ActionEvent JavaDoc evt) {
242                 cancel();
243             }
244         }
245         );
246
247         // Have default button get the keypress event.
248
// This is broken with jdk1.3rc1
249
KeyStroke JavaDoc enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
250         Keymap JavaDoc km = displayText.getKeymap();
251         km.removeKeyStrokeBinding(enter);
252     }
253
254     /**
255      * Override confirm to be able to check password
256      */

257     protected void confirm() {
258         name_ = displayText.getText();
259         password = String.valueOf(jPasswordField1.getPassword());
260
261         if (name_ == null || name_.equals("")) {
262             JOptionPane.showMessageDialog
263                 (this, "A name must be suplied", "Create Error",
264                     JOptionPane.ERROR_MESSAGE);
265         } else if (password == null || password.equals("")) {
266             clearPasswords();
267             JOptionPane.showMessageDialog
268                 (this, "A password must be suplied", "Create Error",
269                     JOptionPane.ERROR_MESSAGE);
270         } else {
271             status_ = CONFIRMED;
272             setVisible(false);
273             dispose();
274         }
275     }
276
277     private void clearPasswords() {
278         jPasswordField1.setText("");
279     }
280
281 }
282
Popular Tags