1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.widgets;
17
18 import java.awt.Component;
19
20 import javax.swing.JPopupMenu;
21
22 import org.xulux.api.gui.IWidget;
23 import org.xulux.api.gui.IXuluxListener;
24 import org.xulux.gui.ContainerWidget;
25
26
27
28
29
30
31
32 public class PopupMenu extends ContainerWidget {
33
34
35
36
37 protected JPopupMenu menu;
38
39
40
41
42 public PopupMenu(String name) {
43 super(name);
44 }
45
46
47
48
49 public Object getNativeWidget() {
50 if (!initialized) {
51 initialize();
52 }
53 return this.menu;
54 }
55
56
57
58
59 public void initialize() {
60 if (initialized) {
61 return;
62 }
63 this.menu = new JPopupMenu();
64 setVisible(false);
65 initialized = true;
66 initializeChildren();
67 refresh();
68 processInit();
69 }
70
71
72
73
74 public void refresh() {
75 initialize();
76 if (isVisible()) {
77
78
79 if (((Component) getParent().getNativeWidget()).isShowing()) {
80 menu.show((Component) getParent().getNativeWidget(), getRectangle().getX(), getRectangle().getY());
81 }
82 }
83 }
84
85
86
87
88 public Object getGuiValue() {
89 return null;
90 }
91
92
93
94
95 public void focus() {
96 menu.requestFocus();
97 }
98
99
100
101
102 public boolean isValueEmpty() {
103 return false;
104 }
105
106
107
108
109 public boolean canContainValue() {
110 return false;
111 }
112
113
114
115
116 public void addToParent(IWidget widget) {
117 if (widget instanceof MenuItem) {
118 menu.add((Component) widget.getNativeWidget());
119 } else {
120 System.out.println("Widgets of type " + widget.getWidgetType() + " is not supported in a popumen");
121 }
122 }
123
124
125
126 public void setVisible(boolean visible) {
127 this.visible = true;
128 if (initialized) {
129 refresh();
130 }
131 }
132
133
134
135
136 public void addXuluxListener(IXuluxListener listener) {
137 }
138
139 }