1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.tethys.swing.dialog;
18
19 import io.github.tonywasher.joceanus.tethys.core.dialog.TethysUICoreBusySpinner;
20 import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
21 import io.github.tonywasher.joceanus.tethys.swing.base.TethysUISwingNode;
22
23 import javax.swing.BorderFactory;
24 import javax.swing.JDialog;
25 import javax.swing.JFrame;
26 import java.awt.Color;
27 import java.awt.Dialog.ModalityType;
28
29
30
31
32 public class TethysUISwingBusySpinner
33 extends TethysUICoreBusySpinner {
34
35
36
37 private final JFrame theFrame;
38
39
40
41
42 private JDialog theDialog;
43
44
45
46
47
48
49
50 TethysUISwingBusySpinner(final TethysUICoreFactory<?> pFactory,
51 final JFrame pFrame) {
52
53 super(pFactory);
54 if (pFrame == null) {
55 throw new IllegalArgumentException("Cannot create Dialog during initialisation");
56 }
57
58
59 theFrame = pFrame;
60 }
61
62 @Override
63 public TethysUISwingNode getNode() {
64 return (TethysUISwingNode) super.getNode();
65 }
66
67 @Override
68 public void setPreferredWidth(final Integer pWidth) {
69 getNode().setPreferredWidth(pWidth);
70 }
71
72 @Override
73 public void setPreferredHeight(final Integer pHeight) {
74 getNode().setPreferredHeight(pHeight);
75 }
76
77 @Override
78 public void showDialog() {
79
80 if (theDialog == null) {
81 makeDialog();
82 }
83
84
85 theDialog.setVisible(true);
86 }
87
88
89
90
91 private void makeDialog() {
92
93 theDialog = new JDialog(theFrame);
94 theDialog.setUndecorated(true);
95 theDialog.setModalityType(ModalityType.MODELESS);
96
97
98 getNode().getNode().setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
99
100
101 theDialog.getContentPane().add(getNode().getNode());
102 theDialog.pack();
103 theDialog.setLocationRelativeTo(theFrame);
104 }
105
106 @Override
107 public void closeDialog() {
108 if (theDialog != null) {
109 theDialog.setVisible(false);
110 }
111 }
112 }