View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.client.widgets;
17  
18  import org.kuali.student.common.ui.client.util.DebugIdUtils;
19  
20  import com.google.gwt.event.dom.client.BlurEvent;
21  import com.google.gwt.event.dom.client.BlurHandler;
22  import com.google.gwt.event.dom.client.FocusEvent;
23  import com.google.gwt.event.dom.client.FocusHandler;
24  import com.google.gwt.event.logical.shared.ValueChangeEvent;
25  import com.google.gwt.event.logical.shared.ValueChangeHandler;
26  import com.google.gwt.user.client.ui.CheckBox;
27  
28  
29  /**
30   * KSCheckBox wraps gwt Checkbox.  This class provides most of the same functionality, but sets KS css styles
31   * for its default look and a variety of checkbox events (for improved browser compatibility and customizability).
32   * @author Kuali Student Team
33   *
34   */
35  public class KSCheckBox extends CheckBox{
36  
37      /**
38       * Creates a check box with no label.
39       *
40       */
41      public KSCheckBox(){
42          super();
43          setupDefaultStyle();
44      }
45  
46      /**
47       * Creates a check box with the specified text label.
48       *
49       * @param label the check box's label
50       */
51      public KSCheckBox(String label){
52          super(label);
53          ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(label));
54          setupDefaultStyle();
55      }
56  
57      /**
58       * This method sets the default style for the checkbox and checkbox events.
59       *
60       */
61      private void setupDefaultStyle(){
62          addStyleName("KS-Checkbox");
63  
64          this.addBlurHandler(new BlurHandler(){
65              public void onBlur(BlurEvent event) {
66                  KSCheckBox.this.removeStyleName("KS-Checkbox-Focus");
67  
68              }
69          });
70  
71          this.addFocusHandler(new FocusHandler(){
72              public void onFocus(FocusEvent event) {
73                  KSCheckBox.this.addStyleName("KS-Checkbox-Focus");
74  
75              }
76          });
77  
78          //hover does not function fully for check boxes as is
79  /*        this.addMouseOverHandler(new MouseOverHandler(){
80              public void onMouseOver(MouseOverEvent event) {
81                  KSCheckBox.this.addStyleName(KSStyles.KS_CHECKBOX_HOVER_STYLE);
82  
83              }
84          });
85  
86          this.addMouseOutHandler(new MouseOutHandler(){
87  
88              public void onMouseOut(MouseOutEvent event) {
89                  KSCheckBox.this.removeStyleName(KSStyles.KS_CHECKBOX_HOVER_STYLE);
90  
91              }
92  
93          });*/
94  
95          this.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
96              @Override
97  
98                  public void onValueChange(ValueChangeEvent<Boolean> event) {
99                      if(KSCheckBox.this.getValue()){
100                         KSCheckBox.this.addStyleName("KS-Checkbox-Checked");
101                     }
102                     else{
103                         KSCheckBox.this.removeStyleName("KS-Checkbox-Checked");
104                         KSCheckBox.this.setFocus(false);
105                     }
106                 }
107             });
108     }
109 
110 }