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 import javax.swing.ButtonGroup;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.JRadioButton;
34 import javax.swing.event.CaretEvent;
35 import javax.swing.event.CaretListener;
36
37 import com.cosylab.gui.components.customizer.AbstractCustomizerPanel;
38
39
40
41
42
43
44
45
46
47 public class DialKnobCustomizer extends AbstractCustomizerPanel {
48 private static final long serialVersionUID = 1L;
49
50
51 public static final String VISUAL_BASIC = "Visual";
52
53
54 public static final String VALUE_DISPLAY = "Value Display";
55
56
57 public static final String AUTO_SYNCHRONIZATION = "Auto synchronization";
58
59
60 public static final String VALUE_POLICY = "Value Display/Value Range Policy";
61
62
63 public static final String VALUE_DISPLAY_ADVANCED = "Value Display/Advanced";
64
65
66 public static String[] ASPECTS = {
67 VISUAL_BASIC, VALUE_DISPLAY, VALUE_DISPLAY_ADVANCED, VALUE_POLICY
68 };
69
70
71 public static final String TITLE_VISIBLE = "titleVisible";
72
73
74 public static final String TITLE = "title";
75
76
77 public static final String UNITS = "units";
78
79
80 public static final String UNITS_VISIBLE = "unitsVisible";
81
82
83 public static final String FORMAT = "format";
84
85
86 public static final String GRAPH_MAX = "graphMax";
87
88
89 public static final String GRAPH_MIN = "graphMin";
90
91
92 public static final String MAXIMUM = "maximum";
93
94
95 public static final String MINIMUM = "minimum";
96
97
98 public static final String EDITABLE = "editable";
99
100
101 public static final String RESIZABLE = "resizable";
102
103
104 public static final String ENHANCED = "enhanced";
105
106
107 public static final String TILTING_ENABLED = "tiltingEnabled";
108
109
110 public static String[] VALUE_DISPLAY_PROPERTIES = {
111 MINIMUM, MAXIMUM, UNITS, UNITS_VISIBLE, FORMAT
112 };
113
114
115 public static String[] VISUAL_BASIC_PROPERTIES = {
116 TITLE, TITLE_VISIBLE, RESIZABLE, ENHANCED, TILTING_ENABLED
117 };
118
119
120 public static String[] ADVANCED_PROPERTIES = { EDITABLE };
121
122
123
124
125
126
127
128
129
130
131 private class SyncPanel extends JPanel implements Customizer {
132 private static final long serialVersionUID = 1L;
133 private DialKnob displayer;
134 private boolean initialized = false;
135 private JPanel displayPanel;
136 private NumberField autoSyncDelay;
137 private JLabel millis;
138 private JLabel syncDelay;
139 private JRadioButton syncManual;
140 private JRadioButton syncAuto;
141
142 public SyncPanel(){
143 if (displayer != null){
144 initialize();
145 }
146 }
147
148 private void initialize()
149 {
150 if (initialized) {
151 return;
152 }
153
154 setLayout(new BorderLayout());
155
156 add(getDisplayPanel(), BorderLayout.CENTER);
157 updateEditor();
158 initialized = true;
159
160 setSize(300, 450);
161 }
162
163 private void updateEditor() {
164 syncAuto.setSelected(displayer.isAutoSynchronize());
165 syncManual.setSelected(!displayer.isAutoSynchronize());
166 autoSyncDelay.setLongValue(displayer.getAutoSynchronizeDelay());
167 autoSyncDelay.setEnabled(displayer.isAutoSynchronize());
168 }
169
170 private JPanel getDisplayPanel() {
171 if (displayPanel == null) {
172 displayPanel = new JPanel();
173 }
174 displayPanel.setBorder(new GroupBoxBorder("Synchronization configuration :"));
175 displayPanel.setLayout(new GridBagLayout());
176
177 syncManual = new JRadioButton("Manual synchronization");
178 syncManual.addActionListener(new ActionListener() {
179
180 public void actionPerformed(ActionEvent e) {
181 autoSyncDelay.setEnabled(false);
182 applySettings();
183 }
184
185
186 });
187 syncAuto = new JRadioButton("Automatic synchronization");
188 syncAuto.addActionListener(new ActionListener() {
189
190 public void actionPerformed(ActionEvent e) {
191 autoSyncDelay.setEnabled(true);
192 applySettings();
193 }
194
195
196 });
197 ButtonGroup syncModeButtonGroup = new ButtonGroup();
198 syncModeButtonGroup.add(syncManual);
199 syncModeButtonGroup.add(syncAuto);
200
201 displayPanel.add(syncManual, new GridBagConstraints(0,0,1,1,1,1,
202 GridBagConstraints.WEST, GridBagConstraints.NONE,
203 new Insets(0,0,0,0), 1,1));
204 displayPanel.add(syncAuto, new GridBagConstraints(0,1,1,1,1,1,
205 GridBagConstraints.WEST, GridBagConstraints.NONE,
206 new Insets(0,0,0,0), 1,1));
207
208 syncDelay = new JLabel("Automatic synchronization delay:");
209 displayPanel.add(syncDelay, new GridBagConstraints(0,2,1,1,1,1,
210 GridBagConstraints.WEST, GridBagConstraints.NONE,
211 new Insets(0,21,0,0), 1,1));
212
213 JPanel fieldPanel = new JPanel();
214 fieldPanel.setLayout(new GridBagLayout());
215 autoSyncDelay = new NumberField();
216 autoSyncDelay.setNumberType(long.class);
217 autoSyncDelay.addCaretListener(new CaretListener(){
218
219 public void caretUpdate(CaretEvent e) {
220 applySettings();
221 }
222
223 });
224 autoSyncDelay.setPreferredSize(new Dimension(70, 20));
225 fieldPanel.add(autoSyncDelay, new GridBagConstraints(0,0,1,1,1,1,
226 GridBagConstraints.WEST, GridBagConstraints.NONE,
227 new Insets(0,0,0,0), 1,1));
228
229 millis = new JLabel("milliseconds");
230 fieldPanel.add(millis, new GridBagConstraints(1,0,1,1,1,1,
231 GridBagConstraints.WEST, GridBagConstraints.NONE,
232 new Insets(0,10,0,0), 1,1));
233
234 displayPanel.add(fieldPanel, new GridBagConstraints(0,3,1,1,1,1,
235 GridBagConstraints.WEST, GridBagConstraints.NONE,
236 new Insets(5,21,0,0), 1,1));
237 return displayPanel;
238 }
239
240 public void applySettings() {
241 boolean auto = syncAuto.isSelected();
242 displayer.setAutoSynchronize(auto);
243 if (syncAuto.isSelected()) {
244 displayer.setAutoSynchronizeDelay(autoSyncDelay.getLongValue());
245 firePropertyChange("autoSynchronizeDelay", -1, autoSyncDelay.getLongValue());
246 }
247 firePropertyChange("autoSynchronize", !auto, auto);
248
249 }
250
251 public void setObject(Object arg0) {
252 displayer = (DialKnob) arg0;
253 initialize();
254 }
255
256 }
257
258 public DialKnobCustomizer() {
259 addCustomizerTable(VISUAL_BASIC, VISUAL_BASIC_PROPERTIES);
260 addCustomizerTable(VALUE_DISPLAY, VALUE_DISPLAY_PROPERTIES);
261 addCustomizerTable(VALUE_DISPLAY_ADVANCED, ADVANCED_PROPERTIES);
262 addCustomizer(VALUE_POLICY, new ValuePolicyCustomizer());
263 addCustomizer(AUTO_SYNCHRONIZATION, new SyncPanel());
264 setSize(423, 184);
265 }
266
267 }