1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.displayers.selector;
24
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.GridBagConstraints;
28 import java.awt.GridBagLayout;
29 import java.awt.Insets;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.awt.event.ItemEvent;
33 import java.awt.event.ItemListener;
34
35 import javax.swing.JButton;
36 import javax.swing.JCheckBox;
37 import javax.swing.JColorChooser;
38 import javax.swing.JComboBox;
39 import javax.swing.JLabel;
40 import javax.swing.JPanel;
41
42 import com.cosylab.gui.components.NumberField;
43 import com.cosylab.gui.components.util.RunnerHelper;
44 import com.cosylab.gui.components.util.ColorManager;
45
46 import de.desy.acop.chart.AcopDisplayMode;
47 import de.desy.acop.chart.AcopDrawStyleEnum;
48 import de.desy.acop.chart.AcopFFTEnum;
49 import de.desy.acop.displayers.tools.AcopGraphParameters;
50
51
52
53
54
55
56
57
58
59
60
61 public class GraphCustomizerPanel extends MultipleDisplayerAbstractSettingsPanel<AcopGraphParameters> {
62
63 private static final long serialVersionUID = -2986099881478526811L;
64 private JLabel graphStyleLabel;
65 private JLabel graphModeLabel;
66 private JLabel graphFFTLabel;
67 private JLabel graphColorLabel;
68 private JLabel trendLengthLabel;
69 private JComboBox drawStyleCombo;
70 private JComboBox graphModeCombo;
71 private JComboBox graphFFTCombo;
72 private JLabel graphColorSelector;
73 private Color selectedColor;
74 private JPanel propertiesPanel;
75 private JButton colorPicker;
76 private JCheckBox trendCheckBox;
77 private NumberField trendLength;
78 private JLabel graphWidthLabel;
79 private NumberField graphWidthField;
80 private JCheckBox useDefaultColor;
81
82
83
84
85
86 public GraphCustomizerPanel() {
87 setLayout(new GridBagLayout());
88 add(getPropertiesPanel(), new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
89 }
90
91 private JPanel getPropertiesPanel() {
92 if (propertiesPanel == null) {
93 propertiesPanel = new JPanel(new GridBagLayout());
94
95 graphStyleLabel = new JLabel("Style");
96 graphStyleLabel.setPreferredSize(new Dimension(50,21));
97 graphStyleLabel.setMinimumSize(new Dimension(50,21));
98 graphStyleLabel.setMaximumSize(new Dimension(50,21));
99 drawStyleCombo = new JComboBox(AcopDrawStyleEnum.values());
100 drawStyleCombo.setPreferredSize(new Dimension(120,21));
101 drawStyleCombo.setMinimumSize(new Dimension(120,21));
102 drawStyleCombo.setMaximumSize(new Dimension(120,21));
103 propertiesPanel.add(graphStyleLabel, new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
104 propertiesPanel.add(drawStyleCombo, new GridBagConstraints(1,0,3,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
105
106 graphModeLabel = new JLabel("Mode");
107 graphModeLabel.setPreferredSize(new Dimension(50,21));
108 graphModeLabel.setMinimumSize(new Dimension(50,21));
109 graphModeLabel.setMaximumSize(new Dimension(50,21));
110 graphModeCombo = new JComboBox(AcopDisplayMode.values());
111 graphModeCombo.setPreferredSize(new Dimension(120,21));
112 graphModeCombo.setMinimumSize(new Dimension(120,21));
113 graphModeCombo.setMaximumSize(new Dimension(120,21));
114 propertiesPanel.add(graphModeLabel, new GridBagConstraints(0,1,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
115 propertiesPanel.add(graphModeCombo, new GridBagConstraints(1,1,3,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
116
117 graphFFTLabel = new JLabel("FFT");
118 graphFFTLabel.setPreferredSize(new Dimension(50,21));
119 graphFFTLabel.setMinimumSize(new Dimension(50,21));
120 graphFFTLabel.setMaximumSize(new Dimension(50,21));
121 graphFFTCombo = new JComboBox(AcopFFTEnum.values());
122 graphFFTCombo.setPreferredSize(new Dimension(120,21));
123 graphFFTCombo.setMinimumSize(new Dimension(120,21));
124 graphFFTCombo.setMaximumSize(new Dimension(120,21));
125 propertiesPanel.add(graphFFTLabel, new GridBagConstraints(0,2,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
126 propertiesPanel.add(graphFFTCombo, new GridBagConstraints(1,2,3,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
127
128 graphColorLabel = new JLabel("Color");
129 graphColorLabel.setPreferredSize(new Dimension(50,21));
130 graphColorLabel.setMinimumSize(new Dimension(50,21));
131 graphColorLabel.setMaximumSize(new Dimension(50,21));
132 graphColorSelector = new JLabel();
133 graphColorSelector.setOpaque(true);
134 graphColorSelector.setPreferredSize(new Dimension(88,21));
135 graphColorSelector.setMinimumSize(new Dimension(88,21));
136 graphColorSelector.setMaximumSize(new Dimension(88,21));
137
138 selectedColor = ColorManager.DEFAULT_COLORS[0];
139 graphColorSelector.setBackground(selectedColor);
140 propertiesPanel.add(graphColorLabel, new GridBagConstraints(0,3,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
141 propertiesPanel.add(graphColorSelector, new GridBagConstraints(1,3,2,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
142
143 colorPicker = new JButton("...");
144 colorPicker.setPreferredSize(new Dimension(28,21));
145 colorPicker.setMinimumSize(new Dimension(28,21));
146 colorPicker.setMaximumSize(new Dimension(28,21));
147 colorPicker.addActionListener(new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 selectColor();
150 if (selectedColor != null)
151 graphColorSelector.setBackground(selectedColor);
152 }
153 });
154 propertiesPanel.add(colorPicker, new GridBagConstraints(3,3,1,1,0.1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
155
156 useDefaultColor = new JCheckBox("Automatic color");
157 useDefaultColor.addItemListener(new ItemListener() {
158 public void itemStateChanged(ItemEvent e) {
159 colorPicker.setEnabled(!useDefaultColor.isSelected());
160 graphColorSelector.setEnabled(!useDefaultColor.isSelected());
161 graphColorLabel.setEnabled(!useDefaultColor.isSelected());
162 }
163 });
164 propertiesPanel.add(useDefaultColor, new GridBagConstraints(0,4,4,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
165 useDefaultColor.setSelected(true);
166
167
168 graphWidthLabel = new JLabel("Width");
169 graphWidthLabel.setPreferredSize(new Dimension(50,21));
170 graphWidthLabel.setMinimumSize(new Dimension(50,21));
171 graphWidthLabel.setMaximumSize(new Dimension(50,21));
172 graphWidthField = new NumberField();
173 graphWidthField.setPreferredSize(new Dimension(120,21));
174 graphWidthField.setMinimumSize(new Dimension(120,21));
175 graphWidthField.setMaximumSize(new Dimension(120,21));
176 graphWidthField.setNumberType(Integer.class);
177 graphWidthField.setValue(new Integer(1));
178 propertiesPanel.add(graphWidthLabel, new GridBagConstraints(0,5,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
179 propertiesPanel.add(graphWidthField, new GridBagConstraints(1,5,3,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
180
181 trendCheckBox = new JCheckBox("Draw as trend");
182 trendCheckBox.addActionListener(new ActionListener() {
183 public void actionPerformed(ActionEvent e) {
184 if (trendCheckBox.isSelected()) {
185 setGraphMode(AcopDisplayMode.PolyLine.ordinal());
186 }
187 }
188 });
189 propertiesPanel.add(trendCheckBox, new GridBagConstraints(0,6,4,1,0.1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
190
191 trendLengthLabel = new JLabel("Trend length");
192 trendLengthLabel.setPreferredSize(new Dimension(80,21));
193 trendLengthLabel.setMinimumSize(new Dimension(80,21));
194 trendLengthLabel.setMaximumSize(new Dimension(80,21));
195
196 trendLength = new NumberField();
197 trendLength.setPreferredSize(new Dimension(90,21));
198 trendLength.setMinimumSize(new Dimension(90,21));
199 trendLength.setMaximumSize(new Dimension(90,21));
200 trendLength.setNumberType(Integer.class);
201 trendLength.setValue(new Integer(100));
202 propertiesPanel.add(trendLengthLabel, new GridBagConstraints(0,7,3,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
203 propertiesPanel.add(trendLength, new GridBagConstraints(2,7,2,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
204
205 }
206
207 return propertiesPanel;
208 }
209
210 private void selectColor() {
211 selectedColor = JColorChooser.showDialog(this, "Graph color", selectedColor);
212 }
213
214
215
216
217
218
219 public Color getColor() {
220 return useDefaultColor.isSelected() ? null : selectedColor;
221 }
222
223
224
225
226
227
228
229 public int getGraphStyle() {
230 return ((AcopDrawStyleEnum)drawStyleCombo.getSelectedItem()).ordinal();
231 }
232
233
234
235
236
237
238
239 public int getGraphMode() {
240 return ((AcopDisplayMode)graphModeCombo.getSelectedItem()).ordinal();
241 }
242
243
244
245
246
247
248
249 public int getGraphFFT() {
250 return ((AcopFFTEnum)graphFFTCombo.getSelectedItem()).ordinal();
251 }
252
253
254
255
256
257
258 public void setColor(Color color) {
259 if (color==null) {
260 color=Color.BLACK;
261 }
262 selectedColor = color;
263 graphColorSelector.setBackground(selectedColor);
264 }
265
266
267
268
269
270
271 public void setDrawStyle(int drawStyle) {
272 drawStyleCombo.setSelectedIndex(drawStyle);
273 }
274
275
276
277
278
279
280
281 public void setGraphMode(int graphMode) {
282 graphModeCombo.setSelectedIndex(graphMode);
283 }
284
285
286
287
288
289
290
291 public void setGraphFFT(int graphFFT) {
292 graphFFTCombo.setSelectedIndex(graphFFT);
293 }
294
295
296
297
298
299
300 public void setTrend(boolean isTrend) {
301 trendCheckBox.setSelected(isTrend);
302 }
303
304
305
306
307
308
309 public boolean isTrend() {
310 return trendCheckBox.isSelected();
311 }
312
313
314
315
316
317
318
319 public void setTrendLength(int length) {
320 trendLength.setValue(length);
321 }
322
323
324
325
326
327
328 public int getTrendLength() {
329 return trendLength.getValue().intValue();
330 }
331
332
333
334
335
336
337 public void setGraphWidth(int width) {
338 graphWidthField.setValue(new Integer(width));
339 }
340
341
342
343
344
345
346 public int getGraphWidth() {
347 return graphWidthField.getValue().intValue();
348 }
349
350
351
352
353
354 public void setParameters(AcopGraphParameters param) {
355 if (param == null) {
356 setColor(null);
357 setGraphFFT(0);
358 setGraphMode(0);
359 setGraphFFT(0);
360 setTrend(false);
361 setGraphWidth(1);
362 setTrendLength(100);
363 } else {
364 setColor(param.getColor());
365 setDrawStyle(param.getDrawStyle());
366 setGraphMode(param.getMode());
367 setGraphFFT(param.getFFT());
368 setTrend(param.isTrend());
369 setGraphWidth(param.getWidth());
370 setTrendLength(param.getTrendLength());
371 }
372 }
373
374 public static void main(String[] args) {
375 RunnerHelper.runComponent(new GraphCustomizerPanel(), 600,600);
376 }
377
378
379
380
381
382
383 public void toggleTrendControls(boolean enable) {
384 trendCheckBox.setVisible(enable);
385 trendLength.setVisible(enable);
386 trendLengthLabel.setVisible(enable);
387 }
388
389 }
390