-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainAppController_MagStat_20112019.java
More file actions
874 lines (645 loc) · 27 KB
/
Copy pathMainAppController_MagStat_20112019.java
File metadata and controls
874 lines (645 loc) · 27 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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
package de.gsi.cs.co.ap.app.magstat.main;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
// import cern.japc.core.ParameterException;
// import cern.japc.core.Parameters;
// import cern.japc.core.Selector;
// import cern.japc.core.factory.ParameterFactory;
// import cern.japc.value.MapParameterValue;
// import cern.lsa.domain.devices.Device;
import cern.lsa.domain.settings.BeamProductionChain;
import cern.lsa.domain.settings.Pattern;
import de.gsi.cs.co.ap.app.magstat.model.domain.Magnet;
import de.gsi.cs.co.ap.app.magstat.utils.AboutPanel;
import de.gsi.cs.co.ap.app.magstat.utils.DeviceCalibrationCurveConverter;
import de.gsi.cs.co.ap.app.magstat.utils.DeviceUpdateFESA;
import de.gsi.cs.co.ap.app.magstat.utils.DeviceUpdateLSA;
import de.gsi.cs.co.ap.app.magstat.utils.DialogMessage;
import de.gsi.cs.co.ap.app.magstat.utils.GraphGeneratorAllDevices;
import de.gsi.cs.co.ap.app.magstat.utils.MagnetDataJoiner;
import de.gsi.cs.co.ap.app.magstat.utils.MagnetDataProcessorFESA;
import de.gsi.cs.co.ap.app.magstat.utils.MagnetDataProcessorLSA;
import de.gsi.cs.co.ap.app.magstat.utils.MagnetRampingMonitor;
import de.gsi.cs.co.ap.app.magstat.utils.PrinterDialog;
import de.gsi.cs.co.ap.app.magstat.utils.RetrieveDateAndTime;
import de.gsi.cs.co.ap.app.magstat.utils.RetrieveOpticsName;
import de.gsi.cs.co.ap.app.magstat.utils.RetrievePatternsAndChains;
import de.gsi.cs.co.ap.app.magstat.utils.SaveData;
import de.gsi.cs.co.ap.app.magstat.utils.SaveDataDialog;
import de.gsi.cs.co.ap.app.magstat.utils.SubscriptionsManager;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.text.TextAlignment;
import javafx.util.Callback;
// 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 MainAppController {
// You can choose a logger (needed imports are given in the import section
// as comments):
// for libraries:
// private static final Logger LOGGER =
// LoggerFactory.getLogger(MainAppController.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
@FXML
private BorderPane borderPane;
@FXML
private TableView<Magnet> magnetTable;
@FXML
private TableColumn<Magnet, String> idColumn;
@FXML
private TableColumn<Magnet, Integer> statusColumn;
@FXML
private TableColumn<Magnet, Boolean> dcmodeColumn;
@FXML
private TableColumn<Magnet, Double> current_measColumn;
@FXML
private TableColumn<Magnet, Double> current_measDCColumn;
@FXML
private TableColumn<Magnet, Double> current_expColumn;
@FXML
private TableColumn<Magnet, Double> bfield_measColumn;
@FXML
private TableColumn<Magnet, Double> bfield_expColumn;
@FXML
private TableColumn<Magnet, Double> klfield_expColumn;
@FXML
private TableColumn<Magnet, Double> current_diffColumn;
@FXML
private TableColumn<Magnet, Double> hallprobeColumn;
@FXML
private Button refresh_bt;
@FXML
private Button save_bt;
@FXML
private Button exit_bt;
@FXML
private Button print_bt;
@FXML
private Button graph_bt;
@FXML
private Button about_bt;
@FXML
private ComboBox<Pattern> patterns_cb;
@FXML
private ComboBox<BeamProductionChain> chains_cb;
@FXML
private CheckBox updateDCValue_cb;
@FXML
private Label status_lb;
@FXML
private Circle dataSavingLed;
private final AboutPanel ap = AboutPanel.getInstance();
private final DeviceCalibrationCurveConverter dccc = DeviceCalibrationCurveConverter.getInstance();
private final DialogMessage dm = DialogMessage.getInstance();
private final GraphGeneratorAllDevices ggenad = GraphGeneratorAllDevices.getInstance();
private final MagnetDataProcessorFESA mdpFESA = MagnetDataProcessorFESA.getInstance();
private final MagnetDataProcessorLSA mdpLSA = MagnetDataProcessorLSA.getInstance();
private final MagnetRampingMonitor mrm = MagnetRampingMonitor.getInstance();
private final PrinterDialog pd = PrinterDialog.getInstance();
private final RetrieveDateAndTime dt = RetrieveDateAndTime.getInstance();
private final RetrieveOpticsName ron = RetrieveOpticsName.getInstance();
private final RetrievePatternsAndChains retrievePatternsAndChains = RetrievePatternsAndChains.getInstance();
private final SaveData sd = SaveData.getInstance();
private final SaveDataDialog sdd = SaveDataDialog.getInstance();
private final SubscriptionsManager sm = SubscriptionsManager.getInstance();
private final MagnetDataJoiner mdpj = MagnetDataJoiner.getInstance();
private final DeviceUpdateFESA duFESA = DeviceUpdateFESA.getInstance();
private final DeviceUpdateLSA duLSA = DeviceUpdateLSA.getInstance();
private Boolean timer_LSA_started = false;
private Boolean timer_dataRecording_started = false;
private Pattern selectedPattern;
private List<BeamProductionChain> chains;
private Timer timer_LSA; // timer for LSA
private Timer timer_dataRecording; // timer for data recorded on disk
/*- Decimal format for the table columns */
private final DecimalFormat df = new DecimalFormat("#0.000000");
private final DecimalFormat df_null = new DecimalFormat("#0.0");
// private final IntegerProperty isDestinationDirectorySelected = new
// SimpleIntegerProperty(0);
private final IntegerProperty isTableFilledWithData = new SimpleIntegerProperty(0);
private final IntegerProperty isAppRunning = new SimpleIntegerProperty(0);
private RadialGradient gradient1;
private RadialGradient gradient2;
private BeamProductionChain chain;
private Map<Pattern, List<BeamProductionChain>> patternsAndChainsMap = new HashMap<>();
private ChangeListener<Pattern> patternsChangeListener;
private ChangeListener<BeamProductionChain> chainsChangeListener;
private Timer dcValueTimer;
@FXML
public void initialize() {
initializeLedGUI();
initializeGUI();
initializeButtonsGUI();
initializeUpdateDCValue();
listenerGenerator();
setPatternsAndChains();
}
private void initializeUpdateDCValue() {
updateDCValue_cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(final ObservableValue<? extends Boolean> observable, final Boolean oldValue,
final Boolean newValue) {
final boolean selected = updateDCValue_cb.isSelected();
//System.out.println("Option Selected");
if (selected) {
mrm.setBeamChain(chain);
mrm.setFrsDevices();
dcValueTimer = new Timer();
dcValueTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
mrm.startDAcquiredDCValueAcq();
magnetTable.refresh();
}
}, 0, 2000);
//mrm.setDataTable(magnetTable);
//mrm.startDAcquiredDCValueAcq();
} else {
dcValueTimer.cancel();
//mrm.getUpdateTimer().cancel();
}
}
});
}
private void createTable() {
updateDCValue_cb.setDisable(true);
// Disable ComboBoxes patterns and chains
patterns_cb.setDisable(true);
chains_cb.setDisable(true);
// mdpFESA.closeDeviceSubscriptions();
sm.closeDeviceSubscriptions();
// duFESA.closeAllSubscriptions();
/*- data should be cleared but app works also without the following line...*/
mdpj.getData().clear();
magnetTable.getItems().clear();
magnetTable.refresh();
isAppRunning.set(0);
isTableFilledWithData.set(0);// Update Magnets
// performeTaskDataTable(chains_cb.getValue());
performeTaskDataTable();
// Temporarily it is a fixed chain
// final BeamProductionChain chain = chains.get(0);
}
private void performeTaskDataTable() {
final Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
updateMessage("Please wait while loading data...");
mdpLSA.setPattern(selectedPattern);
mdpLSA.setBeamChain(chain);
// mdpLSA.setDevices(); // Setting of devices belonging to the
// selected patter/chain
mdpLSA.setStaticDevices(); // Setting of devices belonging to
// the FRS static reference
ron.setBeamChain(chain);
if (mdpLSA.getMagnetData().size() != 0) {
mdpFESA.setBeamChain(chain);
// mdpFESA.setDevices();
// System.out.println("VEDO:" +
// mdpLSA.getMagnetData().size());
mdpFESA.setFrsDevices();
// mdpFESA.setDevices();
// mdpFESA.retrieveDataFromFESA();
// System.out.println("VEDO:" +
// mdpLSA.getMagnetData().size());
mdpj.setDataFESA(mdpFESA.getMagnetData());
mdpj.setDataLSA(mdpLSA.getMagnetData());
mdpj.joinData();
//process the calibration sign of each device by sending its name_id
dccc.clearDeviceCalibrationSign();
for(int i = 0; i < mdpj.getData().size(); i++) {
dccc.setDeviceCalibrationSign(mdpj.getData().get(i).getId());
}
//dccc.printDeviceCalibrationSign();
}
return null;
}
};
status_lb.textProperty().bind(task.messageProperty());
// java 8 construct, replace with java 7 code if using java 7.
task.setOnSucceeded(e -> {
status_lb.textProperty().unbind();
// this message will be seen.
if (mdpj.getData().size() != 0) {
status_lb.setText("Data successfully loaded. Elements [" + mdpj.getData().size() + "]");
isTableFilledWithData.set(1);
magnetTable.setItems(mdpj.getData());
magnetTable.refresh();
//// duFESA.setBeamChain(chain);
// rdSel.setBeamChain(chain);
updateDCValue_cb.setSelected(false);
updateDCValue_cb.setDisable(false);
// Start all device subscriptions
sm.setBeamChain(chain);
sm.setFrsDevices(mdpLSA.getStaticDevices());
sm.setListOfSubscriptions(duFESA.get_subscriptionHandle());
sm.generateDeviceSubscriptions();
} else {
status_lb.textProperty().unbind();
status_lb.setText("No data can be retrieved from the selected Pattern/Chain.");
resetTable();
}
// Start timer for drives update
if (!timer_LSA_started) {
System.out.println("New LSA timer started!");
timer_LSA = new Timer();
// Start timer, LSA enquire every 3 min = 180s
timer_LSA.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
timer_LSA_started = true;
if (mdpj.getData().size() != 0) {
mdpLSA.setPattern(selectedPattern);
mdpLSA.setBeamChain(chain);
/*- Set the devices belonging to a generic pattern/chain */
// mdpLSA.setDevices();
/*- Set the devices belonging to the FRS static reference */
mdpLSA.setStaticDevices();
// optics_name = mdpLSA.getOpticsName();
// mdpj.updateLSAData();
duLSA.updateLSAData();
System.out.println("**********UPDATING LSA...***********");
}
} catch (final Throwable t) { // Catch Throwable rather
// than Exception (a
// subclass).
dm.setIconAndText(null,
"An error occurred while updating LSA data! Press Refresh button to restart.");
dm.showMessangerStage();
timer_LSA_started = false;
}
}
}, 0, 10000);
}
// Enable ComboBoxes patterns and chains
patterns_cb.setDisable(false);
chains_cb.setDisable(false);
// Make the related buttons operative
isAppRunning.set(1);
});
task.setOnFailed(e -> {
// System.out.println("SETonFAIL");
status_lb.textProperty().unbind();
status_lb.setText("An error occurred while retrieving devices data from LSA/FESA.");
resetTable();
});
final Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
@FXML
private void handleAbout() {
ap.showAboutStage();
}
@FXML
private void handleRefresh() {
timer_LSA_started = false;
sdd.fireStopButton();
dataSavingLed.setFill(gradient1);
if (timer_dataRecording_started) {
timer_dataRecording.cancel();
}
timer_dataRecording_started = false;
setPatternsAndChains();
}
@FXML
private void handleGraph() {
ggenad.initGraph();
ggenad.setGraphTitle(selectedPattern.getName() + "/" + chain.getName());
ggenad.showGraphStage();
}
@FXML
private void handleManualSaving() {
sdd.setDialogMessageStage(dm);
sdd.stageShowAndWait();
if (sdd.getSelectedOption() == 0) {
sd.setDateAndTime(dt.getDateAndTime());
sd.setData(mdpj.getData());
sd.writeDataToDisk(patterns_cb.getSelectionModel().getSelectedItem().getName(),
chains_cb.getSelectionModel().getSelectedItem().getName(), ron.getOpticsName(), sdd.getFilePath(),
sdd.getFileName());
}
if (sdd.getSelectedOption() == 1) {
dataSavingLed.setFill(gradient2);
startTimerForDataRecording(sdd.getFrequency());
timer_dataRecording_started = true;
}
if (sdd.getSelectedOption() == 2) {
dataSavingLed.setFill(gradient1);
timer_dataRecording.cancel();
timer_dataRecording_started = false;
}
}
@FXML
private void handlePrint() {
pd.setTableDataHeader(dt.getDateAndTime(), patterns_cb.getSelectionModel().getSelectedItem().getName(),
chains_cb.getSelectionModel().getSelectedItem().getName());
pd.setData(mdpj.getData());
pd.ShowPrinterDialog();
}
@FXML
private void handleExit() {
// maybe not necessary since tasks are Daemon
if (timer_dataRecording_started) {
timer_dataRecording.cancel();
}
if (timer_LSA_started) {
timer_LSA.cancel();
}
sm.closeDeviceSubscriptions();
Platform.exit();
System.exit(0);
}
private void startTimerForDataRecording(final int savingFreq) {
timer_dataRecording = new Timer();
timer_dataRecording.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
sd.setDateAndTime(dt.getDateAndTime());
sd.setData(mdpj.getData());
sd.writeDataToDisk(patterns_cb.getSelectionModel().getSelectedItem().getName(),
chains_cb.getSelectionModel().getSelectedItem().getName(), ron.getOpticsName(),
sdd.getFilePath(), "MagStat_file");
System.out.println("Data are being recorded on Disk!");
/*- Catch Throwable rather than Exception (a subclass). */
} catch (final Throwable t) {
dm.setIconAndText(null, "An error occurred while saving data in Autosave mode! Please try again.");
dm.showMessangerStage();
sdd.fireStopButton();
dataSavingLed.setFill(gradient1);
if (timer_dataRecording_started) {
timer_dataRecording.cancel();
}
timer_dataRecording_started = false;
}
}
}, 0, savingFreq);
}
private void initializeButtonsGUI() {
save_bt.disableProperty()
.bind(Bindings.when(isTableFilledWithData.isNotEqualTo(1)).then(true).otherwise(false));
print_bt.disableProperty().bind(isTableFilledWithData.isNotEqualTo(1));
about_bt.disableProperty().bind(isAppRunning.isNotEqualTo(1));
graph_bt.disableProperty().bind(isTableFilledWithData.isNotEqualTo(1));
}
private void initializeLedGUI() {
gradient1 = new RadialGradient(0, 0, dataSavingLed.getCenterX(), dataSavingLed.getCenterY(),
dataSavingLed.getRadius() + 3, false, CycleMethod.NO_CYCLE, new Stop(0, Color.web("#ffebe6", 1.0)),
new Stop(1, Color.LIGHTGRAY));
gradient2 = new RadialGradient(0, 0, dataSavingLed.getCenterX(), dataSavingLed.getCenterY(),
dataSavingLed.getRadius() + 3, false, CycleMethod.NO_CYCLE, new Stop(0, Color.RED),
new Stop(1, Color.LIGHTGRAY));
dataSavingLed.setFill(gradient1);
}
private void initializeGUI() {
final Callback<TableColumn<Magnet, Double>, TableCell<Magnet, Double>> callBackColumnFunction = new Callback<TableColumn<Magnet, Double>, TableCell<Magnet, Double>>() {
@Override
public TableCell<Magnet, Double> call(final TableColumn<Magnet, Double> param) {
return new TableCell<Magnet, Double>() {
@Override
protected void updateItem(final Double item, final boolean empty) {
super.updateItem(item, empty);
if (!empty) {
final int index = getTableRow().getIndex();
if ((index < mdpj.getData().size()) && (index >= 0)) {
if (item == 999.0) {
setText("N/A");
} else {
if (item != 0) {
setText(df.format(item));
} else {
setText(df_null.format(item));
}
}
}
}
}
};
}
};
status_lb.setText("");
// some table settings to remove user control
magnetTable.setSelectionModel(null); // it removes the row selection
magnetTable.setStyle("-fx-focus-color: LightGray;" + "-fx-faint-focus-color: transparent;"); // not
// visibl
magnetTable.setFocusTraversable(false);
// Initialize column Titles and settings
//final Label columnTitle_current_diffColumn = new Label("\u0394" + "I" + "\n(A)");
final Label columnTitle_current_diffColumn = new Label("\u0394" + "I" + "/I");
columnTitle_current_diffColumn.setPrefHeight(50);
columnTitle_current_diffColumn.setWrapText(true);
columnTitle_current_diffColumn.setTextAlignment(TextAlignment.CENTER);
current_diffColumn.setGraphic(columnTitle_current_diffColumn);
current_diffColumn.setResizable(false);
current_diffColumn.setPrefWidth(118);
current_diffColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
current_diffColumn.setSortable(false);
final Label columnTitle_bfield_expColumn = new Label("BL_soll" + "\n(Tm, T)");
columnTitle_bfield_expColumn.setPrefHeight(50);
columnTitle_bfield_expColumn.setWrapText(true);
columnTitle_bfield_expColumn.setTextAlignment(TextAlignment.CENTER);
bfield_expColumn.setGraphic(columnTitle_bfield_expColumn);
bfield_expColumn.setResizable(false);
bfield_expColumn.setPrefWidth(118);
bfield_expColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
bfield_expColumn.setSortable(false);
//final Label columnTitle_bfield_measColumn = new Label("BL_ist" + "\n(Tm, T)");
final Label columnTitle_bfield_measColumn = new Label("B\u03C1" + "\n(Tm)");
columnTitle_bfield_measColumn.setPrefHeight(50);
columnTitle_bfield_measColumn.setWrapText(true);
columnTitle_bfield_measColumn.setTextAlignment(TextAlignment.CENTER);
bfield_measColumn.setGraphic(columnTitle_bfield_measColumn);
bfield_measColumn.setResizable(false);
bfield_measColumn.setPrefWidth(118);
bfield_measColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
bfield_measColumn.setSortable(false);
final Label columnTitle_current_expColumn = new Label("I_soll" + "\n(A)");
columnTitle_current_expColumn.setPrefHeight(50);
columnTitle_current_expColumn.setWrapText(true);
columnTitle_current_expColumn.setTextAlignment(TextAlignment.CENTER);
current_expColumn.setGraphic(columnTitle_current_expColumn);
current_expColumn.setResizable(false);
current_expColumn.setPrefWidth(118);
current_expColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
current_expColumn.setSortable(false);
final Label columnTitle_current_measColumn = new Label("I_ist" + "\n(A)");
columnTitle_current_measColumn.setPrefHeight(50);
columnTitle_current_measColumn.setWrapText(true);
columnTitle_current_measColumn.setTextAlignment(TextAlignment.CENTER);
current_measColumn.setGraphic(columnTitle_current_measColumn);
current_measColumn.setResizable(false);
current_measColumn.setPrefWidth(118);
current_measColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
current_measColumn.setSortable(false);
final Label columnTitle_current_measDCColumn = new Label("I_ist [DC]" + "\n(A)");
columnTitle_current_measDCColumn.setPrefHeight(50);
columnTitle_current_measDCColumn.setWrapText(true);
columnTitle_current_measDCColumn.setTextAlignment(TextAlignment.CENTER);
current_measDCColumn.setGraphic(columnTitle_current_measDCColumn);
current_measDCColumn.setResizable(false);
current_measDCColumn.setPrefWidth(118);
current_measDCColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
current_measDCColumn.setSortable(false);
final Label columnTitle_klfield_Column = new Label("KL_soll" + "\n(1, 1/m)");
columnTitle_klfield_Column.setPrefHeight(50);
columnTitle_klfield_Column.setWrapText(true);
columnTitle_klfield_Column.setTextAlignment(TextAlignment.CENTER);
klfield_expColumn.setGraphic(columnTitle_klfield_Column);
klfield_expColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
klfield_expColumn.setResizable(false);
klfield_expColumn.setPrefWidth(116);
klfield_expColumn.setSortable(false);
final Label columnTitle_hallProbe_Column = new Label("Hall Probe" + "\n(Tm)");
columnTitle_hallProbe_Column.setPrefHeight(50);
columnTitle_hallProbe_Column.setWrapText(true);
columnTitle_hallProbe_Column.setTextAlignment(TextAlignment.CENTER);
hallprobeColumn.setGraphic(columnTitle_hallProbe_Column);
hallprobeColumn.setStyle("-fx-alignment: CENTER-RIGHT;");
hallprobeColumn.setResizable(false);
hallprobeColumn.setPrefWidth(116);
hallprobeColumn.setSortable(false);
dcmodeColumn.setStyle("-fx-alignment: CENTER;");
dcmodeColumn.setResizable(false);
dcmodeColumn.setPrefWidth(118);
dcmodeColumn.setSortable(false);
statusColumn.setStyle("-fx-alignment: CENTER;");
statusColumn.setResizable(false);
statusColumn.setPrefWidth(120);
statusColumn.setSortable(false);
idColumn.setResizable(false);
idColumn.setPrefWidth(110);
idColumn.setSortable(false);
idColumn.setCellValueFactory(new PropertyValueFactory<Magnet, String>("id"));
// statusColumn.setCellValueFactory(c -> new
// SimpleIntegerProperty(c.getValue().getStatus()));
statusColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Integer>("status"));
dcmodeColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Boolean>("dcmode"));
current_measColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("current_meas"));
current_measDCColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("current_meas_DC"));
current_expColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("current_exp"));
bfield_measColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("bfield_meas"));
bfield_expColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("bfield_exp"));
klfield_expColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("k0lfield_exp"));
current_diffColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("current_diff"));
hallprobeColumn.setCellValueFactory(new PropertyValueFactory<Magnet, Double>("hallprobe"));
magnetTable.setMaxHeight(650);
magnetTable.setFixedCellSize(25);
current_measColumn.setCellFactory(callBackColumnFunction);
current_diffColumn.setCellFactory(callBackColumnFunction);
current_expColumn.setCellFactory(callBackColumnFunction);
current_measDCColumn.setCellFactory(callBackColumnFunction);
bfield_measColumn.setCellFactory(callBackColumnFunction);
bfield_expColumn.setCellFactory(callBackColumnFunction);
klfield_expColumn.setCellFactory(callBackColumnFunction);
hallprobeColumn.setCellFactory(new Callback<TableColumn<Magnet, Double>, TableCell<Magnet, Double>>() {
@Override
public TableCell<Magnet, Double> call(final TableColumn<Magnet, Double> param) {
return new TableCell<Magnet, Double>() {
@Override
protected void updateItem(final Double item, final boolean empty) {
super.updateItem(item, empty);
if (!empty) {
final int index = getTableRow().getIndex();
if ((index < mdpj.getData().size()) && (index >= 0)) {
if (item == 999.0) {
setText("");
} else {
if (item != 0) {
setText(df.format(item));
} else {
setText(df_null.format(item));
}
}
}
}
}
};
}
});
}
private void listenerGenerator() {
// listener for Patterns
patternsChangeListener = new ChangeListener<Pattern>() {
@Override
public void changed(final ObservableValue<? extends Pattern> observable, final Pattern oldValue,
final Pattern newValue) {
if (newValue != null) {
chains_cb.valueProperty().removeListener(chainsChangeListener);
selectedPattern = patterns_cb.getSelectionModel().getSelectedItem();
chains = patternsAndChainsMap.get(selectedPattern);
chains_cb.getItems().clear();
chains_cb.getItems().addAll(chains);
chains_cb.valueProperty().addListener(chainsChangeListener);
chains_cb.getSelectionModel().selectFirst();
chain = chains_cb.getValue();
}
}
};
// listener for Chains
chainsChangeListener = new ChangeListener<BeamProductionChain>() {
@Override
public void changed(final ObservableValue<? extends BeamProductionChain> observable,
final BeamProductionChain oldValue, final BeamProductionChain newValue) {
if (newValue != null) {
chain = chains_cb.getValue();
createTable();
}
}
};
}
private void setPatternsAndChains() {
patterns_cb.valueProperty().removeListener(patternsChangeListener);
patterns_cb.getItems().clear();
chains_cb.valueProperty().removeListener(chainsChangeListener);
chains_cb.getItems().clear();
patternsAndChainsMap = retrievePatternsAndChains.getPatternsAndChains();
try {
patterns_cb.getItems().addAll(patternsAndChainsMap.keySet());
patterns_cb.valueProperty().addListener(patternsChangeListener);
patterns_cb.getSelectionModel().selectFirst();
} catch (final Exception e) {
dm.setIconAndText(null, "An error occurred while loading Patterns and Chains. Please try later.");
dm.showMessangerStage();
handleExit();
}
}
private void resetTable() {
isTableFilledWithData.set(0);
// Enable ComboBoxes patterns and chains
patterns_cb.setDisable(false);
chains_cb.setDisable(false);
}
}