View Javadoc
1   package com.buckosoft.BSAccountMan.ldap;
2   
3   import java.awt.Dialog;
4   import java.awt.Frame;
5   import java.awt.GridBagConstraints;
6   import java.awt.GridBagLayout;
7   import java.awt.Insets;
8   
9   import javax.swing.JButton;
10  import javax.swing.JDialog;
11  import javax.swing.JLabel;
12  import javax.swing.JPanel;
13  import javax.swing.JPasswordField;
14  import javax.swing.JTextField;
15  
16  public class LdapLoginDialog extends JDialog {
17  
18  	private static final long serialVersionUID = 1L;
19  	private JPanel jContentPane = null;
20  	private JLabel jLabelUserID = null;
21  	private JLabel jLabelPassword = null;
22  	private JTextField jTextFieldUserID = null;
23  	private JPasswordField jPasswordField = null;
24  	private JPanel jButtonPanel = null;
25  	private JButton jButtonOK = null;
26  	private JButton jButtonCancel = null;
27  	private JPanel jPanelFields = null;
28  
29  	private	boolean ok = false;
30  	/**
31  	 * @param owner
32  	 */
33  	public LdapLoginDialog(Dialog owner) {
34  		super(owner, true);
35  		initialize();
36  	}
37  
38  	/**
39  	 * @param owner
40  	 */
41  	public LdapLoginDialog(Frame owner) {
42  		super(owner);
43  		initialize();
44  	}
45  
46  	/** Return the status of the ok/cancel exit.
47  	 * @return true if the ok button was pressed.
48  	 */
49  	public boolean isOk() {
50  		return(ok);
51  	}
52  
53  	public String getUserName() {
54  		return(this.getJTextFieldUserID().getText());
55  	}
56  	
57  	public String getPassword() {
58  		char[] c = this.getJPasswordField().getPassword();
59  		String s = new String(c);
60  		return(s);
61  	}
62  	/**
63  	 * This method initializes this
64  	 * 
65  	 * @return void
66  	 */
67  	private void initialize() {
68  		this.setSize(349, 196);
69  		this.setTitle("LDAP login");
70  		this.setContentPane(getJContentPane());
71  	}
72  
73  	/**
74  	 * This method initializes jContentPane
75  	 * 
76  	 * @return javax.swing.JPanel
77  	 */
78  	private JPanel getJContentPane() {
79  		if (jContentPane == null) {
80  			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
81  			gridBagConstraints41.gridx = 0;
82  			gridBagConstraints41.fill = GridBagConstraints.HORIZONTAL;
83  			gridBagConstraints41.weightx = 0.2;
84  			gridBagConstraints41.weighty = 0.4;
85  			gridBagConstraints41.gridy = 0;
86  			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
87  			gridBagConstraints21.gridx = 0;
88  			gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL;
89  			gridBagConstraints21.anchor = GridBagConstraints.CENTER;
90  			gridBagConstraints21.weighty = 0.4;
91  			gridBagConstraints21.gridy = 1;
92  			jContentPane = new JPanel();
93  			jContentPane.setLayout(new GridBagLayout());
94  			jContentPane.add(getJPanelFields(), gridBagConstraints41);
95  			jContentPane.add(getJButtonPanel(), gridBagConstraints21);
96  		}
97  		return jContentPane;
98  	}
99  
100 	/**
101 	 * This method initializes jTextFieldUserID	
102 	 * 	
103 	 * @return javax.swing.JTextField	
104 	 */
105 	private JTextField getJTextFieldUserID() {
106 		if (jTextFieldUserID == null) {
107 			jTextFieldUserID = new JTextField();
108 		}
109 		return jTextFieldUserID;
110 	}
111 
112 	/**
113 	 * This method initializes jPasswordField	
114 	 * 	
115 	 * @return javax.swing.JPasswordField	
116 	 */
117 	private JPasswordField getJPasswordField() {
118 		if (jPasswordField == null) {
119 			jPasswordField = new JPasswordField();
120 		}
121 		return jPasswordField;
122 	}
123 
124 	/**
125 	 * This method initializes jButtonPanel	
126 	 * 	
127 	 * @return javax.swing.JPanel	
128 	 */
129 	private JPanel getJButtonPanel() {
130 		if (jButtonPanel == null) {
131 			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
132 			gridBagConstraints4.gridx = 1;
133 			gridBagConstraints4.insets = new Insets(0, 12, 0, 0);
134 			gridBagConstraints4.gridy = 0;
135 			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
136 			gridBagConstraints3.gridx = 0;
137 			gridBagConstraints3.insets = new Insets(0, 0, 0, 12);
138 			gridBagConstraints3.gridy = 0;
139 			jButtonPanel = new JPanel();
140 			jButtonPanel.setLayout(new GridBagLayout());
141 			jButtonPanel.add(getJButtonOK(), gridBagConstraints3);
142 			jButtonPanel.add(getJButtonCancel(), gridBagConstraints4);
143 		}
144 		return jButtonPanel;
145 	}
146 
147 	/**
148 	 * This method initializes jButtonOK	
149 	 * 	
150 	 * @return javax.swing.JButton	
151 	 */
152 	private JButton getJButtonOK() {
153 		if (jButtonOK == null) {
154 			jButtonOK = new JButton();
155 			jButtonOK.setText("OK");
156 			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
157 				public void actionPerformed(java.awt.event.ActionEvent e) {
158 					System.out.println("OK actionPerformed()");
159 					handleOk();
160 				}
161 			});
162 		}
163 		return jButtonOK;
164 	}
165 
166 	/**
167 	 * This method initializes jButtonCancel	
168 	 * 	
169 	 * @return javax.swing.JButton	
170 	 */
171 	private JButton getJButtonCancel() {
172 		if (jButtonCancel == null) {
173 			jButtonCancel = new JButton();
174 			jButtonCancel.setText("Cancel");
175 			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
176 				public void actionPerformed(java.awt.event.ActionEvent e) {
177 					System.out.println("actionPerformed()");
178 					handleCancel();
179 				}
180 			});
181 		}
182 		return jButtonCancel;
183 	}
184 
185 	private void handleOk() {
186 		this.ok = true;
187 		this.setVisible(false);
188 	}
189 	
190 	private void handleCancel() {
191 		this.ok = false;
192 		this.setVisible(false);
193 	}
194 	
195 	/**
196 	 * This method initializes jPanelFields	
197 	 * 	
198 	 * @return javax.swing.JPanel	
199 	 */
200 	private JPanel getJPanelFields() {
201 		if (jPanelFields == null) {
202 			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
203 			gridBagConstraints5.fill = GridBagConstraints.BOTH;
204 			gridBagConstraints5.gridx = 1;
205 			gridBagConstraints5.gridy = 1;
206 			gridBagConstraints5.weightx = 1.0;
207 			gridBagConstraints5.insets = new Insets(5, 30, 0, 40);
208 			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
209 			gridBagConstraints2.fill = GridBagConstraints.BOTH;
210 			gridBagConstraints2.gridx = 1;
211 			gridBagConstraints2.gridy = 0;
212 			gridBagConstraints2.ipadx = 4;
213 			gridBagConstraints2.ipady = 3;
214 			gridBagConstraints2.weightx = 1.0;
215 			gridBagConstraints2.weighty = 0.0;
216 			gridBagConstraints2.insets = new Insets(0, 30, 0, 40);
217 			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
218 			gridBagConstraints1.insets = new Insets(5, 30, 0, 0);
219 			gridBagConstraints1.gridy = 1;
220 			gridBagConstraints1.gridx = 0;
221 			GridBagConstraints gridBagConstraints = new GridBagConstraints();
222 			gridBagConstraints.insets = new Insets(0, 30, 0, 0);
223 			gridBagConstraints.gridy = 0;
224 			gridBagConstraints.ipadx = 0;
225 			gridBagConstraints.gridx = 0;
226 			jLabelPassword = new JLabel();
227 			jLabelPassword.setText("Password :");
228 			jLabelUserID = new JLabel();
229 			jLabelUserID.setText("User ID :");
230 			jPanelFields = new JPanel();
231 			jPanelFields.setLayout(new GridBagLayout());
232 			jPanelFields.add(jLabelUserID, gridBagConstraints);
233 			jPanelFields.add(jLabelPassword, gridBagConstraints1);
234 			jPanelFields.add(getJTextFieldUserID(), gridBagConstraints2);
235 			jPanelFields.add(getJPasswordField(), gridBagConstraints5);
236 		}
237 		return jPanelFields;
238 	}
239 
240 }  //  @jve:decl-index=0:visual-constraint="10,10"