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.chart;
24  
25  import java.awt.Dimension;
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  import java.awt.event.ItemEvent;
32  import java.awt.event.ItemListener;
33  import java.beans.Customizer;
34  import java.beans.PropertyChangeEvent;
35  import java.beans.PropertyChangeListener;
36  
37  import javax.swing.JButton;
38  import javax.swing.JCheckBox;
39  import javax.swing.JComboBox;
40  import javax.swing.JLabel;
41  import javax.swing.JPanel;
42  import javax.swing.border.TitledBorder;
43  
44  import com.cosylab.gui.components.NumberField;
45  
46  import de.desy.acop.chart.AcopDisplayMode;
47  import de.desy.acop.displayers.AcopChartReorg;
48  
49  /**
50   * <code>AcopChartReorgSettingsCustomizer</code> is a customizer which
51   * allows customization of the common chart options of the 
52   * <code>AcopChartReorg</code>.
53   * 
54   * @author Tilen Kusterle, Cosylab
55   * @see AcopChartReorg
56   */
57  public class AcopChartReorgSettingsCustomizer extends JPanel implements Customizer {
58  
59  	private static final long serialVersionUID = 1L;
60  	
61  	protected static final String NO_STYLE = "No Style";
62  	
63  	protected AcopChartReorg acopChartReorg;
64  	
65  	protected JPanel scalePanel;
66  	private JButton autoscaleXButton;
67  	private JButton autoscaleYButton;
68  	private JCheckBox autoscaleBox;
69  	private JCheckBox logBox;
70  	private NumberField xRangeMinField;
71  	private NumberField xRangeMaxField;
72  	private NumberField yRangeMinField;
73  	private NumberField yRangeMaxField;
74  	protected JPanel stylePanel;
75  	private JCheckBox axisTraceBox;
76  	private JCheckBox chubbyLinesBox;
77  	private JLabel displayModeLabel;
78  	private JComboBox displayModeCombo;
79  	
80  	/**
81  	 * Constructs new AcopChartReorgSettingsCustomizer.
82  	 *
83  	 */
84  	public AcopChartReorgSettingsCustomizer() {
85  		initialize();
86  	}
87  	
88  	protected void initialize() {
89  		setLayout(new GridBagLayout());
90  		
91  		add(getScalePanel(),new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(1,1,1,1),0,0));
92  		add(getStylePanel(),new GridBagConstraints(0,1,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(1,1,1,1),0,0));
93  		
94  	}
95  	
96  	protected JPanel getScalePanel() {
97  		if (scalePanel == null) {
98  			scalePanel = new JPanel();
99  			scalePanel.setBorder(new TitledBorder("Scale"));
100 			scalePanel.setLayout(new GridBagLayout());
101 			
102 			scalePanel.add(getAutoscaleBox(), new GridBagConstraints(0,0,2,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
103 			scalePanel.add(getLogBox(), new GridBagConstraints(2,0,2,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
104 			scalePanel.add(new JLabel("Horizontal Min:"), new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
105 			scalePanel.add(getXRangeMinField(), new GridBagConstraints(1,1,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
106 			scalePanel.add(new JLabel("Horizontal Max:"), new GridBagConstraints(2,1,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
107 			scalePanel.add(getXRangeMaxField(), new GridBagConstraints(3,1,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
108 			scalePanel.add(getAutoscaleXButton(), new GridBagConstraints(4,1,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
109 			scalePanel.add(new JLabel("Vertical Min:"), new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
110 			scalePanel.add(getYRangeMinField(), new GridBagConstraints(1,2,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
111 			scalePanel.add(new JLabel("Vertical Max:"), new GridBagConstraints(2,2,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
112 			scalePanel.add(getYRangeMaxField(), new GridBagConstraints(3,2,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
113 			scalePanel.add(getAutoscaleYButton(), new GridBagConstraints(4,2,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
114 		}
115 
116 		return scalePanel;
117 	}
118 	
119 	protected JButton getAutoscaleXButton() {
120 		if (autoscaleXButton == null) {
121 			autoscaleXButton = new JButton("Autoscale Horizontal");
122 			autoscaleXButton.setToolTipText("Autoscale Horizontal Axis");
123 			autoscaleXButton.setPreferredSize(new Dimension(180, 25));
124 			autoscaleXButton.addActionListener(new ActionListener() {
125 				public void actionPerformed(ActionEvent e) {
126 					if (acopChartReorg != null) acopChartReorg.autoScaleXOnce();					
127 				}});
128 		}
129 
130 		return autoscaleXButton;
131 	}
132 	
133 	protected JButton getAutoscaleYButton() {
134 		if (autoscaleYButton == null) {
135 			autoscaleYButton = new JButton("Autoscale Vertical");
136 			autoscaleYButton.setToolTipText("Autoscale Vertical Axis");
137 			autoscaleYButton.setPreferredSize(new Dimension(180, 25));
138 			autoscaleYButton.addActionListener(new ActionListener() {
139 				public void actionPerformed(ActionEvent e) {
140 					if (acopChartReorg != null) acopChartReorg.autoScaleYOnce();
141 				}});
142 		}
143 
144 		return autoscaleYButton;
145 	}
146 	
147 	protected JCheckBox getAutoscaleBox() {
148 		if (autoscaleBox == null) {
149 			autoscaleBox = new JCheckBox("Automatic Vertical Scaling");
150 			autoscaleBox.setToolTipText("Toggles Automatic Scaling of Vertical Axis");
151 			autoscaleBox.addItemListener(new ItemListener() {
152 				public void itemStateChanged(ItemEvent e) {
153 					if (acopChartReorg != null) {
154 						acopChartReorg.setYAutoScale(autoscaleBox.isSelected());					
155 					}
156 				}
157 			});
158 		}
159 
160 		return autoscaleBox;
161 	}
162 	
163 	protected JCheckBox getLogBox() {
164 		if (logBox == null) {
165 			logBox = new JCheckBox("LOG Vertical Scale");
166 			logBox.setToolTipText("Toggles Lin / Log Mode for Vertical Axis");
167 			logBox.addActionListener(new ActionListener() {
168 				public void actionPerformed(ActionEvent e) {
169 					if (acopChartReorg != null) acopChartReorg.setYLogScale(logBox.isSelected());
170 				}});
171 		}
172 
173 		return logBox;
174 	}
175 	
176 	protected NumberField getXRangeMinField() {
177 		if (xRangeMinField == null) {
178 			xRangeMinField = new NumberField();
179 			xRangeMinField.setColumns(6);
180 			xRangeMinField.setNumberType(Double.class);
181 			xRangeMinField.addPropertyChangeListener(NumberField.VALUE, new PropertyChangeListener() {
182 				public void propertyChange(PropertyChangeEvent evt) {
183 					Number number = (Number) evt.getNewValue();
184 					if (acopChartReorg != null) acopChartReorg.setXRangeMin(number.doubleValue());
185 				}});
186 		}
187 
188 		return xRangeMinField;
189 	}
190 	
191 	protected NumberField getXRangeMaxField() {
192 		if (xRangeMaxField == null) {
193 			xRangeMaxField = new NumberField();
194 			xRangeMaxField.setColumns(6);
195 			xRangeMaxField.setNumberType(Double.class);
196 			xRangeMaxField.addPropertyChangeListener(NumberField.VALUE, new PropertyChangeListener() {
197 				public void propertyChange(PropertyChangeEvent evt) {
198 					Number number = (Number) evt.getNewValue();
199 					if (acopChartReorg != null) {
200 						acopChartReorg.setXRangeMax(number.doubleValue());
201 					}
202 				}});
203 		}
204 
205 		return xRangeMaxField;
206 	}
207 	
208 	protected NumberField getYRangeMinField() {
209 		if (yRangeMinField == null) {
210 			yRangeMinField = new NumberField();
211 			yRangeMinField.setColumns(6);
212 			yRangeMinField.setNumberType(Double.class);
213 			yRangeMinField.addPropertyChangeListener(NumberField.VALUE, new PropertyChangeListener() {
214 				public void propertyChange(PropertyChangeEvent evt) {
215 					Number number = (Number) evt.getNewValue();
216 					if (acopChartReorg != null && !acopChartReorg.isYAutoScale()) {
217 						acopChartReorg.setYRangeMin(number.doubleValue());
218 					}
219 				}});
220 		}
221 
222 		return yRangeMinField;
223 	}
224 	
225 	protected NumberField getYRangeMaxField() {
226 		if (yRangeMaxField == null) {
227 			yRangeMaxField = new NumberField();
228 			yRangeMaxField.setColumns(6);
229 			yRangeMaxField.setNumberType(Double.class);
230 			yRangeMaxField.addPropertyChangeListener(NumberField.VALUE, new PropertyChangeListener() {
231 				public void propertyChange(PropertyChangeEvent evt) {
232 					Number number = (Number) evt.getNewValue();
233 					if (acopChartReorg != null && !acopChartReorg.isYAutoScale()){
234 						acopChartReorg.setYRangeMax(number.doubleValue());
235 					}
236 				}});
237 		}
238 
239 		return yRangeMaxField;
240 	}
241 	
242 	protected JPanel getStylePanel() {
243 		if (stylePanel == null) {
244 			stylePanel = new JPanel();
245 			stylePanel.setBorder(new TitledBorder("Style"));
246 			stylePanel.setLayout(new GridBagLayout());
247 			
248 			JPanel lineStylePanel = new JPanel();
249 			lineStylePanel.setLayout(new GridBagLayout());
250 			lineStylePanel.add(getDisplayModeLabel(),new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.EAST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
251 			lineStylePanel.add(getDisplayModeCombo(),new GridBagConstraints(1,0,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
252 			
253 			
254 			stylePanel.add(getAxisTraceBox(),new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
255 			stylePanel.add(getChubbyLinesBox(),new GridBagConstraints(1,0,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
256 			stylePanel.add(lineStylePanel,new GridBagConstraints(0,1,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
257 			
258 		}
259 
260 		return stylePanel;
261 	}
262 	
263 	protected JCheckBox getAxisTraceBox() {
264 		if (axisTraceBox == null) {
265 			axisTraceBox = new JCheckBox("Axis Trace Visible");
266 			axisTraceBox.setToolTipText("Toggles Axis Trace On / Off");
267 			axisTraceBox.addActionListener(new ActionListener() {
268 				public void actionPerformed(ActionEvent e) {
269 					if (acopChartReorg != null) acopChartReorg.setAxisTraceVisible(axisTraceBox.isSelected());
270 				}});
271 		}
272 
273 		return axisTraceBox;
274 	}
275 	
276 	protected JCheckBox getChubbyLinesBox() {
277 		if (chubbyLinesBox == null) {
278 			chubbyLinesBox = new JCheckBox("Chubby Lines");
279 			chubbyLinesBox.setToolTipText("Toggles Normal / Chubby Lines");
280 			chubbyLinesBox.addActionListener(new ActionListener() {
281 				public void actionPerformed(ActionEvent e) {
282 					if (acopChartReorg != null) acopChartReorg.setChubbyLines(chubbyLinesBox.isSelected());
283 				}});
284 		}
285 
286 		return chubbyLinesBox;
287 	}
288 	
289 	protected JLabel getDisplayModeLabel() {
290 		if (displayModeLabel == null) {
291 			displayModeLabel = new JLabel("Display Mode");
292 		}
293 		return displayModeLabel;
294 	}
295 	
296 	protected JComboBox getDisplayModeCombo() {
297 		if (displayModeCombo == null) {
298 			displayModeCombo = new JComboBox();
299 			displayModeCombo.setToolTipText("Sets Chart Display Mode");
300 			displayModeCombo.addItem(NO_STYLE);
301 			
302 			AcopDisplayMode[] m= AcopDisplayMode.values();
303 			for (int i = 0; i < m.length; i++) {
304 				displayModeCombo.addItem(m[i]);
305 			}
306 
307 			displayModeCombo.addActionListener(new ActionListener() {
308 				public void actionPerformed(ActionEvent e) {
309 					if (acopChartReorg != null) {
310 						Object selected = displayModeCombo.getSelectedItem();
311 						if (selected instanceof AcopDisplayMode) {
312 							acopChartReorg.setDisplayMode((AcopDisplayMode) selected);
313 						}
314 						else acopChartReorg.setDisplayMode(null);
315 					}
316 				}});
317 		}
318 
319 		return displayModeCombo;
320 	}
321 
322 	/* (non-Javadoc)
323 	 * @see java.beans.Customizer#setObject(java.lang.Object)
324 	 */
325 	public void setObject(Object bean) {
326 		acopChartReorg = (AcopChartReorg) bean;
327 		addListener();
328 	}
329 	
330 	protected void addListener() {
331 		if (acopChartReorg == null) return;
332 		acopChartReorg.addPropertyChangeListener(new PropertyChangeListener() {
333 
334 			public void propertyChange(PropertyChangeEvent evt) {
335 				String propertyName = evt.getPropertyName();
336 				if (propertyName.equals(AcopChartReorg.LINE_STYLE)) {
337 					Object style = evt.getNewValue();
338 					if (style == null) getDisplayModeCombo().setSelectedItem(NO_STYLE);
339 					else getDisplayModeCombo().setSelectedItem(style);
340 				}
341 				else if (propertyName.equals(AcopChartReorg.CHUBBY_LINES)) {
342 					getChubbyLinesBox().setSelected((Boolean) evt.getNewValue());
343 				}
344 				else if (propertyName.equals(AcopChartReorg.AXIS_TRACE_VISIBLE)) {
345 					getAxisTraceBox().setSelected((Boolean) evt.getNewValue());
346 				}
347 				else if (propertyName.equals(AcopChartReorg.Y_AUTOSCALE)) {
348 					getAutoscaleBox().setSelected((Boolean) evt.getNewValue());
349 				}
350 				else if (propertyName.equals(AcopChartReorg.Y_LOG_SCALE)) {
351 					getLogBox().setSelected((Boolean) evt.getNewValue());
352 				}
353 				else if (propertyName.equals(AcopChartReorg.X_RANGE_MAX)) {
354 					getXRangeMaxField().setValue((Double) evt.getNewValue());
355 				}
356 				else if (propertyName.equals(AcopChartReorg.X_RANGE_MIN)) {
357 					getXRangeMinField().setValue((Double) evt.getNewValue());
358 				}
359 				else if (propertyName.equals(AcopChartReorg.Y_RANGE_MAX)) {
360 					getYRangeMaxField().setValue((Double) evt.getNewValue());
361 				}
362 				else if (propertyName.equals(AcopChartReorg.Y_RANGE_MIN)) {
363 					getYRangeMinField().setValue((Double) evt.getNewValue());
364 				}
365 				
366 			}});
367 	}
368 
369 }