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.TethysUICoreAboutBox;
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 TethysUIFXAboutBox
32 extends TethysUICoreAboutBox {
33
34
35
36 private static final int APPROX_WIDTH = 200;
37
38
39
40
41 private static final int APPROX_HEIGHT = 100;
42
43
44
45
46 private final TethysUIFXSceneRegister theSceneRegister;
47
48
49
50
51 private final Stage theStage;
52
53
54
55
56 private final Region thePanel;
57
58
59
60
61 private Stage theDialog;
62
63
64
65
66
67
68
69 TethysUIFXAboutBox(final TethysUICoreFactory<?> pFactory,
70 final Stage pStage) {
71
72 super(pFactory);
73 if (pStage == null) {
74 throw new IllegalArgumentException("Cannot create Dialog during initialisation");
75 }
76
77
78 theSceneRegister = (TethysUIFXSceneRegister) pFactory;
79 theStage = pStage;
80 thePanel = (Region) getNode().getNode();
81 }
82
83 @Override
84 public TethysUIFXNode getNode() {
85 return (TethysUIFXNode) super.getNode();
86 }
87
88 @Override
89 public void showDialog() {
90
91 if (theDialog == null) {
92 makeDialog();
93 }
94
95
96 final double myX = (theStage.getWidth() - APPROX_WIDTH) / 2;
97 final double myY = (theStage.getHeight() - APPROX_HEIGHT) / 2;
98 theDialog.setX(theStage.getX() + myX);
99 theDialog.setY(theStage.getY() + myY);
100
101
102 theDialog.show();
103 }
104
105
106
107
108 private void makeDialog() {
109
110 theDialog = new Stage(StageStyle.UNDECORATED);
111 theDialog.initOwner(theStage);
112 theDialog.initModality(Modality.WINDOW_MODAL);
113
114
115 thePanel.getStyleClass().add("-jtethys-about");
116
117
118 final Scene myScene = new Scene(thePanel);
119 theSceneRegister.registerScene(myScene);
120 theDialog.setScene(myScene);
121 }
122
123 @Override
124 public void setPreferredWidth(final Integer pWidth) {
125 thePanel.setPrefWidth(pWidth);
126 }
127
128 @Override
129 public void setPreferredHeight(final Integer pHeight) {
130 thePanel.setPrefHeight(pHeight);
131 }
132
133 @Override
134 protected void closeDialog() {
135 theDialog.close();
136 }
137 }