Clover Coverage Report - Kuali Student 1.2-M5-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Aug 29 2011 05:04:27 EDT
../../../../../../../img/srcFileCovDistChart0.png 42% of files have more coverage
103   367   48   3.55
32   246   0.47   9.67
29     1.66  
3    
 
  KSLightBox       Line # 51 95 0% 43 151 0% 0.0
  KSLightBox.Size       Line # 56 3 0% 3 6 0% 0.0
  KSLightBox.KSDialogResizeHandler       Line # 350 5 0% 2 7 0% 0.0
 
No Tests
 
1   
2    /**
3    * Copyright 2010 The Kuali Foundation Licensed under the
4    * Educational Community License, Version 2.0 (the "License"); you may
5    * not use this file except in compliance with the License. You may
6    * obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
9    *
10    * Unless required by applicable law or agreed to in writing,
11    * software distributed under the License is distributed on an "AS IS"
12    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13    * or implied. See the License for the specific language governing
14    * permissions and limitations under the License.
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    * */
 
51    public class KSLightBox extends DialogBox /*implements HasCloseHandlers<KSLightBox> */{
52    // private final HandlerManager handlers = new HandlerManager(this);
53   
54    private static final List<String> FOCUSABLE_TAGS = Arrays.asList("INPUT", "SELECT", "BUTTON", "TEXTAREA");
55   
 
56    public enum Size{
57    SMALL{
 
58  0 toggle public String toString(){
59  0 return "ks-lightbox-small";
60    }
61    },
62    MEDIUM{
 
63  0 toggle public String toString(){
64  0 return "ks-lightbox-medium";
65    }
66    },
67    LARGE{
 
68  0 toggle 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();
 
89  0 toggle public KSLightBox() {
90  0 ((Widget) this.getCaption()).setVisible(false);
91  0 init();
92    }
 
93  0 toggle private void init(){
94    /*
95    * If statements change the size of the layout table to accommodate
96    * for different size ks-lightboxes.
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    //super.
130  0 closeLink.addClickHandler(new ClickHandler(){
131   
 
132  0 toggle @Override
133    public void onClick(ClickEvent event) {
134  0 hide();
135    }
136    });
137   
138   
139    }
 
140  0 toggle public KSLightBox(boolean addCloseLink) {
141  0 ((Widget) this.getCaption()).setVisible(false);
142  0 init();
143  0 closeLink.setVisible(addCloseLink);
144    }
145    /*
146    * Default constructor
147    */
 
148  0 toggle public KSLightBox(String title) {
149  0 init();
150  0 super.setText(title);
151    }
152   
153    /*Overloaded constructor makes it possible to select one of three sizes
154    * (small,medium,large) and set the size of the KS lightbox accordingly
155    * NOTE: only medium has been implemented in CSS*/
 
156  0 toggle public KSLightBox(String title,Size size)
157    {
158  0 super.setStyleName(size.toString());
159  0 init();
160  0 super.setText(title);
161    }
 
162  0 toggle public void uninstallResizeHandler(){
163  0 if(resizeHandlerRegistrater != null){
164  0 resizeHandlerRegistrater.removeHandler();
165  0 resizeHandlerRegistrater = null;
166   
167    }
168    }
 
169  0 toggle public void installResizeHandler(){
170  0 if(resizeHandlerRegistrater == null){
171  0 resizeHandlerRegistrater = Window.addResizeHandler(resizeHandler);
172    }
173    }
 
174  0 toggle public void setCloseLinkVisible(boolean visible){
175  0 closeLink.setVisible(visible);
176    }
 
177  0 toggle public void addButton(Widget button){
178  0 button.addStyleName("ks-button-spacing");
179  0 buttonPanel.add(button);
180    }
181   
 
182  0 toggle @SuppressWarnings("unchecked")
183    public void addButtonGroup(ButtonGroup group){
184  0 buttonPanel.add(group);
185    }
186   
 
187  0 toggle public void setWidget(Widget content){
188  0 verticalPanel.setWidget(0, 0, content);
189  0 verticalPanel.getRowFormatter().setStyleName(0, "ks-lightbox-contentRow");
190    }
 
191  0 toggle public void setMaxWidth(int width){
192  0 this.maxWidth = width;
193    }
 
194  0 toggle public void setMaxHeight(int height){
195  0 this.maxHeight = height;
196    }
 
197  0 toggle 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   
 
204  0 toggle public void showButtons(boolean show){
205  0 buttonPanel.setVisible(show);
206    }
207   
 
208  0 toggle @Override
209    public void hide(){
210  0 super.hide();
211  0 uninstallResizeHandler();
212    }
 
213  0 toggle @Override
214    public void show(){
215  0 resizeDialog();
216  0 installResizeHandler();
217  0 super.show();
218  0 super.center();
219  0 grabFocus();
220    }
221   
 
222  0 toggle 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    Widget mainContent = verticalPanel.getWidget(0, 0);
236    if(mainContent instanceof HasWidgets){
237    HasWidgets hasWidget = (HasWidgets) mainContent;
238    Iterator<Widget> iter = hasWidget.iterator();
239   
240    for(;iter.hasNext();){
241    Widget w = iter.next();
242    // if(w instanceof Composite ){
243    // Composite c = (Composite)w;
244    // c.
245    // }
246    if(w instanceof FocusWidget){
247    ((FocusWidget)w).setFocus(true);
248    return;
249    }else if(w instanceof HasWidgets){
250    grabFocus((HasWidgets) w);
251    }
252    }
253    }
254    */
255    }
256    /* private void grabFocus(HasWidgets hasWidgets){
257    Iterator<Widget> iter = hasWidgets.iterator();
258    for(;iter.hasNext();){
259    Widget w = iter.next();
260    if(w instanceof FocusWidget){
261    ((FocusWidget)w).setFocus(true);
262    return;
263    }else if(w instanceof HasWidgets){
264    grabFocus((HasWidgets) w);
265    }
266    }
267    }
268    */
 
269  0 toggle @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    }
 
281  0 toggle public Widget getWidget() {
282  0 return verticalPanel.getWidget(0, 0);
283    }
284   
 
285  0 toggle public void removeCloseLink(){
286  0 closeLink.setVisible(false);
287    }
288   
 
289  0 toggle public HandlerRegistration addCloseLinkClickHandler(ClickHandler clickHandler) {
290  0 return closeLink.addClickHandler(clickHandler);
291    }
292    // public HandlerRegistration addCloseHandler(CloseHandler<KSLightBox> handler){
293    // return handlers.addHandler(CloseEvent.getType(), handler);
294    // }
295   
 
296  0 toggle private void resizeDialog(){
297   
298  0 int width = maxWidth;
299  0 int height = maxHeight;
300   
301    //Width calculation
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    //Height calculation
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    /* DeferredCommand.addCommand(new Command(){
338   
339    @Override
340    public void execute() {
341    //center();
342    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
343    int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
344    setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(
345    Window.getScrollTop() + top, 0));
346    }
347    }); */
348    }
349   
 
350    class KSDialogResizeHandler implements ResizeHandler{
 
351  0 toggle @Override
352    public void onResize(ResizeEvent event) {
353  0 DeferredCommand.addCommand(new Command(){
354   
 
355  0 toggle @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    }