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  
25  import java.awt.BorderLayout;
26  import java.awt.GridBagConstraints;
27  import java.awt.GridBagLayout;
28  import java.awt.Insets;
29  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;
31  
32  import javax.swing.BorderFactory;
33  import javax.swing.JCheckBox;
34  import javax.swing.JPanel;
35  import javax.swing.JTextArea;
36  
37  import de.desy.acop.displayers.tools.AcopInfoDialog;
38  import de.desy.acop.transport.ConnectionParameters;
39  import de.desy.tine.client.TLinkFactory;
40  import de.desy.tine.queryUtils.TQuery;
41  
42  /**
43   * <code>AcopDebugPanel</code> shows debug data for certain connection point. 
44   * This panel can be used in combination with <code>AcopInfoDialog</code>.
45   * 
46   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
47   * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
48   * @see AcopInfoDialog
49   */
50  public class AcopDebugPanel extends JPanel {
51  		
52  	private static final long serialVersionUID = -1597262900075362868L;
53  	private JTextArea textArea;
54  	private ConnectionParameters connectionParameters;
55  	private JCheckBox debugCheckBox;
56  	private boolean showDebug = true;
57  	
58  	/**
59  	 * Constructs new AcopDebugPanel.
60  	 *
61  	 */
62  	public AcopDebugPanel() {
63  		super();
64  		initialize();
65  	}
66  	
67  	private void initialize() {
68  		this.setLayout(new BorderLayout());
69  		textArea = new JTextArea();
70  		textArea.setBorder(BorderFactory.createTitledBorder("Fec Information"));
71  		this.add(textArea, BorderLayout.CENTER);
72  		JPanel southPanel = new JPanel(new GridBagLayout());
73  		debugCheckBox = new JCheckBox("Debug");
74  		debugCheckBox.addActionListener(new ActionListener() {
75  			public void actionPerformed(ActionEvent e) {
76  				TLinkFactory.getInstance().setDebugLevel(debugCheckBox.isSelected() ? 2 : 0);					
77  			}
78  		});
79  		southPanel.add(debugCheckBox, new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
80  		this.add(southPanel, BorderLayout.NORTH);			
81  	}
82  	
83  	/**
84  	 * Sets the ConnectionParameters, which specify the connection point that
85  	 * debug data is shown for.
86  	 *  
87  	 * @param param the remote connection point
88  	 */
89  	public void setConnectionParameters(ConnectionParameters param) {
90  		if (this.connectionParameters != null && this.connectionParameters.equals(param)) return;
91  		this.connectionParameters = param;
92  		if (connectionParameters != null){
93  			textArea.setText("Updating ... Please wait.");
94  			new Thread(new Runnable() {
95  				public void run() {
96  					String srv = connectionParameters.getDeviceGroup();
97  			        String con = connectionParameters.getDeviceContext();
98  			        StringBuffer s = new StringBuffer(TQuery.getModuleAddressInfo(srv, con) +"\n");
99  			        s.append(TQuery.getTineVersion(con, srv) + "\n");
100 			        s.append(TQuery.getAppVersion(con, srv) + "\n");
101 			        s.append(TQuery.getAppDate(con, srv) + "\n");
102 			        textArea.setText(s.substring(0));
103 				}
104 			}).start(); 
105 		} else {
106 			textArea.setText("");
107 		}
108 	}
109 	
110 	/**
111 	 * Returns the ConnectionParameters that specify the remote connection point, which
112 	 * is being debugged.
113 	 * 
114 	 * @return
115 	 */
116 	public ConnectionParameters getConnectionParameters() {
117 		return connectionParameters;
118 	}
119 	
120 	/**
121 	 * Sets the debug level for TINE TLinkFactory. It always uses level 2.
122 	 * 
123 	 * @param debug new debug level (0 debug off)
124 	 * @see TLinkFactory#setDebugLevel(int)
125 	 */
126 	public void setDebug(int debug) {
127 		if (debug > 0) {
128 			debugCheckBox.setSelected(true);
129 		} else {
130 			debugCheckBox.setSelected(false);
131 		}
132 	}
133 	
134 	/**
135 	 * Returns the debug level (0 - debug is off, 2 - debug is on).
136 	 * 
137 	 * @return the debug level
138 	 */
139 	public int isDebug() {
140 		return debugCheckBox.isSelected() ? 2 : 0;
141 	}
142 	
143 	/**
144 	 * Sets the visibility of the debug checkbox.
145 	 * 
146 	 * @param showDebug true if the checkbox should be visible, false if not
147 	 */
148 	public void setShowDebug(boolean showDebug) {
149 		if (this.showDebug == showDebug) return;
150 		this.showDebug = showDebug;
151 		debugCheckBox.setVisible(showDebug);
152 		firePropertyChange("showDebug", !showDebug, showDebug);
153 	}
154 	
155 	/**
156 	 * Returns true if the debug check box is visible.
157 	 * @return the debug check box visibile
158 	 */
159 	public boolean isShowDebug() {
160 		return showDebug;
161 	}
162 }