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 import java.awt.Container;
20 import java.awt.LayoutManager;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import javax.swing.JComponent;
25 import javax.swing.JPanel;
26 import javax.swing.JTabbedPane;
27
28 import org.xulux.api.gui.IShowChildWidgets;
29 import org.xulux.api.gui.IWidget;
30 import org.xulux.api.gui.IXuluxLayout;
31 import org.xulux.api.gui.IXuluxListener;
32 import org.xulux.core.XuluxContext;
33 import org.xulux.gui.ContainerWidget;
34 import org.xulux.gui.utils.ColorUtils;
35
36
37
38
39
40
41
42 public class Tab extends ContainerWidget {
43
44
45
46
47 private JPanel panel;
48
49
50
51
52
53 public Tab(String name) {
54 super(name);
55 }
56
57
58
59
60 public void destroy() {
61 super.destroy();
62 if (panel == null) {
63 return;
64 }
65 Container container = panel.getParent();
66 panel.setVisible(false);
67 panel.removeAll();
68 if (container != null) {
69 container.remove(panel);
70 }
71 panel = null;
72 }
73
74
75
76
77 public Object getNativeWidget() {
78 initialize();
79 return panel;
80 }
81
82
83
84
85
86 public void initialize() {
87 if (initialized) {
88 return;
89 }
90
91 initialized = true;
92 IXuluxLayout layout = XuluxContext.getGuiDefaults().getLayout(null, getProperty("layout"));
93 if (layout == null) {
94 layout = XuluxContext.getGuiDefaults().getDefaultLayout();
95 }
96 layout.setParent(this);
97 panel = new JPanel((LayoutManager) layout);
98 initializeChildren();
99 refresh();
100 processInit();
101 }
102
103
104
105
106 public void refresh() {
107 initialize();
108 isRefreshing = true;
109 String backgroundColor = getProperty("default-background-color");
110
111 if (backgroundColor != null) {
112 panel.setBackground(ColorUtils.getSwingColor(backgroundColor));
113 }
114 String tabId = getProperty(TabPanel.TABID);
115 if (tabId == null) {
116 panel.setEnabled(isEnabled());
117 } else {
118 int tabInt = Integer.parseInt(tabId);
119 if (tabInt == ((JTabbedPane) getParent().getNativeWidget()).getSelectedIndex()) {
120 ((JTabbedPane) getParent().getNativeWidget()).setEnabledAt(Integer.parseInt(tabId), isEnabled());
121 }
122 }
123 isRefreshing = false;
124 }
125
126
127
128
129 public boolean canContainChildren() {
130 return true;
131 }
132
133
134
135
136 public List getChildWidgets() {
137 return widgets;
138 }
139
140
141
142
143 public void addToParent(IWidget widget) {
144 if (widget instanceof IShowChildWidgets) {
145 List children = widget.getChildWidgets();
146 if (children != null && children.size() > 0) {
147 Iterator it = children.iterator();
148 while (it.hasNext()) {
149 IWidget w = (IWidget) it.next();
150 panel.add((JComponent) w.getNativeWidget(), w);
151 w.refresh();
152 }
153 }
154 } else {
155 panel.add((Component) widget.getNativeWidget(), widget);
156 widget.refresh();
157 }
158 }
159
160
161
162
163 public void focus() {
164 isRefreshing = true;
165 panel.requestFocus();
166 isRefreshing = false;
167
168
169
170 if (!panel.isShowing() && getParent() != null ||
171 getProperty(TabPanel.TABID) != null) {
172
173
174 getPart().getSession().setValue("nyx.focusrequest", this);
175 getParent().focus();
176
177 getPart().getSession().remove("nyx.focusrequest");
178 panel.requestFocus();
179 }
180 }
181
182
183
184 public Object getGuiValue() {
185 return null;
186 }
187
188
189
190
191 public boolean canContainValue() {
192 return false;
193 }
194
195
196
197
198 public boolean isValueEmpty() {
199 return true;
200 }
201
202
203
204
205 public void addXuluxListener(IXuluxListener listener) {
206 }
207
208 }