-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootLayoutController.java
More file actions
1335 lines (1168 loc) · 45.1 KB
/
Copy pathRootLayoutController.java
File metadata and controls
1335 lines (1168 loc) · 45.1 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
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Bao Lab 2017
*/
package wormguides.controllers;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.*;
import Timeline.TimelineChart;
import javafx.beans.*;
import javafx.collections.ListChangeListener;
import javafx.scene.control.Tooltip;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Popup;
import javafx.stage.Stage;
import acetree.LineageData;
import connectome.Connectome;
import partslist.PartsList;
import partslist.celldeaths.CellDeaths;
import wormguides.MainApp;
import wormguides.layers.DisplayLayer;
import wormguides.layers.SearchLayer;
import wormguides.layers.StoriesLayer;
import wormguides.layers.StructuresLayer;
import wormguides.loaders.ImageLoader;
import wormguides.models.LineageTree;
import wormguides.models.cellcase.CasesLists;
import wormguides.models.colorrule.Rule;
import wormguides.models.subscenegeometry.SceneElementsList;
import wormguides.models.subscenegeometry.StructureTreeNode;
import wormguides.resources.ProductionInfo;
import wormguides.stories.Story;
import wormguides.util.ColorHash;
import wormguides.util.StringCellFactory;
import wormguides.util.subsceneparameters.Parameters;
import wormguides.view.DraggableTab;
import wormguides.view.infowindow.InfoWindow;
import wormguides.view.popups.AboutPane;
import wormguides.view.popups.StorySavePane;
import wormguides.view.popups.SulstonTreePane;
import wormguides.view.urlwindow.URLLoadWarningDialog;
import wormguides.view.urlwindow.URLLoadWindow;
import wormguides.view.urlwindow.URLShareWindow;
import static java.lang.System.lineSeparator;
import static java.time.Duration.between;
import static java.util.Collections.sort;
import static javafx.application.Platform.runLater;
import static javafx.collections.FXCollections.observableArrayList;
import static javafx.scene.Cursor.DEFAULT;
import static javafx.scene.Cursor.HAND;
import static javafx.scene.SceneAntialiasing.BALANCED;
import static javafx.scene.input.MouseEvent.MOUSE_PRESSED;
import static javafx.scene.layout.AnchorPane.setBottomAnchor;
import static javafx.scene.layout.AnchorPane.setLeftAnchor;
import static javafx.scene.layout.AnchorPane.setRightAnchor;
import static javafx.scene.layout.AnchorPane.setTopAnchor;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.GRAY;
import static javafx.stage.Modality.NONE;
import static javafx.stage.StageStyle.UNDECORATED;
import static acetree.tablelineagedata.AceTreeTableLineageDataLoader.getAvgXOffsetFromZero;
import static acetree.tablelineagedata.AceTreeTableLineageDataLoader.getAvgYOffsetFromZero;
import static acetree.tablelineagedata.AceTreeTableLineageDataLoader.getAvgZOffsetFromZero;
import static acetree.tablelineagedata.AceTreeTableLineageDataLoader.loadNucFiles;
import static acetree.tablelineagedata.AceTreeTableLineageDataLoader.setOriginToZero;
import static partslist.PartsList.getFunctionalNameByLineageName;
import static partslist.celldeaths.CellDeaths.isInCellDeaths;
import static search.SearchUtil.getStructureComment;
import static search.SearchUtil.isMulticellularStructureByName;
import static search.SearchUtil.isStructureWithComment;
import static wormguides.util.colorurl.UrlParser.processUrl;
/**
* Controller for RootLayout.fxml that contains all GUI components of the main WormGUIDES application window
*/
public class RootLayoutController extends BorderPane implements Initializable {
private static final String UNLINEAGED_START = "Nuc";
private static final String ROOT = "ROOT";
// Panels stuff
@FXML
private BorderPane rootBorderPane;
@FXML
private VBox displayVBox;
@FXML
private AnchorPane modelAnchorPane;
@FXML
private ScrollPane infoPane;
@FXML
private HBox sceneControlsBox;
// Subscene controls
@FXML
private Button backwardButton,
forwardButton,
playButton;
@FXML
private Label timeLabel,
totalNucleiLabel;
@FXML
private Slider timeSlider;
@FXML
private Button zoomInButton,
zoomOutButton;
// Tab stuff
@FXML
private TabPane mainTabPane;
@FXML
private Tab storiesTab;
@FXML
private Tab colorAndDisplayTab;
@FXML
private TabPane colorAndDisplayTabPane;
@FXML
private Tab cellsTab;
@FXML
private Tab structuresTab;
@FXML
private Tab displayTab;
// Search stuff
@FXML
private TextField searchField;
@FXML
private ListView<String> searchResultsListView;
@FXML
private RadioButton sysRadioBtn,
funRadioBtn,
desRadioBtn,
genRadioBtn,
conRadioBtn,
multiRadioBtn;
@FXML
private CheckBox cellNucleusCheckBox,
cellBodyCheckBox,
ancestorCheckBox,
descendantCheckBox;
@FXML
private Label descendantLabel;
@FXML
private AnchorPane colorPickerPane;
@FXML
private ColorPicker colorPicker;
@FXML
private Button addSearchBtn;
@FXML
private CheckBox presynapticCheckBox,
postsynapticCheckBox,
electricalCheckBox,
neuromuscularCheckBox;
@FXML
private ListView<Rule> rulesListView;
@FXML
private CheckBox uniformSizeCheckBox;
@FXML
private Button clearAllLabelsButton;
@FXML
private Slider opacitySlider;
// Structures tab
private StructuresLayer structuresLayer;
@FXML
private TextField structuresSearchField;
@FXML
private ListView<String> structuresSearchListView;
@FXML
private TreeView<StructureTreeNode> structuresTreeView;
@FXML
private Button addStructureRuleBtn;
@FXML
private ColorPicker structureRuleColorPicker;
// Cell information panel
@FXML
private Text displayedName;
@FXML
private Text moreInfoClickableText;
@FXML
private Text displayedDescription;
@FXML
private Text displayedStory;
@FXML
private Text displayedStoryDescription;
// Stories tab
@FXML
private ListView<Story> storiesListView;
@FXML
private Button editNoteButton;
@FXML
private Button newStoryButton;
@FXML
private Button deleteStoryButton;
// Movie capture stuff
@FXML
private MenuItem captureVideoMenuItem;
@FXML
private MenuItem stopCaptureVideoMenuItem;
// Root layout's own stage (the main application stage)
private Stage mainStage;
// Other windows
private Stage aboutStage;
private Stage sulstonTreeStage;
private Stage urlDisplayStage;
private Stage urlLoadStage;
private Stage rotationControllerStage;
private Stage contextMenuStage;
private Popup exitSavePopup;
private Stage timelineStage = new Stage();
// URL generation/loading
private URLShareWindow urlShareWindow;
private URLLoadWindow urlLoadWindow;
private URLLoadWarningDialog warning;
private RotationController rotationController;
private Window3DController window3DController;
private DoubleProperty subsceneWidth;
private DoubleProperty subsceneHeight;
private SearchLayer searchLayer;
private Connectome connectome;
private StoriesLayer storiesLayer;
private SceneElementsList sceneElementsList;
private DisplayLayer displayLayer;
private ProductionInfo productionInfo;
// Info window stuff
private CasesLists casesLists;
private InfoWindow infoWindow;
private ImageView playIcon, pauseIcon;
// Lineage tree stuff
private TreeItem<String> lineageTreeRoot;
private LineageData lineageData;
// Shared properties
/** Name that appears in the info panel */
private StringProperty selectedEntityNameProperty;
private StringProperty selectedNameLabeledProperty;
private StringProperty activeStoryProperty;
private BooleanProperty geneResultsUpdatedFlag;
private BooleanProperty usingInternalRulesFlag;
private BooleanProperty bringUpInfoFlag;
private BooleanProperty playingMovieFlag;
private BooleanProperty capturingVideoFlag;
private BooleanProperty cellClickedFlag;
private BooleanProperty rebuildSubsceneFlag;
private IntegerProperty timeProperty;
private IntegerProperty totalNucleiProperty;
private DoubleProperty rotateXAngleProperty;
private DoubleProperty rotateYAngleProperty;
private DoubleProperty rotateZAngleProperty;
private DoubleProperty translateXProperty;
private DoubleProperty translateYProperty;
private DoubleProperty zoomProperty;
private DoubleProperty othersOpacityProperty;
// Other shared variables
private ObservableList<Rule> rulesList;
private ObservableList<String> searchResultsList;
private int startTime;
private int endTime;
private int movieTimeOffset;
private boolean defaultEmbryoFlag;
private Service<Void> searchResultsUpdateService;
private ContextMenuController contextMenuController;
private ColorHash colorHash;
private SubScene subscene;
private Group rootEntitiesGroup;
@FXML
public void menuLoadStory() {
if (storiesLayer != null) {
storiesLayer.loadStory();
}
}
@FXML
public void menuSaveStory() {
storiesLayer.saveActiveStory();
}
@FXML
public void menuSaveImageAction() {
window3DController.stillscreenCapture();
}
@FXML
public void menuCloseAction() {
initCloseApplication();
}
@FXML
public void menuAboutAction() {
if (aboutStage == null) {
aboutStage = new Stage();
aboutStage.setScene(new Scene(new AboutPane()));
aboutStage.setTitle("About WormGUIDES");
aboutStage.initModality(NONE);
aboutStage.setHeight(400.0);
aboutStage.setWidth(300.0);
aboutStage.setResizable(false);
}
aboutStage.show();
}
@FXML
public void viewTreeAction() {
if (sulstonTreeStage == null) {
sulstonTreeStage = new Stage();
final SulstonTreePane treePane = new SulstonTreePane(
sulstonTreeStage,
searchLayer,
lineageData,
movieTimeOffset,
lineageTreeRoot,
rulesList,
colorHash,
timeProperty,
contextMenuStage,
contextMenuController,
selectedNameLabeledProperty,
rebuildSubsceneFlag,
defaultEmbryoFlag);
sulstonTreeStage.setScene(new Scene(treePane));
sulstonTreeStage.setTitle("LineageTree");
sulstonTreeStage.initModality(NONE);
sulstonTreeStage.show();
treePane.addDrawing();
mainStage.show();
} else {
sulstonTreeStage.show();
runLater(() -> ((Stage) sulstonTreeStage.getScene().getWindow()).toFront());
}
}
@FXML
public void viewTimeline() {
timelineStage.setTitle("Timeline");
final TimelineChart<Number, String> chart = TimelineChart.intialize(storiesLayer, productionInfo);
chart.getStylesheets().add(getClass().getResource("/Timeline/chart.css").toExternalForm());
Scene scene = new Scene(chart, 1500, 700);
timelineStage.setScene(scene);
timelineStage.show();
}
@FXML
public void generateURLAction() {
if (urlDisplayStage == null) {
urlDisplayStage = new Stage();
urlShareWindow = new URLShareWindow(
rulesList,
timeProperty,
rotateXAngleProperty,
rotateYAngleProperty,
rotateZAngleProperty,
translateXProperty,
translateYProperty,
zoomProperty,
othersOpacityProperty);
urlShareWindow.getCloseButton().setOnAction(event -> urlDisplayStage.hide());
urlDisplayStage.setScene(new Scene(urlShareWindow));
urlDisplayStage.setTitle("Share Scene");
urlDisplayStage.setResizable(false);
urlDisplayStage.initModality(NONE);
}
urlShareWindow.resetURLs();
urlDisplayStage.show();
}
@FXML
public void loadURLAction() {
if (urlLoadStage == null) {
urlLoadStage = new Stage();
urlLoadWindow = new URLLoadWindow();
urlLoadWindow.getLoadButton().setOnAction(event -> {
if (warning == null) {
warning = new URLLoadWarningDialog();
}
if (!warning.doNotShowAgain()) {
final Optional<ButtonType> result = warning.showAndWait();
if (result.get() == warning.getButtonTypeOkay()) {
urlLoadStage.hide();
processUrl(
urlLoadWindow.getInputURL(),
rulesList,
searchLayer,
timeProperty,
rotateXAngleProperty,
rotateYAngleProperty,
rotateZAngleProperty,
translateXProperty,
translateYProperty,
zoomProperty,
othersOpacityProperty,
rebuildSubsceneFlag);
}
} else {
urlLoadStage.hide();
processUrl(
urlLoadWindow.getInputURL(),
rulesList,
searchLayer,
timeProperty,
rotateXAngleProperty,
rotateYAngleProperty,
rotateZAngleProperty,
translateXProperty,
translateYProperty,
zoomProperty,
othersOpacityProperty,
rebuildSubsceneFlag);
}
});
urlLoadWindow.getCancelButton().setOnAction(event -> urlLoadStage.hide());
urlLoadStage.setScene(new Scene(urlLoadWindow));
urlLoadStage.setTitle("Load Scene");
urlLoadStage.setResizable(false);
urlLoadStage.initModality(NONE);
}
urlLoadWindow.clearField();
urlLoadStage.show();
}
@FXML
public void saveSearchResultsAction() {
final ObservableList<String> items = searchResultsListView.getItems();
if (!(items.size() > 0)) {
System.out.println("no searchLayer results to write to file");
}
final Stage fileChooserStage = new Stage();
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Choose Save Location");
fileChooser.getExtensionFilters().add(new ExtensionFilter("TXT File", "*.txt"));
try {
final File output = fileChooser.showSaveDialog(fileChooserStage);
// check
if (output == null) {
System.out.println("error creating file to write searchLayer results");
return;
}
// create the header line that will format the search criteria corresponding to these search results
String searchType = "";
if (sysRadioBtn.isSelected()) {
searchType = "Lineage Name";
} else if (funRadioBtn.isSelected()) {
searchType = "Function Name";
} else if (desRadioBtn.isSelected()) {
searchType = "PartsList Desciption";
} else if (genRadioBtn.isSelected()) {
searchType = "Gene";
} else if (conRadioBtn.isSelected()) {
searchType = "Connectome - ";
if (presynapticCheckBox.isSelected()) {
searchType += "pre-synaptic, ";
}
if (postsynapticCheckBox.isSelected()) {
searchType += "post-synaptic, ";
}
if (electricalCheckBox.isSelected()) {
searchType += "electrical, ";
}
if (neuromuscularCheckBox.isSelected()) {
searchType += "neuromuscular";
}
if (searchType.substring(searchType.length()-2).equals(", ")) {
searchType = searchType.substring(0, searchType.length()-2);
}
} else if (multiRadioBtn.isSelected()) {
searchType = "Multicellular Structure";
}
String searchOptions = "";
if (ancestorCheckBox.isSelected() && descendantCheckBox.isSelected()) {
searchOptions = "ancestors, descdendants";
} else if (ancestorCheckBox.isSelected() && !descendantCheckBox.isSelected()) {
searchOptions = "ancestors";
} else if (!ancestorCheckBox.isSelected() && descendantCheckBox.isSelected()) {
searchOptions = "descendants";
}
String searchCriteria = "'" + searchField.getText() + "' (Options: " + searchType;
if (!searchOptions.isEmpty()) {
searchCriteria += ", " + searchOptions;
}
searchCriteria += ")";
final FileWriter writer = new FileWriter(output);
// write header line to file
writer.write(searchCriteria);
writer.write(lineSeparator());
for (String s : items) {
writer.write(s);
writer.write(lineSeparator());
}
writer.flush();
writer.close();
} catch (IOException e) {
System.out.println("IOException thrown writing searchLayer results to file");
}
}
@FXML
public void openInfoWindow() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.showWindow();
}
// START View->Primary Data menu items
@FXML
public void viewCellShapesIndex() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.generateCellShapesIndexWindow(sceneElementsList.getElementsList());
}
@FXML
public void viewPartsList() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.generatePartsListWindow();
}
@FXML
public void viewConnectome() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.generateConnectomeWindow(connectome.getSynapseList());
}
@FXML
public void viewCellDeaths() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.generateCellDeathsWindow(CellDeaths.getCellDeathsAsArray());
}
@FXML
public void productionInfoAction() {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.generateProductionInfoWindow();
}
// END View->Primary Data menu items
@FXML
public void openRotationController() {
if (rotationControllerStage == null) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/layouts/RotationControllerLayout.fxml"));
if (rotationController == null) {
rotationController = new RotationController(
rotateXAngleProperty,
rotateYAngleProperty,
rotateZAngleProperty);
}
rotationControllerStage = new Stage();
loader.setController(rotationController);
try {
rotationControllerStage.setScene(new Scene(loader.load()));
rotationControllerStage.setTitle("Rotation Controller");
rotationControllerStage.initOwner(mainStage);
rotationControllerStage.initModality(NONE);
rotationControllerStage.setResizable(true);
} catch (IOException e) {
System.out.println("error in initializing note editor.");
e.printStackTrace();
}
}
rotationControllerStage.show();
rotationControllerStage.toFront();
}
@FXML
public void captureVideo() {
captureVideoMenuItem.setDisable(true);
stopCaptureVideoMenuItem.setDisable(false);
// start the image capture
if (window3DController != null) {
if (!window3DController.captureImagesForMovie()) {
// error saving movie, update UI
captureVideoMenuItem.setDisable(false);
stopCaptureVideoMenuItem.setDisable(true);
capturingVideoFlag.set(false);
}
}
}
@FXML
public void stopCaptureAndSave() {
captureVideoMenuItem.setDisable(false);
stopCaptureVideoMenuItem.setDisable(true);
capturingVideoFlag.set(false);
// convert captured images to movie
if (window3DController != null) {
window3DController.convertImagesToMovie();
}
}
public void initCloseApplication() {
// check if there is an active story to prompt save dialog
if (storiesLayer.getActiveStory() != null) {
promptStorySave();
} else {
exitApplication();
}
}
private void promptStorySave() {
if (exitSavePopup == null) {
// create handlers for yes, no and cancel buttons
final EventHandler<ActionEvent> yesHandler = event -> {
exitSavePopup.hide();
if (storiesLayer.saveActiveStory()) {
exitApplication();
}
};
final EventHandler<ActionEvent> noHandler = event -> {
exitSavePopup.hide();
exitApplication();
};
final EventHandler<ActionEvent> cancelHandler = event -> exitSavePopup.hide();
exitSavePopup = new Popup();
exitSavePopup.getContent().add(new StorySavePane(
yesHandler,
noHandler,
cancelHandler));
// position dialog on screen
exitSavePopup.setAutoFix(true);
}
exitSavePopup.show(mainStage);
exitSavePopup.centerOnScreen();
}
private void exitApplication() {
System.out.println("Exiting...");
if (!defaultEmbryoFlag) {
sulstonTreeStage.hide();
mainStage.hide();
return;
}
System.exit(0);
}
private void initWindow3DController() {
final double[] xyzScale = lineageData.getXYZScale();
window3DController = new Window3DController(
mainStage,
rootEntitiesGroup,
subscene,
modelAnchorPane,
lineageData,
casesLists,
productionInfo,
connectome,
sceneElementsList,
structuresLayer.getStructuresTreeRoot(),
storiesLayer,
searchLayer,
bringUpInfoFlag,
getAvgXOffsetFromZero(),
getAvgYOffsetFromZero(),
getAvgZOffsetFromZero(),
defaultEmbryoFlag,
xyzScale[0],
xyzScale[1],
xyzScale[2],
modelAnchorPane,
backwardButton,
forwardButton,
zoomOutButton,
zoomInButton,
clearAllLabelsButton,
searchField,
opacitySlider,
uniformSizeCheckBox,
cellNucleusCheckBox,
cellBodyCheckBox,
multiRadioBtn,
startTime,
endTime,
timeProperty,
totalNucleiProperty,
zoomProperty,
othersOpacityProperty,
rotateXAngleProperty,
rotateYAngleProperty,
rotateZAngleProperty,
translateXProperty,
translateYProperty,
selectedEntityNameProperty,
selectedNameLabeledProperty,
cellClickedFlag,
playingMovieFlag,
geneResultsUpdatedFlag,
rebuildSubsceneFlag,
rulesList,
colorHash,
contextMenuStage,
contextMenuController,
searchResultsUpdateService,
searchResultsList,
timelineStage
);
timeProperty.addListener((observable, oldValue, newValue) -> {
timeSlider.setValue(timeProperty.get());
if (timeProperty.get() >= endTime - 1) {
playButton.setGraphic(playIcon);
playingMovieFlag.set(false);
}
});
timeSlider.valueProperty().addListener((observable, oldValue, newValue) -> {
final int value = newValue.intValue();
if (value != oldValue.intValue()) {
timeProperty.set(value);
rebuildSubsceneFlag.set(true);
}
});
// initial start at movie end (builds subscene automatically)
timeProperty.set(endTime);
}
public void setStage(final Stage stage) {
mainStage = stage;
}
private void addListeners() {
// searchLayer stuff
searchResultsListView.getSelectionModel()
.selectedItemProperty()
.addListener((observable, oldValue, newValue) -> selectedEntityNameProperty.set(newValue));
searchField.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.isEmpty()) {
mainTabPane.getSelectionModel().select(colorAndDisplayTab);
colorAndDisplayTabPane.getSelectionModel().select(cellsTab);
}
});
// selectedName string property that has the name of the clicked sphere
selectedEntityNameProperty.addListener((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.isEmpty()) {
setSelectedEntityInfo(selectedEntityNameProperty.get());
}
});
// Disable click on structures search results list view
structuresSearchListView.addEventFilter(MOUSE_PRESSED, Event::consume);
// Modify font for string list/tree cells
structuresSearchListView.setCellFactory(new StringCellFactory.StringListCellFactory());
searchResultsListView.setCellFactory(new StringCellFactory.StringListCellFactory());
// More info clickable text
moreInfoClickableText.setOnMouseClicked(event -> {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.addName(selectedEntityNameProperty.get());
openInfoWindow();
});
moreInfoClickableText.setOnMouseEntered(event -> moreInfoClickableText.setCursor(HAND));
moreInfoClickableText.setOnMouseExited(event -> moreInfoClickableText.setCursor(DEFAULT));
// More info in context menu
bringUpInfoFlag.addListener((observable, oldValue, newValue) -> {
if (newValue) {
if (infoWindow == null) {
initInfoWindow();
}
infoWindow.addName(selectedEntityNameProperty.get());
openInfoWindow();
}
});
}
private void setSelectedEntityInfo(String name) {
if (name == null || name.isEmpty()) {
displayedName.setText("Active Cell: none");
moreInfoClickableText.setVisible(false);
displayedDescription.setText("");
return;
}
if (name.contains("(")) {
name = name.substring(0, name.indexOf("("));
}
name = name.trim();
displayedName.setText("Active Cell: " + name);
moreInfoClickableText.setVisible(true);
if (isMulticellularStructureByName(name)) {
moreInfoClickableText.setDisable(true);
moreInfoClickableText.setFill(GRAY);
} else {
moreInfoClickableText.setDisable(false);
moreInfoClickableText.setFill(BLACK);
}
displayedDescription.setText("");
// Note
displayedDescription.setText(storiesLayer.getNoteComments(name));
// Cell body/structue
if (isStructureWithComment(name)) {
displayedDescription.setText(getStructureComment(name));
}
// Cell lineage name
else {
String functionalName = getFunctionalNameByLineageName(name);
if (functionalName != null) {
displayedName.setText("Active Cell: " + name + " (" + functionalName + ")");
displayedDescription.setText(PartsList.getDescriptionByFunctionalName(functionalName));
} else if (isInCellDeaths(name)) {
displayedName.setText("Active Cell: " + name);
displayedDescription.setText("Cell Death");
}
}
}
/**
* Binds the subscene width and height to those of its parent anchor pane
*/
private void sizeSubscene() {
subsceneWidth = new SimpleDoubleProperty();
subsceneWidth.bind(modelAnchorPane.widthProperty());
subsceneHeight = new SimpleDoubleProperty();
subsceneHeight.bind(modelAnchorPane.heightProperty());
setTopAnchor(subscene, 0.0);
setLeftAnchor(subscene, 0.0);
setRightAnchor(subscene, 0.0);
setBottomAnchor(subscene, 0.0);
subscene.widthProperty().bind(subsceneWidth);
subscene.heightProperty().bind(subsceneHeight);
subscene.setManaged(false);
}
/**
* Binds the widths and heights of components in the information panel below the subscene so that it scales nicely
*/
private void sizeInfoPane() {
infoPane.prefHeightProperty().bind(displayVBox.heightProperty().divide(6.5));
displayedDescription.wrappingWidthProperty().bind(infoPane.widthProperty().subtract(15));
displayedStory.wrappingWidthProperty().bind(infoPane.widthProperty().subtract(15));
displayedStoryDescription.wrappingWidthProperty().bind(infoPane.widthProperty().subtract(15));
}
/**
* Sets the appropriate labels for movie timeProperty and number of nuclei in a timeProperty frame
*/
private void setLabels() {
timeProperty.addListener((observable, oldValue, newValue) -> {
if (defaultEmbryoFlag) {
timeLabel.setText("~" + (newValue.intValue() + movieTimeOffset) + " min p.f.c.");
} else {
timeLabel.setText("~" + newValue.intValue() + " min");
}
});
timeLabel.setText("~" + (timeProperty.get() + movieTimeOffset) + " min p.f.c.");
timeLabel.toFront();
totalNucleiProperty.addListener((observable, oldValue, newValue) -> {
if (newValue.intValue() == 1) {
totalNucleiLabel.setText(newValue.intValue() + " Nucleus");
} else {
totalNucleiLabel.setText(newValue.intValue() + " Nuclei");
}
});
totalNucleiLabel.setText(totalNucleiProperty.get() + " Nuclei");
totalNucleiLabel.toFront();
}
/**
* Sets the icons for the GUI buttons
*/
private void setIcons() {
backwardButton.setGraphic(ImageLoader.getBackwardIcon());
forwardButton.setGraphic(ImageLoader.getForwardIcon());
zoomInButton.setGraphic(new ImageView(ImageLoader.getPlusIcon()));
zoomOutButton.setGraphic(new ImageView(ImageLoader.getMinusIcon()));
playIcon = ImageLoader.getPlayIcon();
pauseIcon = ImageLoader.getPauseIcon();
playButton.setGraphic(playIcon);
playButton.setOnAction(event -> {
playingMovieFlag.set(!playingMovieFlag.get());
if (playingMovieFlag.get()) {
playButton.setGraphic(pauseIcon);
} else {
playButton.setGraphic(playIcon);
}
});
}
private void setSlidersProperties() {
timeSlider.setMin(startTime);
timeSlider.setMax(endTime);
opacitySlider.setMin(0);
opacitySlider.setMax(100);
}
private void initSearchLayer() {
cellNucleusCheckBox.setSelected(true);
searchLayer = new SearchLayer(
rulesList,
searchResultsList,