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 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
58
59
60
61
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
70
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
83
84
85 public String getServerName() {
86 return((String)this.jComboBoxServerName.getSelectedItem());
87 }
88
89
90
91
92 public int getPort() {
93 return(4321);
94 }
95
96
97
98
99 public void setServerName(String s) {
100 this.jComboBoxServerName.setSelectedItem(s);
101 }
102
103
104
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
129
130
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
158
159
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
175
176
177 private void selectPortDialog() {
178
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
190
191
192
193
194
195 }
196
197 }