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 			@Override
707 			public void actionPerformed(ActionEvent theE) {
708 				myConnection.setHohAuthenticationEnabled(myHohAuthEnabledCheckbox.isSelected());
709 			}
710 		});
711 		GridBagConstraints gbc_HohAuthEnabledCheckbox = new GridBagConstraints();
712 		gbc_HohAuthEnabledCheckbox.insets = new Insets(0, 0, 0, 5);
713 		gbc_HohAuthEnabledCheckbox.gridx = 0;
714 		gbc_HohAuthEnabledCheckbox.gridy = 0;
715 		hohAuthPanel.add(myHohAuthEnabledCheckbox, gbc_HohAuthEnabledCheckbox);
716 		
717 		mylabel_7 = new JLabel("Username:");
718 		GridBagConstraints gbc_label_7 = new GridBagConstraints();
719 		gbc_label_7.insets = new Insets(0, 0, 0, 5);
720 		gbc_label_7.anchor = GridBagConstraints.EAST;
721 		gbc_label_7.gridx = 1;
722 		gbc_label_7.gridy = 0;
723 		hohAuthPanel.add(mylabel_7, gbc_label_7);
724 		
725 		myHohAuthUsernameTextbox = new JTextField();
726 		myHohAuthUsernameTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
727 			@Override
728 			public void update(DocumentEvent theE) {
729 				myConnection.setHohAuthenticationUsername(myHohAuthUsernameTextbox.getText());
730 			}
731 		});
732 		myHohAuthUsernameTextbox.setMaximumSize(new Dimension(200, 2147483647));
733 		myHohAuthUsernameTextbox.setMinimumSize(new Dimension(100, 28));
734 		myHohAuthUsernameTextbox.setPreferredSize(new Dimension(100, 28));
735 		GridBagConstraints gbc_HohUsernameTextbox2 = new GridBagConstraints();
736 		gbc_HohUsernameTextbox2.insets = new Insets(0, 0, 0, 5);
737 		gbc_HohUsernameTextbox2.fill = GridBagConstraints.HORIZONTAL;
738 		gbc_HohUsernameTextbox2.gridx = 2;
739 		gbc_HohUsernameTextbox2.gridy = 0;
740 		hohAuthPanel.add(myHohAuthUsernameTextbox, gbc_HohUsernameTextbox2);
741 		myHohAuthUsernameTextbox.setColumns(10);
742 		
743 		mylabel_8 = new JLabel("Password:");
744 		GridBagConstraints gbc_label_8 = new GridBagConstraints();
745 		gbc_label_8.insets = new Insets(0, 0, 0, 5);
746 		gbc_label_8.anchor = GridBagConstraints.EAST;
747 		gbc_label_8.gridx = 3;
748 		gbc_label_8.gridy = 0;
749 		hohAuthPanel.add(mylabel_8, gbc_label_8);
750 		
751 		myHohAuthPasswordTextbox = new JTextField();
752 		myHohAuthPasswordTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
753 			@Override
754 			public void update(DocumentEvent theE) {
755 				myConnection.setHohAuthenticationPassword(myHohAuthPasswordTextbox.getText());
756 			}
757 		});
758 		myHohAuthPasswordTextbox.setPreferredSize(new Dimension(100, 28));
759 		myHohAuthPasswordTextbox.setMaximumSize(new Dimension(200, 2147483647));
760 		myHohAuthPasswordTextbox.setMinimumSize(new Dimension(100, 28));
761 		GridBagConstraints gbc_textField = new GridBagConstraints();
762 		gbc_textField.insets = new Insets(0, 0, 0, 5);
763 		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
764 		gbc_textField.gridx = 4;
765 		gbc_textField.gridy = 0;
766 		hohAuthPanel.add(myHohAuthPasswordTextbox, gbc_textField);
767 		myHohAuthPasswordTextbox.setColumns(10);
768 
769 		mylabel_2 = new JLabel("Security Profile");
770 		GridBagConstraints gbc_label_2 = new GridBagConstraints();
771 		gbc_label_2.insets = new Insets(0, 0, 5, 5);
772 		gbc_label_2.gridx = 0;
773 		gbc_label_2.gridy = 1;
774 		myHoHCard.add(mylabel_2, gbc_label_2);
775 
776 		securityProfilePanel = new JPanel();
777 		GridBagConstraints gbc_securityProfilePanel = new GridBagConstraints();
778 		gbc_securityProfilePanel.insets = new Insets(0, 0, 5, 0);
779 		gbc_securityProfilePanel.fill = GridBagConstraints.BOTH;
780 		gbc_securityProfilePanel.gridx = 1;
781 		gbc_securityProfilePanel.gridy = 1;
782 		myHoHCard.add(securityProfilePanel, gbc_securityProfilePanel);
783 		securityProfilePanel.setLayout(new BorderLayout(0, 0));
784 
785 		myHohTlsCheckbox = new JCheckBox("TLS Enabled");
786 		myHohTlsCheckbox.addActionListener(new ActionListener() {
787 			public void actionPerformed(ActionEvent e) {
788 				myConnection.setTls(myHohTlsCheckbox.isSelected());
789 				myTlsCheckbox.setSelected(myHohTlsCheckbox.isSelected());
790 				updatePortsUi();
791 			}
792 		});
793 		securityProfilePanel.add(myHohTlsCheckbox, BorderLayout.WEST);
794 
795 		tlsKeystorePanel = new JPanel();
796 		tlsKeystorePanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
797 		securityProfilePanel.add(tlsKeystorePanel, BorderLayout.CENTER);
798 		GridBagLayout gbl_tlsKeystorePanel = new GridBagLayout();
799 		gbl_tlsKeystorePanel.columnWidths = new int[] { 58, 107, 77, 0, 0 };
800 		gbl_tlsKeystorePanel.rowHeights = new int[] { 28, 16, 0 };
801 		gbl_tlsKeystorePanel.columnWeights = new double[] { 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE };
802 		gbl_tlsKeystorePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
803 		tlsKeystorePanel.setLayout(gbl_tlsKeystorePanel);
804 
805 		mylabel_3 = new JLabel("Keystore:");
806 		GridBagConstraints gbc_label_3 = new GridBagConstraints();
807 		gbc_label_3.anchor = GridBagConstraints.WEST;
808 		gbc_label_3.fill = GridBagConstraints.VERTICAL;
809 		gbc_label_3.insets = new Insets(0, 0, 5, 5);
810 		gbc_label_3.gridx = 0;
811 		gbc_label_3.gridy = 0;
812 		tlsKeystorePanel.add(mylabel_3, gbc_label_3);
813 
814 		myHohSecurityKeystoreTextbox = new JTextField();
815 		GridBagConstraints gbc_HohKeystoreTextbox = new GridBagConstraints();
816 		gbc_HohKeystoreTextbox.gridwidth = 2;
817 		gbc_HohKeystoreTextbox.anchor = GridBagConstraints.NORTH;
818 		gbc_HohKeystoreTextbox.fill = GridBagConstraints.HORIZONTAL;
819 		gbc_HohKeystoreTextbox.insets = new Insets(0, 0, 5, 5);
820 		gbc_HohKeystoreTextbox.gridx = 1;
821 		gbc_HohKeystoreTextbox.gridy = 0;
822 		tlsKeystorePanel.add(myHohSecurityKeystoreTextbox, gbc_HohKeystoreTextbox);
823 		myHohSecurityKeystoreTextbox.setColumns(10);
824 		myHohSecurityKeystoreTextbox.getDocument().addDocumentListener(new SimpleDocumentListener() {
825 			@Override
826 			public void update(DocumentEvent theE) {
827 				String text = myHohSecurityKeystoreTextbox.getText();
828 				myHohSecurityKeyPwTextBox.setEnabled(isNotBlank(text));
829 				myConnection.setTlsKeystoreLocation(text);
830 				scheduleHohSecurityKeystoreCheck();
831 			}
832 		});
833 
834 		myHohSecurityKeystoreChooseBtn = new JButton("Choose");
835 		myHohSecurityKeystoreChooseBtn.addActionListener(new ActionListener() {
836 			public void actionPerformed(ActionEvent e) {
837 				String directory = Prefs.getInstance().getInterfaceHohSecurityKeystoreDirectory();
838 				directory = StringUtils.defaultString(directory, ".");
839 				JFileChooser chooser = new JFileChooser(directory);
840 				chooser.setDialogType(JFileChooser.OPEN_DIALOG);
841 				chooser.setDialogTitle("Select a Java Keystore");
842 				int result = chooser.showOpenDialog(Hl7ConnectionPanelBackup.this);
843 				if (result == JFileChooser.APPROVE_OPTION) {
844 					Prefs.getInstance().setInterfaceHohSecurityKeystoreDirectory(chooser.getSelectedFile().getParent());
845 					myHohSecurityKeystoreTextbox.setText(chooser.getSelectedFile().getAbsolutePath());
846 				}
847 			}
848 		});
849 		myHohSecurityKeystoreChooseBtn.setIcon(new ImageIcon(Hl7ConnectionPanelBackup.class.getResource("/ca/uhn/hl7v2/testpanel/images/open.png")));
850 		GridBagConstraints gbc_button = new GridBagConstraints();
851 		gbc_button.insets = new Insets(0, 0, 5, 0);
852 		gbc_button.gridx = 3;
853 		gbc_button.gridy = 0;
854 		tlsKeystorePanel.add(myHohSecurityKeystoreChooseBtn, gbc_button);
855 
856 		mylabel_4 = new JLabel("Store Pass:");
857 		GridBagConstraints gbc_label_4 = new GridBagConstraints();
858 		gbc_label_4.insets = new Insets(0, 0, 0, 5);
859 		gbc_label_4.anchor = GridBagConstraints.EAST;
860 		gbc_label_4.gridx = 0;
861 		gbc_label_4.gridy = 1;
862 		tlsKeystorePanel.add(mylabel_4, gbc_label_4);
863 
864 		myHohSecurityKeyPwTextBox = new JTextField();
865 		myHohSecurityKeyPwTextBox.getDocument().addDocumentListener(new SimpleDocumentListener() {
866 			@Override
867 			public void update(DocumentEvent theE) {
868 				myConnection.setTlsKeystorePassword(myHohSecurityKeyPwTextBox.getText());
869 				scheduleHohSecurityKeystoreCheck();
870 			}
871 		});
872 		GridBagConstraints gbc_HohSecurityKeyPwTextBox = new GridBagConstraints();
873 		gbc_HohSecurityKeyPwTextBox.insets = new Insets(0, 0, 0, 5);
874 		gbc_HohSecurityKeyPwTextBox.fill = GridBagConstraints.HORIZONTAL;
875 		gbc_HohSecurityKeyPwTextBox.gridx = 1;
876 		gbc_HohSecurityKeyPwTextBox.gridy = 1;
877 		tlsKeystorePanel.add(myHohSecurityKeyPwTextBox, gbc_HohSecurityKeyPwTextBox);
878 		myHohSecurityKeyPwTextBox.setColumns(10);
879 
880 		myHohSecurityProfileKeystoreStatus = new JLabel("Value goes here");
881 		myHohSecurityProfileKeystoreStatus.setHorizontalAlignment(SwingConstants.LEFT);
882 		GridBagConstraints gbc_HohSecurityProfileKeystoreStatus = new GridBagConstraints();
883 		gbc_HohSecurityProfileKeystoreStatus.anchor = GridBagConstraints.NORTH;
884 		gbc_HohSecurityProfileKeystoreStatus.fill = GridBagConstraints.HORIZONTAL;
885 		gbc_HohSecurityProfileKeystoreStatus.gridwidth = 2;
886 		gbc_HohSecurityProfileKeystoreStatus.gridx = 2;
887 		gbc_HohSecurityProfileKeystoreStatus.gridy = 1;
888 		tlsKeystorePanel.add(myHohSecurityProfileKeystoreStatus, gbc_HohSecurityProfileKeystoreStatus);
889 
890 		init();
891 
892 	}
893 
894 	public void destroy() {
895 		myConnection.removePropertyChangeListener(OutboundConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
896 		myConnection.removePropertyChangeListener(OutboundConnection.STATUS_LINE_PROPERTY, myStatusLinePropertyChangeListener);
897 	}
898 
899 	private void init() {
900 		List<String> charSets = new ArrayList<String>(Charset.availableCharsets().keySet());
901 		Collections.sort(charSets);
902 		ComboBoxModel charsetModel = new DefaultComboBoxModel(charSets.toArray(new String[0]));
903 		myCharsetCombo.setModel(charsetModel);
904 	}
905 
906 	private boolean isChangesAllowed() {
907 		return myConnection.getStatus() == StatusEnum.STOPPED || myConnection.getStatus() == StatusEnum.FAILED;
908 	}
909 
910 	private String portToString(int thePort) {
911 		if (thePort > 0) {
912 			return Integer.toString(thePort);
913 		} else {
914 			return "";
915 		}
916 	}
917 
918 	private void scheduleHohSecurityKeystoreCheck() {
919 		myHohSecurityKeystoreCheckIsScheduled = true;
920 		myController.invokeInBackground(new CheckHohSecurityKeystoreRunnable());
921 	}
922 
923 	public void setConnection(AbstractConnection theConnection) {
924 		myConnection = theConnection;
925 
926 		myHohSecurityKeyPwTextBox.setText(myConnection.getTlsKeystorePassword());
927 		myHohSecurityKeystoreTextbox.setText(myConnection.getTlsKeystoreLocation());
928 		myHohSecurityProfileKeystoreStatus.setText("");
929 
930 		myCharsetCombo.setSelectedItem(theConnection.getCharSet());
931 
932 		myTlsCheckbox.setSelected(theConnection.isTls());
933 		myHohTlsCheckbox.setSelected(theConnection.isTls());
934 		myCaptureByteStreamCheckbox.setSelected(theConnection.isCaptureBytes());
935 
936 		myHohAuthEnabledCheckbox.setSelected(myConnection.isHohAuthenticationEnabled());
937 		myHohAuthUsernameTextbox.setText(myConnection.getHohAuthenticationUsername());
938 		myHohAuthPasswordTextbox.setText(myConnection.getHohAuthenticationPassword());
939 		
940 		updateCharset();
941 
942 		Hl7V2EncodingTypeEnum encoding = theConnection.getEncoding();
943 		myEr7Radio.setSelected(encoding == Hl7V2EncodingTypeEnum.ER_7);
944 		myXmlRadio.setSelected(encoding == Hl7V2EncodingTypeEnum.XML);
945 		myHostBox.setText(theConnection.getHost());
946 
947 		updatePortsUi();
948 
949 		myStatusPropertyChangeListener = new PropertyChangeListener() {
950 
951 			public void propertyChange(PropertyChangeEvent theEvt) {
952 				updateStatus();
953 			}
954 		};
955 		myConnection.addPropertyChangeListener(OutboundConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
956 
957 		myStatusLinePropertyChangeListener = new PropertyChangeListener() {
958 
959 			public void propertyChange(PropertyChangeEvent theEvt) {
960 				updateStatus();
961 			}
962 		};
963 		myConnection.addPropertyChangeListener(OutboundConnection.STATUS_LINE_PROPERTY, myStatusLinePropertyChangeListener);
964 
965 		updateStatus();
966 
967 	}
968 
969 	private void updateCharset() {
970 		if (myConnection.isDetectCharSetInMessage()) {
971 			myCharsetDetectRadio.setSelected(true);
972 			myCharsetSelectRadio.setSelected(false);
973 			myCharsetCombo.setEnabled(false);
974 		} else {
975 			myCharsetDetectRadio.setSelected(false);
976 			myCharsetSelectRadio.setSelected(true);
977 			myCharsetCombo.setEnabled(true);
978 		}
979 	}
980 
981 	private void updateCharsetModel() {
982 		if (myCharsetDetectRadio.isSelected()) {
983 			myConnection.setDetectCharSetInMessage(true);
984 		} else {
985 			myConnection.setDetectCharSetInMessage(false);
986 			myConnection.setCharSet((String) myCharsetCombo.getSelectedItem());
987 		}
988 	}
989 
990 	private void updateEncodingModel() {
991 		if (myEr7Radio.isSelected()) {
992 			myConnection.setEncoding(Hl7V2EncodingTypeEnum.ER_7);
993 		} else {
994 			myConnection.setEncoding(Hl7V2EncodingTypeEnum.XML);
995 		}
996 	}
997 
998 	private void updatePortsModel() {
999 		if (mySinglePortRadio.isSelected()) {
1000 			myConnection.setTransport(TransportStyleEnum.SINGLE_PORT_MLLP);
1001 		} else if (myDualPortRadio.isSelected()) {
1002 			myConnection.setTransport(TransportStyleEnum.DUAL_PORT_MLLP);
1003 		} else {
1004 			myConnection.setTransport(TransportStyleEnum.HL7_OVER_HTTP);
1005 		}
1006 	}
1007 
1008 	private void updatePortsUi() {
1009 		boolean changesAllowed = isChangesAllowed();
1010 		CardLayout cl = (CardLayout) myInterfaceTypeCardPanel.getLayout();
1011 
1012 		switch (myConnection.getTransport()) {
1013 		case DUAL_PORT_MLLP: {
1014 			mySinglePortRadio.setSelected(false);
1015 			myDualPortRadio.setSelected(true);
1016 			myHl7OverHttpRadioButton.setSelected(false);
1017 
1018 			myDualIncomingTextBox.setText(portToString(myConnection.getIncomingOrSinglePort()));
1019 			myDualOutgoingTextBox.setText(portToString(myConnection.getOutgoingPort()));
1020 
1021 			mySinglePortTextBox.setEnabled(false);
1022 			myDualIncomingTextBox.setEnabled(true && changesAllowed);
1023 			myDualOutgoingTextBox.setEnabled(true && changesAllowed);
1024 			myHoHUrlTextField.setEnabled(false);
1025 			mySinglePortTextBox.repaint();
1026 			myDualIncomingTextBox.repaint();
1027 			myDualOutgoingTextBox.repaint();
1028 
1029 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_MLLP);
1030 			break;
1031 		}
1032 		case SINGLE_PORT_MLLP: {
1033 			mySinglePortRadio.setSelected(true);
1034 			myDualPortRadio.setSelected(false);
1035 			myHl7OverHttpRadioButton.setSelected(false);
1036 
1037 			mySinglePortTextBox.setText(portToString(myConnection.getIncomingOrSinglePort()));
1038 
1039 			mySinglePortTextBox.setEnabled(true && changesAllowed);
1040 			myDualIncomingTextBox.setEnabled(false);
1041 			myDualOutgoingTextBox.setEnabled(false);
1042 			myHoHUrlTextField.setEnabled(false);
1043 			mySinglePortTextBox.repaint();
1044 			myDualIncomingTextBox.repaint();
1045 			myDualOutgoingTextBox.repaint();
1046 
1047 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_MLLP);
1048 			break;
1049 		}
1050 		case HL7_OVER_HTTP: {
1051 			mySinglePortTextBox.setEnabled(false);
1052 			myDualIncomingTextBox.setEnabled(false);
1053 			myDualOutgoingTextBox.setEnabled(false);
1054 			mySinglePortRadio.setSelected(false);
1055 			myDualPortRadio.setSelected(false);
1056 			myHl7OverHttpRadioButton.setSelected(true);
1057 
1058 			cl.show(myInterfaceTypeCardPanel, Hl7ConnectionPanelBackup.IFACE_TYPE_CARD_HOH);
1059 
1060 			StringBuilder urlBuilder = new StringBuilder();
1061 			urlBuilder.append((myConnection.isTls() ? "https://" : "http://"));
1062 			urlBuilder.append(StringUtils.defaultString(myConnection.getHost(), "localhost"));
1063 			urlBuilder.append(":").append(myConnection.getIncomingOrSinglePort());
1064 			urlBuilder.append(StringUtils.defaultString(myConnection.getHttpUriPath(), "/"));
1065 			String url = urlBuilder.toString();
1066 			if (!myHohUrlTextFieldUpdating) {
1067 				myHohUrlTextFieldUpdating = true;
1068 				myHoHUrlTextField.setText(url);
1069 				myHohUrlTextFieldUpdating = false;
1070 			}
1071 
1072 			myHoHUrlTextField.setEnabled(true && changesAllowed);
1073 
1074 			break;
1075 		}
1076 		}
1077 	}
1078 
1079 	private void updateStatus() {
1080 		boolean changesAllowed = isChangesAllowed();
1081 		myHostBox.setEnabled(changesAllowed);
1082 
1083 		updatePortsUi();
1084 
1085 		mySinglePortRadio.setEnabled(changesAllowed);
1086 		myDualPortRadio.setEnabled(changesAllowed);
1087 		myHl7OverHttpRadioButton.setEnabled(changesAllowed);
1088 		myCharsetCombo.setEnabled(changesAllowed);
1089 		myCharsetDetectRadio.setEnabled(changesAllowed);
1090 		myCharsetSelectRadio.setEnabled(changesAllowed);
1091 		myEr7Radio.setEnabled(changesAllowed);
1092 		myTlsCheckbox.setEnabled(changesAllowed);
1093 		myHohTlsCheckbox.setEnabled(changesAllowed);
1094 		myXmlRadio.setEnabled(changesAllowed);
1095 		myCaptureByteStreamCheckbox.setEnabled(changesAllowed);
1096 
1097 	}
1098 
1099 	private final class CheckHohSecurityKeystoreRunnable implements Runnable {
1100 		@Override
1101 		public void run() {
1102 			try {
1103 				Thread.sleep(500);
1104 			} catch (InterruptedException e) {
1105 				// wait a bit
1106 			}
1107 
1108 			if (!myHohSecurityKeystoreCheckIsScheduled) {
1109 				return;
1110 			}
1111 			myHohSecurityKeystoreCheckIsScheduled = false;
1112 
1113 			KeyStore keystore;
1114 			try {
1115 				keystore = myConnection.getTlsKeystore();
1116 				if (keystore == null) {
1117 					myHohSecurityProfileKeystoreStatus.setText("Using system keystore");
1118 				} else {
1119 					myHohSecurityProfileKeystoreStatus.setText("Keystore appears good");
1120 				}
1121 			} catch (KeyStoreException e) {
1122 				ourLog.error("Keystore problem", e);
1123 				myHohSecurityProfileKeystoreStatus.setText("<html>" + e.getMessage() + "</html>");
1124 			}
1125 		}
1126 	}
1127 
1128 }