001/** 002The contents of this file are subject to the Mozilla Public License Version 1.1 003(the "License"); you may not use this file except in compliance with the License. 004You may obtain a copy of the License at http://www.mozilla.org/MPL/ 005Software distributed under the License is distributed on an "AS IS" basis, 006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 007specific language governing rights and limitations under the License. 008 009The Original Code is "ConnectionDialog.java". Description: 010"A dialog box for opening a new Connection (used with TestPanel)." 011 012The Initial Developer of the Original Code is University Health Network. Copyright (C) 0132001. All Rights Reserved. 014 015Contributor(s): ______________________________________. 016 017Alternatively, the contents of this file may be used under the terms of the 018GNU General Public License (the �GPL�), in which case the provisions of the GPL are 019applicable instead of those above. If you wish to allow use of your version of this 020file only under the terms of the GPL and not to allow others to use your version 021of this file under the MPL, indicate your decision by deleting the provisions above 022and replace them with the notice and other provisions required by the GPL License. 023If you do not delete the provisions above, a recipient may use your version of 024this file under either the MPL or the GPL. 025 026*/ 027 028package ca.uhn.hl7v2.app; 029 030import javax.swing.*; 031import java.awt.event.*; 032import java.awt.*; 033 034/** 035 * A dialog box for opening a new Connection (used with TestPanel). 036 * @author Bryan Tripp 037 * @deprecated 038 */ 039@SuppressWarnings("serial") 040public class ConnectionDialog extends JDialog { 041 042 private JTextField port; 043 private JTextField inPort; 044 private JTextField outPort; 045 private JTextField host; 046 private JRadioButton onePort; 047 private JCheckBox tls; 048 private TestPanel testPanel; 049 050 /** Creates a new instance of ConnectionDialog */ 051 public ConnectionDialog(TestPanel testPanel) { 052 super(); 053 this.testPanel = testPanel; 054 initUI(); 055 } 056 057 /** Initialize UI */ 058 private void initUI() { 059 Box box = new Box(BoxLayout.Y_AXIS); 060 getContentPane().add(box); 061 062 host = new JTextField(20); 063 JPanel hostPanel = new JPanel(); 064 ((FlowLayout) hostPanel.getLayout()).setAlignment(FlowLayout.LEFT); 065 hostPanel.add(new JLabel(" Host: ")); 066 hostPanel.add(host); 067 box.add(hostPanel); 068 069 070 onePort = new JRadioButton(" Single Port "); 071 onePort.setSelected(true); 072 port = new JTextField(5); 073 JPanel onePortPanel = new JPanel(); 074 ((FlowLayout) onePortPanel.getLayout()).setAlignment(FlowLayout.LEFT); 075 onePortPanel.add(onePort, FlowLayout.LEFT); 076 onePortPanel.add(port); 077 box.add(onePortPanel); 078 079 080 JRadioButton twoPort = new JRadioButton(" Separate Inbound & Outbound Ports "); 081 JPanel twoPortPanel = new JPanel(); 082 ((FlowLayout) twoPortPanel.getLayout()).setAlignment(FlowLayout.LEFT); 083 twoPortPanel.add(twoPort); 084 box.add(twoPortPanel); 085 086 JPanel twoPortPanel2 = new JPanel(); 087 ((FlowLayout) twoPortPanel2.getLayout()).setAlignment(FlowLayout.LEFT); 088 twoPortPanel2.add(new JLabel(" Inbound: ")); 089 inPort = new JTextField(5); 090 inPort.setEnabled(false); 091 twoPortPanel2.add(inPort); 092 twoPortPanel2.add(new JLabel(" Outbound: ")); 093 outPort = new JTextField(5); 094 outPort.setEnabled(false); 095 twoPortPanel2.add(outPort); 096 box.add(twoPortPanel2); 097 098 099 tls = new JCheckBox("use TLS"); 100 tls.setSelected(false); 101 box.add(tls); 102 JPanel tlsPanel = new JPanel(); 103 ((FlowLayout) tlsPanel.getLayout()).setAlignment(FlowLayout.LEFT); 104 tlsPanel.add(tls, FlowLayout.LEFT); 105 box.add(tlsPanel); 106 107 JPanel buttonPanel = new JPanel(); 108 JButton OK = new JButton(" OK "); 109 JButton cancel = new JButton(" Cancel "); 110 buttonPanel.add(OK); 111 buttonPanel.add(cancel); 112 box.add(buttonPanel); 113 114 ButtonGroup portSelect = new ButtonGroup(); 115 portSelect.add(twoPort); 116 portSelect.add(onePort); 117 118 OK.addActionListener(new ActionListener() { 119 public void actionPerformed(ActionEvent e) { 120 connect(); 121 } 122 }); 123 124 cancel.addActionListener(new ActionListener() { 125 public void actionPerformed(ActionEvent e) { 126 close(); 127 } 128 }); 129 130 onePort.addActionListener(new ActionListener() { 131 132 public void actionPerformed(ActionEvent e) { 133 inPort.setEnabled(false); 134 outPort.setEnabled(false); 135 port.setEnabled(true); 136 } 137 138 }); 139 twoPort.addActionListener(new ActionListener() { 140 141 public void actionPerformed(ActionEvent e) { 142 inPort.setEnabled(true); 143 outPort.setEnabled(true); 144 port.setEnabled(false); 145 } 146 147 }); 148 149 pack(); 150 setVisible(true); 151 } 152 153 @SuppressWarnings("deprecation") 154 private void connect() { 155 try { 156 if (onePort.isSelected()) { 157 testPanel.connect(host.getText(), Integer.parseInt(port.getText())); 158 } else { 159 testPanel.connect(host.getText(), Integer.parseInt(inPort.getText()), Integer.parseInt(outPort.getText())); 160 } 161 close(); 162 } catch (NumberFormatException e) { 163 JOptionPane.showMessageDialog(this, "Invalid port number", "", JOptionPane.ERROR_MESSAGE); 164 } catch (Exception e) { 165 JOptionPane.showMessageDialog(this, e.getMessage(), e.getClass().getName(), JOptionPane.ERROR_MESSAGE); 166 } 167 } 168 169 private void close() { 170 this.dispose(); 171 } 172 173 174}