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