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 java.awt.BorderLayout;
29  import java.awt.GridBagConstraints;
30  import java.awt.GridBagLayout;
31  import java.awt.Insets;
32  import java.beans.PropertyChangeEvent;
33  import java.beans.PropertyChangeListener;
34  
35  import javax.swing.JLabel;
36  import javax.swing.JPanel;
37  import javax.swing.JTabbedPane;
38  
39  import ca.uhn.hl7v2.testpanel.controller.Controller;
40  import ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection;
41  import ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.StatusEnum;
42  import ca.uhn.hl7v2.testpanel.model.conn.OutboundConnection;
43  import ca.uhn.hl7v2.testpanel.ui.ActivityTable;
44  import ca.uhn.hl7v2.testpanel.ui.BaseMainPanel;
45  import ca.uhn.hl7v2.testpanel.ui.IDestroyable;
46  
47  public class OutboundConnectionPanel extends BaseMainPanel implements IDestroyable {
48  
49  	private ActivityTable myActivityTable;
50  	private OutboundConnection myConnection;
51  	private PropertyChangeListener myNameListener;
52  	private Hl7ConnectionPanel mySettingPanel;
53  	private JTabbedPane myTabbedPane;
54  	private JPanel myActivityPanelTab;
55  	private Hl7ConnectionPanelHeader myHeaderPanel;
56  	private PropertyChangeListener myStatusPropertyChangeListener;
57  	private Controller myController;
58  
59  	/**
60  	 * Create the panel.
61  	 */
62  	public OutboundConnectionPanel(Controller theController) {
63  		myController =theController;
64  		GridBagLayout gridBagLayout = new GridBagLayout();
65  		gridBagLayout.columnWidths = new int[] { 593, 0 };
66  		gridBagLayout.rowHeights = new int[] { 0, 313, 0 };
67  		gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
68  		gridBagLayout.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
69  		setLayout(gridBagLayout);
70  		
71  		myHeaderPanel = new Hl7ConnectionPanelHeader();
72  		GridBagConstraints gbc_panel = new GridBagConstraints();
73  		gbc_panel.insets = new Insets(0, 0, 5, 0);
74  		gbc_panel.fill = GridBagConstraints.BOTH;
75  		gbc_panel.gridx = 0;
76  		gbc_panel.gridy = 0;
77  		add(myHeaderPanel, gbc_panel);
78  		
79  		myTabbedPane = new JTabbedPane(JTabbedPane.TOP);
80  		GridBagConstraints gbc_TabbedPane = new GridBagConstraints();
81  		gbc_TabbedPane.fill = GridBagConstraints.BOTH;
82  		gbc_TabbedPane.gridx = 0;
83  		gbc_TabbedPane.gridy = 1;
84  		add(myTabbedPane, gbc_TabbedPane);
85  		mySettingPanel = new Hl7ConnectionPanel(myController);
86  		myTabbedPane.addTab("Settings", null, mySettingPanel, null);
87  		mySettingPanel.setBorder(null);
88  		
89  				myActivityPanelTab = new JPanel();
90  				myTabbedPane.addTab("Activity", null, myActivityPanelTab, null);
91  				myActivityPanelTab.setLayout(new BorderLayout(0, 0));
92  				
93  						JLabel lblActivity = new JLabel("Activity");
94  						myActivityPanelTab.add(lblActivity, BorderLayout.NORTH);
95  						
96  								myActivityTable = new ActivityTable();
97  								myActivityPanelTab.add(myActivityTable, BorderLayout.CENTER);
98  
99  	}
100 
101 	public void destroy() {
102 		mySettingPanel.destroy();
103 		myActivityTable.destroy();
104 		myHeaderPanel.destroy();
105 		myConnection.removePropertyChangeListener(OutboundConnection.NAME_PROPERTY, myNameListener);
106 		myConnection.removePropertyChangeListener(AbstractConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
107 	}
108 
109 	public void setConnection(OutboundConnection theConnection) {
110 		mySettingPanel.setConnection(theConnection);
111 		myHeaderPanel.setConnection(theConnection);
112 		myActivityTable.setConnection(theConnection);
113 		myConnection = theConnection;
114 
115 		myNameListener = new PropertyChangeListener() {
116 			public void propertyChange(PropertyChangeEvent theEvt) {
117 				updateWindowTitle();
118 			}
119 		};
120 		theConnection.addPropertyChangeListener(OutboundConnection.NAME_PROPERTY, myNameListener);
121 		updateWindowTitle();
122 
123 		if (theConnection.getStatus() == StatusEnum.STARTED || theConnection.getStatus() == StatusEnum.TRYING_TO_START) {
124 			myTabbedPane.setSelectedIndex(1);
125 		} else {
126 			myTabbedPane.setSelectedIndex(0);
127 		}
128 
129 		myStatusPropertyChangeListener = new PropertyChangeListener() {
130 			public void propertyChange(PropertyChangeEvent theEvt) {
131 				StatusEnum oldVal = (StatusEnum) theEvt.getOldValue();
132 				StatusEnum newVal = (StatusEnum) theEvt.getNewValue();
133 				if (oldVal == StatusEnum.STOPPED && (newVal == StatusEnum.TRYING_TO_START||newVal == StatusEnum.STARTED)) {
134 					myTabbedPane.setSelectedIndex(1);
135 				}else if ((oldVal == StatusEnum.TRYING_TO_START||oldVal == StatusEnum.STARTED) && newVal == StatusEnum.STOPPED) {
136 					myTabbedPane.setSelectedIndex(0);
137 				}
138 			}
139 		};
140 		myConnection.addPropertyChangeListener(AbstractConnection.STATUS_PROPERTY, myStatusPropertyChangeListener);
141 
142 	}
143 
144 	public void setController(Controller theController) {
145 		myActivityTable.setController(theController);
146 	}
147 
148 	private void updateWindowTitle() {
149 		setWindowTitle(myConnection.getName());
150 	}
151 
152 }