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;
49 import java.awt.FlowLayout;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.KeyEvent;
53 import java.awt.event.WindowAdapter;
54 import java.awt.event.WindowEvent;
55
56 import javax.swing.BorderFactory;
57 import javax.swing.JButton;
58 import javax.swing.JFrame;
59 import javax.swing.JLabel;
60 import javax.swing.JOptionPane;
61 import javax.swing.JPanel;
62 import javax.swing.JPasswordField;
63 import javax.swing.JSeparator;
64 import javax.swing.JTextField;
65 import javax.swing.KeyStroke;
66 import javax.swing.SwingConstants;
67 import javax.swing.SwingUtilities;
68 import javax.swing.border.Border;
69 import javax.swing.text.Keymap;
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
82 private JPanel jPanel1;
83 private JButton okButton;
84 private JButton cancelButton;
85 private JPanel jPanel2;
86 private JSeparator jSeparator2;
87 private JLabel jLabel1;
88 private JPanel jPanel3;
89 private JPanel jPanel4;
90 private JLabel jLabel2;
91 private JPasswordField jPasswordField1;
92
93
94 protected String password;
95 protected String confirmedPassword;
96
97
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 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() {
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 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 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();
170 okButton = new JButton();
171 cancelButton = new JButton();
172 jPanel2 = new JPanel();
173 jPanel3 = new JPanel();
174 jPanel4 = new JPanel();
175 jLabel2 = new JLabel();
176 jLabel2.setText("Enter password");
177 jPasswordField1 = new JPasswordField();
178
179
180 jLabel1 = new JLabel();
181 jLabel1.setText("Enter the user name");
182 displayText = new JTextField();
183 jSeparator2 = new JSeparator();
184 setTitle("Logon");
185 setModal(true);
186 setResizable(true);
187 addWindowListener(new WindowAdapter() {
188
189 public void windowClosing(WindowEvent evt) {
190 closeDialog(evt);
191 }
192 }
193 );
194
195 jPanel1.setLayout(new FlowLayout(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(0, 15));
206 jPanel2.add(jPanel3, BorderLayout.NORTH);
207 jPanel2.add(jPanel4, BorderLayout.CENTER);
208 getContentPane().add(jPanel2, BorderLayout.CENTER);
209
210
211 jPanel3.setLayout(new BorderLayout(0, 15));
212 Border 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
222 jPanel4.setLayout(new BorderLayout(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() {
232
233 public void actionPerformed(ActionEvent evt) {
234 confirm();
235 }
236 }
237 );
238
239 cancelButton.addActionListener(new ActionListener() {
240
241 public void actionPerformed(ActionEvent evt) {
242 cancel();
243 }
244 }
245 );
246
247
248
249 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
250 Keymap 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 }