1 package org.catacomb.druid.dialog;
2
3 import org.catacomb.druid.build.Druid;
4 import org.catacomb.interlish.structure.*;
5
6
7
8 public abstract class DialogController implements Controller {
9
10 private Druid druid;
11
12
13 public DialogController() {
14 super();
15
16 }
17
18
19 public void checkInit() {
20 if (druid == null) {
21 druid = new Druid(getDialogDeclaration());
22 druid.buildGUI();
23 druid.attachSingleController(this);
24 }
25 }
26
27 public String getDialogDeclaration() {
28 String scn = getClass().getName();
29
30 if (scn.endsWith("Controller")) {
31 scn = scn.substring(0, scn.indexOf("Controller"));
32 }
33 return scn;
34 }
35
36
37
38 public void attached() {
39 }
40
41 private boolean isShowing() {
42 return druid.isShowing();
43 }
44 public void show(Object obj) {
45 }
46
47
48 public void hideDialog() {
49 checkInit();
50 druid.hide();
51
52 }
53
54
55 public void showModalAt(int x, int y) {
56 checkInit();
57 druid.setModal(true);
58 if (isShowing()) {
59 show();
60 } else {
61 showAt(x, y);
62 }
63 }
64
65
66
67 public void showNonModalAt(int x, int y) {
68 checkInit();
69 druid.setModal(false);
70
71 if (isShowing()) {
72 show();
73 } else {
74 showAt(x, y);
75 }
76 }
77
78 protected void show() {
79 FrameShowable fs = druid.getFrameShowable();
80 fs.pack();
81 fs.show();
82 fs.toFront();
83 }
84
85
86 protected void showAt(int x, int y) {
87 checkInit();
88 FrameShowable fs = druid.getFrameShowable();
89 fs.pack();
90
91 fs.setLocation(x, y);
92
93 fs.show();
94 fs.toFront();
95 }
96
97
98 }