1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components;
21
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.beans.Customizer;
30
31 import javax.swing.ButtonGroup;
32 import javax.swing.JButton;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JRadioButton;
36 import javax.swing.event.CaretEvent;
37 import javax.swing.event.CaretListener;
38
39 import com.cosylab.gui.components.customizer.AbstractCustomizerPanel;
40
41
42
43
44
45
46
47
48
49 public class SliderCustomizer extends AbstractCustomizerPanel {
50 private static final long serialVersionUID = 1L;
51
52
53 public static final String VALUE_DISPLAY = "Value Display";
54
55
56 public static final String VALUE_DISPLAY_ADVANCED = "Value Display/Advanced";
57
58
59 public static final String STEP_CONFIGURATION = "Step configuration";
60
61
62 public static final String AUTO_SYNCHRONIZATION = "Auto synchronization";
63
64
65 public static final String VISUAL_BASIC = "Visual";
66
67
68 public static String[] ASPECTS = {
69 VISUAL_BASIC, VALUE_DISPLAY, VALUE_DISPLAY_ADVANCED,
70 STEP_CONFIGURATION, AUTO_SYNCHRONIZATION
71 };
72
73
74 public static final String TITLE = "title";
75
76
77 public static final String TITLE_VISIBLE = "titleVisible";
78
79
80 public static final String UNITS = "units";
81
82
83 public static final String UNITS_VISIBLE = "unitsVisible";
84
85
86 @Deprecated
87 public static final String FORMAT = "format";
88
89
90 public static final String TICKS_FORMAT = "ticksFormat";
91
92
93 public static final String FIELD_FORMAT = "fieldFormat";
94
95
96 public static final String GRAPH_MAX = "maximum";
97
98
99 public static final String GRAPH_MIN = "minimum";
100
101
102 public static final String EDITABLE = "editable";
103
104
105 public static String[] VALUE_DISPLAY_PROPERTIES = {
106 GRAPH_MIN, GRAPH_MAX, UNITS, UNITS_VISIBLE, TICKS_FORMAT, FIELD_FORMAT
107 };
108
109
110 public static String[] VISUAL_BASIC_PROPERTIES = {TITLE, TITLE_VISIBLE};
111
112
113 public static String[] ADVANCED_PROPERTIES = { EDITABLE , "snapToTicks", "continuousControlVisible", "continuousModeEnabled", "continuousModeRepeatTime", "continuousModeDelayTime"};
114
115 private class WPanel extends JPanel implements Customizer
116 {
117 private static final long serialVersionUID = 1L;
118 private static final String TOOL_TIP2 = "When selected , slow step will increment/decrement on value(0-100 reprisenting procents ! )";
119 private static final String TOOL_TIP1 = "User defines own step values !";
120 private boolean initialized = false;
121 private Slider displayer;
122
123
124 private JPanel displayPanel;
125 private JLabel beforeInput;
126 private JButton resetSteps;
127
128
129 private NumberField bitInputValue;
130 private JRadioButton useAbsulutBitValue;
131 private JRadioButton useRelativeBitValue;
132
133
134 private NumberField smallInputValue;
135 private JRadioButton useAbsulutSmallValue;
136 private JRadioButton useRelativeSmallValue;
137
138
139 private NumberField largeInputValue;
140 private JRadioButton useAbsulutLargeValue;
141 private JRadioButton useRelativeLargeValue;
142
143 public WPanel(){
144 if (displayer != null){
145 initialize();
146 }
147 }
148
149 private void initialize()
150 {
151 if (initialized) {
152 return;
153 }
154
155 setLayout(new BorderLayout());
156
157 add(getDisplayPanel(), BorderLayout.CENTER);
158 updateEditor();
159 initialized = true;
160
161 setSize(300, 450);
162 }
163
164 private JPanel getDisplayPanel()
165 {
166 if (displayPanel == null) {
167 displayPanel = new JPanel();
168 }
169
170 displayPanel.setBorder(new GroupBoxBorder("Step configuration :"));
171 displayPanel.setLayout(new GridBagLayout());
172
173
174 useAbsulutBitValue = new JRadioButton(" Use absulute bit step");
175 useAbsulutBitValue.addActionListener(new ActionListener() {
176 public void actionPerformed(ActionEvent e)
177 {
178 if (useAbsulutBitValue.isSelected() == true) {
179 useRelativeBitValue.setSelected(false);
180 } else {
181 useRelativeBitValue.setSelected(true);
182 }
183 applySettings();
184 }
185 });
186 useAbsulutBitValue.setToolTipText(TOOL_TIP1);
187 useRelativeBitValue = new JRadioButton(" Use relative bit step");
188 useRelativeBitValue.addActionListener(new ActionListener() {
189 public void actionPerformed(ActionEvent e)
190 {
191 if (useRelativeBitValue.isSelected() == true) {
192 useAbsulutBitValue.setSelected(false);
193 } else {
194 useAbsulutBitValue.setSelected(true);
195 }
196 applySettings();
197 }
198 });
199 useRelativeBitValue.setToolTipText(
200 "When selected , bit step will increment/decrement on value(0-100 reprisenting procents ! )");
201 beforeInput = new JLabel("Value : ");
202
203 displayPanel.add(useAbsulutBitValue,
204 new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
205 GridBagConstraints.WEST, GridBagConstraints.NONE,
206 new Insets(4, 4, 4, 4), 0, 0));
207
208 displayPanel.add(useRelativeBitValue,
209 new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
210 GridBagConstraints.WEST, GridBagConstraints.NONE,
211 new Insets(4, 4, 4, 4), 0, 0));
212
213 displayPanel.add(beforeInput,
214 new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
215 GridBagConstraints.WEST, GridBagConstraints.NONE,
216 new Insets(4, 4, 4, 4), 0, 0));
217
218 displayPanel.add(getBitField(),
219 new GridBagConstraints(0, 2, 1, 1, 4.0, 1.0,
220 GridBagConstraints.WEST, GridBagConstraints.NONE,
221 new Insets(4, 50, 4, 4), 0, 0));
222
223
224 useAbsulutSmallValue = new JRadioButton(" Use absulute small step ");
225 useAbsulutSmallValue.addActionListener(new ActionListener() {
226 public void actionPerformed(ActionEvent e)
227 {
228 if (useAbsulutSmallValue.isSelected() == true) {
229 useRelativeSmallValue.setSelected(false);
230 } else {
231 useRelativeSmallValue.setSelected(true);
232 }
233 applySettings();
234 }
235 });
236 useAbsulutSmallValue.setToolTipText(TOOL_TIP1);
237 useRelativeSmallValue = new JRadioButton(" Use relative small step");
238 useRelativeSmallValue.addActionListener(new ActionListener() {
239 public void actionPerformed(ActionEvent e)
240 {
241 if (useRelativeSmallValue.isSelected() == true) {
242 useAbsulutSmallValue.setSelected(false);
243 } else {
244 useAbsulutSmallValue.setSelected(true);
245 }
246 applySettings();
247 }
248 });
249 useRelativeSmallValue.setToolTipText(TOOL_TIP2);
250
251 displayPanel.add(useAbsulutSmallValue,
252 new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
253 GridBagConstraints.WEST, GridBagConstraints.NONE,
254 new Insets(4, 4, 4, 4), 0, 0));
255
256 displayPanel.add(useRelativeSmallValue,
257 new GridBagConstraints(0, 5, 1, 1, 1.0, 1.0,
258 GridBagConstraints.WEST, GridBagConstraints.NONE,
259 new Insets(4, 4, 4, 4), 0, 0));
260
261 displayPanel.add(beforeInput,
262 new GridBagConstraints(0, 6, 1, 1, 1.0, 1.0,
263 GridBagConstraints.WEST, GridBagConstraints.NONE,
264 new Insets(4, 4, 4, 4), 0, 0));
265
266 displayPanel.add(getSmallField(),
267 new GridBagConstraints(0, 6, 1, 1, 4.0, 1.0,
268 GridBagConstraints.WEST, GridBagConstraints.NONE,
269 new Insets(4, 50, 4, 4), 0, 0));
270
271
272 useAbsulutLargeValue = new JRadioButton(" Use absulute fast step");
273 useAbsulutLargeValue.addActionListener(new ActionListener() {
274 public void actionPerformed(ActionEvent e)
275 {
276 if (useAbsulutLargeValue.isSelected() == true) {
277 useRelativeLargeValue.setSelected(false);
278 } else {
279 useRelativeLargeValue.setSelected(true);
280 }
281 applySettings();
282 }
283 });
284 useAbsulutLargeValue.setToolTipText(TOOL_TIP1);
285 useRelativeLargeValue = new JRadioButton(" Use relative fast step");
286 useRelativeLargeValue.addActionListener(new ActionListener() {
287 public void actionPerformed(ActionEvent e)
288 {
289 if (useRelativeLargeValue.isSelected() == true) {
290 useAbsulutLargeValue.setSelected(false);
291 } else {
292 useAbsulutLargeValue.setSelected(true);
293 }
294 applySettings();
295 }
296 });
297 useRelativeLargeValue.setToolTipText(
298 "When selected , fast step will increment/decrement on value(0-100 reprisenting procents ! )");
299
300 displayPanel.add(useAbsulutLargeValue,
301 new GridBagConstraints(0, 7, 1, 1, 1.0, 1.0,
302 GridBagConstraints.WEST, GridBagConstraints.NONE,
303 new Insets(4, 4, 4, 4), 0, 0));
304
305 displayPanel.add(useRelativeLargeValue,
306 new GridBagConstraints(0, 8, 1, 1, 1.0, 1.0,
307 GridBagConstraints.WEST, GridBagConstraints.NONE,
308 new Insets(4, 4, 4, 4), 0, 0));
309
310 displayPanel.add(beforeInput,
311 new GridBagConstraints(0, 9, 1, 1, 1.0, 1.0,
312 GridBagConstraints.WEST, GridBagConstraints.NONE,
313 new Insets(4, 4, 4, 4), 0, 0));
314
315 displayPanel.add(getLargeField(),
316 new GridBagConstraints(0, 9, 1, 1, 4.0, 1.0,
317 GridBagConstraints.WEST, GridBagConstraints.NONE,
318 new Insets(4, 50, 4, 4), 0, 0));
319
320
321 resetSteps = new JButton("RESET STEPS");
322 resetSteps.setToolTipText("Resets all steps to default value...");
323 resetSteps.addActionListener(new ActionListener() {
324 public void actionPerformed(ActionEvent e)
325 {
326 displayer.resetSteps();
327 updateEditor();
328 }
329 });
330 displayPanel.add(resetSteps,
331 new GridBagConstraints(0, 12, 1, 1, 4.0, 1.0,
332 GridBagConstraints.WEST, GridBagConstraints.NONE,
333 new Insets(4, 50, 4, 4), 0, 0));
334
335
336 bitInputValue.addCaretListener(new CaretListener(){
337 public void caretUpdate(CaretEvent e) {
338 applySettings();
339 }
340 });
341 smallInputValue.addCaretListener(new CaretListener(){
342 public void caretUpdate(CaretEvent e) {
343 applySettings();
344 }
345 });
346 largeInputValue.addCaretListener(new CaretListener(){
347 public void caretUpdate(CaretEvent e) {
348 applySettings();
349 }
350 });
351
352 return displayPanel;
353 }
354
355 private void updateEditor()
356 {
357 if (displayer == null) return;
358 double oldValue = bitInputValue.getDoubleValue();
359 bitInputValue.setValue(new Double(displayer.getBitStep()));
360 useAbsulutBitValue.setSelected(!displayer.isBitStepRelative());
361 useRelativeBitValue.setSelected(displayer.isBitStepRelative());
362 boolean bitStepRelative = useAbsulutBitValue.isSelected();
363 firePropertyChange("bitStepRelative", !bitStepRelative, bitStepRelative);
364 firePropertyChange("bitStep", oldValue, bitInputValue.getDoubleValue());
365
366 oldValue = smallInputValue.getDoubleValue();
367 smallInputValue.setValue(new Double(displayer.getSmallStep()));
368 useAbsulutSmallValue.setSelected(!displayer.isSmallStepRelative());
369 useRelativeSmallValue.setSelected(displayer.isSmallStepRelative());
370 boolean smallStepRelative = useRelativeSmallValue.isSelected();
371 firePropertyChange("smallStepRelative", !smallStepRelative, smallStepRelative);
372 firePropertyChange("smallStep", oldValue, smallInputValue.getDoubleValue());
373
374 oldValue = largeInputValue.getDoubleValue();
375 largeInputValue.setValue(new Double(displayer.getLargeStep()));
376 useAbsulutLargeValue.setSelected(!displayer.isLargeStepRelative());
377 useRelativeLargeValue.setSelected(displayer.isLargeStepRelative());
378 boolean largeStepRelative = useRelativeLargeValue.isSelected();
379 firePropertyChange("largeStepRelative", !largeStepRelative, largeStepRelative);
380 firePropertyChange("largeStep", oldValue, largeInputValue.getDoubleValue());
381 }
382
383 private NumberField getBitField()
384 {
385 if (bitInputValue == null) {
386 bitInputValue = new NumberField();
387 bitInputValue.setNumberType(Double.class);
388 bitInputValue.setPreferredSize(new Dimension(100, 20));
389 bitInputValue.setToolTipText("Bit step");
390
391 if (displayer == null){
392 System.out.println("displayer = null");
393 }else bitInputValue.setValue(new Double(displayer.getBitStep()));
394 }
395
396 return bitInputValue;
397 }
398
399 private NumberField getSmallField()
400 {
401 if (smallInputValue == null) {
402 smallInputValue = new NumberField();
403 smallInputValue.setNumberType(Double.class);
404 smallInputValue.setPreferredSize(new Dimension(100, 20));
405 smallInputValue.setToolTipText("Slow step");
406 if (displayer != null) smallInputValue.setValue(new Double(displayer.getSmallStep()));
407
408 }
409
410 return smallInputValue;
411 }
412
413 private NumberField getLargeField()
414 {
415 if (largeInputValue == null) {
416 largeInputValue = new NumberField();
417 largeInputValue.setNumberType(Double.class);
418 largeInputValue.setPreferredSize(new Dimension(100, 20));
419 largeInputValue.setToolTipText("Fast step");
420 if (displayer != null) largeInputValue.setValue(new Double(displayer.getLargeStep()));
421
422 }
423
424 return largeInputValue;
425 }
426
427
428
429
430
431
432 public void applySettings()
433 {
434
435
436
437 boolean bitStepRelative = useRelativeBitValue.isSelected();
438 displayer.setBitStepRelative(bitStepRelative);
439 firePropertyChange("bitStepRelative", !bitStepRelative, bitStepRelative);
440
441 double oldValue = displayer.getBitStep();
442 displayer.setBitStep(bitInputValue.getDoubleValue());
443 firePropertyChange("bitStep", oldValue, bitInputValue.getDoubleValue());
444
445 boolean smallStepRelative = useRelativeSmallValue.isSelected();
446 displayer.setSmallStepRelative(smallStepRelative);
447 firePropertyChange("smallStepRelative", !smallStepRelative, smallStepRelative);
448
449 oldValue = displayer.getSmallStep();
450 displayer.setSmallStep(smallInputValue.getDoubleValue());
451 firePropertyChange("smallStep", oldValue, smallInputValue.getDoubleValue());
452
453 boolean largeStepRelative = useRelativeLargeValue.isSelected();
454 displayer.setLargeStepRelative(largeStepRelative);
455 firePropertyChange("largeStepRelative", !largeStepRelative, largeStepRelative);
456
457 oldValue = displayer.getLargeStep();
458 displayer.setLargeStep(largeInputValue.getDoubleValue());
459 firePropertyChange("largeStep", oldValue, largeInputValue.getDoubleValue());
460 updateEditor();
461 }
462
463 public void setObject(Object arg0) {
464 displayer = (Slider) arg0;
465 initialize();
466 }
467 }
468
469
470
471
472
473
474
475
476
477
478 private class SyncPanel extends JPanel implements Customizer {
479 private static final long serialVersionUID = 1L;
480 private Slider displayer;
481 private boolean initialized = false;
482 private JPanel displayPanel;
483 private NumberField autoSyncDelay;
484 private JLabel millis;
485 private JLabel syncDelay;
486 private JRadioButton syncManual;
487 private JRadioButton syncAuto;
488
489 public SyncPanel(){
490 if (displayer != null){
491 initialize();
492 }
493 }
494
495 private void initialize()
496 {
497 if (initialized) {
498 return;
499 }
500
501 setLayout(new BorderLayout());
502
503 add(getDisplayPanel(), BorderLayout.CENTER);
504 updateEditor();
505 initialized = true;
506
507 setSize(300, 450);
508 }
509
510 private void updateEditor() {
511 syncAuto.setSelected(displayer.isAutoSynchronize());
512 syncManual.setSelected(!displayer.isAutoSynchronize());
513 autoSyncDelay.setLongValue(displayer.getAutoSynchronizeDelay());
514 autoSyncDelay.setEnabled(displayer.isAutoSynchronize());
515 }
516
517 private JPanel getDisplayPanel() {
518 if (displayPanel == null) {
519 displayPanel = new JPanel();
520 }
521 displayPanel.setBorder(new GroupBoxBorder("Synchronization configuration :"));
522 displayPanel.setLayout(new GridBagLayout());
523
524 syncManual = new JRadioButton("Manual synchronization");
525 syncManual.addActionListener(new ActionListener() {
526
527 public void actionPerformed(ActionEvent e) {
528 autoSyncDelay.setEnabled(false);
529 applySettings();
530 }
531
532
533 });
534 syncAuto = new JRadioButton("Automatic synchronization");
535 syncAuto.addActionListener(new ActionListener() {
536
537 public void actionPerformed(ActionEvent e) {
538 autoSyncDelay.setEnabled(true);
539 applySettings();
540 }
541
542
543 });
544 ButtonGroup syncModeButtonGroup = new ButtonGroup();
545 syncModeButtonGroup.add(syncManual);
546 syncModeButtonGroup.add(syncAuto);
547
548 displayPanel.add(syncManual, new GridBagConstraints(0,0,1,1,1,1,
549 GridBagConstraints.WEST, GridBagConstraints.NONE,
550 new Insets(0,0,0,0), 1,1));
551 displayPanel.add(syncAuto, new GridBagConstraints(0,1,1,1,1,1,
552 GridBagConstraints.WEST, GridBagConstraints.NONE,
553 new Insets(0,0,0,0), 1,1));
554
555 syncDelay = new JLabel("Automatic synchronization delay:");
556 displayPanel.add(syncDelay, new GridBagConstraints(0,2,1,1,1,1,
557 GridBagConstraints.WEST, GridBagConstraints.NONE,
558 new Insets(0,21,0,0), 1,1));
559
560 JPanel fieldPanel = new JPanel();
561 fieldPanel.setLayout(new GridBagLayout());
562 autoSyncDelay = new NumberField();
563 autoSyncDelay.setNumberType(long.class);
564 autoSyncDelay.addCaretListener(new CaretListener(){
565
566 public void caretUpdate(CaretEvent e) {
567 applySettings();
568 }
569
570 });
571 autoSyncDelay.setPreferredSize(new Dimension(70, 20));
572 fieldPanel.add(autoSyncDelay, new GridBagConstraints(0,0,1,1,1,1,
573 GridBagConstraints.WEST, GridBagConstraints.NONE,
574 new Insets(0,0,0,0), 1,1));
575
576 millis = new JLabel("milliseconds");
577 fieldPanel.add(millis, new GridBagConstraints(1,0,1,1,1,1,
578 GridBagConstraints.WEST, GridBagConstraints.NONE,
579 new Insets(0,10,0,0), 1,1));
580
581 displayPanel.add(fieldPanel, new GridBagConstraints(0,3,1,1,1,1,
582 GridBagConstraints.WEST, GridBagConstraints.NONE,
583 new Insets(5,21,0,0), 1,1));
584 return displayPanel;
585 }
586
587
588 public void applySettings() {
589 boolean auto = syncAuto.isSelected();
590 displayer.setAutoSynchronize(auto);
591 if (syncAuto.isSelected()) {
592 displayer.setAutoSynchronizeDelay(autoSyncDelay.getLongValue());
593 firePropertyChange("autoSynchronizeDelay", -1, autoSyncDelay.getLongValue());
594 }
595 firePropertyChange("autoSynchronize", !auto, auto);
596
597 }
598
599 public void setObject(Object arg0) {
600 displayer = (Slider) arg0;
601 initialize();
602 }
603
604 }
605
606 public SliderCustomizer() {
607 super();
608 addCustomizerTable(VALUE_DISPLAY_ADVANCED,ADVANCED_PROPERTIES);
609 addCustomizerTable(VALUE_DISPLAY, VALUE_DISPLAY_PROPERTIES);
610 addCustomizerTable(VISUAL_BASIC,VISUAL_BASIC_PROPERTIES);
611 addCustomizer(STEP_CONFIGURATION, new WPanel());
612 addCustomizer(AUTO_SYNCHRONIZATION, new SyncPanel());
613 setSize(452, 399);
614 }
615 }