View Javadoc
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 2000 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: CreateUserDialog.java,v 1.3 2003/08/17 01:32:27 tanderson Exp $ 44 * 45 * Date Author Changes 46 * $Date jimm Created 47 */ 48 49 package org.exolab.jms.tools.admin; 50 51 import java.awt.BorderLayout; 52 import java.awt.FlowLayout; 53 import java.awt.event.ActionEvent; 54 import java.awt.event.ActionListener; 55 import java.awt.event.KeyEvent; 56 import java.awt.event.WindowAdapter; 57 import java.awt.event.WindowEvent; 58 59 import javax.swing.BorderFactory; 60 import javax.swing.JButton; 61 import javax.swing.JFrame; 62 import javax.swing.JLabel; 63 import javax.swing.JOptionPane; 64 import javax.swing.JPanel; 65 import javax.swing.JPasswordField; 66 import javax.swing.JSeparator; 67 import javax.swing.JTextField; 68 import javax.swing.KeyStroke; 69 import javax.swing.SwingConstants; 70 import javax.swing.SwingUtilities; 71 import javax.swing.border.Border; 72 import javax.swing.text.Keymap; 73 74 75 /*** 76 * A simple dialog to collect information for creating a User 77 * 78 * @version $Revision: 1.3 $ $Date: 2003/08/17 01:32:27 $ 79 * @author <a href="mailto:knut@lerpold.no">Knut Lerpold</a> 80 * @see AdminMgr 81 */ 82 public class CreateUserDialog extends BaseDialog { 83 84 // All the gui objects for this dialog 85 private JPanel jPanel1; 86 private JButton okButton; 87 private JButton cancelButton; 88 private JPanel jPanel2; 89 private JSeparator jSeparator2; 90 private JLabel jLabel1; 91 private JPanel jPanel3; 92 private JPanel jPanel4; 93 private JPanel jPanel5; 94 private JLabel jLabel2; 95 private JLabel jLabel3; 96 private JPasswordField jPasswordField1; 97 private JPasswordField jPasswordField2; 98 99 100 protected String password; 101 protected String confirmedPassword; 102 103 // The one and only instance of this object. 104 static private CreateUserDialog instance_; 105 106 107 /*** 108 * Creates new form UserDialog 109 * 110 * @param parent The parent form. 111 */ 112 public CreateUserDialog(JFrame parent) { 113 super(parent); 114 } 115 116 /*** 117 * Create all the gui components that comprise this form, and setup all 118 * action handlers. 119 * 120 */ 121 protected void initComponents() { 122 jPanel1 = new JPanel(); 123 okButton = new JButton(); 124 cancelButton = new JButton(); 125 jPanel2 = new JPanel(); 126 jPanel3 = new JPanel(); 127 jPanel4 = new JPanel(); 128 jPanel5 = new JPanel(); 129 jLabel2 = new JLabel(); 130 jLabel2.setText("Enter password"); 131 jLabel3 = new JLabel(); 132 jLabel3.setText("Confirm password"); 133 jPasswordField1 = new JPasswordField(); 134 jPasswordField2 = new JPasswordField(); 135 136 137 jLabel1 = new JLabel(); 138 jLabel1.setText("Enter the user name"); 139 displayText = new JTextField(); 140 jSeparator2 = new JSeparator(); 141 setTitle("Create User"); 142 setModal(true); 143 setResizable(true); 144 addWindowListener(new WindowAdapter() { 145 146 public void windowClosing(WindowEvent evt) { 147 closeDialog(evt); 148 } 149 } 150 ); 151 152 jPanel1.setLayout(new FlowLayout(1, 50, 10)); 153 okButton.setToolTipText("Press to confirm Action"); 154 okButton.setText("OK"); 155 getRootPane().setDefaultButton(okButton); 156 jPanel1.add(okButton); 157 cancelButton.setToolTipText("Press to abort Action"); 158 cancelButton.setText("Cancel"); 159 jPanel1.add(cancelButton); 160 getContentPane().add(jPanel1, BorderLayout.SOUTH); 161 162 jPanel2.setLayout(new BorderLayout(0, 15)); 163 jPanel2.add(jPanel3, BorderLayout.NORTH); 164 jPanel2.add(jPanel4, BorderLayout.CENTER); 165 jPanel2.add(jPanel5, BorderLayout.SOUTH); 166 getContentPane().add(jPanel2, BorderLayout.CENTER); 167 168 //Username 169 jPanel3.setLayout(new BorderLayout(0, 15)); 170 Border loweredbevel = BorderFactory.createLoweredBevelBorder(); 171 displayText.setBorder(loweredbevel); 172 displayText.setEditable(true); 173 displayText.setText(""); 174 displayText.setToolTipText 175 ("Enter the unique name for this user"); 176 displayText.setHorizontalAlignment(SwingConstants.LEFT); 177 jPanel3.add(jLabel1, BorderLayout.NORTH); 178 jPanel3.add(displayText, BorderLayout.CENTER); 179 jPanel3.add(jSeparator2, BorderLayout.SOUTH); 180 //getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER); 181 182 //Password 183 jPanel4.setLayout(new BorderLayout(0, 15)); 184 jPasswordField1.setBorder(loweredbevel); 185 jPasswordField1.setEditable(true); 186 jPasswordField1.setText(""); 187 jPasswordField1.setHorizontalAlignment(SwingConstants.LEFT); 188 jPanel4.add(jLabel2, BorderLayout.NORTH); 189 jPanel4.add(jPasswordField1, BorderLayout.CENTER); 190 jPanel4.add(jSeparator2, BorderLayout.SOUTH); 191 //getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 192 193 //Confirm password 194 jPanel5.setLayout(new BorderLayout(0, 15)); 195 jPasswordField2.setBorder(loweredbevel); 196 jPasswordField2.setEditable(true); 197 jPasswordField2.setText(""); 198 jPasswordField2.setHorizontalAlignment(SwingConstants.LEFT); 199 jPanel5.add(jLabel3, BorderLayout.NORTH); 200 jPanel5.add(jPasswordField2, BorderLayout.CENTER); 201 jPanel5.add(jSeparator2, BorderLayout.SOUTH); 202 //getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER); 203 204 okButton.addActionListener(new ActionListener() { 205 206 public void actionPerformed(ActionEvent evt) { 207 confirm(); 208 } 209 } 210 ); 211 212 cancelButton.addActionListener(new ActionListener() { 213 214 public void actionPerformed(ActionEvent evt) { 215 cancel(); 216 } 217 } 218 ); 219 220 // Have default button get the keypress event. 221 // This is broken with jdk1.3rc1 222 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 223 Keymap km = displayText.getKeymap(); 224 km.removeKeyStrokeBinding(enter); 225 } 226 227 /*** 228 * Display the create user dialog box 229 */ 230 public void displayCreateUser() { 231 clearPasswords(); 232 displayText.setText(""); 233 234 setLocationRelativeTo(getParent()); 235 status_ = CANCELED; 236 setVisible(true); 237 238 SwingUtilities.invokeLater(new Runnable() { 239 240 public void run() { 241 cancelButton.requestFocus(); 242 } 243 } 244 ); 245 } 246 247 /*** 248 * Override confirm to be able to check password 249 * 250 */ 251 protected void confirm() { 252 name_ = displayText.getText(); 253 password = String.valueOf(jPasswordField1.getPassword()); 254 confirmedPassword = String.valueOf(jPasswordField2.getPassword()); 255 256 if (name_ == null || name_.equals("")) { 257 JOptionPane.showMessageDialog 258 (this, "A name must be suplied", "Create Error", 259 JOptionPane.ERROR_MESSAGE); 260 } else if (password == null || password.equals("")) { 261 clearPasswords(); 262 JOptionPane.showMessageDialog 263 (this, "A password must be suplied", "Create Error", 264 JOptionPane.ERROR_MESSAGE); 265 } else if (confirmedPassword == null || confirmedPassword.equals("")) { 266 clearPasswords(); 267 JOptionPane.showMessageDialog 268 (this, "A confirmed password must be suplied", "Create Error", 269 JOptionPane.ERROR_MESSAGE); 270 } else if (!password.equals(confirmedPassword)) { 271 clearPasswords(); 272 JOptionPane.showMessageDialog 273 (this, "Confirmed password don't match password", "Create Error", 274 JOptionPane.ERROR_MESSAGE); 275 } else { 276 status_ = CONFIRMED; 277 setVisible(false); 278 dispose(); 279 } 280 } 281 282 private void clearPasswords() { 283 jPasswordField1.setText(""); 284 jPasswordField2.setText(""); 285 } 286 287 /*** 288 * Get the one and only instance of this dialog. The dialog must first 289 * have been created with the create call below. 290 * 291 * @return UserDialog the one and only instance 292 * 293 */ 294 public static CreateUserDialog instance() { 295 return instance_; 296 } 297 298 /*** 299 * Create the one and only instance of the User Dialog. 300 * 301 * @param parent the parent of this dialog 302 * @return QueueDialog the one and only instance 303 * 304 */ 305 public static CreateUserDialog create(JFrame parent) { 306 if (instance_ == null) { 307 instance_ = new CreateUserDialog(parent); 308 } 309 return instance_; 310 } 311 312 /*** Getter for property password. 313 * @return Value of property password. 314 * 315 */ 316 public String getPassword() { 317 return password; 318 } 319 320 }

This page was automatically generated by Maven