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.slider;
21
22 import java.awt.Color;
23 import java.awt.Font;
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
30 import javax.swing.JButton;
31 import javax.swing.JCheckBox;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.SwingConstants;
35
36 import com.cosylab.gui.components.ResizableTextLabel;
37 import com.cosylab.gui.components.Slider;
38 import com.cosylab.gui.components.util.ColorHelper;
39
40
41
42
43
44
45
46
47 public class InfoBar extends JPanel {
48
49 private static final long serialVersionUID = 1L;
50
51 private ResizableTextLabel deviceName;
52
53 private JButton sync;
54 private JButton set;
55 private JButton store;
56 private JButton restore;
57
58 private Slider slider;
59
60 private JLabel stored;
61 private JCheckBox continuousMode;
62
63 private boolean storedValueLabelVisible = true;
64
65
66
67
68
69
70 public InfoBar(Slider slider) {
71 super();
72 this.slider = slider;
73 initialize();
74 }
75
76 private void initialize() {
77 setLayout(new GridBagLayout());
78 setOpaque(false);
79
80 add(getTitleComponent(), new GridBagConstraints(0, 0, 1, 1, 1, 0,
81 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
82 new Insets(0, 4, 0, 0), 0, 0));
83
84 add(getSetButton(), new GridBagConstraints(1, 0, 1, 1, 0, 0,
85 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
86 0, 1, 0, 0), 0, 0));
87 getSetButton().setVisible(false);
88
89 add(getContinuousMode(), new GridBagConstraints(2, 0, 1, 1, 1, 0,
90 GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,
91 4, 0, 4), 0, 0));
92 add(getStoreButton(), new GridBagConstraints(3, 0, 1, 1, 0, 0,
93 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
94 0, 1, 0, 0), 0, 0));
95 add(getStoredValueLabel(), new GridBagConstraints(4, 0, 1, 1, 0, 0,
96 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
97 0, 4, 0, 3), 0, 0));
98 add(getRestoreButton(), new GridBagConstraints(5, 0, 1, 1, 0, 0,
99 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
100 0, 1, 0, 0), 0, 0));
101
102 add(getSyncButton(), new GridBagConstraints(6, 0, 1, 1, 0, 0,
103 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
104 1, 0, 4), 0, 0));
105 }
106
107 private ResizableTextLabel getTitleComponent() {
108 if (deviceName == null) {
109 deviceName = new ResizableTextLabel("");
110 deviceName.setOpaque(false);
111 deviceName.setResizable(false);
112 deviceName.setHorizontalAlignment(SwingConstants.LEFT);
113 }
114
115 return deviceName;
116 }
117
118 private JButton getSyncButton() {
119 if (sync == null) {
120 sync = new JButton("Sync");
121 sync.setMargin(new Insets(0, 1, 0, 1));
122 sync.setFont(new Font(sync.getFont().getName(), Font.PLAIN, 9));
123 sync.setOpaque(true);
124 sync.setBackground(ColorHelper.getCosyControl());
125 sync.addActionListener(new ActionListener() {
126 public void actionPerformed(ActionEvent e) {
127 slider.synchronize();
128 }
129 });
130 sync.setToolTipText("Synchronize Value with Readback");
131 }
132
133 return sync;
134 }
135
136 private JButton getStoreButton() {
137 if (store == null) {
138 store = new JButton("Store");
139 store.setMargin(new Insets(0, 1, 0, 1));
140 store.setFont(new Font(store.getFont().getName(), Font.PLAIN, 9));
141 store.setOpaque(true);
142 store.setBackground(ColorHelper.getCosyControl());
143 store.addActionListener(new ActionListener() {
144 public void actionPerformed(ActionEvent e) {
145 slider.storeValue();
146 }
147 });
148 store.setToolTipText("Store Current Readback Value");
149
150 }
151
152 return store;
153 }
154
155 private JButton getRestoreButton() {
156 if (restore == null) {
157 restore = new JButton("Restore");
158 restore.setMargin(new Insets(0, 1, 0, 1));
159 restore.setFont(new Font(restore.getFont().getName(),Font.PLAIN,9));
160 restore.setOpaque(true);
161 restore.setBackground(ColorHelper.getCosyControl());
162 restore.addActionListener(new ActionListener() {
163 public void actionPerformed(ActionEvent e) {
164 slider.restoreValue();
165 }
166 });
167 restore.setToolTipText("Set value to: <no value>");
168
169 }
170
171 return restore;
172 }
173
174 private JLabel getStoredValueLabel() {
175 if (stored == null) {
176 stored = new JLabel("<no value>");
177 stored.setFont(new Font(stored.getFont().getName(), Font.PLAIN,12));
178 stored.setOpaque(true);
179
180 stored.setToolTipText("<no value>");
181 }
182
183 return stored;
184 }
185
186 private JButton getSetButton() {
187 if (set == null) {
188 set = new JButton("Set");
189 set.setMargin(new Insets(0, 1, 0, 1));
190 set.setFont(new Font(set.getFont().getName(), Font.PLAIN, 9));
191 set.setOpaque(true);
192 set.setBackground(ColorHelper.getCosyControl());
193 set.addActionListener(new ActionListener() {
194 public void actionPerformed(ActionEvent e) {
195 slider.setManual();
196 }
197 });
198 set.setToolTipText("Set Value");
199 }
200
201 return set;
202 }
203
204
205
206
207
208
209 public void setSetButtonVisible(boolean visible) {
210 getSetButton().setVisible(visible);
211 }
212
213
214
215
216
217
218 @Override
219 public void setBackground(Color bg) {
220 super.setBackground(bg);
221 getSyncButton().setBackground(bg);
222 getStoreButton().setBackground(bg);
223 getRestoreButton().setBackground(bg);
224 getSetButton().setBackground(bg);
225 getTitleComponent().setBackground(bg);
226 getStoredValueLabel().setBackground(bg);
227 getContinuousMode().setBackground(bg);
228 }
229
230
231
232
233
234
235 @Override
236 public void setForeground(Color fg) {
237 super.setForeground(fg);
238 getSyncButton().setForeground(fg);
239 getStoreButton().setForeground(fg);
240 getSetButton().setForeground(fg);
241 getRestoreButton().setForeground(fg);
242 getTitleComponent().setForeground(fg);
243 getStoredValueLabel().setForeground(fg);
244 getContinuousMode().setForeground(fg);
245 }
246
247
248
249
250
251
252
253 public void setTitle(String title) {
254 getTitleComponent().setText(title);
255 }
256
257
258
259
260
261
262 public String getTitle() {
263 return getTitleComponent().getText();
264 }
265
266
267
268
269
270
271 public void setFont(Font font) {
272 super.setFont(font);
273 getTitleComponent().setFont(font);
274 }
275
276
277
278
279
280
281 public Font getFont() {
282 return getTitleComponent().getFont();
283 }
284
285
286
287
288
289
290 @Override
291 public void setEnabled(boolean enabled) {
292 super.setEnabled(enabled);
293 getSyncButton().setEnabled(enabled);
294 getSetButton().setEnabled(enabled);
295 getContinuousMode().setEnabled(enabled);
296 getRestoreButton().setEnabled(enabled);
297 getStoreButton().setEnabled(enabled);
298 getStoredValueLabel().setEnabled(enabled);
299 }
300
301
302
303
304
305
306 public void setStoredValue(String value) {
307 if (value == null) {
308 getRestoreButton().setToolTipText("Set value to: <no value>");
309 getStoredValueLabel().setText("<no value>");
310 getStoredValueLabel().setToolTipText("<no value>");
311 } else {
312 getRestoreButton().setToolTipText("Set value to: " + value);
313 getStoredValueLabel().setText(value);
314 getStoredValueLabel().setToolTipText(value);
315 }
316 }
317
318
319
320
321
322
323 public void setRestoreButtonTitle(String title) {
324 getRestoreButton().setText(title);
325 }
326
327
328
329
330
331
332 public String getRestoreButtonTitle() {
333 return getRestoreButton().getText();
334 }
335
336
337
338
339
340
341
342
343
344 public void setStorageButtonsVisible(boolean visible) {
345 getStoreButton().setVisible(visible);
346 getRestoreButton().setVisible(visible);
347 getStoredValueLabel().setVisible(
348 storedValueLabelVisible && getStoreButton().isVisible());
349 }
350
351
352
353
354
355
356
357
358
359 public void setStoredValueLabelVisible(boolean visible) {
360 storedValueLabelVisible = visible;
361 getStoredValueLabel().setVisible(
362 storedValueLabelVisible && getStoreButton().isVisible());
363 }
364
365
366
367
368
369
370
371 public boolean isStorageButtonsVisible() {
372 return getStoreButton().isVisible();
373 }
374
375
376
377
378
379
380
381
382
383 public void setSyncButtonVisible(boolean visible) {
384 getSyncButton().setVisible(visible);
385 }
386
387
388
389
390
391
392
393 public boolean isSyncButtonVisible() {
394 return getSyncButton().isVisible();
395 }
396
397
398
399
400
401
402 public boolean isStoredValueLabelVisible() {
403 return storedValueLabelVisible;
404 }
405
406
407
408
409
410
411 private JCheckBox getContinuousMode() {
412 if (continuousMode == null) {
413 continuousMode = new JCheckBox("Continuous");
414 continuousMode.setFont(new Font(continuousMode.getFont().getName(),Font.PLAIN, 9));
415 continuousMode.setOpaque(false);
416 continuousMode.addActionListener(new ActionListener() {
417 public void actionPerformed(ActionEvent ae) {
418 if(continuousMode.isSelected()){
419 slider.setContinuousModeEnabled(true);
420 } else {
421 slider.setContinuousModeEnabled(false);
422 }
423 }
424 });
425 }
426 return continuousMode;
427 }
428
429
430
431
432
433
434
435
436 public void setContinuousMode(boolean b) {
437 if (b!=getContinuousMode().isSelected()) {
438 getContinuousMode().setSelected(b);
439 }
440 }
441
442
443
444
445
446
447 public void setContinuousModeVisible(boolean b) {
448 if (b!=getContinuousMode().isVisible()) {
449 getContinuousMode().setVisible(b);
450 }
451 }
452
453
454
455
456
457
458 public boolean isContinuousMode() {
459 return getContinuousMode().isSelected();
460 }
461
462
463
464
465
466
467 public boolean isContinuousModeVisible() {
468 return getContinuousMode().isVisible();
469 }
470
471 }
472
473