View Javadoc
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  public class ServerPortSelectorPanel extends JPanel {
64  	private static final long serialVersionUID = 1L;
65  	private JComboBox<String> jComboBoxServerName = null;
66  	private JButton jButtonPort = null;
67  	private	BFProperties properties = null;
68  
69  	/** Create a ServerPortSelectorPanel
70  	 * This method initializes 
71  	 */
72  	public ServerPortSelectorPanel(BFProperties properties) {
73  		super();
74  		this.properties = properties;
75  		initialize();
76  	}
77  
78  	public void setProperties(BFProperties properties) {
79  		this.properties = properties;
80  	}
81  	
82  	/** Get the name of the selected server.
83  	 * @return most likely fibs.com
84  	 */
85  	public String getServerName() {
86  		return((String)this.jComboBoxServerName.getSelectedItem());
87  	}
88  
89  	/** Get the selected port number.
90  	 * @return always 4321
91  	 */
92  	public int getPort() {
93  		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 		this.jComboBoxServerName.setSelectedItem(s);
101 	}
102 
103 	/**
104 	 * This method initializes this
105 	 * 
106 	 */
107 	private void initialize() {
108         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
109         gridBagConstraints1.insets = new Insets(5, 3, 6, 5);
110         gridBagConstraints1.gridy = 0;
111         gridBagConstraints1.anchor = GridBagConstraints.EAST;
112         gridBagConstraints1.gridx = 1;
113         GridBagConstraints gridBagConstraints = new GridBagConstraints();
114         gridBagConstraints.fill = GridBagConstraints.BOTH;
115         gridBagConstraints.gridx = 0;
116         gridBagConstraints.gridy = 0;
117         gridBagConstraints.weightx = 1.0;
118         gridBagConstraints.anchor = GridBagConstraints.WEST;
119         gridBagConstraints.insets = new Insets(5, 5, 5, 2);
120         this.setLayout(new GridBagLayout());
121         this.setSize(new Dimension(99, 35));
122         this.add(getJComboBoxServerName(), gridBagConstraints);
123         this.add(getJButtonPort(), gridBagConstraints1);
124 			
125 	}
126 
127 	/**
128 	 * This method initializes jComboBoxServerName	
129 	 * 	
130 	 * @return javax.swing.JComboBox	
131 	 */
132 	private JComboBox<String> getJComboBoxServerName() {
133 		if (jComboBoxServerName == null) {
134 			jComboBoxServerName = new JComboBox<String>();
135 			jComboBoxServerName.setToolTipText("select a server");
136 			jComboBoxServerName.setSelectedIndex(-1);
137 			jComboBoxServerName.addItem("fibs.com");
138 			jComboBoxServerName.addItem("localhost");
139 			for (int i=0; i<this.properties.getProfileCount(); i++) {
140 				String s = properties.getServerName(i);
141 				boolean match = false;
142 				ComboBoxModel<String> cm = jComboBoxServerName.getModel();
143 				for (int j=0; j<cm.getSize(); j++) {
144 					if (s.equals(cm.getElementAt(j))) {
145 						match = true;
146 						break;
147 					}
148 				}
149 				if (!match)
150 					jComboBoxServerName.addItem(s);
151 			}
152 		}
153 		return jComboBoxServerName;
154 	}
155 
156 	/**
157 	 * This method initializes jButtonPort	
158 	 * 	
159 	 * @return javax.swing.JButton	
160 	 */
161 	private JButton getJButtonPort() {
162 		if (jButtonPort == null) {
163 			jButtonPort = new JButton();
164 			jButtonPort.setText("Port");
165 			jButtonPort.setFont(new Font("Dialog", Font.PLAIN, 10));
166 			jButtonPort.addActionListener(new java.awt.event.ActionListener() {
167 				public void actionPerformed(java.awt.event.ActionEvent e) {
168 					selectPortDialog();
169 				}
170 			});
171 		}
172 		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 		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 		if (s == null || s.length() == 0)
188 			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 	}
196 
197 }  //  @jve:decl-index=0:visual-constraint="0,0"