1 7 package org.enhydra.base.tool; 8 9 import javax.swing.JPanel ; 10 11 import javax.swing.JLabel ; 12 import javax.swing.JOptionPane ; 13 import javax.swing.JTextField ; 14 import javax.swing.JPasswordField ; 15 21 public class AuthenticationConfigurationPanel extends JPanel { 22 23 private JLabel head = null; 24 private JLabel usernameLabel = null; 25 private JTextField usernameText = null; 26 private JLabel passwordLabel = null; 27 private JPasswordField passwordText = null; 28 private JLabel confirmPasswordLabel = null; 29 private JPasswordField confirmPasswordText = null; 30 33 public AuthenticationConfigurationPanel() { 34 super(); 35 initialize(); 36 } 37 42 private void initialize() { 43 head = new JLabel (); 44 usernameLabel = new JLabel (); 45 passwordLabel = new JLabel (); 46 confirmPasswordLabel = new JLabel (); 47 this.setSize(300, 150); 48 head.setText(""); 49 head.setName("head"); 50 head.setPreferredSize(new java.awt.Dimension (300,25)); 51 usernameLabel.setText("Username:"); 52 usernameLabel.setName("usernameLabel"); 53 usernameLabel.setPreferredSize(new java.awt.Dimension (125,16)); 54 passwordLabel.setText("Password (*enhydra):"); 55 passwordLabel.setName("passwordLabel"); 56 passwordLabel.setPreferredSize(new java.awt.Dimension (125,16)); 57 confirmPasswordLabel.setText("Confirm Password:"); 58 confirmPasswordLabel.setName("confirmPasswordLabel"); 59 confirmPasswordLabel.setPreferredSize(new java.awt.Dimension (125,16)); 60 this.add(head, null); 61 this.add(usernameLabel, null); 62 this.add(getUsernameText(), null); 63 this.add(passwordLabel, null); 64 this.add(getPasswordText(), null); 65 this.add(confirmPasswordLabel, null); 66 this.add(getConfirmPasswordText(), null); 67 } 68 73 private JTextField getUsernameText() { 74 if (usernameText == null) { 75 usernameText = new JTextField (); 76 usernameText.setName("usernameText"); 77 usernameText.setPreferredSize(new java.awt.Dimension (150,20)); 78 usernameText.setText("admin"); 79 } 80 return usernameText; 81 } 82 87 private JPasswordField getPasswordText() { 88 if (passwordText == null) { 89 passwordText = new JPasswordField (); 90 passwordText.setName("passwordText"); 91 passwordText.setPreferredSize(new java.awt.Dimension (150,20)); 92 passwordText.setText("enhydra"); 93 } 94 return passwordText; 95 } 96 101 private JPasswordField getConfirmPasswordText() { 102 if (confirmPasswordText == null) { 103 confirmPasswordText = new JPasswordField (); 104 confirmPasswordText.setPreferredSize(new java.awt.Dimension (150,20)); 105 confirmPasswordText.setText("enhydra"); 106 confirmPasswordText.setName("confirmPasswordText"); 107 } 108 return confirmPasswordText; 109 } 110 111 public void setUserName (String name){ 112 getUsernameText().setText(name); 113 } 114 115 public String getUserName (){ 116 return getUsernameText().getText(); 117 } 118 119 public void setPassword (String pass){ 120 getPasswordText().setText(pass); 121 getConfirmPasswordText().setText(pass); 122 } 123 124 public String getPassword (){ 125 return new String (getPasswordText().getPassword()); 126 } 127 128 public boolean checkEntries() { 129 boolean valid = true; 130 if ("".equals(usernameText.getText())||usernameText.getText()==null){ 131 displayErrorMessage("UserName"); 132 valid = false; 133 } 134 String password = new String (passwordText.getPassword()); 135 String passwordConfirm = new String (confirmPasswordText.getPassword()); 136 if ("".equals(password)||password==null){ 137 displayErrorMessage("Password"); 138 valid = false; 139 } else { 140 if (!password.equals(passwordConfirm)){ 141 displayErrorMessage("Password Confirmation"); 142 valid = false; 143 } 144 145 } 146 147 return valid; 148 } 149 150 private void displayErrorMessage(String field) { 151 JOptionPane.showMessageDialog(null, "Check '" + field 152 + "' Field Setting!", 153 "Enhydra Configuration Tool - Houston, we have a problem!", 154 JOptionPane.ERROR_MESSAGE); 155 } 156 } 157 | Popular Tags |