1 22 package org.objectweb.joram.client.tools.admin; 23 24 import javax.swing.*; 25 import java.awt.*; 26 import java.awt.event.*; 27 28 29 public class CreateUserDialog extends JDialog { 30 private static CreateUserDialog dialog; 31 private static JLabel nameLabel; 32 private static JLabel passwdLabel; 33 private static JLabel passwd2Label; 34 35 private Frame parent = null; 36 private String name = ""; 37 private String passwd = ""; 38 private String passwd2 = ""; 39 40 private JTextField nameField = null; 41 private JPasswordField passwdField = null; 42 private JPasswordField passwd2Field = null; 43 private JButton submitButton = null; 44 private boolean actionCancelled = false; 45 46 51 public static CreateUserDialog initialize(Frame parent) { 52 nameLabel = new JLabel("User name: "); 54 passwdLabel = new JLabel("Password: "); 55 passwd2Label = new JLabel("Password again: "); 56 57 dialog = new CreateUserDialog(parent); 58 59 return dialog; 60 } 61 62 68 public static CreateUserDialog showDialog() { 69 return showDialog("", false); 70 } 71 72 public static CreateUserDialog showDialog(String name, boolean passwdOnly) { 73 dialog.nameField.setText(name); 74 dialog.passwdField.setText(""); 75 dialog.passwd2Field.setText(""); 76 77 if (passwdOnly) { 78 dialog.setTitle("Change Password"); 79 dialog.nameField.setEditable(false); 80 dialog.submitButton.setText("Apply"); 81 } 82 else { 83 dialog.setTitle("Create User"); 84 dialog.nameField.setEditable(true); 85 dialog.submitButton.setText("Create"); 86 } 87 88 dialog.setActionCancelled(false); 89 dialog.setLocationRelativeTo(dialog.parent); 90 dialog.setVisible(true); 91 return dialog; 92 } 93 94 95 private CreateUserDialog(Frame frame) 96 { 97 super(frame, true); 98 99 parent = frame; 100 101 submitButton = new JButton("Create"); 103 JButton cancelButton = new JButton("Cancel"); 104 cancelButton.addActionListener(new ActionListener() { 105 public void actionPerformed(ActionEvent e) { 106 CreateUserDialog.dialog.setVisible(false); 107 CreateUserDialog.dialog.setActionCancelled(true); 108 } 109 }); 110 111 submitButton.addActionListener(new ActionListener() { 112 public void actionPerformed(ActionEvent e) { 113 CreateUserDialog.dialog.setVisible(false); 114 name = nameField.getText(); 115 passwd = new String (passwdField.getPassword()); 116 passwd2 = new String (passwd2Field.getPassword()); 117 } 118 }); 119 getRootPane().setDefaultButton(submitButton); 120 121 nameField = new JTextField(name, 20); 123 passwdField = new JPasswordField(passwd, 20); 124 passwd2Field = new JPasswordField(passwd2, 20); 125 JLabel[] labels = {nameLabel, passwdLabel, passwd2Label}; 126 JTextField[] textFields = {nameField, passwdField, passwd2Field}; 127 JPanel form = new InputFormPanel(labels, textFields); 128 form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 129 130 JPanel buttonPane = new JPanel(); 132 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); 133 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 134 buttonPane.add(Box.createHorizontalGlue()); 135 buttonPane.add(submitButton); 136 buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); 137 buttonPane.add(cancelButton); 138 139 Container contentPane = getContentPane(); 141 contentPane.add(form, BorderLayout.CENTER); 142 contentPane.add(buttonPane, BorderLayout.SOUTH); 143 144 pack(); 145 } 146 147 public boolean getActionCancelled() { return actionCancelled; } 148 149 public void setActionCancelled(boolean cancelled) 150 { 151 actionCancelled = cancelled; 152 } 153 154 public String getUserName() { return name; } 155 156 public void setUserName(String name) 157 { 158 this.name = name; 159 } 160 161 public String getPassword() { return passwd; } 162 163 public String getConfirmationPassword() { return passwd2; } 164 165 public void setPassword(String passwd) 166 { 167 this.passwd = passwd; 168 this.passwd2 = passwd; 169 } 170 } 171 | Popular Tags |