1 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 82 public class CreateUserDialog extends BaseDialog { 83 84 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 static private CreateUserDialog instance_; 105 106 107 112 public CreateUserDialog(JFrame parent) { 113 super(parent); 114 } 115 116 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 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 182 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 193 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 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 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 223 Keymap km = displayText.getKeymap(); 224 km.removeKeyStrokeBinding(enter); 225 } 226 227 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 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 294 public static CreateUserDialog instance() { 295 return instance_; 296 } 297 298 305 public static CreateUserDialog create(JFrame parent) { 306 if (instance_ == null) { 307 instance_ = new CreateUserDialog(parent); 308 } 309 return instance_; 310 } 311 312 316 public String getPassword() { 317 return password; 318 } 319 320 } 321 | Popular Tags |