1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.tethys.javafx.dialog;
18
19 import javafx.scene.Scene;
20 import javafx.scene.layout.Region;
21 import javafx.stage.Modality;
22 import javafx.stage.Stage;
23 import javafx.stage.StageStyle;
24 import io.github.tonywasher.joceanus.tethys.core.dialog.TethysUICoreBusySpinner;
25 import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
26 import io.github.tonywasher.joceanus.tethys.javafx.base.TethysUIFXNode;
27
28
29
30
31 public class TethysUIFXBusySpinner
32 extends TethysUICoreBusySpinner {
33
34
35
36 private final TethysUIFXSceneRegister theSceneRegister;
37
38
39
40
41 private final Stage theStage;
42
43
44
45
46 private final Region thePanel;
47
48
49
50
51 private Stage theDialog;
52
53
54
55
56
57
58
59 TethysUIFXBusySpinner(final TethysUICoreFactory<?> pFactory,
60 final Stage pStage) {
61
62 super(pFactory);
63 if (pStage == null) {
64 throw new IllegalArgumentException("Cannot create Dialog during initialisation");
65 }
66
67
68 theSceneRegister = (TethysUIFXSceneRegister) pFactory;
69 theStage = pStage;
70 thePanel = (Region) getNode().getNode();
71 }
72
73 @Override
74 public TethysUIFXNode getNode() {
75 return (TethysUIFXNode) super.getNode();
76 }
77
78 @Override
79 public void showDialog() {
80
81 if (theDialog == null) {
82 makeDialog();
83 }
84
85
86 final double myX = (theStage.getWidth() - SPINNER_SIZE) / 2;
87 final double myY = (theStage.getHeight() - SPINNER_SIZE) / 2;
88 theDialog.setX(theStage.getX() + myX);
89 theDialog.setY(theStage.getY() + myY);
90
91
92 theDialog.show();
93 }
94
95
96
97
98 private void makeDialog() {
99
100 theDialog = new Stage(StageStyle.UNDECORATED);
101 theDialog.initOwner(theStage);
102 theDialog.initModality(Modality.NONE);
103
104
105 thePanel.getStyleClass().add("-jtethys-about");
106
107
108 final Scene myScene = new Scene(thePanel);
109 theSceneRegister.registerScene(myScene);
110 theDialog.setScene(myScene);
111 }
112
113 @Override
114 public void setPreferredWidth(final Integer pWidth) {
115 thePanel.setPrefWidth(pWidth);
116 }
117
118 @Override
119 public void setPreferredHeight(final Integer pHeight) {
120 thePanel.setPrefHeight(pHeight);
121 }
122
123 @Override
124 public void closeDialog() {
125 if (theDialog != null) {
126 theDialog.close();
127 }
128 }
129 }