Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.account.ConnectToServerDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectToServerDialog
0%
0/180
0%
0/18
1.474
ConnectToServerDialog$1
0%
0/3
N/A
1.474
ConnectToServerDialog$2
0%
0/3
N/A
1.474
ConnectToServerDialog$3
0%
0/3
N/A
1.474
 
 1  
 /******************************************************************************
 2  
  * ConnectToServerDialog.java - Manage the Connect to Server dialog
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.3  2010/03/03 13:12:21  inim
 10  
  * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
 11  
  *
 12  
  * Revision 1.2  2010/03/03 12:19:49  inim
 13  
  * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010.
 14  
  *
 15  
  * Revision 1.1  2010/02/04 05:57:53  inim
 16  
  * Mavenized project folder layout
 17  
  *
 18  
  * Revision 1.8  2009/01/28 18:15:10  dick
 19  
  * Prettier cvs link in the javadoc.
 20  
  *
 21  
  * Revision 1.7  2009/01/18 05:00:40  dick
 22  
  * The owner is a JFrame, not a JDialog.
 23  
  *
 24  
  * Revision 1.6  2009/01/09 07:17:38  dick
 25  
  * Initialize the data after constructing the widget.
 26  
  *
 27  
  * Revision 1.5  2009/01/07 20:03:22  dick
 28  
  * Cleanups and Javadoc.
 29  
  *
 30  
  * Revision 1.4  2009/01/07 08:33:31  dick
 31  
  * Change the settings when the profile changes.
 32  
  *
 33  
  * Revision 1.3  2009/01/06 08:10:37  dick
 34  
  * Don't use deprecated password stuff.
 35  
  *
 36  
  * Revision 1.2  2009/01/05 07:16:09  dick
 37  
  * @see moved to .../account
 38  
  *
 39  
  * Revision 1.1  2009/01/05 07:09:53  dick
 40  
  * ConnectToServerDialog and CreateAccountDialog moved to account.
 41  
  *
 42  
  * Revision 1.5  2009/01/04 19:57:49  dick
 43  
  * Add the New Account handling.
 44  
  *
 45  
  * Revision 1.4  2008/12/11 08:47:55  dick
 46  
  * Center the dialog over the MainDialog. (Looks like poo, but better than being at 0,0).
 47  
  *
 48  
  * Revision 1.3  2008/10/03 06:57:08  dick
 49  
  * Set modal to true.
 50  
  *
 51  
  * Revision 1.2  2008/03/31 07:10:11  dick
 52  
  * Add the username and password.
 53  
  * Use a GridBagLayout.
 54  
  *
 55  
  * Revision 1.1  2008/03/30 05:42:26  dick
 56  
  * Make sure we are connecting correctly...
 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  
 /** Manage the Connect to Server dialog.
 77  
  * @author Dick Balaska
 78  
  * @since 2008/03/30
 79  
  * @version $Revision$ <br> $Date$
 80  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/account/ConnectToServerDialog.java">cvs ConnectToServerDialog.java</a>
 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;  //  @jve:decl-index=0:
 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  
         /** Create the Connect to Server dialog
 102  
          * @param owner The parent dialog
 103  
          * @param commandDispatcher The commandDispatcher
 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  
          * This method initializes this
 123  
          * 
 124  
          * @return void
 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  
         /* (non-Javadoc)
 159  
          * @see com.buckosoft.fibs.BuckoFIBS.gui.account.ProfileSelectorNotifier#profileChanged()
 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  
          * This method initializes jContentPane
 171  
          * 
 172  
          * @return javax.swing.JPanel
 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  
         /** This method initializes userNameField        
 250  
          * @return javax.swing.JTextField        
 251  
          */
 252  
         private JTextField getUserNameField() {
 253  0
                 if (userNameField == null) {
 254  0
                         userNameField = new JTextField();
 255  
                 }
 256  0
                 return userNameField;
 257  
         }
 258  
 
 259  
         /**
 260  
          * This method initializes passwordTextField        
 261  
          *         
 262  
          * @return javax.swing.JTextField        
 263  
          */
 264  
         private JPasswordField getPasswordTextField() {
 265  0
                 if (passwordTextField == null) {
 266  0
                         passwordTextField = new JPasswordField();
 267  
                 }
 268  0
                 return passwordTextField;
 269  
         }
 270  
 
 271  
         /**
 272  
          * This method initializes jButtonConnect        
 273  
          *         
 274  
          * @return javax.swing.JButton        
 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  
          * This method initializes jButtonCancel        
 291  
          *         
 292  
          * @return javax.swing.JButton        
 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  
          * This method initializes jCreateNewAccountButton        
 309  
          *         
 310  
          * @return javax.swing.JButton        
 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  
          * This method initializes jButtonPanel        
 327  
          *         
 328  
          * @return javax.swing.JPanel        
 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  
          * This method initializes jPanelServerPort        
 362  
          *         
 363  
          * @return javax.swing.JPanel        
 364  
          */
 365  
         private ServerPortSelectorPanel getJPanelServerPort() {
 366  0
                 if (jPanelServerPort == null) {
 367  0
                         jPanelServerPort = new ServerPortSelectorPanel(properties);
 368  
 //                        jPanelServerPort.setProperties(properties);
 369  0
                         jPanelServerPort.setLayout(new GridBagLayout());
 370  
                 }
 371  0
                 return jPanelServerPort;
 372  
         }
 373  
 
 374  
         /**
 375  
          * This method initializes jPanelProfileSelector        
 376  
          *         
 377  
          * @return javax.swing.JPanel        
 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  
 }  //  @jve:decl-index=0:visual-constraint="10,10"