Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.account.ServerPortSelectorPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
ServerPortSelectorPanel
0%
0/58
0%
0/16
1.8
ServerPortSelectorPanel$1
0%
0/3
N/A
1.8
 
 1  
 /******************************************************************************
 2  
  * ServerPortSelectorPanel.java - A little panel the selects a server and a port
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.5  2013/09/08 06:21:17  dick
 10  
  * Pass the properties to the ServerPortSelectorPanel, so we can dynamically build the list of servers based on what's in the properties.
 11  
  * (Still need a way to add a new server, super low priority.)
 12  
  *
 13  
  * Revision 1.4  2011/05/31 19:37:28  dick
 14  
  * Add localhost to the list of servers.
 15  
  *
 16  
  * Revision 1.3  2010/03/03 13:12:21  inim
 17  
  * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
 18  
  *
 19  
  * Revision 1.2  2010/03/03 12:19:49  inim
 20  
  * 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.
 21  
  *
 22  
  * Revision 1.1  2010/02/04 05:57:53  inim
 23  
  * Mavenized project folder layout
 24  
  *
 25  
  * Revision 1.5  2009/02/11 09:05:36  dick
 26  
  * Make fibs.com the default server.
 27  
  *
 28  
  * Revision 1.4  2009/01/28 18:15:10  dick
 29  
  * Prettier cvs link in the javadoc.
 30  
  *
 31  
  * Revision 1.3  2009/01/07 20:33:04  dick
 32  
  * Show a dummy port selector dialog.
 33  
  *
 34  
  * Revision 1.2  2009/01/07 08:36:53  dick
 35  
  * Add setServerName for when the profile changes.
 36  
  *
 37  
  * Revision 1.1  2009/01/05 07:16:48  dick
 38  
  * A little panel the selects a server and a port
 39  
  *
 40  
  */
 41  
 package com.buckosoft.fibs.BuckoFIBS.gui.account;
 42  
 
 43  
 import javax.swing.ComboBoxModel;
 44  
 import javax.swing.JOptionPane;
 45  
 import javax.swing.JPanel;
 46  
 import javax.swing.JComboBox;
 47  
 import javax.swing.JButton;
 48  
 
 49  
 import com.buckosoft.fibs.BuckoFIBS.BFProperties;
 50  
 
 51  
 import java.awt.Font;
 52  
 import java.awt.Dimension;
 53  
 import java.awt.GridBagLayout;
 54  
 import java.awt.GridBagConstraints;
 55  
 import java.awt.Insets;
 56  
 
 57  
 /** A little panel the selects a server and a port
 58  
  * @author Dick Balaska
 59  
  * @since 2009/01/04
 60  
  * @version $Revision$ <br> $Date$
 61  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/account/ServerPortSelectorPanel.java">cvs ServerPortSelectorPanel.java</a>
 62  
  */
 63  0
 public class ServerPortSelectorPanel extends JPanel {
 64  
         private static final long serialVersionUID = 1L;
 65  0
         private JComboBox<String> jComboBoxServerName = null;
 66  0
         private JButton jButtonPort = null;
 67  0
         private        BFProperties properties = null;
 68  
 
 69  
         /** Create a ServerPortSelectorPanel
 70  
          * This method initializes 
 71  
          */
 72  
         public ServerPortSelectorPanel(BFProperties properties) {
 73  0
                 super();
 74  0
                 this.properties = properties;
 75  0
                 initialize();
 76  0
         }
 77  
 
 78  
         public void setProperties(BFProperties properties) {
 79  0
                 this.properties = properties;
 80  0
         }
 81  
         
 82  
         /** Get the name of the selected server.
 83  
          * @return most likely fibs.com
 84  
          */
 85  
         public String getServerName() {
 86  0
                 return((String)this.jComboBoxServerName.getSelectedItem());
 87  
         }
 88  
 
 89  
         /** Get the selected port number.
 90  
          * @return always 4321
 91  
          */
 92  
         public int getPort() {
 93  0
                 return(4321);
 94  
         }
 95  
 
 96  
         /** Set the selected server to be this one
 97  
          * @param s The name of the server to select.
 98  
          */
 99  
         public void setServerName(String s) {
 100  0
                 this.jComboBoxServerName.setSelectedItem(s);
 101  0
         }
 102  
 
 103  
         /**
 104  
          * This method initializes this
 105  
          * 
 106  
          */
 107  
         private void initialize() {
 108  0
         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
 109  0
         gridBagConstraints1.insets = new Insets(5, 3, 6, 5);
 110  0
         gridBagConstraints1.gridy = 0;
 111  0
         gridBagConstraints1.anchor = GridBagConstraints.EAST;
 112  0
         gridBagConstraints1.gridx = 1;
 113  0
         GridBagConstraints gridBagConstraints = new GridBagConstraints();
 114  0
         gridBagConstraints.fill = GridBagConstraints.BOTH;
 115  0
         gridBagConstraints.gridx = 0;
 116  0
         gridBagConstraints.gridy = 0;
 117  0
         gridBagConstraints.weightx = 1.0;
 118  0
         gridBagConstraints.anchor = GridBagConstraints.WEST;
 119  0
         gridBagConstraints.insets = new Insets(5, 5, 5, 2);
 120  0
         this.setLayout(new GridBagLayout());
 121  0
         this.setSize(new Dimension(99, 35));
 122  0
         this.add(getJComboBoxServerName(), gridBagConstraints);
 123  0
         this.add(getJButtonPort(), gridBagConstraints1);
 124  
                         
 125  0
         }
 126  
 
 127  
         /**
 128  
          * This method initializes jComboBoxServerName        
 129  
          *         
 130  
          * @return javax.swing.JComboBox        
 131  
          */
 132  
         private JComboBox<String> getJComboBoxServerName() {
 133  0
                 if (jComboBoxServerName == null) {
 134  0
                         jComboBoxServerName = new JComboBox<String>();
 135  0
                         jComboBoxServerName.setToolTipText("select a server");
 136  0
                         jComboBoxServerName.setSelectedIndex(-1);
 137  0
                         jComboBoxServerName.addItem("fibs.com");
 138  0
                         jComboBoxServerName.addItem("localhost");
 139  0
                         for (int i=0; i<this.properties.getProfileCount(); i++) {
 140  0
                                 String s = properties.getServerName(i);
 141  0
                                 boolean match = false;
 142  0
                                 ComboBoxModel<String> cm = jComboBoxServerName.getModel();
 143  0
                                 for (int j=0; j<cm.getSize(); j++) {
 144  0
                                         if (s.equals(cm.getElementAt(j))) {
 145  0
                                                 match = true;
 146  0
                                                 break;
 147  
                                         }
 148  
                                 }
 149  0
                                 if (!match)
 150  0
                                         jComboBoxServerName.addItem(s);
 151  
                         }
 152  
                 }
 153  0
                 return jComboBoxServerName;
 154  
         }
 155  
 
 156  
         /**
 157  
          * This method initializes jButtonPort        
 158  
          *         
 159  
          * @return javax.swing.JButton        
 160  
          */
 161  
         private JButton getJButtonPort() {
 162  0
                 if (jButtonPort == null) {
 163  0
                         jButtonPort = new JButton();
 164  0
                         jButtonPort.setText("Port");
 165  0
                         jButtonPort.setFont(new Font("Dialog", Font.PLAIN, 10));
 166  0
                         jButtonPort.addActionListener(new java.awt.event.ActionListener() {
 167  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 168  0
                                         selectPortDialog();
 169  0
                                 }
 170  
                         });
 171  
                 }
 172  0
                 return jButtonPort;
 173  
         }
 174  
         /** Show the dialog and return the name of the new Profile
 175  
          * @return The name of the new Profile, or null
 176  
          */
 177  
         private        void selectPortDialog() {
 178  
                 //newProfileNameDialog = new NewProfileNameDialog(owningDialog);
 179  0
                 String s = (String)JOptionPane.showInputDialog(
 180  
                                 this,
 181  
                 "Enter the port to connect to.\r\nDon't bother.  You get '4321' only.",
 182  
                 "Server Port",
 183  
                 JOptionPane.PLAIN_MESSAGE,
 184  
                 null,
 185  
                 null,
 186  
                 "4321");
 187  0
                 if (s == null || s.length() == 0)
 188  0
                         return;
 189  
 /*                this.properties.setProfileName(profileId, s);
 190  
                 this.properties.setUserName(profileId, "");
 191  
                 this.properties.setPassword(profileId, "");
 192  
                 this.jComboBoxProfileName.addItem(s);
 193  
                 this.jComboBoxProfileName.setSelectedIndex(profileId);
 194  
 */
 195  0
         }
 196  
 
 197  
 }  //  @jve:decl-index=0:visual-constraint="0,0"