1 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 79 public class CreateLogonDialog extends BaseDialog { 80 81 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 static private CreateLogonDialog instance_; 99 100 101 106 public CreateLogonDialog(JFrame parent) { 107 super(parent); 108 } 109 110 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 137 public static CreateLogonDialog instance() { 138 return instance_; 139 } 140 141 148 public static CreateLogonDialog create(JFrame parent) { 149 if (instance_ == null) { 150 instance_ = new CreateLogonDialog(parent); 151 } 152 return instance_; 153 } 154 155 160 public String getPassword() { 161 return password; 162 } 163 164 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 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 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 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 250 Keymap km = displayText.getKeymap(); 251 km.removeKeyStrokeBinding(enter); 252 } 253 254 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 |