View Javadoc
1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is ""  Description:
10   * ""
11   *
12   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13   * 2001.  All Rights Reserved.
14   *
15   * Contributor(s): ______________________________________.
16   *
17   * Alternatively, the contents of this file may be used under the terms of the
18   * GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
19   * applicable instead of those above.  If you wish to allow use of your version of this
20   * file only under the terms of the GPL and not to allow others to use your version
21   * of this file under the MPL, indicate your decision by deleting  the provisions above
22   * and replace  them with the notice and other provisions required by the GPL License.
23   * If you do not delete the provisions above, a recipient may use your version of
24   * this file under either the MPL or the GPL.
25   */
26  package ca.uhn.hl7v2.testpanel.ui.conn;
27  
28  import static org.apache.commons.lang.StringUtils.*;
29  
30  import java.awt.BorderLayout;
31  import java.awt.CardLayout;
32  import java.awt.Color;
33  import java.awt.Dimension;
34  import java.awt.GridBagConstraints;
35  import java.awt.GridBagLayout;
36  import java.awt.Insets;
37  import java.awt.event.ActionEvent;
38  import java.awt.event.ActionListener;
39  import java.beans.PropertyChangeEvent;
40  import java.beans.PropertyChangeListener;
41  import java.net.MalformedURLException;
42  import java.net.URL;
43  import java.nio.charset.Charset;
44  import java.security.KeyStore;
45  import java.security.KeyStoreException;
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  import javax.swing.ButtonGroup;
51  import javax.swing.ComboBoxModel;
52  import javax.swing.DefaultComboBoxModel;
53  import javax.swing.ImageIcon;
54  import javax.swing.JButton;
55  import javax.swing.JCheckBox;
56  import javax.swing.JComboBox;
57  import javax.swing.JFileChooser;
58  import javax.swing.JLabel;
59  import javax.swing.JPanel;
60  import javax.swing.JRadioButton;
61  import javax.swing.JTextField;
62  import javax.swing.SwingConstants;
63  import javax.swing.SwingUtilities;
64  import javax.swing.border.EtchedBorder;
65  import javax.swing.event.DocumentEvent;
66  
67  import org.apache.commons.lang.StringUtils;
68  
69  import ca.uhn.hl7v2.testpanel.controller.Controller;
70  import ca.uhn.hl7v2.testpanel.controller.Prefs;
71  import ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection;
72  import ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.StatusEnum;
73  import ca.uhn.hl7v2.testpanel.model.conn.OutboundConnection;
74  import ca.uhn.hl7v2.testpanel.model.conn.TransportStyleEnum;
75  import ca.uhn.hl7v2.testpanel.ui.IDestroyable;
76  import ca.uhn.hl7v2.testpanel.util.SimpleDocumentListener;
77  import ca.uhn.hl7v2.testpanel.xsd.Hl7V2EncodingTypeEnum;
78  
79  public class Hl7ConnectionPanelBackup extends JPanel implements IDestroyable {
80  	private static final Color ERROR_BG = new Color(1.0f, 0.8f, 0.8f);
81  	private static final String IFACE_TYPE_CARD_HOH = "hohCard";
82  	private static final String IFACE_TYPE_CARD_MLLP = "name_1344598061103376000";
83  
84  	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Hl7ConnectionPanelBackup.class);
85  	private final ButtonGroup charsetButtonGroup = new ButtonGroup();
86  	private final ButtonGroup encodingButtonGroup = new ButtonGroup();
87  	private JCheckBox myCaptureByteStreamCheckbox;
88  	private JComboBox myCharsetCombo;
89  	private JRadioButton myCharsetDetectRadio;
90  	private JRadioButton myCharsetSelectRadio;
91  	private AbstractConnection myConnection;
92  	private Controller myController;
93  	private JTextField myDualIncomingTextBox;
94  	private JTextField myDualOutgoingTextBox;
95  	private JRadioButton myDualPortRadio;
96  	private JRadioButton myEr7Radio;
97  	private JRadioButton myHl7OverHttpRadioButton;
98  	private JPanel myHoHCard;
99  	private JTextField myHohSecurityKeyPwTextBox;
100 	private boolean myHohSecurityKeystoreCheckIsScheduled;
101 	private JButton myHohSecurityKeystoreChooseBtn;
102 	private JTextField myHohSecurityKeystoreTextbox;
103 	private JLabel myHohSecurityProfileKeystoreStatus;
104 	private JCheckBox myHohTlsCheckbox;
105 	private JTextField myHoHUrlTextField;
106 	private boolean myHohUrlTextFieldUpdating;
107 	private JTextField myHostBox;
108 	private JPanel myInterfaceTypeCardPanel;
109 	private JLabel mylabel;
110 	private JLabel mylabel_1;
111 	private JLabel mylabel_2;
112 	private JLabel mylabel_3;
113 	private JLabel mylabel_4;
114 	private JPanel myMllpCard;
115 	private JPanel mypanel;
116 	private JPanel mypanel_1;
117 	private final ButtonGroup myPortButtonGroup = new ButtonGroup();
118 	private JRadioButton mySinglePortRadio;
119 	private JTextField mySinglePortTextBox;
120 	private PropertyChangeListener myStatusLinePropertyChangeListener;
121 	private PropertyChangeListener myStatusPropertyChangeListener;
122 	private JCheckBox myTlsCheckbox;
123 	private JRadioButton myXmlRadio;
124 
125 	private JPanel securityProfilePanel;
126 
127 	private JPanel tlsKeystorePanel;
128 	private JLabel mylabel_5;
129 	private JPanel mypanel_2;
130 	private JLabel mylabel_6;
131 	private JPanel hohAuthPanel;
132 	private JCheckBox myHohAuthEnabledCheckbox;
133 	private JLabel mylabel_7;
134 	private JTextField myHohAuthUsernameTextbox;
135 	private JLabel mylabel_8;
136 	private JTextField myHohAuthPasswordTextbox;
137 
138 	/**
139 	 * Create the panel.
140 	 */
141 	public Hl7ConnectionPanelBackup(Controller theController) {
142 		myController = theController;
143 
144 		setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
145 		GridBagLayout gridBagLayout = new GridBagLayout();
146 		gridBagLayout.columnWidths = new int[] { 150, 0 };
147 		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
148 		gridBagLayout.columnWeights = new double[] { 0.0, 1.0 };
149 		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
150 		setLayout(gridBagLayout);
151 
152 		mySinglePortRadio = new JRadioButton("Single Port MLLP");
153 		mySinglePortRadio.addActionListener(new ActionListener() {
154 			public void actionPerformed(ActionEvent e) {
155 				updatePortsModel();
156 				updatePortsUi();
157 			}
158 		});
159 		myPortButtonGroup.add(mySinglePortRadio);
160 		GridBagConstraints gbc_SinglePortRadio = new GridBagConstraints();
161 		gbc_SinglePortRadio.anchor = GridBagConstraints.WEST;
162 		gbc_SinglePortRadio.insets = new Insets(0, 0, 5, 5);
163 		gbc_SinglePortRadio.gridx = 0;
164 		gbc_SinglePortRadio.gridy = 0;
165 		add(mySinglePortRadio, gbc_SinglePortRadio);
166 
167 		JPanel panel_4 = new JPanel();
168 		panel_4.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
169 		GridBagConstraints gbc_panel_4 = new GridBagConstraints();
170 		gbc_panel_4.fill = GridBagConstraints.BOTH;
171 		gbc_panel_4.insets = new Insets(0, 0, 5, 0);
172 		gbc_panel_4.gridx = 1;
173 		gbc_panel_4.gridy = 0;
174 		add(panel_4, gbc_panel_4);
175 		GridBagLayout gbl_panel_4 = new GridBagLayout();
176 		gbl_panel_4.columnWidths = new int[] { 0, 0, 0 };
177 		gbl_panel_4.rowHeights = new int[] { 0, 0 };
178 		gbl_panel_4.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
179 		gbl_panel_4.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
180 		panel_4.setLayout(gbl_panel_4);
181 
182 		mySinglePortTextBox = new JTextField();
183 		mySinglePortTextBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
184 			@Override
185 			public void update(DocumentEvent theE) {
186 				String text = mySinglePortTextBox.getText();
187 				text = text.replaceAll("[^0-9]+", "");
188 				if (!StringUtils.equals(mySinglePortTextBox.getText(), text)) {
189 					final String newVal = text;
190 					SwingUtilities.invokeLater(new Runnable() {
191 						public void run() {
192 							mySinglePortTextBox.setText(newVal);
193 						}
194 					});
195 				}
196 				if (mySinglePortRadio.isSelected()) {
197 					if (text.length() > 0) {
198 						myConnection.setIncomingOrSinglePort(Integer.parseInt(text));
199 					} else {
200 						myConnection.setIncomingOrSinglePort(-1);
201 					}
202 				}
203 			}
204 		});
205 
206 		mylabel = new JLabel("Port");
207 		mylabel.setHorizontalAlignment(SwingConstants.CENTER);
208 		mylabel.setPreferredSize(new Dimension(60, 16));
209 		mylabel.setMinimumSize(new Dimension(60, 16));
210 		mylabel.setMaximumSize(new Dimension(60, 16));
211 		GridBagConstraints gbc_label = new GridBagConstraints();
212 		gbc_label.anchor = GridBagConstraints.EAST;
213 		gbc_label.insets = new Insets(0, 0, 0, 5);
214 		gbc_label.gridx = 0;
215 		gbc_label.gridy = 0;
216 		panel_4.add(mylabel, gbc_label);
217 		GridBagConstraints gbc_SinglePortTextBox = new GridBagConstraints();
218 		gbc_SinglePortTextBox.insets = new Insets(0, 5, 0, 0);
219 		gbc_SinglePortTextBox.anchor = GridBagConstraints.WEST;
220 		gbc_SinglePortTextBox.gridx = 1;
221 		gbc_SinglePortTextBox.gridy = 0;
222 		panel_4.add(mySinglePortTextBox, gbc_SinglePortTextBox);
223 		mySinglePortTextBox.setMinimumSize(new Dimension(100, 28));
224 		mySinglePortTextBox.setMaximumSize(new Dimension(100, 2147483647));
225 		mySinglePortTextBox.setColumns(10);
226 
227 		myDualPortRadio = new JRadioButton("Dual Port MLLP");
228 		myDualPortRadio.addActionListener(new ActionListener() {
229 			public void actionPerformed(ActionEvent e) {
230 				updatePortsModel();
231 				updatePortsUi();
232 			}
233 		});
234 		myPortButtonGroup.add(myDualPortRadio);
235 		GridBagConstraints gbc_DualPortRadio = new GridBagConstraints();
236 		gbc_DualPortRadio.anchor = GridBagConstraints.WEST;
237 		gbc_DualPortRadio.insets = new Insets(0, 0, 5, 5);
238 		gbc_DualPortRadio.gridx = 0;
239 		gbc_DualPortRadio.gridy = 1;
240 		add(myDualPortRadio, gbc_DualPortRadio);
241 
242 		JPanel panel = new JPanel();
243 		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
244 		GridBagConstraints gbc_BottomPanel = new GridBagConstraints();
245 		gbc_BottomPanel.insets = new Insets(0, 0, 5, 0);
246 		gbc_BottomPanel.fill = GridBagConstraints.BOTH;
247 		gbc_BottomPanel.gridx = 1;
248 		gbc_BottomPanel.gridy = 1;
249 		add(panel, gbc_BottomPanel);
250 		GridBagLayout gbl_panel = new GridBagLayout();
251 		gbl_panel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0 };
252 		gbl_panel.rowHeights = new int[] { 0, 0 };
253 		gbl_panel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
254 		gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
255 		panel.setLayout(gbl_panel);
256 
257 		JLabel lblInbound = new JLabel("Inbound");
258 		lblInbound.setHorizontalAlignment(SwingConstants.CENTER);
259 		lblInbound.setPreferredSize(new Dimension(60, 16));
260 		lblInbound.setMinimumSize(new Dimension(60, 16));
261 		lblInbound.setMaximumSize(new Dimension(60, 16));
262 		GridBagConstraints gbc_lblInbound = new GridBagConstraints();
263 		gbc_lblInbound.insets = new Insets(0, 5, 0, 5);
264 		gbc_lblInbound.anchor = GridBagConstraints.EAST;
265 		gbc_lblInbound.gridx = 0;
266 		gbc_lblInbound.gridy = 0;
267 		panel.add(lblInbound, gbc_lblInbound);
268 
269 		myDualIncomingTextBox = new JTextField();
270 		myDualIncomingTextBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
271 			@Override
272 			public void update(DocumentEvent theE) {
273 				String text = myDualIncomingTextBox.getText();
274 				text = text.replaceAll("[^0-9]+", "");
275 				if (!StringUtils.equals(myDualIncomingTextBox.getText(), text)) {
276 					final String newVal = text;
277 					SwingUtilities.invokeLater(new Runnable() {
278 						public void run() {
279 							myDualIncomingTextBox.setText(newVal);
280 						}
281 					});
282 				}
283 				if (myDualPortRadio.isSelected()) {
284 					if (text.length() > 0) {
285 						myConnection.setIncomingOrSinglePort(Integer.parseInt(text));
286 					} else {
287 						myConnection.setIncomingOrSinglePort(-1);
288 					}
289 				}
290 			}
291 		});
292 		myDualIncomingTextBox.setMaximumSize(new Dimension(100, 2147483647));
293 		myDualIncomingTextBox.setMinimumSize(new Dimension(100, 28));
294 		GridBagConstraints gbc_DualIncomingTextBox = new GridBagConstraints();
295 		gbc_DualIncomingTextBox.anchor = GridBagConstraints.WEST;
296 		gbc_DualIncomingTextBox.insets = new Insets(0, 0, 0, 5);
297 		gbc_DualIncomingTextBox.gridx = 1;
298 		gbc_DualIncomingTextBox.gridy = 0;
299 		panel.add(myDualIncomingTextBox, gbc_DualIncomingTextBox);
300 		myDualIncomingTextBox.setColumns(10);
301 
302 		JLabel lblOutbound = new JLabel("Outbound");
303 		GridBagConstraints gbc_lblOutbound = new GridBagConstraints();
304 		gbc_lblOutbound.anchor = GridBagConstraints.EAST;
305 		gbc_lblOutbound.insets = new Insets(0, 0, 0, 5);
306 		gbc_lblOutbound.gridx = 2;
307 		gbc_lblOutbound.gridy = 0;
308 		panel.add(lblOutbound, gbc_lblOutbound);
309 
310 		myDualOutgoingTextBox = new JTextField();
311 		myDualOutgoingTextBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
312 			@Override
313 			public void update(DocumentEvent theE) {
314 				String text = myDualOutgoingTextBox.getText();
315 				text = text.replaceAll("[^0-9]+", "");
316 				if (!StringUtils.equals(myDualOutgoingTextBox.getText(), text)) {
317 					final String newVal = text;
318 					SwingUtilities.invokeLater(new Runnable() {
319 						public void run() {
320 							myDualOutgoingTextBox.setText(newVal);
321 						}
322 					});
323 				}
324 				if (myDualPortRadio.isSelected()) {
325 					if (text.length() > 0) {
326 						myConnection.setOutgoingPort(Integer.parseInt(text));
327 					} else {
328 						myConnection.setOutgoingPort(-1);
329 					}
330 				}
331 			}
332 		});
333 		myDualOutgoingTextBox.setMinimumSize(new Dimension(100, 28));
334 		myDualOutgoingTextBox.setMaximumSize(new Dimension(100, 2147483647));
335 		GridBagConstraints gbc_DualOutgoingTextBox = new GridBagConstraints();
336 		gbc_DualOutgoingTextBox.insets = new Insets(0, 0, 0, 5);
337 		gbc_DualOutgoingTextBox.anchor = GridBagConstraints.WEST;
338 		gbc_DualOutgoingTextBox.gridx = 3;
339 		gbc_DualOutgoingTextBox.gridy = 0;
340 		panel.add(myDualOutgoingTextBox, gbc_DualOutgoingTextBox);
341 		myDualOutgoingTextBox.setColumns(10);
342 
343 		myHl7OverHttpRadioButton = new JRadioButton("HL7 over HTTP");
344 		myHl7OverHttpRadioButton.addActionListener(new ActionListener() {
345 			public void actionPerformed(ActionEvent e) {
346 				updatePortsModel();
347 				updatePortsUi();
348 			}
349 		});
350 		myPortButtonGroup.add(myHl7OverHttpRadioButton);
351 		GridBagConstraints gbc_Hl7OverHttpRadioButton = new GridBagConstraints();
352 		gbc_Hl7OverHttpRadioButton.anchor = GridBagConstraints.WEST;
353 		gbc_Hl7OverHttpRadioButton.insets = new Insets(0, 0, 5, 5);
354 		gbc_Hl7OverHttpRadioButton.gridx = 0;
355 		gbc_Hl7OverHttpRadioButton.gridy = 2;
356 		add(myHl7OverHttpRadioButton, gbc_Hl7OverHttpRadioButton);
357 
358 		mypanel = new JPanel();
359 		mypanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
360 		GridBagConstraints gbc_panel = new GridBagConstraints();
361 		gbc_panel.insets = new Insets(0, 0, 5, 0);
362 		gbc_panel.fill = GridBagConstraints.BOTH;
363 		gbc_panel.gridx = 1;
364 		gbc_panel.gridy = 2;
365 		add(mypanel, gbc_panel);
366 		GridBagLayout gbl_panel2 = new GridBagLayout();
367 		gbl_panel2.columnWidths = new int[] { 0, 0 };
368 		gbl_panel2.rowHeights = new int[] { 0, 0 };
369 		gbl_panel2.columnWeights = new double[] { 0.0, 1.0 };
370 		gbl_panel2.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
371 		mypanel.setLayout(gbl_panel2);
372 
373 		mylabel_1 = new JLabel("URL");
374 		mylabel_1.setHorizontalAlignment(SwingConstants.CENTER);
375 		mylabel_1.setPreferredSize(new Dimension(60, 16));
376 		mylabel_1.setMinimumSize(new Dimension(60, 16));
377 		mylabel_1.setMaximumSize(new Dimension(60, 16));
378 		GridBagConstraints gbc_label_1 = new GridBagConstraints();
379 		gbc_label_1.anchor = GridBagConstraints.EAST;
380 		gbc_label_1.insets = new Insets(0, 0, 0, 5);
381 		gbc_label_1.gridx = 0;
382 		gbc_label_1.gridy = 0;
383 		mypanel.add(mylabel_1, gbc_label_1);
384 
385 		myHoHUrlTextField = new JTextField();
386 		myHoHUrlTextField.getDocument().addDocumentListener(new SimpleDocumentListener() {
387 			@Override
388 			public void update(DocumentEvent theE) {
389 				if (myHohUrlTextFieldUpdating) {
390 					return;
391 				}
392 
393 				String value = myHoHUrlTextField.getText();
394 				try {
395 					URL url = new URL(value);
396 					boolean tls;
397 					if (url.getProtocol().equals("http")) {
398 						tls = false;
399 					} else if (url.getProtocol().equals("https")) {
400 						tls = true;
401 					} else {
402 						ourLog.info("Unknown protocol: {}", url.getProtocol());
403 						myHoHUrlTextField.setBackground(ERROR_BG);
404 						return;
405 					}
406 
407 					myConnection.setTls(tls);
408 					myConnection.setHost(url.getHost());
409 					myConnection.setIncomingOrSinglePort(url.getPort() != -1 ? url.getPort() : url.getDefaultPort());
410 					myConnection.setHttpUriPath(url.getPath());
411 
412 					myHohUrlTextFieldUpdating = true;
413 					updatePortsUi();
414 					myHohUrlTextFieldUpdating = false;
415 
416 					myTlsCheckbox.setSelected(tls);
417 					myHohTlsCheckbox.setSelected(tls);
418 
419 					myHoHUrlTextField.setBackground(Color.white);
420 				} catch (MalformedURLException e) {
421 					myHoHUrlTextField.setBackground(ERROR_BG);
422 				}
423 
424 			}
425 		});
426 		GridBagConstraints gbc_HohUsernameTextbox = new GridBagConstraints();
427 		gbc_HohUsernameTextbox.fill = GridBagConstraints.HORIZONTAL;
428 		gbc_HohUsernameTextbox.gridx = 1;
429 		gbc_HohUsernameTextbox.gridy = 0;
430 		mypanel.add(myHoHUrlTextField, gbc_HohUsernameTextbox);
431 		myHoHUrlTextField.setColumns(10);
432 
433 		JLabel lblEncoding = new JLabel("Encoding");
434 		GridBagConstraints gbc_lblEncoding = new GridBagConstraints();
435 		gbc_lblEncoding.insets = new Insets(0, 0, 5, 5);
436 		gbc_lblEncoding.gridx = 0;
437 		gbc_lblEncoding.gridy = 3;
438 		add(lblEncoding, gbc_lblEncoding);
439 
440 		JPanel encodingPanel = new JPanel();
441 		GridBagConstraints gbc_encodingPanel = new GridBagConstraints();
442 		gbc_encodingPanel.fill = GridBagConstraints.HORIZONTAL;
443 		gbc_encodingPanel.insets = new Insets(0, 0, 5, 0);
444 		gbc_encodingPanel.gridx = 1;
445 		gbc_encodingPanel.gridy = 3;
446 		add(encodingPanel, gbc_encodingPanel);
447 		encodingPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
448 		GridBagLayout gbl_encodingPanel = new GridBagLayout();
449 		gbl_encodingPanel.columnWidths = new int[] { 144, 58, 0 };
450 		gbl_encodingPanel.rowHeights = new int[] { 23, 0 };
451 		gbl_encodingPanel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
452 		gbl_encodingPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
453 		encodingPanel.setLayout(gbl_encodingPanel);
454 
455 		myXmlRadio = new JRadioButton("XML");
456 		myXmlRadio.addActionListener(new ActionListener() {
457 
458 			public void actionPerformed(ActionEvent theE) {
459 				updateEncodingModel();
460 			}
461 		});
462 
463 		myEr7Radio = new JRadioButton("ER7 (Pipe and hat)");
464 		myEr7Radio.addActionListener(new ActionListener() {
465 			public void actionPerformed(ActionEvent e) {
466 				updateEncodingModel();
467 			}
468 		});
469 		encodingButtonGroup.add(myEr7Radio);
470 		GridBagConstraints gbc_Er7Radio = new GridBagConstraints();
471 		gbc_Er7Radio.anchor = GridBagConstraints.NORTHWEST;
472 		gbc_Er7Radio.insets = new Insets(0, 0, 0, 5);
473 		gbc_Er7Radio.gridx = 0;
474 		gbc_Er7Radio.gridy = 0;
475 		encodingPanel.add(myEr7Radio, gbc_Er7Radio);
476 		encodingButtonGroup.add(myXmlRadio);
477 		GridBagConstraints gbc_XmlRadio = new GridBagConstraints();
478 		gbc_XmlRadio.anchor = GridBagConstraints.NORTHWEST;
479 		gbc_XmlRadio.gridx = 1;
480 		gbc_XmlRadio.gridy = 0;
481 		encodingPanel.add(myXmlRadio, gbc_XmlRadio);
482 
483 		JLabel lblCharset = new JLabel("Charset");
484 		GridBagConstraints gbc_lblCharset = new GridBagConstraints();
485 		gbc_lblCharset.insets = new Insets(0, 0, 5, 5);
486 		gbc_lblCharset.gridx = 0;
487 		gbc_lblCharset.gridy = 4;
488 		add(lblCharset, gbc_lblCharset);
489 
490 		JPanel panel_2 = new JPanel();
491 		GridBagConstraints gbc_panel_2 = new GridBagConstraints();
492 		gbc_panel_2.fill = GridBagConstraints.HORIZONTAL;
493 		gbc_panel_2.insets = new Insets(0, 0, 5, 0);
494 		gbc_panel_2.gridx = 1;
495 		gbc_panel_2.gridy = 4;
496 		add(panel_2, gbc_panel_2);
497 		panel_2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
498 		GridBagLayout gbl_panel_2 = new GridBagLayout();
499 		gbl_panel_2.columnWidths = new int[] { 28, 198, 0, 0 };
500 		gbl_panel_2.rowHeights = new int[] { 27, 0 };
501 		gbl_panel_2.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
502 		gbl_panel_2.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
503 		panel_2.setLayout(gbl_panel_2);
504 
505 		myCharsetSelectRadio = new JRadioButton("");
506 		myCharsetSelectRadio.addActionListener(new ActionListener() {
507 			public void actionPerformed(ActionEvent e) {
508 				updateCharsetModel();
509 			}
510 		});
511 		charsetButtonGroup.add(myCharsetSelectRadio);
512 		GridBagConstraints gbc_CharsetSelectRadio = new GridBagConstraints();
513 		gbc_CharsetSelectRadio.anchor = GridBagConstraints.WEST;
514 		gbc_CharsetSelectRadio.insets = new Insets(0, 0, 0, 5);
515 		gbc_CharsetSelectRadio.gridx = 0;
516 		gbc_CharsetSelectRadio.gridy = 0;
517 		panel_2.add(myCharsetSelectRadio, gbc_CharsetSelectRadio);
518 
519 		myCharsetCombo = new JComboBox();
520 		myCharsetCombo.addActionListener(new ActionListener() {
521 			public void actionPerformed(ActionEvent e) {
522 				updateCharsetModel();
523 			}
524 		});
525 		GridBagConstraints gbc_CharsetCombo = new GridBagConstraints();
526 		gbc_CharsetCombo.anchor = GridBagConstraints.NORTHWEST;
527 		gbc_CharsetCombo.insets = new Insets(0, 0, 0, 5);
528 		gbc_CharsetCombo.gridx = 1;
529 		gbc_CharsetCombo.gridy = 0;
530 		panel_2.add(myCharsetCombo, gbc_CharsetCombo);
531 
532 		myCharsetDetectRadio = new JRadioButton("Detect in Message (MSH-18)");
533 		myCharsetDetectRadio.addActionListener(new ActionListener() {
534 			public void actionPerformed(ActionEvent e) {
535 				updateCharsetModel();
536 			}
537 		});
538 		charsetButtonGroup.add(myCharsetDetectRadio);
539 		GridBagConstraints gbc_CharsetDetectRadio = new GridBagConstraints();
540 		gbc_CharsetDetectRadio.anchor = GridBagConstraints.NORTH;
541 		gbc_CharsetDetectRadio.gridwidth = 2;
542 		gbc_CharsetDetectRadio.gridx = 2;
543 		gbc_CharsetDetectRadio.gridy = 0;
544 		panel_2.add(myCharsetDetectRadio, gbc_CharsetDetectRadio);
545 		
546 		mylabel_5 = new JLabel("Debug");
547 		GridBagConstraints gbc_label_5 = new GridBagConstraints();
548 		gbc_label_5.insets = new Insets(0, 0, 5, 5);
549 		gbc_label_5.gridx = 0;
550 		gbc_label_5.gridy = 5;
551 		add(mylabel_5, gbc_label_5);
552 		
553 		mypanel_2 = new JPanel();
554 		mypanel_2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
555 		GridBagConstraints gbc_panel_75 = new GridBagConstraints();
556 		gbc_panel_75.insets = new Insets(0, 0, 5, 0);
557 		gbc_panel_75.fill = GridBagConstraints.BOTH;
558 		gbc_panel_75.gridx = 1;
559 		gbc_panel_75.gridy = 5;
560 		add(mypanel_2, gbc_panel_75);
561 		GridBagLayout gbl_panel_74 = new GridBagLayout();
562 		gbl_panel_74.columnWidths = new int[]{0, 0};
563 		gbl_panel_74.rowHeights = new int[]{0, 0};
564 		gbl_panel_74.columnWeights = new double[]{0.0, Double.MIN_VALUE};
565 		gbl_panel_74.rowWeights = new double[]{0.0, Double.MIN_VALUE};
566 		mypanel_2.setLayout(gbl_panel_74);
567 		
568 				myCaptureByteStreamCheckbox = new JCheckBox("Capture Bytes");
569 				GridBagConstraints gbc_CaptureByteStreamCheckbox = new GridBagConstraints();
570 				gbc_CaptureByteStreamCheckbox.gridx = 0;
571 				gbc_CaptureByteStreamCheckbox.gridy = 0;
572 				mypanel_2.add(myCaptureByteStreamCheckbox, gbc_CaptureByteStreamCheckbox);
573 				myCaptureByteStreamCheckbox.addActionListener(new ActionListener() {
574 					public void actionPerformed(ActionEvent e) {
575 						myConnection.setCaptureBytes(myCaptureByteStreamCheckbox.isSelected());
576 					}
577 				});
578 				myCaptureByteStreamCheckbox.setToolTipText("Check this box to capture the transport level communication");
579 
580 		myInterfaceTypeCardPanel = new JPanel();
581 		myInterfaceTypeCardPanel.setBorder(null);
582 		GridBagConstraints gbc_InterfaceTypeCardPanel = new GridBagConstraints();
583 		gbc_InterfaceTypeCardPanel.gridwidth = 2;
584 		gbc_InterfaceTypeCardPanel.fill = GridBagConstraints.BOTH;
585 		gbc_InterfaceTypeCardPanel.gridx = 0;
586 		gbc_InterfaceTypeCardPanel.gridy = 6;
587 		add(myInterfaceTypeCardPanel, gbc_InterfaceTypeCardPanel);
588 		myInterfaceTypeCardPanel.setLayout(new CardLayout(0, 0));
589 
590 		myMllpCard = new JPanel();
591 		myMllpCard.setBorder(null);
592 		myInterfaceTypeCardPanel.add(myMllpCard, IFACE_TYPE_CARD_MLLP);
593 		GridBagLayout gbl_MllpCard = new GridBagLayout();
594 		gbl_MllpCard.columnWidths = new int[] { 150, 0, 0 };
595 		gbl_MllpCard.rowHeights = new int[] { 0, 0, 0, 0 };
596 		gbl_MllpCard.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
597 		gbl_MllpCard.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
598 		myMllpCard.setLayout(gbl_MllpCard);
599 
600 		JLabel lblHost = new JLabel("Host");
601 		GridBagConstraints gbc_lblHost = new GridBagConstraints();
602 		gbc_lblHost.insets = new Insets(0, 0, 5, 5);
603 		gbc_lblHost.gridx = 0;
604 		gbc_lblHost.gridy = 0;
605 		myMllpCard.add(lblHost, gbc_lblHost);
606 
607 		mypanel_1 = new JPanel();
608 		mypanel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
609 		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
610 		gbc_panel_1.insets = new Insets(0, 0, 5, 0);
611 		gbc_panel_1.fill = GridBagConstraints.BOTH;
612 		gbc_panel_1.gridx = 1;
613 		gbc_panel_1.gridy = 0;
614 		myMllpCard.add(mypanel_1, gbc_panel_1);
615 		GridBagLayout gbl_panel_1 = new GridBagLayout();
616 		gbl_panel_1.columnWidths = new int[] { 134, 0 };
617 		gbl_panel_1.rowHeights = new int[] { 28, 0 };
618 		gbl_panel_1.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
619 		gbl_panel_1.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
620 		mypanel_1.setLayout(gbl_panel_1);
621 
622 		myHostBox = new JTextField();
623 		GridBagConstraints gbc_HostBox = new GridBagConstraints();
624 		gbc_HostBox.fill = GridBagConstraints.HORIZONTAL;
625 		gbc_HostBox.anchor = GridBagConstraints.NORTH;
626 		gbc_HostBox.gridx = 0;
627 		gbc_HostBox.gridy = 0;
628 		mypanel_1.add(myHostBox, gbc_HostBox);
629 		myHostBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
630 			@Override
631 			public void update(DocumentEvent theE) {
632 				myConnection.setHost(myHostBox.getText());
633 			}
634 		});
635 		myHostBox.setColumns(10);
636 
637 		JLabel lblTransport = new JLabel("Transport");
638 		GridBagConstraints gbc_lblTransport = new GridBagConstraints();
639 		gbc_lblTransport.insets = new Insets(0, 0, 5, 5);
640 		gbc_lblTransport.gridx = 0;
641 		gbc_lblTransport.gridy = 1;
642 		myMllpCard.add(lblTransport, gbc_lblTransport);
643 
644 		JPanel panel_3 = new JPanel();
645 		GridBagConstraints gbc_hohAuthPanel = new GridBagConstraints();
646 		gbc_hohAuthPanel.fill = GridBagConstraints.HORIZONTAL;
647 		gbc_hohAuthPanel.insets = new Insets(0, 0, 5, 0);
648 		gbc_hohAuthPanel.gridx = 1;
649 		gbc_hohAuthPanel.gridy = 1;
650 		myMllpCard.add(panel_3, gbc_hohAuthPanel);
651 		panel_3.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
652 		GridBagLayout gbl_hohAuthPanel = new GridBagLayout();
653 		gbl_hohAuthPanel.columnWidths = new int[] { 0, 0, 0 };
654 		gbl_hohAuthPanel.rowHeights = new int[] { 0, 0 };
655 		gbl_hohAuthPanel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
656 		gbl_hohAuthPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
657 		panel_3.setLayout(gbl_hohAuthPanel);
658 
659 		myTlsCheckbox = new JCheckBox("Use TLS/SSL");
660 		myTlsCheckbox.addActionListener(new ActionListener() {
661 			public void actionPerformed(ActionEvent e) {
662 				myHohTlsCheckbox.setSelected(myTlsCheckbox.isSelected());
663 				myConnection.setTls(myTlsCheckbox.isSelected());
664 			}
665 		});
666 		GridBagConstraints gbc_TlsCheckbox = new GridBagConstraints();
667 		gbc_TlsCheckbox.insets = new Insets(0, 0, 0, 5);
668 		gbc_TlsCheckbox.anchor = GridBagConstraints.WEST;
669 		gbc_TlsCheckbox.gridx = 0;
670 		gbc_TlsCheckbox.gridy = 0;
671 		panel_3.add(myTlsCheckbox, gbc_TlsCheckbox);
672 
673 		myHoHCard = new JPanel();
674 		myInterfaceTypeCardPanel.add(myHoHCard, IFACE_TYPE_CARD_HOH);
675 		GridBagLayout gbl_HoHCard = new GridBagLayout();
676 		gbl_HoHCard.columnWidths = new int[] { 150, 0, 0 };
677 		gbl_HoHCard.rowHeights = new int[] { 0, 0, 0, 0 };
678 		gbl_HoHCard.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
679 		gbl_HoHCard.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
680 		myHoHCard.setLayout(gbl_HoHCard);
681 		
682 		mylabel_6 = new JLabel("Authorization");
683 		GridBagConstraints gbc_label_6 = new GridBagConstraints();
684 		gbc_label_6.insets = new Insets(0, 0, 5, 5);
685 		gbc_label_6.gridx = 0;
686 		gbc_label_6.gridy = 0;
687 		myHoHCard.add(mylabel_6, gbc_label_6);
688 		
689 		hohAuthPanel = new JPanel();
690 		hohAuthPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
691 		GridBagConstraints gbc_hohAuthPanel2 = new GridBagConstraints();
692 		gbc_hohAuthPanel2.insets = new Insets(0, 0, 5, 0);
693 		gbc_hohAuthPanel2.fill = GridBagConstraints.BOTH;
694 		gbc_hohAuthPanel2.gridx = 1;
695 		gbc_hohAuthPanel2.gridy = 0;
696 		myHoHCard.add(hohAuthPanel, gbc_hohAuthPanel2);
697 		GridBagLayout gbl_hohAuthPanel3 = new GridBagLayout();
698 		gbl_hohAuthPanel3.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0};
699 		gbl_hohAuthPanel3.rowHeights = new int[]{0, 0};
700 		gbl_hohAuthPanel3.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
701 		gbl_hohAuthPanel3.rowWeights = new double[]{0.0, Double.MIN_VALUE};
702 		hohAuthPanel.setLayout(gbl_hohAuthPanel3);
703 		
704 		myHohAuthEnabledCheckbox = new JCheckBox("Enabled");
705 		myHohAuthEnabledCheckbox.addActionListener(new ActionListener() {
706 			public void actionPerformed(ActionEvent theE) {
707 				myConnection.setHohAuthenticationEnabled(myHohAuthEnabledCheckbox.isSelected());
708 			}
709 		});
710 		GridBagConstraints gbc_HohAuthEnabledCheckbox = new GridBagConstraints();
711 		gbc_HohAuthEnabledCheckbox.insets = new Insets(0, 0, 0, 5);
712 		gbc_HohAuthEnabledCheckbox.gridx = 0;
713 		gbc_HohAuthEnabledCheckbox.gridy = 0;
714 		hohAuthPanel.add(myHohAuthEnabledCheckbox, gbc_HohAuthEnabledCheckbox);
715 		
716 		mylabel_7 = new JLabel("Username:");
717 		GridBagConstraints gbc_label_7 = new GridBagConstraints();
718 		gbc_label_7.insets = new Insets(0, 0, 0, 5);
719 		gbc_label_7.anchor = GridBagConstraints.EAST;
720 		gbc_label_7.gridx = 1;
721 		gbc_label_7.gridy = 0;
722 		hohAuthPanel.add(mylabel_7, gbc_label_7);
723 		
724 		myHohAuthUsernameTextbox = new JTextField();
725 		myHohAuthUsernameTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
726 			@Override
727 			public void update(DocumentEvent theE) {
728 				myConnection.setHohAuthenticationUsername(myHohAuthUsernameTextbox.getText());
729 			}
730 		});
731 		myHohAuthUsernameTextbox.setMaximumSize(new Dimension(200, 2147483647));
732 		myHohAuthUsernameTextbox.setMinimumSize(new Dimension(100, 28));
733 		myHohAuthUsernameTextbox.setPreferredSize(new Dimension(100, 28));
734 		GridBagConstraints gbc_HohUsernameTextbox2 = new GridBagConstraints();
735 		gbc_HohUsernameTextbox2.insets = new Insets(0, 0, 0, 5);
736 		gbc_HohUsernameTextbox2.fill = GridBagConstraints.HORIZONTAL;
737 		gbc_HohUsernameTextbox2.gridx = 2;
738 		gbc_HohUsernameTextbox2.gridy = 0;
739 		hohAuthPanel.add(myHohAuthUsernameTextbox, gbc_HohUsernameTextbox2);
740 		myHohAuthUsernameTextbox.setColumns(10);
741 		
742 		mylabel_8 = new JLabel("Password:");
743 		GridBagConstraints gbc_label_8 = new GridBagConstraints();
744 		gbc_label_8.insets = new Insets(0, 0, 0, 5);
745 		gbc_label_8.anchor = GridBagConstraints.EAST;
746 		gbc_label_8.gridx = 3;
747 		gbc_label_8.gridy = 0;
748 		hohAuthPanel.add(mylabel_8, gbc_label_8);
749 		
750 		myHohAuthPasswordTextbox = new JTextField();
751 		myHohAuthPasswordTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
752 			@Override
753 			public void update(DocumentEvent theE) {
754 				myConnection.setHohAuthenticationPassword(myHohAuthPasswordTextbox.getText());
755 			}
756 		});
757 		myHohAuthPasswordTextbox.setPreferredSize(new Dimension(100, 28));
758 		myHohAuthPasswordTextbox.setMaximumSize(new Dimension(200, 2147483647));
759 		myHohAuthPasswordTextbox.setMinimumSize(new Dimension(100, 28));
760 		GridBagConstraints gbc_textField = new GridBagConstraints();
761 		gbc_textField.insets = new Insets(0, 0, 0, 5);
762 		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
763 		gbc_textField.gridx = 4;
764 		gbc_textField.gridy = 0;
765 		hohAuthPanel.add(myHohAuthPasswordTextbox, gbc_textField);
766 		myHohAuthPasswordTextbox.setColumns(10);
767 
768 		mylabel_2 = new JLabel("Security Profile");
769 		GridBagConstraints gbc_label_2 = new GridBagConstraints();
770 		gbc_label_2.insets = new Insets(0, 0, 5, 5);
771 		gbc_label_2.gridx = 0;
772 		gbc_label_2.gridy = 1;
773 		myHoHCard.add(mylabel_2, gbc_label_2);
774 
775 		securityProfilePanel = new JPanel();
776 		GridBagConstraints gbc_securityProfilePanel = new GridBagConstraints();
777 		gbc_securityProfilePanel.insets = new Insets(0, 0, 5, 0);
778 		gbc_securityProfilePanel.fill = GridBagConstraints.BOTH;
779 		gbc_securityProfilePanel.gridx = 1;
780 		gbc_securityProfilePanel.gridy = 1;
781 		myHoHCard.add(securityProfilePanel, gbc_securityProfilePanel);
782 		securityProfilePanel.setLayout(new BorderLayout(0, 0));
783 
784 		myHohTlsCheckbox = new JCheckBox("TLS Enabled");
785 		myHohTlsCheckbox.addActionListener(new ActionListener() {
786 			public void actionPerformed(ActionEvent e) {
787 				myConnection.setTls(myHohTlsCheckbox.isSelected());
788 				myTlsCheckbox.setSelected(myHohTlsCheckbox.isSelected());
789 				updatePortsUi();
790 			}
791 		});
792 		securityProfilePanel.add(myHohTlsCheckbox, BorderLayout.WEST);
793 
794 		tlsKeystorePanel = new JPanel();
795 		tlsKeystorePanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
796 		securityProfilePanel.add(tlsKeystorePanel, BorderLayout.CENTER);
797 		GridBagLayout gbl_tlsKeystorePanel = new GridBagLayout();
798 		gbl_tlsKeystorePanel.columnWidths = new int[] { 58, 107, 77, 0, 0 };
799 		gbl_tlsKeystorePanel.rowHeights = new int[] { 28, 16, 0 };
800 		gbl_tlsKeystorePanel.columnWeights = new double[] { 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE };
801 		gbl_tlsKeystorePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
802 		tlsKeystorePanel.setLayout(gbl_tlsKeystorePanel);
803 
804 		mylabel_3 = new JLabel("Keystore:");
805 		GridBagConstraints gbc_label_3 = new GridBagConstraints();
806 		gbc_label_3.anchor = GridBagConstraints.WEST;
807 		gbc_label_3.fill = GridBagConstraints.VERTICAL;
808 		gbc_label_3.insets = new Insets(0, 0, 5, 5);
809 		gbc_label_3.gridx = 0;
810 		gbc_label_3.gridy = 0;
811 		tlsKeystorePanel.add(mylabel_3, gbc_label_3);
812 
813 		myHohSecurityKeystoreTextbox = new JTextField();
814 		GridBagConstraints gbc_HohKeystoreTextbox = new GridBagConstraints();
815 		gbc_HohKeystoreTextbox.gridwidth = 2;
816 		gbc_HohKeystoreTextbox.anchor = GridBagConstraints.NORTH;
817 		gbc_HohKeystoreTextbox.fill = GridBagConstraints.HORIZONTAL;
818 		gbc_HohKeystoreTextbox.insets = new Insets(0, 0, 5, 5);
819 		gbc_HohKeystoreTextbox.gridx = 1;
820 		gbc_HohKeystoreTextbox.gridy = 0;
821 		tlsKeystorePanel.add(myHohSecurityKeystoreTextbox, gbc_HohKeystoreTextbox);
822 		myHohSecurityKeystoreTextbox.setColumns(10);
823 		myHohSecurityKeystoreTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
824 			@Override
825 			public void update(DocumentEvent theE) {
826 				String text = myHohSecurityKeystoreTextbox.getText();
827 				myHohSecurityKeyPwTextBox.setEnabled(isNotBlank(text));
828 				myConnection.setTlsKeystoreLocation(text);
829 				scheduleHohSecurityKeystoreCheck();
830 			}
831 		});
832 
833 		myHohSecurityKeystoreChooseBtn = new JButton("Choose");
834 		myHohSecurityKeystoreChooseBtn.addActionListener(new ActionListener() {
835 			public void actionPerformed(ActionEvent e) {
836 				String directory = Prefs.getInstance().getInterfaceHohSecurityKeystoreDirectory();
837 				directory = StringUtils.defaultString(directory, ".");
838 				JFileChooser chooser = new JFileChooser(directory);
839 				chooser.setDialogType(JFileChooser.OPEN_DIALOG);
840 				chooser.setDialogTitle("Select a Java Keystore");
841 				int result = chooser.showOpenDialog(Hl7ConnectionPanelBackup.this);
842 				if (result == JFileChooser.APPROVE_OPTION) {
843 					Prefs.getInstance().setInterfaceHohSecurityKeystoreDirectory(chooser.getSelectedFile().getParent());
844 					myHohSecurityKeystoreTextbox.setText(chooser.getSelectedFile().getAbsolutePath());
845 				}
846 			}
847 		});
848 		myHohSecurityKeystoreChooseBtn.setIcon(new ImageIcon(Hl7ConnectionPanelBackup.class.getResource("/ca/uhn/hl7v2/testpanel/images/open.png")));
849 		GridBagConstraints gbc_button = new GridBagConstraints();
850 		gbc_button.insets = new Insets(0, 0, 5, 0);
851 		gbc_button.gridx = 3;
852 		gbc_button.gridy = 0;
853 		tlsKeystorePanel.add(myHohSecurityKeystoreChooseBtn, gbc_button);
854 
855 		mylabel_4 = new JLabel("Store Pass:");
856 		GridBagConstraints gbc_label_4 = new GridBagConstraints();
857 		gbc_label_4.insets = new Insets(0, 0, 0, 5);
858 		gbc_label_4.anchor = GridBagConstraints.EAST;
859 		gbc_label_4.gridx = 0;
860 		gbc_label_4.gridy = 1;
861 		tlsKeystorePanel.add(mylabel_4, gbc_label_4);
862 
863 		myHohSecurityKeyPwTextBox = new JTextField();
864 		myHohSecurityKeyPwTextBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
865 			@Override
866 			public void update(DocumentEvent theE) {
867 				myConnection.setTlsKeystorePassword(myHohSecurityKeyPwTextBox.getText());
868 				scheduleHohSecurityKeystoreCheck();
869 			}
870 		});
871 		GridBagConstraints gbc_HohSecurityKeyPwTextBox = new GridBagConstraints();
872 		gbc_HohSecurityKeyPwTextBox.insets = new Insets(0, 0, 0, 5);
873 		gbc_HohSecurityKeyPwTextBox.fill = GridBagConstraints.HORIZONTAL;
874 		gbc_HohSecurityKeyPwTextBox.gridx = 1;
875 		gbc_HohSecurityKeyPwTextBox.gridy = 1;
876 		tlsKeystorePanel.add(myHohSecurityKeyPwTextBox, gbc_HohSecurityKeyPwTextBox);
877 		myHohSecurityKeyPwTextBox.setColumns(10);
878 
879 		myHohSecurityProfileKeystoreStatus = new JLabel("Value goes here");
880 		myHohSecurityProfileKeystoreStatus.setHorizontalAlignment(SwingConstants.LEFT);
881 		GridBagConstraints gbc_HohSecurityProfileKeystoreStatus = new GridBagConstraints();
882 		gbc_HohSecurityProfileKeystoreStatus.anchor = GridBagConstraints.NORTH;
883 		gbc_HohSecurityProfileKeystoreStatus.fill = GridBagConstraints.HORIZONTAL;
884 		gbc_HohSecurityProfileKeystoreStatus.gridwidth = 2;
885 		gbc_HohSecurityProfileKeystoreStatus.gridx = 2;
886 		gbc_HohSecurityProfileKeystoreStatus.gridy = 1;
887 		tlsKeystorePanel.add(myHohSecurityProfileKeystoreStatus, gbc_HohSecurityProfileKeystoreStatus);
888 
889 		init();
890 
891 	}
892 
893 	public void destroy() {
894 		myConnection.removePropertyChangeListener(OutboundConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
895 		myConnection.removePropertyChangeListener(OutboundConnection.STATUS_LINE_PROPERTY, myStatusLinePropertyChangeListener);
896 	}
897 
898 	private void init() {
899 		List<String> charSets = new ArrayList<String>(Charset.availableCharsets().keySet());
900 		Collections.sort(charSets);
901 		ComboBoxModel charsetModel = new DefaultComboBoxModel(charSets.toArray(new String[0]));
902 		myCharsetCombo.setModel(charsetModel);
903 	}
904 
905 	private boolean isChangesAllowed() {
906 		return myConnection.getStatus() == StatusEnum.STOPPED || myConnection.getStatus() == StatusEnum.FAILED;
907 	}
908 
909 	private String portToString(int thePort) {
910 		if (thePort > 0) {
911 			return Integer.toString(thePort);
912 		} else {
913 			return "";
914 		}
915 	}
916 
917 	private void scheduleHohSecurityKeystoreCheck() {
918 		myHohSecurityKeystoreCheckIsScheduled = true;
919 		myController.invokeInBackground(new CheckHohSecurityKeystoreRunnable());
920 	}
921 
922 	public void setConnection(AbstractConnection theConnection) {
923 		myConnection = theConnection;
924 
925 		myHohSecurityKeyPwTextBox.setText(myConnection.getTlsKeystorePassword());
926 		myHohSecurityKeystoreTextbox.setText(myConnection.getTlsKeystoreLocation());
927 		myHohSecurityProfileKeystoreStatus.setText("");
928 
929 		myCharsetCombo.setSelectedItem(theConnection.getCharSet());
930 
931 		myTlsCheckbox.setSelected(theConnection.isTls());
932 		myHohTlsCheckbox.setSelected(theConnection.isTls());
933 		myCaptureByteStreamCheckbox.setSelected(theConnection.isCaptureBytes());
934 
935 		myHohAuthEnabledCheckbox.setSelected(myConnection.isHohAuthenticationEnabled());
936 		myHohAuthUsernameTextbox.setText(myConnection.getHohAuthenticationUsername());
937 		myHohAuthPasswordTextbox.setText(myConnection.getHohAuthenticationPassword());
938 		
939 		updateCharset();
940 
941 		Hl7V2EncodingTypeEnum encoding = theConnection.getEncoding();
942 		myEr7Radio.setSelected(encoding == Hl7V2EncodingTypeEnum.ER_7);
943 		myXmlRadio.setSelected(encoding == Hl7V2EncodingTypeEnum.XML);
944 		myHostBox.setText(theConnection.getHost());
945 
946 		updatePortsUi();
947 
948 		myStatusPropertyChangeListener = new PropertyChangeListener() {
949 
950 			public void propertyChange(PropertyChangeEvent theEvt) {
951 				updateStatus();
952 			}
953 		};
954 		myConnection.addPropertyChangeListener(OutboundConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
955 
956 		myStatusLinePropertyChangeListener = new PropertyChangeListener() {
957 
958 			public void propertyChange(PropertyChangeEvent theEvt) {
959 				updateStatus();
960 			}
961 		};
962 		myConnection.addPropertyChangeListener(OutboundConnection.STATUS_LINE_PROPERTY, myStatusLinePropertyChangeListener);
963 
964 		updateStatus();
965 
966 	}
967 
968 	private void updateCharset() {
969 		if (myConnection.isDetectCharSetInMessage()) {
970 			myCharsetDetectRadio.setSelected(true);
971 			myCharsetSelectRadio.setSelected(false);
972 			myCharsetCombo.setEnabled(false);
973 		} else {
974 			myCharsetDetectRadio.setSelected(false);
975 			myCharsetSelectRadio.setSelected(true);
976 			myCharsetCombo.setEnabled(true);
977 		}
978 	}
979 
980 	private void updateCharsetModel() {
981 		if (myCharsetDetectRadio.isSelected()) {
982 			myConnection.setDetectCharSetInMessage(true);
983 		} else {
984 			myConnection.setDetectCharSetInMessage(false);
985 			myConnection.setCharSet((String) myCharsetCombo.getSelectedItem());
986 		}
987 	}
988 
989 	private void updateEncodingModel() {
990 		if (myEr7Radio.isSelected()) {
991 			myConnection.setEncoding(Hl7V2EncodingTypeEnum.ER_7);
992 		} else {
993 			myConnection.setEncoding(Hl7V2EncodingTypeEnum.XML);
994 		}
995 	}
996 
997 	private void updatePortsModel() {
998 		if (mySinglePortRadio.isSelected()) {
999 			myConnection.setTransport(TransportStyleEnum.SINGLE_PORT_MLLP);
1000 		} else if (myDualPortRadio.isSelected()) {
1001 			myConnection.setTransport(TransportStyleEnum.DUAL_PORT_MLLP);
1002 		} else {
1003 			myConnection.setTransport(TransportStyleEnum.HL7_OVER_HTTP);
1004 		}
1005 	}
1006 
1007 	private void updatePortsUi() {
1008 		boolean changesAllowed = isChangesAllowed();
1009 		CardLayout cl = (CardLayout) myInterfaceTypeCardPanel.getLayout();
1010 
1011 		switch (myConnection.getTransport()) {
1012 		case DUAL_PORT_MLLP: {
1013 			mySinglePortRadio.setSelected(false);
1014 			myDualPortRadio.setSelected(true);
1015 			myHl7OverHttpRadioButton.setSelected(false);
1016 
1017 			myDualIncomingTextBox.setText(portToString(myConnection.getIncomingOrSinglePort()));
1018 			myDualOutgoingTextBox.setText(portToString(myConnection.getOutgoingPort()));
1019 
1020 			mySinglePortTextBox.setEnabled(false);
1021 			myDualIncomingTextBox.setEnabled(true && changesAllowed);
1022 			myDualOutgoingTextBox.setEnabled(true && changesAllowed);
1023 			myHoHUrlTextField.setEnabled(false);
1024 			mySinglePortTextBox.repaint();
1025 			myDualIncomingTextBox.repaint();
1026 			myDualOutgoingTextBox.repaint();
1027 
1028 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_MLLP);
1029 			break;
1030 		}
1031 		case SINGLE_PORT_MLLP: {
1032 			mySinglePortRadio.setSelected(true);
1033 			myDualPortRadio.setSelected(false);
1034 			myHl7OverHttpRadioButton.setSelected(false);
1035 
1036 			mySinglePortTextBox.setText(portToString(myConnection.getIncomingOrSinglePort()));
1037 
1038 			mySinglePortTextBox.setEnabled(true && changesAllowed);
1039 			myDualIncomingTextBox.setEnabled(false);
1040 			myDualOutgoingTextBox.setEnabled(false);
1041 			myHoHUrlTextField.setEnabled(false);
1042 			mySinglePortTextBox.repaint();
1043 			myDualIncomingTextBox.repaint();
1044 			myDualOutgoingTextBox.repaint();
1045 
1046 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_MLLP);
1047 			break;
1048 		}
1049 		case HL7_OVER_HTTP: {
1050 			mySinglePortTextBox.setEnabled(false);
1051 			myDualIncomingTextBox.setEnabled(false);
1052 			myDualOutgoingTextBox.setEnabled(false);
1053 			mySinglePortRadio.setSelected(false);
1054 			myDualPortRadio.setSelected(false);
1055 			myHl7OverHttpRadioButton.setSelected(true);
1056 
1057 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_HOH);
1058 
1059 			StringBuilder urlBuilder = new StringBuilder();
1060 			urlBuilder.append((myConnection.isTls() ? "https://" : "http://"));
1061 			urlBuilder.append(StringUtils.defaultString(myConnection.getHost(), "localhost"));
1062 			urlBuilder.append(":").append(myConnection.getIncomingOrSinglePort());
1063 			urlBuilder.append(StringUtils.defaultString(myConnection.getHttpUriPath(), "/"));
1064 			String url = urlBuilder.toString();
1065 			if (!myHohUrlTextFieldUpdating) {
1066 				myHohUrlTextFieldUpdating = true;
1067 				myHoHUrlTextField.setText(url);
1068 				myHohUrlTextFieldUpdating = false;
1069 			}
1070 
1071 			myHoHUrlTextField.setEnabled(true && changesAllowed);
1072 
1073 			break;
1074 		}
1075 		}
1076 	}
1077 
1078 	private void updateStatus() {
1079 		boolean changesAllowed = isChangesAllowed();
1080 		myHostBox.setEnabled(changesAllowed);
1081 
1082 		updatePortsUi();
1083 
1084 		mySinglePortRadio.setEnabled(changesAllowed);
1085 		myDualPortRadio.setEnabled(changesAllowed);
1086 		myHl7OverHttpRadioButton.setEnabled(changesAllowed);
1087 		myCharsetCombo.setEnabled(changesAllowed);
1088 		myCharsetDetectRadio.setEnabled(changesAllowed);
1089 		myCharsetSelectRadio.setEnabled(changesAllowed);
1090 		myEr7Radio.setEnabled(changesAllowed);
1091 		myTlsCheckbox.setEnabled(changesAllowed);
1092 		myHohTlsCheckbox.setEnabled(changesAllowed);
1093 		myXmlRadio.setEnabled(changesAllowed);
1094 		myCaptureByteStreamCheckbox.setEnabled(changesAllowed);
1095 
1096 	}
1097 
1098 	private final class CheckHohSecurityKeystoreRunnable implements Runnable {
1099 		public void run() {
1100 			try {
1101 				Thread.sleep(500);
1102 			} catch (InterruptedException e) {
1103 				// wait a bit
1104 			}
1105 
1106 			if (!myHohSecurityKeystoreCheckIsScheduled) {
1107 				return;
1108 			}
1109 			myHohSecurityKeystoreCheckIsScheduled = false;
1110 
1111 			KeyStore keystore;
1112 			try {
1113 				keystore = myConnection.getTlsKeystore();
1114 				if (keystore == null) {
1115 					myHohSecurityProfileKeystoreStatus.setText("Using system keystore");
1116 				} else {
1117 					myHohSecurityProfileKeystoreStatus.setText("Keystore appears good");
1118 				}
1119 			} catch (KeyStoreException e) {
1120 				ourLog.error("Keystore problem", e);
1121 				myHohSecurityProfileKeystoreStatus.setText("<html>" + e.getMessage() + "</html>");
1122 			}
1123 		}
1124 	}
1125 
1126 }