| 1 19 package org.openharmonise.him.authentication.gui; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.LayoutManager ; 27 import java.awt.event.KeyEvent ; 28 import java.awt.event.KeyListener ; 29 30 import javax.swing.BorderFactory ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.JPasswordField ; 34 import javax.swing.JTextField ; 35 36 43 public class ChangePasswordPanel extends JPanel implements LayoutManager , KeyListener { 44 45 48 private JLabel m_usernameLabel = null; 49 50 53 private JLabel m_passwordLabel = null; 54 55 58 private JTextField m_username = null; 59 60 63 private JPasswordField m_password = null; 64 65 68 private JLabel m_newPassword1Label = null; 69 70 73 private JLabel m_newPassword2Label = null; 74 75 78 private JPasswordField m_newPassword1Password = null; 79 80 83 private JPasswordField m_newPassword2Password = null; 84 85 88 private boolean m_bUsernameVisible = true; 89 90 93 private boolean m_bPasswordVisible = true; 94 95 96 101 public ChangePasswordPanel(ChangePasswordDialog dialog) { 102 super(); 103 this.setup(dialog); 104 } 105 106 111 private void setup(ChangePasswordDialog dialog) { 112 this.setLayout(this); 113 114 String fontName = "Dialog"; 115 int fontSize = 11; 116 Font font = new Font (fontName, Font.PLAIN, fontSize); 117 118 m_usernameLabel = new JLabel ("User name"); 119 m_usernameLabel.setFont(font); 120 this.add(m_usernameLabel); 121 122 m_passwordLabel = new JLabel ("Password"); 123 m_passwordLabel.setFont(font); 124 this.add(m_passwordLabel); 125 126 m_username = new JTextField (); 127 m_username.addKeyListener(dialog); 128 this.add(m_username); 129 130 m_password = new JPasswordField (); 131 m_password.addKeyListener(dialog); 132 this.add(m_password); 133 134 m_newPassword1Label = new JLabel ("New Password"); 135 m_newPassword1Label.setFont(font); 136 this.add(m_newPassword1Label); 137 138 m_newPassword1Password = new JPasswordField (); 139 m_newPassword1Password.setBorder(BorderFactory.createLineBorder(Color.RED)); 140 m_newPassword1Password.addKeyListener(this); 141 m_newPassword1Password.addKeyListener(dialog); 142 this.add(m_newPassword1Password); 143 144 m_newPassword2Label = new JLabel ("Repeat New Password"); 145 m_newPassword2Label.setFont(font); 146 this.add(m_newPassword2Label); 147 148 m_newPassword2Password = new JPasswordField (); 149 m_newPassword2Password.setBorder(BorderFactory.createLineBorder(Color.RED)); 150 m_newPassword2Password.addKeyListener(this); 151 m_newPassword2Password.addKeyListener(dialog); 152 this.add(m_newPassword2Password); 153 } 154 155 158 public void keyReleased(KeyEvent ke) { 159 if(ke.getSource()==this.m_newPassword1Password || ke.getSource()==this.m_newPassword2Password) { 160 this.checkPasswordsSame(); 161 } 162 } 163 164 169 public boolean checkPasswordsSame() { 170 this.m_newPassword1Password.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 171 this.m_newPassword2Password.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 172 173 if(!this.m_newPassword1Password.getText().trim().equals(this.m_newPassword2Password.getText().trim()) || this.m_newPassword1Password.getText().trim().equals(getPassword().trim()) || this.m_newPassword2Password.getText().trim().equals(getPassword().trim())) { 174 this.m_newPassword1Password.setBorder(BorderFactory.createLineBorder(Color.RED)); 175 this.m_newPassword2Password.setBorder(BorderFactory.createLineBorder(Color.RED)); 176 return false; 177 } else { 178 return true; 179 } 180 } 181 182 185 private ChangePasswordPanel(boolean arg0) { 186 super(arg0); 187 } 188 189 192 private ChangePasswordPanel(LayoutManager arg0) { 193 super(arg0); 194 } 195 196 200 private ChangePasswordPanel(LayoutManager arg0, boolean arg1) { 201 super(arg0, arg1); 202 } 203 204 207 public void removeLayoutComponent(Component arg0) { 208 210 } 211 212 215 public void layoutContainer(Container arg0) { 216 int nHeight = 50; 217 218 if(this.m_bUsernameVisible) { 219 m_usernameLabel.setLocation(20,nHeight); 220 m_usernameLabel.setSize(110,20); 221 222 m_username.setLocation(150, nHeight); 223 m_username.setSize(300,20); 224 nHeight = nHeight + 50; 225 } 226 227 if(this.m_bPasswordVisible) { 228 m_passwordLabel.setLocation(20,nHeight); 229 m_passwordLabel.setSize(110,20); 230 m_password.setLocation(150, nHeight); 231 m_password.setSize(300,20); 232 nHeight = nHeight + 50; 233 } 234 235 m_newPassword1Label.setLocation(20,nHeight); 236 m_newPassword1Label.setSize(110,20); 237 238 m_newPassword1Password.setLocation(150, nHeight); 239 m_newPassword1Password.setSize(300,20); 240 nHeight = nHeight + 50; 241 242 m_newPassword2Label.setLocation(20,nHeight); 243 m_newPassword2Label.setSize(120,20); 244 245 m_newPassword2Password.setLocation(150, nHeight); 246 m_newPassword2Password.setSize(300,20); 247 } 248 249 254 public String getUsername() { 255 return this.m_username.getText().trim(); 256 } 257 258 263 public void setUsername(String sUsername) { 264 this.m_username.setText(sUsername); 265 this.m_username.setVisible(false); 266 this.m_usernameLabel.setVisible(false); 267 this.m_bUsernameVisible = false; 268 } 269 270 275 public String getPassword() { 276 return this.m_password.getText().trim(); 277 } 278 279 285 public void setPassword(String sPassword) { 286 this.m_password.setText(sPassword); 287 this.m_password.setVisible(false); 288 this.m_passwordLabel.setVisible(false); 289 this.m_bPasswordVisible = false; 290 } 291 292 297 public String getNewPassword() { 298 if(this.checkPasswordsSame()) { 299 return this.m_newPassword1Password.getText().trim(); 300 } else { 301 return ""; 302 } 303 } 304 305 308 public void addLayoutComponent(String arg0, Component arg1) { 309 311 } 312 313 316 public Dimension minimumLayoutSize(Container arg0) { 317 return this.getPreferredSize(); 318 } 319 320 323 public Dimension preferredLayoutSize(Container arg0) { 324 return this.getPreferredSize(); 325 } 326 327 330 public void keyPressed(KeyEvent arg0) { 331 } 332 333 336 public void keyTyped(KeyEvent arg0) { 337 } 338 339 340 341 } 342 | Popular Tags |