KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > base > tool > AuthenticationConfigurationPanel


1 /*
2  * Created on Jul 19, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.base.tool;
8
9 import javax.swing.JPanel JavaDoc;
10
11 import javax.swing.JLabel JavaDoc;
12 import javax.swing.JOptionPane JavaDoc;
13 import javax.swing.JTextField JavaDoc;
14 import javax.swing.JPasswordField JavaDoc;
15 /**
16  * @author slobodan
17  *
18  * TODO To change the template for this generated type comment go to
19  * Window - Preferences - Java - Code Style - Code Templates
20  */

21 public class AuthenticationConfigurationPanel extends JPanel JavaDoc {
22
23     private JLabel JavaDoc head = null;
24     private JLabel JavaDoc usernameLabel = null;
25     private JTextField JavaDoc usernameText = null;
26     private JLabel JavaDoc passwordLabel = null;
27     private JPasswordField JavaDoc passwordText = null;
28     private JLabel JavaDoc confirmPasswordLabel = null;
29     private JPasswordField JavaDoc confirmPasswordText = null;
30     /**
31      * This is the default constructor
32      */

33     public AuthenticationConfigurationPanel() {
34         super();
35         initialize();
36     }
37     /**
38      * This method initializes this
39      *
40      * @return void
41      */

42     private void initialize() {
43         head = new JLabel JavaDoc();
44         usernameLabel = new JLabel JavaDoc();
45         passwordLabel = new JLabel JavaDoc();
46         confirmPasswordLabel = new JLabel JavaDoc();
47         this.setSize(300, 150);
48         head.setText("");
49         head.setName("head");
50         head.setPreferredSize(new java.awt.Dimension JavaDoc(300,25));
51         usernameLabel.setText("Username:");
52         usernameLabel.setName("usernameLabel");
53         usernameLabel.setPreferredSize(new java.awt.Dimension JavaDoc(125,16));
54         passwordLabel.setText("Password (*enhydra):");
55         passwordLabel.setName("passwordLabel");
56         passwordLabel.setPreferredSize(new java.awt.Dimension JavaDoc(125,16));
57         confirmPasswordLabel.setText("Confirm Password:");
58         confirmPasswordLabel.setName("confirmPasswordLabel");
59         confirmPasswordLabel.setPreferredSize(new java.awt.Dimension JavaDoc(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     /**
69      * This method initializes jTextField
70      *
71      * @return javax.swing.JTextField
72      */

73     private JTextField JavaDoc getUsernameText() {
74         if (usernameText == null) {
75             usernameText = new JTextField JavaDoc();
76             usernameText.setName("usernameText");
77             usernameText.setPreferredSize(new java.awt.Dimension JavaDoc(150,20));
78             usernameText.setText("admin");
79         }
80         return usernameText;
81     }
82     /**
83      * This method initializes jPasswordField
84      *
85      * @return javax.swing.JPasswordField
86      */

87     private JPasswordField JavaDoc getPasswordText() {
88         if (passwordText == null) {
89             passwordText = new JPasswordField JavaDoc();
90             passwordText.setName("passwordText");
91             passwordText.setPreferredSize(new java.awt.Dimension JavaDoc(150,20));
92             passwordText.setText("enhydra");
93         }
94         return passwordText;
95     }
96     /**
97      * This method initializes jPasswordField
98      *
99      * @return javax.swing.JPasswordField
100      */

101     private JPasswordField JavaDoc getConfirmPasswordText() {
102         if (confirmPasswordText == null) {
103             confirmPasswordText = new JPasswordField JavaDoc();
104             confirmPasswordText.setPreferredSize(new java.awt.Dimension JavaDoc(150,20));
105             confirmPasswordText.setText("enhydra");
106             confirmPasswordText.setName("confirmPasswordText");
107         }
108         return confirmPasswordText;
109     }
110     
111     public void setUserName (String JavaDoc name){
112         getUsernameText().setText(name);
113     }
114     
115     public String JavaDoc getUserName (){
116         return getUsernameText().getText();
117     }
118     
119     public void setPassword (String JavaDoc pass){
120         getPasswordText().setText(pass);
121         getConfirmPasswordText().setText(pass);
122     }
123     
124     public String JavaDoc getPassword (){
125         return new String JavaDoc(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 JavaDoc password = new String JavaDoc(passwordText.getPassword());
135         String JavaDoc passwordConfirm = new String JavaDoc(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 JavaDoc 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