1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 package com.buckosoft.fibs.BuckoFIBS.gui.account;
60
61 import java.awt.GridBagConstraints;
62 import java.awt.GridBagLayout;
63 import java.awt.Insets;
64
65 import javax.swing.JButton;
66 import javax.swing.JDialog;
67 import javax.swing.JFrame;
68 import javax.swing.JLabel;
69 import javax.swing.JPanel;
70 import javax.swing.JPasswordField;
71 import javax.swing.JTextField;
72
73 import com.buckosoft.fibs.BuckoFIBS.BFProperties;
74 import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher;
75
76
77
78
79
80
81
82 public class ConnectToServerDialog extends JDialog implements ProfileSelectorNotifier {
83
84 private static final long serialVersionUID = 1L;
85 private JPanel jContentPane = null;
86 private JLabel serverNameLabel = null;
87 private JButton jButtonConnect = null;
88 private JButton jButtonCancel = null;
89 private CommandDispatcher commandDispatcher;
90 private BFProperties properties;
91 private JLabel userNameLabel = null;
92 private JTextField userNameField = null;
93 private JLabel passwordLabel = null;
94 private JPasswordField passwordTextField = null;
95 private JButton jCreateNewAccountButton = null;
96 private JPanel jButtonPanel = null;
97 private ServerPortSelectorPanel jPanelServerPort = null;
98 private JLabel jLabelProfiles = null;
99 private ProfileSelectorPanel jPanelProfileSelector = null;
100
101
102
103
104
105 public ConnectToServerDialog(JFrame owner, CommandDispatcher commandDispatcher) {
106 super(owner, true);
107 this.commandDispatcher = commandDispatcher;
108 this.properties = commandDispatcher.getProperties();
109 initialize();
110 this.setLocationRelativeTo(owner);
111 activateProfileObjects();
112 this.profileChanged();
113 }
114
115 private void activateProfileObjects() {
116 boolean b = this.properties.isAllowMultiplePersonalities();
117 this.jLabelProfiles.setVisible(b);
118 this.jPanelProfileSelector.setVisible(b);
119 }
120
121
122
123
124
125
126 private void initialize() {
127 this.setSize(309, 211);
128 this.setModal(true);
129 this.setTitle("Connect To Server");
130 this.setContentPane(getJContentPane());
131 userNameField.setText(this.properties.getUserName(jPanelProfileSelector.getSelectedProfile()));
132 passwordTextField.setText(this.properties.getPassword(jPanelProfileSelector.getSelectedProfile()));
133 }
134
135 private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {
136 setVisible(false);
137 int profileId = jPanelProfileSelector.getSelectedProfile();
138 this.properties.setUserName(profileId, this.userNameField.getText());
139 this.properties.setPassword(profileId, new String(this.passwordTextField.getPassword()));
140 this.properties.setServerName(profileId, (String)this.jPanelServerPort.getServerName());
141 this.properties.setServerPort(profileId, this.jPanelServerPort.getPort());
142 dispose();
143 commandDispatcher.dispatch(CommandDispatcher.Command.CONNECT_TO_SERVER);
144 }
145
146 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
147 setVisible(false);
148 dispose();
149 }
150
151 private void newAccountButtonActionPerformed(java.awt.event.ActionEvent evt) {
152 setVisible(false);
153 dispose();
154 commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_NEW_ACCOUNT_DIALOG);
155 }
156
157
158
159
160
161 @Override
162 public void profileChanged() {
163 int profileId = this.properties.getSelectedProfile();
164 this.userNameField.setText(this.properties.getUserName(profileId));
165 this.passwordTextField.setText(this.properties.getPassword(profileId));
166 this.jPanelServerPort.setServerName(this.properties.getServerName(profileId));
167 }
168
169
170
171
172
173
174 private JPanel getJContentPane() {
175 if (jContentPane == null) {
176 GridBagConstraints gridBagConstraints71 = new GridBagConstraints();
177 gridBagConstraints71.gridx = 1;
178 gridBagConstraints71.fill = GridBagConstraints.HORIZONTAL;
179 gridBagConstraints71.gridy = 0;
180 GridBagConstraints gridBagConstraints61 = new GridBagConstraints();
181 gridBagConstraints61.gridx = 0;
182 gridBagConstraints61.anchor = GridBagConstraints.EAST;
183 gridBagConstraints61.gridy = 0;
184 jLabelProfiles = new JLabel();
185 jLabelProfiles.setText("Profile:");
186 GridBagConstraints gridBagConstraints51 = new GridBagConstraints();
187 gridBagConstraints51.gridx = 1;
188 gridBagConstraints51.fill = GridBagConstraints.HORIZONTAL;
189 gridBagConstraints51.weightx = 1.0;
190 gridBagConstraints51.anchor = GridBagConstraints.CENTER;
191 gridBagConstraints51.gridy = 1;
192 GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
193 gridBagConstraints31.gridx = 0;
194 gridBagConstraints31.gridwidth = 2;
195 gridBagConstraints31.insets = new Insets(0, 0, 5, 0);
196 gridBagConstraints31.anchor = GridBagConstraints.SOUTH;
197 gridBagConstraints31.weighty = 1.0;
198 gridBagConstraints31.gridy = 10;
199 GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
200 gridBagConstraints9.fill = GridBagConstraints.HORIZONTAL;
201 gridBagConstraints9.gridy = 4;
202 gridBagConstraints9.weightx = 1.0;
203 gridBagConstraints9.insets = new Insets(0, 0, 30, 0);
204 gridBagConstraints9.gridwidth = 1;
205 gridBagConstraints9.gridx = 1;
206 GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
207 gridBagConstraints8.gridx = 0;
208 gridBagConstraints8.anchor = GridBagConstraints.WEST;
209 gridBagConstraints8.ipady = 0;
210 gridBagConstraints8.insets = new Insets(0, 0, 30, 0);
211 gridBagConstraints8.gridy = 4;
212 passwordLabel = new JLabel();
213 passwordLabel.setText("Password:");
214 GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
215 gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL;
216 gridBagConstraints7.gridy = 3;
217 gridBagConstraints7.weightx = 1.0;
218 gridBagConstraints7.gridwidth = 1;
219 gridBagConstraints7.gridx = 1;
220 GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
221 gridBagConstraints6.gridx = 0;
222 gridBagConstraints6.anchor = GridBagConstraints.WEST;
223 gridBagConstraints6.gridy = 3;
224 userNameLabel = new JLabel();
225 userNameLabel.setText("Username:");
226 GridBagConstraints gridBagConstraints = new GridBagConstraints();
227 gridBagConstraints.gridx = 0;
228 gridBagConstraints.ipadx = 0;
229 gridBagConstraints.ipady = 4;
230 gridBagConstraints.anchor = GridBagConstraints.EAST;
231 gridBagConstraints.gridy = 1;
232 serverNameLabel = new JLabel();
233 serverNameLabel.setText("Server:");
234 jContentPane = new JPanel();
235 jContentPane.setLayout(new GridBagLayout());
236 jContentPane.add(serverNameLabel, gridBagConstraints);
237 jContentPane.add(userNameLabel, gridBagConstraints6);
238 jContentPane.add(getUserNameField(), gridBagConstraints7);
239 jContentPane.add(passwordLabel, gridBagConstraints8);
240 jContentPane.add(getPasswordTextField(), gridBagConstraints9);
241 jContentPane.add(getJButtonPanel(), gridBagConstraints31);
242 jContentPane.add(getJPanelServerPort(), gridBagConstraints51);
243 jContentPane.add(jLabelProfiles, gridBagConstraints61);
244 jContentPane.add(getJPanelProfileSelector(), gridBagConstraints71);
245 }
246 return jContentPane;
247 }
248
249
250
251
252 private JTextField getUserNameField() {
253 if (userNameField == null) {
254 userNameField = new JTextField();
255 }
256 return userNameField;
257 }
258
259
260
261
262
263
264 private JPasswordField getPasswordTextField() {
265 if (passwordTextField == null) {
266 passwordTextField = new JPasswordField();
267 }
268 return passwordTextField;
269 }
270
271
272
273
274
275
276 private JButton getJButtonConnect() {
277 if (jButtonConnect == null) {
278 jButtonConnect = new JButton();
279 jButtonConnect.setText("Connect");
280 jButtonConnect.addActionListener(new java.awt.event.ActionListener() {
281 public void actionPerformed(java.awt.event.ActionEvent e) {
282 connectButtonActionPerformed(e);
283 }
284 });
285 }
286 return jButtonConnect;
287 }
288
289
290
291
292
293
294 private JButton getJButtonCancel() {
295 if (jButtonCancel == null) {
296 jButtonCancel = new JButton();
297 jButtonCancel.setText("Cancel");
298 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
299 public void actionPerformed(java.awt.event.ActionEvent e) {
300 cancelButtonActionPerformed(e);
301 }
302 });
303 }
304 return jButtonCancel;
305 }
306
307
308
309
310
311
312 private JButton getJCreateNewAccountButton() {
313 if (jCreateNewAccountButton == null) {
314 jCreateNewAccountButton = new JButton();
315 jCreateNewAccountButton.setText("New Account");
316 jCreateNewAccountButton.addActionListener(new java.awt.event.ActionListener() {
317 public void actionPerformed(java.awt.event.ActionEvent e) {
318 newAccountButtonActionPerformed(e);
319 }
320 });
321 }
322 return jCreateNewAccountButton;
323 }
324
325
326
327
328
329
330 private JPanel getJButtonPanel() {
331 if (jButtonPanel == null) {
332 GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
333 gridBagConstraints5.insets = new Insets(0, 4, 1, 4);
334 gridBagConstraints5.gridy = -1;
335 gridBagConstraints5.weightx = 0.3;
336 gridBagConstraints5.gridx = -1;
337 GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
338 gridBagConstraints4.insets = new Insets(0, 4, 1, 0);
339 gridBagConstraints4.gridy = -1;
340 gridBagConstraints4.ipadx = 0;
341 gridBagConstraints4.ipady = 0;
342 gridBagConstraints4.weightx = 0.3;
343 gridBagConstraints4.gridx = -1;
344 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
345 gridBagConstraints1.insets = new Insets(0, 0, 1, 4);
346 gridBagConstraints1.gridy = -1;
347 gridBagConstraints1.ipadx = 0;
348 gridBagConstraints1.ipady = 0;
349 gridBagConstraints1.weightx = 0.3;
350 gridBagConstraints1.gridx = -1;
351 jButtonPanel = new JPanel();
352 jButtonPanel.setLayout(new GridBagLayout());
353 jButtonPanel.add(getJButtonConnect(), gridBagConstraints1);
354 jButtonPanel.add(getJCreateNewAccountButton(), gridBagConstraints5);
355 jButtonPanel.add(getJButtonCancel(), gridBagConstraints4);
356 }
357 return jButtonPanel;
358 }
359
360
361
362
363
364
365 private ServerPortSelectorPanel getJPanelServerPort() {
366 if (jPanelServerPort == null) {
367 jPanelServerPort = new ServerPortSelectorPanel(properties);
368
369 jPanelServerPort.setLayout(new GridBagLayout());
370 }
371 return jPanelServerPort;
372 }
373
374
375
376
377
378
379 private ProfileSelectorPanel getJPanelProfileSelector() {
380 if (jPanelProfileSelector == null) {
381 jPanelProfileSelector = new ProfileSelectorPanel(this, this, properties);
382 jPanelProfileSelector.setLayout(new GridBagLayout());
383 }
384 return jPanelProfileSelector;
385 }
386
387 }