1
2
3
4 package com.buckosoft.BSAccountMan.ldap;
5
6 import java.awt.Frame;
7 import java.awt.GridBagConstraints;
8 import java.awt.GridBagLayout;
9 import java.awt.Insets;
10
11 import javax.swing.JButton;
12 import javax.swing.JDialog;
13 import javax.swing.JPanel;
14 import javax.swing.JTextPane;
15 import javax.swing.text.BadLocationException;
16 import javax.swing.text.StyledDocument;
17
18
19
20
21
22 public class LdapTestDialog extends JDialog {
23
24 private static final long serialVersionUID = 1L;
25 private JPanel jContentPane = null;
26 private JButton jButtonLogin = null;
27 private JTextPane jTextPane = null;
28 private JPanel jPanelButtons = null;
29 private JButton jButtonExit = null;
30
31
32
33
34
35
36 private JButton getJButtonLogin() {
37 if (jButtonLogin == null) {
38 jButtonLogin = new JButton();
39 jButtonLogin.setText("Login");
40 jButtonLogin.addActionListener(new java.awt.event.ActionListener() {
41 public void actionPerformed(java.awt.event.ActionEvent e) {
42 System.out.println("login actionPerformed()");
43 doLogin();
44 }
45 });
46 }
47 return jButtonLogin;
48 }
49
50
51
52
53
54
55 private JButton getJButtonExit() {
56 if (jButtonExit == null) {
57 jButtonExit = new JButton();
58 jButtonExit.setText("Exit");
59 jButtonExit.addActionListener(new java.awt.event.ActionListener() {
60 public void actionPerformed(java.awt.event.ActionEvent e) {
61 System.out.println("exit actionPerformed()");
62 ((JButton)e.getSource()).getParent().getParent().setVisible(false);
63 System.exit(0);
64 }
65 });
66 }
67 return jButtonExit;
68 }
69
70
71
72
73
74
75 private JTextPane getJTextPane() {
76 if (jTextPane == null) {
77 jTextPane = new JTextPane();
78 }
79 return jTextPane;
80 }
81
82
83
84
85
86
87 private JPanel getJPanelButtons() {
88 if (jPanelButtons == null) {
89 GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
90 gridBagConstraints3.gridx = 0;
91 gridBagConstraints3.insets = new Insets(0, 0, 0, 10);
92 gridBagConstraints3.gridy = 0;
93 GridBagConstraints gridBagConstraints = new GridBagConstraints();
94 gridBagConstraints.insets = new Insets(0, 10, 0, 0);
95 gridBagConstraints.gridy = -1;
96 gridBagConstraints.ipadx = 0;
97 gridBagConstraints.weighty = 0.3;
98 gridBagConstraints.gridx = 1;
99 jPanelButtons = new JPanel();
100 jPanelButtons.setLayout(new GridBagLayout());
101 jPanelButtons.add(getJButtonLogin(), gridBagConstraints);
102 jPanelButtons.add(getJButtonExit(), gridBagConstraints3);
103 }
104 return jPanelButtons;
105 }
106
107 private static void createAndShowGUI() {
108 LdapTestDialog ltd = new LdapTestDialog(null);
109 ltd.setVisible(true);
110 }
111
112
113
114
115 public static void main(String[] args) {
116 javax.swing.SwingUtilities.invokeLater(new Runnable() {
117 public void run() {
118 createAndShowGUI();
119 }
120 });
121 }
122
123
124
125
126 public LdapTestDialog(Frame owner) {
127 super(owner);
128 initialize();
129 }
130
131
132
133
134
135
136 private void initialize() {
137 this.setSize(461, 307);
138 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
139 this.setTitle("LDAPTestDialog");
140 this.setContentPane(getJContentPane());
141 addWindowListener(new java.awt.event.WindowAdapter() {
142 public void windowClosing(java.awt.event.WindowEvent evt) {
143 System.exit(0);
144 }
145 });
146 }
147
148
149
150
151
152
153 private JPanel getJContentPane() {
154 if (jContentPane == null) {
155 GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
156 gridBagConstraints2.gridx = 0;
157 gridBagConstraints2.weighty = 0.3;
158 gridBagConstraints2.gridy = 1;
159 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
160 gridBagConstraints1.fill = GridBagConstraints.BOTH;
161 gridBagConstraints1.gridx = 0;
162 gridBagConstraints1.gridy = 0;
163 gridBagConstraints1.ipadx = 0;
164 gridBagConstraints1.weightx = 1.0;
165 gridBagConstraints1.weighty = 1.0;
166 gridBagConstraints1.insets = new Insets(0, 0, 0, 0);
167 jContentPane = new JPanel();
168 jContentPane.setLayout(new GridBagLayout());
169 jContentPane.add(getJTextPane(), gridBagConstraints1);
170 jContentPane.add(getJPanelButtons(), gridBagConstraints2);
171 }
172 return jContentPane;
173 }
174
175 private void doLogin() {
176 LdapLoginDialog lld = new LdapLoginDialog(this);
177 lld.setVisible(true);
178 System.out.println("doLogin: " + (lld.isOk() ? "OK" : "Cancel") + " pressed");
179 if (lld.isOk()) {
180 try {
181 LdapManager lm = new LdapManager();
182 StyledDocument doc = jTextPane.getStyledDocument();
183 String s;
184 s = "authenticate \"" + lld.getUserName() + "\" , \"" + lld.getPassword() + "\"";
185 doc.insertString(doc.getLength(), s, null);
186
187 boolean result = lm.authenticate(lld.getUserName(), lld.getPassword());
188 s = ("auth result = " + result);
189 doc.insertString(doc.getLength(), s, null);
190 } catch (BadLocationException e) {
191 e.printStackTrace();
192 }
193
194 }
195
196 }
197 }