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  
34  import javax.swing.JCheckBox;
35  import javax.swing.JComboBox;
36  import javax.swing.JPanel;
37  
38  import de.desy.acop.chart.AcopDisplayMode;
39  
40  /**
41   * <code>ChartOptionPanel</code> is a visual component for customizing
42   * Acop chart options. The panel is independent of any chart objects
43   * and only shows checkboxes and comboboxes for particular properties. 
44   * Any change made to this properties triggers a <code>PropertyChangeEvent</code>
45   * which notifies the registered listeners. 
46   * <p>
47   * The properties which can be changed using this panel include:
48   * <ul>
49   * 	<li>text printing</li>
50   * 	<li>chubby lines</li>
51   *  <li>line style - dots, line etc.</li>
52   *  <li>extra digits</li>
53   *  <li>show grid</li>
54   *  <li>best scale</li>
55   * </ul>
56   *  
57   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
58   * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
59   *
60   */
61  public class ChartOptionsPanel extends JPanel {
62  
63  	private static final long serialVersionUID = 1L;
64  	private JCheckBox textCheckBox;
65  	private JCheckBox chubbyLinesCheckBox;
66  	private JComboBox lineDotsCombo;
67  	private JCheckBox extraDigitCheckBox;
68  	private JCheckBox showGridCheckBox;
69  	private JCheckBox useBestScaleCheckBox;
70  	
71  	private boolean textSelected;
72  	private AcopDisplayMode lineStyle;
73  	private boolean chubbyLines;
74  	private boolean extraDigits;
75  	private boolean showGrid;
76  	private boolean useBestScale;
77  	
78  	protected Dimension comboDim = new Dimension(110, 24);
79  	protected Dimension dim = new Dimension(110,21);
80  	
81  	public ChartOptionsPanel() {
82  		super();
83  		initialize();
84  	}
85  	
86  	private void initialize() {
87  		setLayout(new GridBagLayout());
88  
89  		textCheckBox = new JCheckBox("Text");
90  		textCheckBox.addItemListener(new ItemListener(){
91  			public void itemStateChanged(ItemEvent e) {
92  				setTextSelected(textCheckBox.isSelected());
93  			}
94  		});
95  		textCheckBox.setMinimumSize(dim);
96  		textCheckBox.setMaximumSize(dim);
97  		textCheckBox.setPreferredSize(dim);
98  		textCheckBox.setToolTipText("Enables Text Markers");
99  		
100 		extraDigitCheckBox = new JCheckBox("Extra Digits");
101 		extraDigitCheckBox.addActionListener(new ActionListener(){
102 			public void actionPerformed(ActionEvent e) {
103 				setExtraDigits(extraDigitCheckBox.isSelected());				
104 			}
105 		});
106 		extraDigitCheckBox.setMinimumSize(dim);
107 		extraDigitCheckBox.setMaximumSize(dim);
108 		extraDigitCheckBox.setPreferredSize(dim);
109 		extraDigitCheckBox.setToolTipText("Shows Extra Digits Where Applicable");
110 		
111 		chubbyLinesCheckBox = new JCheckBox("Chubby Lines");
112 		chubbyLinesCheckBox.addItemListener(new ItemListener(){
113 			public void itemStateChanged(ItemEvent e) {
114 				setChubbyLines(chubbyLinesCheckBox.isSelected());
115 			}
116 		});	
117 		chubbyLinesCheckBox.setMinimumSize(dim);
118 		chubbyLinesCheckBox.setMaximumSize(dim);
119 		chubbyLinesCheckBox.setPreferredSize(dim);
120 		chubbyLinesCheckBox.setToolTipText("Toggles Chubby/Normal lines");
121 		
122 		showGridCheckBox = new JCheckBox("Show Grid");
123 		showGridCheckBox.addItemListener(new ItemListener(){
124 			public void itemStateChanged(ItemEvent e) {
125 				setShowGrid(showGridCheckBox.isSelected());
126 			}
127 		});	
128 		showGridCheckBox.setMinimumSize(dim);
129 		showGridCheckBox.setMaximumSize(dim);
130 		showGridCheckBox.setPreferredSize(dim);
131 		showGridCheckBox.setToolTipText("Toggles grid lines visibility");
132 		
133 		useBestScaleCheckBox = new JCheckBox("Best Scale");
134 		useBestScaleCheckBox.addItemListener(new ItemListener(){
135 			public void itemStateChanged(ItemEvent e) {
136 				setUseBestScale(useBestScaleCheckBox.isSelected());
137 			}
138 		});	
139 		useBestScaleCheckBox.setMinimumSize(dim);
140 		useBestScaleCheckBox.setMaximumSize(dim);
141 		useBestScaleCheckBox.setPreferredSize(dim);
142 		useBestScaleCheckBox.setToolTipText("Toggles XY best scale enabled/disabled");
143 		
144 		lineDotsCombo = new JComboBox(AcopDisplayMode.values());
145 		lineDotsCombo.addItemListener(new ItemListener(){
146 			public void itemStateChanged(ItemEvent e) {
147 				if (e.getStateChange() == ItemEvent.SELECTED) {
148 					setLineDisplayMode((AcopDisplayMode)lineDotsCombo.getSelectedItem());
149 				}
150 			}
151 		});
152 		lineDotsCombo.setMinimumSize(comboDim);
153 		lineDotsCombo.setMaximumSize(comboDim);
154 		lineDotsCombo.setPreferredSize(comboDim);
155 		lineDotsCombo.setToolTipText("Sets Chart Style");
156 				
157 		this.add(extraDigitCheckBox, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4,4,2,4),0,0));
158 		this.add(textCheckBox, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,4,2,4),0,0));
159 		this.add(chubbyLinesCheckBox, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,4,2,4),0,0));
160 		this.add(showGridCheckBox, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,4,2,4),0,0));
161 		this.add(useBestScaleCheckBox, new GridBagConstraints(0,4,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,4,2,4),0,0));
162 		this.add(lineDotsCombo, new GridBagConstraints(0,5,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,4,4,4),0,0));
163 	}
164 	
165 	/**
166 	 * Returns the chubbyLines property value.
167 	 * @return the chubby lines
168 	 */
169 	public boolean isChubbyLines() {
170 		return chubbyLines;
171 	}
172 	
173 	/**
174 	 * Sets the chubby lines property.
175 	 * 
176 	 * @param chubby new chubby lines value
177 	 */
178 	public void setChubbyLines(boolean chubby) {
179 		if (this.chubbyLines == chubby) return;
180 		boolean oldChubbyLines = this.chubbyLines;
181 		this.chubbyLines = chubby;
182 		chubbyLinesCheckBox.setSelected(this.chubbyLines);
183 		firePropertyChange("chubbyLines", oldChubbyLines, this.chubbyLines);
184 
185 	}
186 	
187 	/**
188 	 * Sets the extra digits property.
189 	 * 
190 	 * @param extra new extra digits value
191 	 */
192 	public void setExtraDigits(boolean extra) {
193 		if (this.extraDigits == extra) return;
194 		boolean oldExtraDigits = this.extraDigits;
195 		this.extraDigits = extra;
196 		extraDigitCheckBox.setSelected(this.extraDigits);
197 		firePropertyChange("extraDigits", oldExtraDigits, this.extraDigits);
198 
199 	}
200 	
201 	/**
202 	 * Returns the extra digits property value.
203 	 * @return the extra digits
204 	 */
205 	public boolean isExtraDigits() {
206 		return extraDigits;
207 	}
208 	
209 	/**
210 	 * Returns the line display mode.
211 	 * 
212 	 * @return display mode
213 	 */
214 	public AcopDisplayMode getLineDisplayMode() {
215 		return lineStyle;
216 	}
217 	
218 	/**
219 	 * Sets the line display mode.
220 	 * 
221 	 * @param style new display mode value
222 	 */
223 	public void setLineDisplayMode(AcopDisplayMode style) {
224 		if (lineStyle == style) return;
225 		AcopDisplayMode oldStyle = this.lineStyle;
226 		this.lineStyle = style;
227 		lineDotsCombo.setSelectedItem(style);
228 		firePropertyChange("lineDisplayMode", oldStyle, style);
229 	}
230 	
231 	/**
232 	 * Sets the text selected property.
233 	 * 
234 	 * @param visible new text selected value
235 	 */
236 	public void setTextSelected(boolean visible) {
237 		if (this.textSelected == visible) return;
238 		boolean oldTextSelected = this.textSelected;
239 		this.textSelected = visible;
240 		textCheckBox.setSelected(this.textSelected);
241 		firePropertyChange("textSelected", oldTextSelected, this.textSelected);
242 	}
243 	
244 	/**
245 	 * Returns the text selected property value.
246 	 * 
247 	 * @return the text selected
248 	 */
249 	public boolean isTextSelected() {
250 		return textSelected;
251 	}
252 	
253 	/**
254 	 * Returns the use best scale property value.
255 	 * 
256 	 * @return the use best scale
257 	 */
258 	public boolean isUseBestScale() {
259 		return useBestScale;
260 	}
261 	
262 	/**
263 	 * Sets the use best scale property.
264 	 * 
265 	 * @param selected new use best scale value
266 	 */
267 	public void setUseBestScale(boolean selected) {
268 		if (this.useBestScale == selected) return;
269 		boolean oldUseBestScale = this.useBestScale;
270 		this.useBestScale = selected;
271 		useBestScaleCheckBox.setSelected(this.useBestScale);
272 		firePropertyChange("useBestScale", oldUseBestScale, this.useBestScale);
273 	}
274 	
275 	/**
276 	 * Returns the show grid property value.
277 	 * 
278 	 * @return show grid value
279 	 */
280 	public boolean isShowGrid() {
281 		return showGrid;
282 	}
283 	
284 	/**
285 	 * Sets the show grid property.
286 	 * 
287 	 * @param selected new show grid property value
288 	 */
289 	public void setShowGrid(boolean selected) {
290 		if (this.showGrid == selected) return;
291 		boolean oldShowGrid = this.showGrid;
292 		this.showGrid = selected;
293 		showGridCheckBox.setSelected(this.showGrid);
294 		firePropertyChange("showGrid", oldShowGrid, this.showGrid);
295 	}
296 	
297 	/*
298 	 * (non-Javadoc)
299 	 * @see javax.swing.JComponent#setEnabled(boolean)
300 	 */
301 	@Override
302 	public void setEnabled(boolean enabled) {
303 		super.setEnabled(enabled);
304 		textCheckBox.setEnabled(enabled);
305 		chubbyLinesCheckBox.setEnabled(enabled);
306 		lineDotsCombo.setEnabled(enabled);
307 		extraDigitCheckBox.setEnabled(enabled);
308 		showGridCheckBox.setEnabled(enabled);
309 		useBestScaleCheckBox.setEnabled(enabled);
310 	}
311 		
312 	/**
313 	 * Toggles the visibility of the chubby lines check box.
314 	 * 
315 	 * @param visible
316 	 */
317 	public void setChubbyLinesView(boolean visible) {
318 		if (chubbyLinesCheckBox.isVisible() == visible) return;
319 		chubbyLinesCheckBox.setVisible(visible);
320 		firePropertyChange("chubbyLinesView", !visible, visible);
321 	}
322 	
323 	/**
324 	 * Returns true if chubby lines chaeck box is visible.
325 	 * 
326 	 * @return
327 	 */
328 	public boolean isChubbyLinesView() {
329 		return chubbyLinesCheckBox.isVisible();
330 	}
331 	
332 	/**
333 	 * Toggles the visibility of the extra digits checkbox.
334 	 * @param visible
335 	 */
336 	public void setExtraDigitsView(boolean visible) {
337 		if (extraDigitCheckBox.isVisible() == visible) return;
338 		extraDigitCheckBox.setVisible(visible);
339 		firePropertyChange("extraDigitsView", !visible, visible);
340 	}
341 	
342 	/**
343 	 * Returns true if extra digits check box is visible.
344 	 * 
345 	 * @return
346 	 */
347 	public boolean isExtraDigitsView() {
348 		return extraDigitCheckBox.isVisible();
349 	}
350 	
351 	/**
352 	 * Toggles the visibility of the show grid checkbox.
353 	 * @param visible
354 	 */
355 	public void setShowGridView(boolean visible) {
356 		if (showGridCheckBox.isVisible() == visible) return;
357 		showGridCheckBox.setVisible(visible);
358 		firePropertyChange("showGridView", !visible, visible);
359 	}
360 	
361 	/**
362 	 * Returns true if show grid check box is visible.
363 	 * 
364 	 * @return
365 	 */
366 	public boolean isShowGridView() {
367 		return showGridCheckBox.isVisible();
368 	}
369 	
370 	/**
371 	 * Toggles the visibility of the text checkbox.
372 	 * @param visible
373 	 */
374 	public void setTextView(boolean visible) {
375 		if (textCheckBox.isVisible() == visible) return;
376 		textCheckBox.setVisible(visible);
377 		firePropertyChange("textView", !visible, visible);
378 	}
379 	
380 	/**
381 	 * Returns true if text check box is visible.
382 	 * 
383 	 * @return
384 	 */
385 	public boolean isTextView() {
386 		return textCheckBox.isVisible();
387 	}
388 	
389 	/**
390 	 * Toggles the visibility of the best scale checkbox.
391 	 * @param visible
392 	 */
393 	public void setBestScaleView(boolean visible) {
394 		if (useBestScaleCheckBox.isVisible() == visible) return;
395 		useBestScaleCheckBox.setVisible(visible);
396 		firePropertyChange("bestScaleView", !visible, visible);
397 	}
398 	
399 	/**
400 	 * Toggles the visibility of the line display mode view.
401 	 * 
402 	 * @param visible
403 	 */
404 	public void setLineDisplayModeView(boolean visible) {
405 		if (lineDotsCombo.isVisible() == visible) return;
406 		lineDotsCombo.setVisible(visible);
407 		firePropertyChange("lineDisplayModeView",!visible, visible);
408 	}
409 	
410 	/**
411 	 * Returns the visibility of the line display mode combo box.
412 	 * 
413 	 * @return 
414 	 */
415 	public boolean isLineDisplayModeView() {
416 		return lineDotsCombo.isVisible();
417 	}
418 	
419 	/**
420 	 * Returns true if best scale check box is visible.
421 	 * 
422 	 * @return
423 	 */
424 	public boolean isBestScaleView() {
425 		return useBestScaleCheckBox.isVisible();
426 	}
427 	
428 }