View Javadoc

1   /*
2    * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton,
3    * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
4    *
5    * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
6    * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
7    * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND
8    * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
9    * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
11   * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE
12   * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR
13   * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
14   * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
15   * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
16   * OR MODIFICATIONS.
17   * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION,
18   * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS
19   * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY
20   * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
21   */
22  
23  package de.desy.acop.displayers.info;
24  import java.awt.Dimension;
25  import java.awt.GridBagConstraints;
26  import java.awt.GridBagLayout;
27  import java.awt.Insets;
28  
29  import javax.swing.JLabel;
30  import javax.swing.JPanel;
31  
32  import com.cosylab.gui.displayers.CommonDisplayer;
33  
34  import de.desy.acop.displayers.tools.AcopInfoDialog;
35  import de.desy.acop.transport.ConnectionFailed;
36  import de.desy.acop.transport.ConnectionParameters;
37  import de.desy.acop.transport.adapters.AdapterFactoryService;
38  
39  /**
40   * <code>ConnectionPanel</code> shows the connection points as specified
41   * by the ConnectionParameter. This panel can be used in combination with
42   * <code>AcopInfoDialog</code>.
43   * 
44   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
45   * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
46   * @see AcopInfoDialog
47   */
48  public class ConnectionPanel extends JPanel {
49  	private static final long serialVersionUID = -8289192882139945420L;
50  	private JLabel protocolLabel;
51  	private JLabel protocol;
52  	private JLabel contextLabel;
53  	private JLabel context;
54  	private JLabel serverLabel;
55  	private JLabel server;
56  	private JLabel deviceLabel;
57  	private JLabel device;
58  	private JLabel propertyLabel;
59  	private JLabel property;
60  	private JLabel accessRateLabel;
61  	private JLabel accessRate;
62  	private JLabel accessModeLabel;
63  	private JLabel accessMode;
64  	private JLabel sizeLabel;
65  	private JLabel size;
66  	private JLabel infoLabel;
67  	private ConnectionParameters connectionParameters;
68  	
69  	/**
70  	 * Constructs new ConnectionPanel.
71  	 *
72  	 */
73  	public ConnectionPanel() {
74  		super();
75  		initialize();
76  	}
77  	
78  	private void initialize() {
79  		this.setLayout(new GridBagLayout());
80  		
81  		protocolLabel = new JLabel("Protocol:");
82  		protocolLabel.setMinimumSize(new Dimension(120,21));
83  		protocolLabel.setMaximumSize(new Dimension(120,21));
84  		protocolLabel.setPreferredSize(new Dimension(120,21));
85  		add(protocolLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11,11,1,1),0,0));
86  		
87  		protocol = new JLabel("N/A");
88  		protocol.setMinimumSize(new Dimension(120,21));
89  		protocol.setMaximumSize(new Dimension(120,21));
90  		protocol.setPreferredSize(new Dimension(120,21));
91  		add(protocol, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11,1,1,11),0,0));
92  					
93  		contextLabel = new JLabel("Context:");
94  		contextLabel.setMinimumSize(new Dimension(120,21));
95  		contextLabel.setMaximumSize(new Dimension(120,21));
96  		contextLabel.setPreferredSize(new Dimension(120,21));
97  		add(contextLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
98  		
99  		context = new JLabel("N/A");
100 		context.setMinimumSize(new Dimension(120,21));
101 		context.setMaximumSize(new Dimension(120,21));
102 		context.setPreferredSize(new Dimension(120,21));
103 		add(context, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
104 		
105 		serverLabel = new JLabel("Server:");
106 		serverLabel.setMinimumSize(new Dimension(120,21));
107 		serverLabel.setMaximumSize(new Dimension(120,21));
108 		serverLabel.setPreferredSize(new Dimension(120,21));
109 		add(serverLabel, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
110 		
111 		server = new JLabel("N/A");
112 		server.setMinimumSize(new Dimension(120,21));
113 		server.setMaximumSize(new Dimension(120,21));
114 		server.setPreferredSize(new Dimension(120,21));
115 		add(server, new GridBagConstraints(1,2,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
116 		
117 		deviceLabel = new JLabel("Device:");
118 		deviceLabel.setMinimumSize(new Dimension(120,21));
119 		deviceLabel.setMaximumSize(new Dimension(120,21));
120 		deviceLabel.setPreferredSize(new Dimension(120,21));
121 		add(deviceLabel, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
122 		
123 		device = new JLabel("N/A");
124 		device.setMinimumSize(new Dimension(120,21));
125 		device.setMaximumSize(new Dimension(120,21));
126 		device.setPreferredSize(new Dimension(120,21));
127 		add(device, new GridBagConstraints(1,3,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
128 		
129 		propertyLabel = new JLabel("Property:");
130 		propertyLabel.setMinimumSize(new Dimension(120,21));
131 		propertyLabel.setMaximumSize(new Dimension(120,21));
132 		propertyLabel.setPreferredSize(new Dimension(120,21));
133 		add(propertyLabel, new GridBagConstraints(0,4,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
134 		
135 		property = new JLabel("N/A");
136 		property.setMinimumSize(new Dimension(120,21));
137 		property.setMaximumSize(new Dimension(120,21));
138 		property.setPreferredSize(new Dimension(120,21));
139 		add(property, new GridBagConstraints(1,4,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
140 		
141 		sizeLabel = new JLabel("Size:");
142 		sizeLabel.setMinimumSize(new Dimension(120,21));
143 		sizeLabel.setMaximumSize(new Dimension(120,21));
144 		sizeLabel.setPreferredSize(new Dimension(120,21));
145 		add(sizeLabel, new GridBagConstraints(0,5,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
146 		
147 		size = new JLabel("N/A");
148 		size.setMinimumSize(new Dimension(120,21));
149 		size.setMaximumSize(new Dimension(120,21));
150 		size.setPreferredSize(new Dimension(120,21));
151 		add(size, new GridBagConstraints(1,5,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
152 
153 		accessRateLabel = new JLabel("Access Rate:");
154 		accessRateLabel.setMinimumSize(new Dimension(120,21));
155 		accessRateLabel.setMaximumSize(new Dimension(120,21));
156 		accessRateLabel.setPreferredSize(new Dimension(120,21));
157 		add(accessRateLabel, new GridBagConstraints(0,6,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
158 		
159 		accessRate = new JLabel("N/A");
160 		accessRate.setMinimumSize(new Dimension(120,21));
161 		accessRate.setMaximumSize(new Dimension(120,21));
162 		accessRate.setPreferredSize(new Dimension(120,21));
163 		add(accessRate, new GridBagConstraints(1,6,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
164 		
165 		accessModeLabel = new JLabel("Access Mode:");
166 		accessModeLabel.setMinimumSize(new Dimension(120,21));
167 		accessModeLabel.setMaximumSize(new Dimension(120,21));
168 		accessModeLabel.setPreferredSize(new Dimension(120,21));
169 		add(accessModeLabel, new GridBagConstraints(0,7,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,11,1,1),0,0));
170 		
171 		accessMode = new JLabel("N/A");
172 		accessMode.setMinimumSize(new Dimension(120,21));
173 		accessMode.setMaximumSize(new Dimension(120,21));
174 		accessMode.setPreferredSize(new Dimension(120,21));
175 		add(accessMode, new GridBagConstraints(1,7,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,11),0,0));
176 		
177 		infoLabel = new JLabel();
178 		infoLabel.setMinimumSize(new Dimension(240,21));
179 		infoLabel.setMaximumSize(new Dimension(240,21));
180 		infoLabel.setPreferredSize(new Dimension(240,21));
181 		add(infoLabel, new GridBagConstraints(0,8,2,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4,11,11,11),0,0));
182 		
183 	}
184 	
185 	/**
186 	 * Sets new remote connection point to this panel.
187 	 * 
188 	 * @param p the parameters that specify the connection point
189 	 */
190 	public void setConnectionParameters(ConnectionParameters p) {
191 		this.connectionParameters = p;
192 		
193 		if (this.connectionParameters != null) {
194 			protocol.setText(connectionParameters.getAccessProtocol());
195 			context.setText(connectionParameters.getDeviceContext());
196 			server.setText(connectionParameters.getDeviceGroup());
197 			device.setText(connectionParameters.getDeviceName());
198 			property.setText(connectionParameters.getDeviceProperty());
199 			size.setText(String.valueOf(connectionParameters.getPropertySize()));
200 			accessRate.setText(String.valueOf(connectionParameters.getAccessRate()));
201 			accessMode.setText(String.valueOf(connectionParameters.getAccessMode()));
202 			infoLabel.setText(getInfo(connectionParameters));
203 		} else {
204 			protocol.setText("N/A");
205 			context.setText("N/A");
206 			server.setText("N/A");
207 			device.setText("N/A");
208 			property.setText("N/A");
209 			size.setText("N/A");
210 			accessRate.setText("N/A");
211 			accessMode.setText("N/A");
212 		}
213 	}
214 	
215 	/**
216 	 * Returns the ConnectionParameters associated with this panel.
217 	 * 
218 	 * @return the remote connection point
219 	 */
220 	public ConnectionParameters getConnectionParameters() {
221 		return connectionParameters;
222 	}
223 	
224 	private String getInfo(ConnectionParameters param) {
225 		try {
226 			return (String) AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(param).get(CommonDisplayer.C_DESCRIPTION);
227 		} catch (ConnectionFailed e) {
228 			e.printStackTrace();
229 		}
230 		return "N/A";
231 	}
232 }