-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFMGSKAL_AppController.java
More file actions
656 lines (467 loc) · 21.3 KB
/
Copy pathFMGSKAL_AppController.java
File metadata and controls
656 lines (467 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
package de.gs.aco.playground.FMGSKAL.main;
import java.rmi.RemoteException;
// import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import de.gsi.sequencer.sequences.superfrs.CalibrateAllHallProbes;
import de.gsi.sequencer.sequences.superfrs.HallProbeCalibrationCycle;
import de.gsi.sequencer.sequences.superfrs.PrecycleAllFrsMagnets;
// import de.gsi.sequencer.sequences.superfrs.*;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class FMGSKAL_AppController {
@FXML
Button hpCal_bt;
@FXML
Button cycling_bt;
@FXML
Button about_bt;
@FXML
Button switchBL_bt;
@FXML
Button exitl_bt;
@FXML
CheckBox taToS1_cb;
@FXML
CheckBox s1ToS2_cb;
@FXML
CheckBox s2ToS3_cb;
@FXML
CheckBox s3ToS4_cb;
@FXML
CheckBox s3ToS5_cb;
@FXML
CheckBox s5ToS6_cb;
@FXML
CheckBox s5ToS7_cb;
@FXML
CheckBox s7ToS8_cb;
@FXML
CheckBox s6ToESR_cb;
@FXML
CheckBox onlyDipoles_cb;
@FXML
Label status_lb;
// The static list of devices per Accelerator sections
private static final String[] taToS1_dv = new String[] { "GTS2QT11", "GTS2QT12", "GTS2QT13", "GTS3MU1", "GTS3QD11",
"GTS3QD11" };
private static final String[] s1ToS2_dv = new String[] { "GTS3QD21", "GTS3QD22", "GTS3MU2", "GTS3QT31", "GTS3QT32",
"GTS3QT33" };
private static final String[] s2ToS3_dv = new String[] { "GTS4QT11", "GTS4QT12", "GTS4QT13", "GTS4MU1", "GTS4QD21",
" GTS4QD22" };
private static final String[] s3ToS4_dv = new String[] { "GTS4QD31", "GTS4QD32", "GHFSMU1", "GHFSQT11", "GHFSQT12",
"GHFSQT13" };
private static final String[] s3ToS5_dv = new String[] { "GTS4QD31", "GTS4QD32", "GHFSMU1", "GTS5MU1" };
private static final String[] s5ToS6_dv = new String[] { "GTS5QT11", "GTS5QT12", "GTS5QT13", "GTS6MU1", "GTE5QD11",
"GTE5QD12" };
private static final String[] s5ToS7_dv = new String[] { "GTS5QT11", "GTS5QT12", "GTS5QT13", "GTS6MU1" };
private static final String[] s7ToS8_dv = new String[] { "GTS7QD11", "GTS7QD12", "GTS7MU1", "GTH4QD11",
"GTH4QD12" };
private static final String[] s6ToESR_dv = new String[] { "GTE5MU0", "GTE5QD21", "GTE5QD22" };
// List of CheckBox
// List of String[]
private static final List<String[]> stringList = new ArrayList<>();
private static final List<CheckBox> checkBoxList = new ArrayList<>();
// The list of devices to be injected to the Sequencer
private final List<String> magnetList = new ArrayList<>();
private final List<String> magnetListFiltered = new ArrayList<>();
private String final_status;
// private BooleanProperty operation_performed = new SimpleBooleanProperty(false);
private final IntegerProperty process_started = new SimpleIntegerProperty(0);
// You can choose a logger (needed imports are given in the import section as comments):
// for libraries:
// private static final Logger LOGGER = LoggerFactory.getLogger(FMGSKAL_AppController.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
@FXML
public void initialize() {
status_lb.setText("");
// final BooleanBinding process_started_binding = operation_performed.not().not();
final BooleanBinding process_started_binding = process_started.isEqualTo(1);
hpCal_bt.disableProperty().bind(process_started_binding);
cycling_bt.disableProperty().bind(process_started_binding);
switchBL_bt.disableProperty().bind(process_started_binding);
// ((Property<Boolean>) switchBL_bt.disabledProperty()).bind(process_started_binding);
stringList.add(taToS1_dv);
stringList.add(s1ToS2_dv);
stringList.add(s2ToS3_dv);
stringList.add(s3ToS4_dv);
stringList.add(s3ToS5_dv);
stringList.add(s5ToS6_dv);
stringList.add(s5ToS7_dv);
stringList.add(s7ToS8_dv);
stringList.add(s6ToESR_dv);
checkBoxList.add(taToS1_cb);
checkBoxList.add(s1ToS2_cb);
checkBoxList.add(s2ToS3_cb);
checkBoxList.add(s3ToS4_cb);
checkBoxList.add(s3ToS5_cb);
checkBoxList.add(s5ToS6_cb);
checkBoxList.add(s5ToS7_cb);
checkBoxList.add(s7ToS8_cb);
checkBoxList.add(s6ToESR_cb);
for (int i = 0; i < stringList.size(); i++) {
final int j = i;
checkBoxList.get(i).selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(final ObservableValue<? extends Boolean> observable, final Boolean oldValue,
final Boolean newValue) {
// onlyDipoles_cb.setSelected(false);
// System.out.println(newValue);
if (newValue) {
magnetList.addAll(Arrays.asList(stringList.get(j)));
// printDevices();
} else {
removeDevices(stringList.get(j));
// printDevices();
}
}
});
}
hpCal_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
final Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
onlyDipoles_cb.setSelected(true);
process_started.set(1);
updateMessage("Please wait while performing the calibration...");
magnetListFiltered.clear();
getFilteredDevicesForCalibration();
try {
final_status = CalibrateAllHallProbes.runSequence(getFilteredDevicesForCalibration());
} catch (final RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
};
status_lb.textProperty().bind(task.messageProperty());
// java 8 construct, replace with java 7 code if using java 7.
task.setOnSucceeded(e -> {
process_started.set(0);
status_lb.textProperty().unbind();
// this message will be seen.
if (final_status.equals("OK")) {
status_lb.setText("Calibration successfully performed.");
} else {
status_lb.setText("Error while performing the calibration. Please try later.");
}
});
task.setOnFailed(e -> {
process_started.set(0);
status_lb.textProperty().unbind();
status_lb.setText("Error while performing the calibration. Please try later.");
});
final Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
});
cycling_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
final Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
process_started.set(1);
updateMessage("Please wait while performing the precycling...");
// cycling_bt.setDisable(true);
// hpCal_bt.setDisable(true);
magnetListFiltered.clear();
final_status = PrecycleAllFrsMagnets.runSequence(getFilteredDevices());
// System.out.println(final_status);
// System.exit(0);
// enableButtons();
getFilteredDevices();
return null;
}
};
status_lb.textProperty().bind(task.messageProperty());
// java 8 construct, replace with java 7 code if using java 7.
task.setOnSucceeded(e -> {
process_started.set(0);
// cycling_bt.setDisable(false);
// hpCal_bt.setDisable(false);
status_lb.textProperty().unbind();
// this message will be seen.
if (final_status.equals("OK")) {
status_lb.setText("Precycling operation successfully performed.");
} else {
status_lb.setText("Error while performing the precycling. Please try later.");
}
});
task.setOnFailed(e -> {
process_started.set(0);
// cycling_bt.setDisable(false);
// hpCal_bt.setDisable(false);
status_lb.textProperty().unbind();
status_lb.setText("Error while performing the precycling. Please try later.");
});
final Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
// magnetListFiltered.clear();
// ToDO disable and enable
// disableButtons()
// final String final_status = PrecycleAllFrsMagnets.runSequence(getFilteredDevices());
// System.out.println(status);
// enableButtons();
// getFilteredDevices();
}
});
switchBL_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
final Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
process_started.set(1);
updateMessage("Please wait while switching the beamline...");
magnetListFiltered.clear();
// PUT HERE YOUR FUNCTIONS
// Your function must return a string like "OK" (see below in comment) if all the procedure was
// successfully performed
// Otherwise something like "ERROR"
// final_status = PrecycleAllFrsMagnets.runSequence(getFilteredDevices());
getFilteredDevices();
return null;
}
};
status_lb.textProperty().bind(task.messageProperty());
task.setOnSucceeded(e -> {
process_started.set(0);
status_lb.textProperty().unbind();
// this message will be seen.
// final_status = "OK";
if (final_status.equals("OK")) {
status_lb.setText("Switching beamline successfully performed.");
} else {
status_lb.setText("Error while switching the beamline. Please try later.");
}
});
task.setOnFailed(e -> {
process_started.set(0);
status_lb.textProperty().unbind();
status_lb.setText("Error while performing the precycling. Please try later.");
});
final Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
});
}
@FXML
private void handleHPCal() {
onlyDipoles_cb.setSelected(true);
magnetListFiltered.clear();
// CalibrateAllHallProbes.runSequence(getFilteredDevices());
getFilteredDevices();
}
@FXML
private void handlePrecycling() {
magnetListFiltered.clear();
// PrecycleAllFrsMagnets.runSequence(getFilteredDevices());
getFilteredDevices();
// Give the filteredlist to object and start processing
}
@FXML
private void handleAbout() {
final Stage dialogStage = new Stage();
dialogStage.setTitle("About");
dialogStage.setResizable(false);
dialogStage.initModality(Modality.APPLICATION_MODAL);
final Group root = new Group();
final Scene scene = new Scene(root, 640, 350);
dialogStage.setScene(scene);
final GridPane gridpane = new GridPane();
// gridpane.setPadding(new Insets(5));
gridpane.setHgap(10);
gridpane.setVgap(0);
final DropShadow ds = new DropShadow();
ds.setOffsetY(3.0f);
ds.setColor(Color.color(0.4f, 0.4f, 0.4f));
final Label appTitle_lb = new Label();
appTitle_lb.setText("");
// appTitle_lb.setStyle("-fx-font-size: 32px;");
// appTitle_lb.setEffect(ds);
final ButtonBar button_bar = new ButtonBar();
final Button about_exit_bt = new Button("Close");
about_exit_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
dialogStage.close();
}
});
button_bar.getButtons().addAll(about_exit_bt);
final VBox vBox = new VBox();
vBox.setPrefWidth(640);
vBox.setPrefHeight(350);
vBox.setAlignment(Pos.TOP_CENTER);
vBox.setSpacing(20);
vBox.setPadding(new Insets(10, 10, 10, 10));
vBox.getChildren().addAll(appTitle_lb, gridpane, button_bar);
final VBox vBox_gridPane_left = new VBox();
vBox_gridPane_left.setPrefWidth(300);
vBox_gridPane_left.setMaxHeight(250);
// vBox_gridPane_left.setStyle("-fx-background-color: #ffaadd;");
vBox_gridPane_left.setAlignment(Pos.CENTER);
// vBox_gridPane_left.setSpacing(15);
// vBox_gridPane_left.setPadding(new Insets(10, 10, 10, 10));
final VBox vBox_gridPane_right = new VBox();
vBox_gridPane_right.setPrefWidth(300);
vBox_gridPane_right.setMaxHeight(250);
vBox_gridPane_right.setAlignment(Pos.CENTER);
// vBox_gridPane_right.setStyle("-fx-background-color: #ffaadd;");
// vBox_gridPane_right.setSpacing(10);
// vBox_gridPane_right.setPadding(new Insets(10, 10, 10, 10));
GridPane.setValignment(vBox_gridPane_right, VPos.TOP);
gridpane.add(vBox_gridPane_left, 0, 1);
gridpane.add(vBox_gridPane_right, 1, 1);
final GridPane gridpane_appInfoContainer = new GridPane();
gridpane_appInfoContainer.setPadding(new Insets(-15, 0, 0, 0));
gridpane_appInfoContainer.setHgap(40);
gridpane_appInfoContainer.setVgap(15);
// gridpane_appInfoContainer.setAlignment(Pos.TOP_LEFT);
// GridPane.setValignment(gridpane_appInfoContainer, VPos.TOP);
final Label version_tx_lb = new Label();
version_tx_lb.setText("Version");
version_tx_lb.setStyle("-fx-font-size: 14px;");
final Label version_val_lb = new Label();
version_val_lb.setText("1.0");
version_val_lb.setStyle("-fx-font-size: 14px;");
gridpane_appInfoContainer.add(version_tx_lb, 0, 1);
gridpane_appInfoContainer.add(version_val_lb, 1, 1);
final Label author_tx_lb = new Label();
author_tx_lb.setText("Authors");
author_tx_lb.setStyle("-fx-font-size: 14px;");
final Label author_val_lb = new Label();
author_val_lb.setText("Jan-Paul Hu" + "\u010D" + "ka" + "\nFabio Schirru");
author_val_lb.setStyle("-fx-font-size: 14px;");
gridpane_appInfoContainer.add(author_tx_lb, 0, 2);
gridpane_appInfoContainer.add(author_val_lb, 1, 2);
final Label coauthor_tx_lb = new Label();
coauthor_tx_lb.setText("Co-Authors");
coauthor_tx_lb.setStyle("-fx-font-size: 14px;");
final Label coauthor_val_lb = new Label();
coauthor_val_lb.setText("Jutta Fitzek" + "\nSigrid Heymell" + "\nRalph Steinhagen");
coauthor_val_lb.setStyle("-fx-font-size: 14px;");
gridpane_appInfoContainer.add(coauthor_tx_lb, 0, 3);
gridpane_appInfoContainer.add(coauthor_val_lb, 1, 3);
final Label authorMail_tx_lb = new Label();
authorMail_tx_lb.setText("Contact");
authorMail_tx_lb.setStyle("-fx-font-size: 14px;");
final Label authorMail_val_lb = new Label();
authorMail_val_lb.setText("[email protected]");
authorMail_val_lb.setStyle("-fx-font-size: 14px;");
gridpane_appInfoContainer.add(authorMail_tx_lb, 0, 4);
gridpane_appInfoContainer.add(authorMail_val_lb, 1, 4);
final ImageView selectedImage = new ImageView();
// final Image image1 = new Image(getClass().getResource("../view/images/logo1.png").toExternalForm());
final Image image1 = new Image(getClass().getResource("../view/images/FMGSkal.png").toExternalForm());
selectedImage.setImage(image1);
// selectedImage.setImage(null);
selectedImage.setFitHeight(image1.getHeight() * 0.3);
selectedImage.setFitWidth(image1.getWidth() * 0.3);
vBox_gridPane_left.getChildren().add(selectedImage);
vBox_gridPane_right.getChildren().add(gridpane_appInfoContainer);
root.getChildren().add(vBox);
dialogStage.show();
about_exit_bt.requestFocus();
}
@FXML
private void handleExit() {
Platform.exit();
System.exit(0);
}
private void removeDevices(final String deviceNames[]) {
for (int i = 0; i < deviceNames.length; i++) {
for (int j = 0; j < magnetList.size(); j++) {
if (deviceNames[i].equals(magnetList.get(j))) {
magnetList.remove(j);
}
}
}
}
private List<String> getFilteredDevices() {
if (onlyDipoles_cb.isSelected()) {
for (int i = 0; i < magnetList.size(); i++) {
if (magnetList.get(i).substring(4, 5).equals("M")) {
magnetListFiltered.add(magnetList.get(i));
}
}
System.out.println("----------");
printFilteredDevices();
} else {
for (int i = 0; i < magnetList.size(); i++) {
magnetListFiltered.add(magnetList.get(i));
}
System.out.println("----------");
printFilteredDevices();
}
return magnetListFiltered;
}
private List<String> getFilteredDevicesForCalibration() {
for (int i = 0; i < magnetList.size(); i++) {
if (magnetList.get(i).substring(4, 5).equals("M")) {
magnetListFiltered.add(magnetList.get(i));
}
}
System.out.println("----------");
printFilteredDevices();
return magnetListFiltered;
}
private void printDevices() {
for (int i = 0; i < magnetList.size(); i++) {
System.out.println("Element " + i + " : " + magnetList.get(i));
}
}
private void printFilteredDevices() {
for (int i = 0; i < magnetListFiltered.size(); i++) {
System.out.println("Element " + i + " : " + magnetListFiltered.get(i));
}
}
}