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 2003 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: ChangePasswordDialog.java,v 1.3 2003/08/17 01:32:27 tanderson Exp $ 44 */ 45 package org.exolab.jms.tools.admin; 46 47 import java.awt.BorderLayout; 48 import java.awt.FlowLayout; 49 import java.awt.event.ActionEvent; 50 import java.awt.event.ActionListener; 51 import java.awt.event.KeyEvent; 52 import java.awt.event.WindowAdapter; 53 import java.awt.event.WindowEvent; 54 55 import javax.swing.BorderFactory; 56 import javax.swing.JButton; 57 import javax.swing.JFrame; 58 import javax.swing.JLabel; 59 import javax.swing.JOptionPane; 60 import javax.swing.JPanel; 61 import javax.swing.JPasswordField; 62 import javax.swing.JSeparator; 63 import javax.swing.JTextField; 64 import javax.swing.KeyStroke; 65 import javax.swing.SwingConstants; 66 import javax.swing.SwingUtilities; 67 import javax.swing.border.Border; 68 import javax.swing.text.Keymap; 69 70 71 /*** 72 * A simple dialog to collect information for change password 73 * 74 * @version $Revision: 1.3 $ $Date: 2003/08/17 01:32:27 $ 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 jPanel1; 82 private JButton okButton; 83 private JButton cancelButton; 84 private JPanel jPanel2; 85 private JSeparator jSeparator2; 86 private JLabel jLabel1; 87 private JPanel jPanel3; 88 private JPanel jPanel4; 89 private JPanel jPanel5; 90 private JLabel jLabel2; 91 private JLabel jLabel3; 92 private JPasswordField jPasswordField1; 93 private JPasswordField jPasswordField2; 94 95 96 protected String password; 97 protected String 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 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(); 118 okButton = new JButton(); 119 cancelButton = new JButton(); 120 jPanel2 = new JPanel(); 121 jPanel3 = new JPanel(); 122 jPanel4 = new JPanel(); 123 jPanel5 = new JPanel(); 124 jLabel2 = new JLabel(); 125 jLabel2.setText("Enter password"); 126 jLabel3 = new JLabel(); 127 jLabel3.setText("Confirm password"); 128 jPasswordField1 = new JPasswordField(); 129 jPasswordField2 = new JPasswordField(); 130 131 132 jLabel1 = new JLabel(); 133 jLabel1.setText("Username"); 134 displayText = new JTextField(); 135 jSeparator2 = new JSeparator(); 136 setTitle("Change password"); 137 setModal(true); 138 setResizable(true); 139 addWindowListener(new WindowAdapter() { 140 141 public void windowClosing(WindowEvent evt) { 142 closeDialog(evt); 143 } 144 } 145 ); 146 147 jPanel1.setLayout(new FlowLayout(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(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(0, 15)); 165 Border 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(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(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() { 196 197 public void actionPerformed(ActionEvent evt) { 198 confirm(); 199 } 200 } 201 ); 202 203 cancelButton.addActionListener(new ActionListener() { 204 205 public void actionPerformed(ActionEvent evt) { 206 cancel(); 207 } 208 } 209 ); 210 211 // Have default button get the keypress event. 212 // This is broken with jdk1.3rc1 213 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 214 Keymap km = displayText.getKeymap(); 215 km.removeKeyStrokeBinding(enter); 216 } 217 218 /*** 219 * Display the create changepassword dialog box 220 */ 221 public void displayChangePassword(String username) { 222 clearPasswords(); 223 displayText.setText(username); 224 225 setLocationRelativeTo(getParent()); 226 status_ = CANCELED; 227 setVisible(true); 228 229 SwingUtilities.invokeLater(new Runnable() { 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 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 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

This page was automatically generated by Maven