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.tools;
24  
25  import java.awt.GridBagConstraints;
26  import java.awt.GridBagLayout;
27  import java.awt.Insets;
28  import java.awt.event.WindowAdapter;
29  import java.awt.event.WindowEvent;
30  import java.beans.PropertyChangeEvent;
31  import java.beans.PropertyChangeListener;
32  
33  import javax.swing.JPanel;
34  
35  import com.cosylab.gui.InfoDialog;
36  import com.cosylab.gui.displayers.Displayer;
37  
38  import de.desy.acop.displayers.info.AcopDebugPanel;
39  import de.desy.acop.displayers.info.CharacteristicsPanel;
40  import de.desy.acop.displayers.info.ConnectionPanel;
41  import de.desy.acop.transport.ConnectionFailed;
42  import de.desy.acop.transport.adapters.AdapterFactoryService;
43  import de.desy.tine.client.TLinkFactory;
44  
45  /**
46   * <code>AcopInfoDialog</code> is an extension of <code>InfoDialog</code>
47   * which in addition to existing data also shows connection details and 
48   * characteristics of property that is connected with the displayer that this
49   * dialog is attached to.
50   * 
51   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
52   * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
53   *
54   */
55  public class AcopInfoDialog extends InfoDialog {
56  	
57  	private static final long serialVersionUID = 513076582058739594L;
58  	
59  	private ConnectionPanel connectionPanel;
60  	private CharacteristicsPanel characteristicsPanel;
61  	private AcopDebugPanel acopDebugPanel;
62  	private JPanel debugCompositionPanel;
63  		
64  	private PropertyChangeListener propertyListener;
65  		
66  	/**
67  	 * Constructs a new AcopInfoDialog.
68  	 *
69  	 */
70  	public AcopInfoDialog() {
71  		this(null);
72  	}
73  	
74  	/**
75  	 * Constructs a new AcopInfoDialog and associates it with the given displyer.
76  	 * 
77  	 * @param displayer
78  	 */
79  	public AcopInfoDialog(AcopDisplayer displayer) {
80  		super(displayer);
81  		setSize(500,400);
82  		this.addWindowListener(new WindowAdapter(){
83  			@Override
84  			public void windowActivated(WindowEvent e) {
85  				getAcopDebugPanel().setDebug(TLinkFactory.getInstance().getDebugLevel());
86  			}
87  		});
88  		this.addPanel(getConnectionPanel(), "Connection", 0, true);
89  		this.addPanel(getCharacteristicsPanel(), "Prop Info");
90  		this.addPanel(getDebugCompositionPanel(), "Debug", 1, false);
91  	}
92  	
93  	private ConnectionPanel getConnectionPanel() {
94  		if (connectionPanel == null) {
95  			connectionPanel = new ConnectionPanel();
96  		}
97  		return connectionPanel;
98  	}
99  	
100 	private CharacteristicsPanel getCharacteristicsPanel() {
101 		if (characteristicsPanel == null) {
102 			characteristicsPanel = new CharacteristicsPanel();
103 		}
104 		return characteristicsPanel;
105 	}
106 	
107 	private AcopDebugPanel getAcopDebugPanel() {
108 		if (acopDebugPanel == null) {
109 			acopDebugPanel = new AcopDebugPanel();
110 		}
111 		return acopDebugPanel;
112 	}
113 	
114 	private JPanel getDebugCompositionPanel() {
115 		if (debugCompositionPanel == null) {
116 			debugCompositionPanel = new JPanel(new GridBagLayout());
117 			debugCompositionPanel.add(getAcopDebugPanel(), new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11,11,1,11),0,0));
118 			debugCompositionPanel.add(getDebugPanel(), new GridBagConstraints(0,1,1,1,1,0.1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1,11,11,11),0,0));
119 		}
120 		return debugCompositionPanel;		
121 	}
122 
123 	/* (non-Javadoc)
124 	 * @see com.cosylab.gui.InfoDialog#setDisplayer(com.cosylab.gui.displayers.Displayer)
125 	 */
126 	@Override
127 	public void setDisplayer(Displayer displayer) {
128 		
129 		if (getDisplayer() != null && !getDisplayer().equals(displayer)) {
130 			getDisplayer().removePropertyChangeListener(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY,getPropertyListener());
131 			if (displayer != null)
132 				displayer.addPropertyChangeListener(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY,getPropertyListener());
133 		} else if (getDisplayer() == null && displayer != null) {
134 			displayer.addPropertyChangeListener(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY,getPropertyListener());
135 		}
136 
137 		super.setDisplayer(displayer);
138 		if (getDisplayer() != null) {
139 			setTitle("Info for "+getDisplayer().getClass().getSimpleName());
140 			getConnectionPanel().setConnectionParameters(((AcopDisplayer)getDisplayer()).getConnectionParameters());
141 			getAcopDebugPanel().setConnectionParameters(((AcopDisplayer)getDisplayer()).getConnectionParameters());
142 			try {
143 				getCharacteristicsPanel().setCharacteristics(AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(((AcopDisplayer)getDisplayer()).getConnectionParameters()));
144 			} catch (ConnectionFailed e) {
145 				e.printStackTrace();
146 			}
147 		} else {
148 			setTitle("Info dialog");
149 			getConnectionPanel().setConnectionParameters(null);
150 			getAcopDebugPanel().setConnectionParameters(null);
151 			getCharacteristicsPanel().setCharacteristics(null);
152 		}
153 		getAcopDebugPanel().setDebug(TLinkFactory.getInstance().getDebugLevel());
154 		
155 	}
156 	
157 	private PropertyChangeListener getPropertyListener() {
158 		if (propertyListener == null) {
159 			propertyListener = new PropertyChangeListener() {
160 				public void propertyChange(PropertyChangeEvent evt) {
161 					if (AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY.equals(evt.getPropertyName())) {
162 						getConnectionPanel().setConnectionParameters(((AcopDisplayer)getDisplayer()).getConnectionParameters());
163 						getAcopDebugPanel().setConnectionParameters(((AcopDisplayer)getDisplayer()).getConnectionParameters());
164 						try {
165 							getCharacteristicsPanel().setCharacteristics(AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(((AcopDisplayer)getDisplayer()).getConnectionParameters()));
166 						} catch (ConnectionFailed e) {
167 							e.printStackTrace();
168 						}
169 					}
170 				}
171 			};
172 		}
173 		return propertyListener;
174 	}
175 	
176 	public static void main(String[] args) {
177 		new AcopInfoDialog().setVisible(true);
178 	}
179 	
180 }