1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.kuali.student.common.ui.client.widgets; |
18 |
|
|
19 |
|
import java.util.Arrays; |
20 |
|
import java.util.List; |
21 |
|
|
22 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup; |
23 |
|
|
24 |
|
import com.google.gwt.dom.client.Element; |
25 |
|
import com.google.gwt.dom.client.NativeEvent; |
26 |
|
import com.google.gwt.dom.client.NodeList; |
27 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
28 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
29 |
|
import com.google.gwt.event.dom.client.KeyCodes; |
30 |
|
import com.google.gwt.event.logical.shared.ResizeEvent; |
31 |
|
import com.google.gwt.event.logical.shared.ResizeHandler; |
32 |
|
import com.google.gwt.event.shared.HandlerRegistration; |
33 |
|
import com.google.gwt.user.client.Command; |
34 |
|
import com.google.gwt.user.client.DeferredCommand; |
35 |
|
import com.google.gwt.user.client.Window; |
36 |
|
import com.google.gwt.user.client.Event.NativePreviewEvent; |
37 |
|
import com.google.gwt.user.client.ui.Anchor; |
38 |
|
import com.google.gwt.user.client.ui.Composite; |
39 |
|
import com.google.gwt.user.client.ui.DialogBox; |
40 |
|
import com.google.gwt.user.client.ui.FlexTable; |
41 |
|
import com.google.gwt.user.client.ui.FlowPanel; |
42 |
|
import com.google.gwt.user.client.ui.FocusWidget; |
43 |
|
import com.google.gwt.user.client.ui.HasWidgets; |
44 |
|
import com.google.gwt.user.client.ui.HorizontalPanel; |
45 |
|
import com.google.gwt.user.client.ui.ScrollPanel; |
46 |
|
import com.google.gwt.user.client.ui.Widget; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 0% |
Uncovered Elements: 151 (151) |
Complexity: 43 |
Complexity Density: 0.45 |
|
51 |
|
public class KSLightBox extends DialogBox { |
52 |
|
|
53 |
|
|
54 |
|
private static final List<String> FOCUSABLE_TAGS = Arrays.asList("INPUT", "SELECT", "BUTTON", "TEXTAREA"); |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
56 |
|
public enum Size{ |
57 |
|
SMALL{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0
|
public String toString(){... |
59 |
0
|
return "ks-lightbox-small"; |
60 |
|
} |
61 |
|
}, |
62 |
|
MEDIUM{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0
|
public String toString(){... |
64 |
0
|
return "ks-lightbox-medium"; |
65 |
|
} |
66 |
|
}, |
67 |
|
LARGE{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
0
|
public String toString(){... |
69 |
0
|
return "ks-lightbox-large"; |
70 |
|
} |
71 |
|
} |
72 |
|
} |
73 |
|
private int maxWidth = 800; |
74 |
|
private int maxHeight = 0; |
75 |
|
private int minWidth = 400; |
76 |
|
private int minHeight = 200; |
77 |
|
private int permWidth = -1; |
78 |
|
private int permHeight = -1; |
79 |
|
private FlowPanel mainPanel = new FlowPanel(); |
80 |
|
private FlowPanel titlePanel = new FlowPanel(); |
81 |
|
private ScrollPanel scrollPanel = new ScrollPanel(); |
82 |
|
|
83 |
|
private Anchor closeLink = new Anchor(); |
84 |
|
private KSDialogResizeHandler resizeHandler = new KSDialogResizeHandler(); |
85 |
|
private HandlerRegistration resizeHandlerRegistrater; |
86 |
|
|
87 |
|
private FlexTable verticalPanel = new FlexTable(); |
88 |
|
private HorizontalPanel buttonPanel = new HorizontalPanel(); |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
89 |
0
|
public KSLightBox() {... |
90 |
0
|
((Widget) this.getCaption()).setVisible(false); |
91 |
0
|
init(); |
92 |
|
} |
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 4 |
Complexity Density: 0.18 |
|
93 |
0
|
private void init(){... |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0
|
if(super.getStyleName().equals("ks-lightbox-small")) |
99 |
0
|
verticalPanel.setStyleName("ks-lightbox-small-layoutTable"); |
100 |
|
|
101 |
0
|
else if(super.getStyleName().equals("ks-lightbox-medium")) |
102 |
0
|
verticalPanel.setStyleName("ks-lightbox-medium-layoutTable"); |
103 |
|
|
104 |
0
|
else if(super.getStyleName().equals("ks-lightbox-large")) |
105 |
0
|
verticalPanel.setStyleName("ks-lightbox-large-layoutTable"); |
106 |
|
|
107 |
|
else{ |
108 |
0
|
verticalPanel.setStyleName("ks-lightbox-layoutTable"); |
109 |
0
|
super.setStyleName("ks-lightbox"); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
0
|
mainPanel.setStyleName("ks-lightbox-mainPanel"); |
114 |
0
|
titlePanel.setStyleName("ks-lightbox-titlePanel"); |
115 |
0
|
closeLink.setStyleName("ks-lightbox-title-closeLink"); |
116 |
0
|
scrollPanel.setStyleName("ks-lightbox-title-scrollPanel"); |
117 |
|
|
118 |
0
|
setGlassEnabled(true); |
119 |
0
|
super.setWidget(mainPanel); |
120 |
0
|
mainPanel.add(titlePanel); |
121 |
0
|
mainPanel.add(scrollPanel); |
122 |
0
|
titlePanel.add(closeLink); |
123 |
|
|
124 |
0
|
verticalPanel.setWidget(1, 0, buttonPanel); |
125 |
0
|
verticalPanel.getRowFormatter().setStyleName(1, "ks-lightbox-buttonRow"); |
126 |
0
|
scrollPanel.add(verticalPanel); |
127 |
|
|
128 |
0
|
installResizeHandler(); |
129 |
|
|
130 |
0
|
closeLink.addClickHandler(new ClickHandler(){ |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0
|
@Override... |
133 |
|
public void onClick(ClickEvent event) { |
134 |
0
|
hide(); |
135 |
|
} |
136 |
|
}); |
137 |
|
|
138 |
|
|
139 |
|
} |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
140 |
0
|
public KSLightBox(boolean addCloseLink) {... |
141 |
0
|
((Widget) this.getCaption()).setVisible(false); |
142 |
0
|
init(); |
143 |
0
|
closeLink.setVisible(addCloseLink); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
148 |
0
|
public KSLightBox(String title) {... |
149 |
0
|
init(); |
150 |
0
|
super.setText(title); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
156 |
0
|
public KSLightBox(String title,Size size)... |
157 |
|
{ |
158 |
0
|
super.setStyleName(size.toString()); |
159 |
0
|
init(); |
160 |
0
|
super.setText(title); |
161 |
|
} |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
162 |
0
|
public void uninstallResizeHandler(){... |
163 |
0
|
if(resizeHandlerRegistrater != null){ |
164 |
0
|
resizeHandlerRegistrater.removeHandler(); |
165 |
0
|
resizeHandlerRegistrater = null; |
166 |
|
|
167 |
|
} |
168 |
|
} |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
169 |
0
|
public void installResizeHandler(){... |
170 |
0
|
if(resizeHandlerRegistrater == null){ |
171 |
0
|
resizeHandlerRegistrater = Window.addResizeHandler(resizeHandler); |
172 |
|
} |
173 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0
|
public void setCloseLinkVisible(boolean visible){... |
175 |
0
|
closeLink.setVisible(visible); |
176 |
|
} |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
177 |
0
|
public void addButton(Widget button){... |
178 |
0
|
button.addStyleName("ks-button-spacing"); |
179 |
0
|
buttonPanel.add(button); |
180 |
|
} |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0
|
@SuppressWarnings("unchecked")... |
183 |
|
public void addButtonGroup(ButtonGroup group){ |
184 |
0
|
buttonPanel.add(group); |
185 |
|
} |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
187 |
0
|
public void setWidget(Widget content){... |
188 |
0
|
verticalPanel.setWidget(0, 0, content); |
189 |
0
|
verticalPanel.getRowFormatter().setStyleName(0, "ks-lightbox-contentRow"); |
190 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
0
|
public void setMaxWidth(int width){... |
192 |
0
|
this.maxWidth = width; |
193 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
194 |
0
|
public void setMaxHeight(int height){... |
195 |
0
|
this.maxHeight = height; |
196 |
|
} |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
197 |
0
|
public void setSize(int width, int height){... |
198 |
0
|
super.setSize(width+"px", height+"px"); |
199 |
0
|
this.permHeight = height; |
200 |
0
|
this.permWidth = width; |
201 |
0
|
scrollPanel.setSize((width+10)+"px", (height+10)+"px"); |
202 |
|
} |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
0
|
public void showButtons(boolean show){... |
205 |
0
|
buttonPanel.setVisible(show); |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
208 |
0
|
@Override... |
209 |
|
public void hide(){ |
210 |
0
|
super.hide(); |
211 |
0
|
uninstallResizeHandler(); |
212 |
|
} |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
213 |
0
|
@Override... |
214 |
|
public void show(){ |
215 |
0
|
resizeDialog(); |
216 |
0
|
installResizeHandler(); |
217 |
0
|
super.show(); |
218 |
0
|
super.center(); |
219 |
0
|
grabFocus(); |
220 |
|
} |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
222 |
0
|
private void grabFocus() {... |
223 |
0
|
Widget mainContent = verticalPanel.getWidget(0, 0); |
224 |
0
|
NodeList<Element> nodeList = mainContent.getElement().getElementsByTagName("*"); |
225 |
0
|
for (int i = 0; i < nodeList.getLength(); i++) { |
226 |
0
|
Element e = nodeList.getItem(i); |
227 |
0
|
if (FOCUSABLE_TAGS.contains(e.getTagName().toUpperCase())) { |
228 |
0
|
e.focus(); |
229 |
0
|
return; |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
269 |
0
|
@Override... |
270 |
|
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
271 |
0
|
super.onPreviewNativeEvent(preview); |
272 |
0
|
NativeEvent evt = preview.getNativeEvent(); |
273 |
0
|
if (evt.getType().equals("keydown")) { |
274 |
0
|
switch (evt.getKeyCode()) { |
275 |
0
|
case KeyCodes.KEY_ESCAPE: |
276 |
0
|
hide(); |
277 |
0
|
break; |
278 |
|
} |
279 |
|
} |
280 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
281 |
0
|
public Widget getWidget() {... |
282 |
0
|
return verticalPanel.getWidget(0, 0); |
283 |
|
} |
284 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
285 |
0
|
public void removeCloseLink(){... |
286 |
0
|
closeLink.setVisible(false); |
287 |
|
} |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
289 |
0
|
public HandlerRegistration addCloseLinkClickHandler(ClickHandler clickHandler) {... |
290 |
0
|
return closeLink.addClickHandler(clickHandler); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 11 |
Complexity Density: 0.55 |
|
296 |
0
|
private void resizeDialog(){... |
297 |
|
|
298 |
0
|
int width = maxWidth; |
299 |
0
|
int height = maxHeight; |
300 |
|
|
301 |
|
|
302 |
0
|
if(permWidth != -1){ |
303 |
0
|
width = permWidth; |
304 |
|
} |
305 |
|
else{ |
306 |
0
|
if (Window.getClientWidth() < 850){ |
307 |
0
|
width = Window.getClientWidth() - 160; |
308 |
|
} |
309 |
0
|
if(width > maxWidth){ |
310 |
0
|
width = maxWidth; |
311 |
|
} |
312 |
0
|
if(width < minWidth){ |
313 |
0
|
width = minWidth; |
314 |
|
} |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
0
|
if(permHeight != -1){ |
319 |
0
|
height = permHeight; |
320 |
|
} |
321 |
|
else{ |
322 |
0
|
height = Window.getClientHeight() - 160; |
323 |
|
|
324 |
0
|
if(height > maxHeight && maxHeight != 0){ |
325 |
0
|
height = maxHeight; |
326 |
|
} |
327 |
0
|
if(height < minHeight){ |
328 |
0
|
height = minHeight; |
329 |
|
} |
330 |
|
} |
331 |
|
|
332 |
0
|
if(width > 0 && height > 0){ |
333 |
0
|
super.setSize(width + "px", height + "px"); |
334 |
0
|
scrollPanel.setSize((width+10)+"px", (height+10)+"px"); |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
} |
349 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
350 |
|
class KSDialogResizeHandler implements ResizeHandler{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
351 |
0
|
@Override... |
352 |
|
public void onResize(ResizeEvent event) { |
353 |
0
|
DeferredCommand.addCommand(new Command(){ |
354 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
355 |
0
|
@Override... |
356 |
|
public void execute() { |
357 |
0
|
resizeDialog(); |
358 |
0
|
int left = (Window.getClientWidth() - getOffsetWidth()) >> 1; |
359 |
0
|
int top = (Window.getClientHeight() - getOffsetHeight()) >> 1; |
360 |
0
|
setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max( |
361 |
|
Window.getScrollTop() + top, 0)); |
362 |
|
} |
363 |
|
}); |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
|
} |