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.RadioButton;
27  
28  /**
29   * KSRadioButton wraps gwt RadioButton.  This class provides most of the same functionality, but sets KS css styles
30   * for its default look and a variety of RadioButton events (for improved browser compatibility and customizability).
31   *
32   * @author Kuali Student Team
33   *
34   */
35  public class KSRadioButton extends RadioButton{
36  
37      /**
38       * Creates a new radio button associated with a particular group name, and initialized with the given label (optionally treated as HTML).
39       *
40       * @param name the name of the radio button group
41       * @param label the text to appear in the label
42       * @param asHTML true to treat the label as HTML, false otherwise.
43       */
44      public KSRadioButton(String group, String label, boolean asHTML) {
45          super(group, label, asHTML);
46          ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(group + "-" + label));
47          setupDefaultStyle();
48      }
49  
50      /**
51       * Creates a new radio associated with a particular group name, and initialized with the given HTML label.
52       *
53       * @param name the name of the radio button group
54       * @param label the text to appear in the label
55       */
56      public KSRadioButton(String group, String label) {
57          super(group, label);
58          ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(group + "-" + label));
59          setupDefaultStyle();
60      }
61  
62      /**
63       * Creates a new radio associated with a particular group name.
64       *
65       * @param name the name of the radio button group
66       */
67      public KSRadioButton(String group) {
68          super(group);
69          setupDefaultStyle();
70      }
71  
72      /**
73       * This method sets the default style for the radio button and radio button events.
74       *
75       */
76      private void setupDefaultStyle() {
77          addStyleName("KS-Radio");
78  
79          this.addBlurHandler(new BlurHandler(){
80              public void onBlur(BlurEvent event) {
81                  KSRadioButton.this.removeStyleName("KS-Radio-Focus");
82  
83              }
84          });
85  
86          this.addFocusHandler(new FocusHandler(){
87              public void onFocus(FocusEvent event) {
88                  KSRadioButton.this.addStyleName("KS-Radio-Focus");
89  
90              }
91          });
92  
93          //hover does not function correctly on radio buttons
94  /*        this.addMouseOverHandler(new MouseOverHandler(){
95              public void onMouseOver(MouseOverEvent event) {
96                  KSRadioButton.this.addStyleName(KSStyles.KS_RADIO_HOVER_STYLE);
97  
98              }
99          });
100 
101         this.addMouseOutHandler(new MouseOutHandler(){
102 
103             public void onMouseOut(MouseOutEvent event) {
104                 KSRadioButton.this.removeStyleName(KSStyles.KS_RADIO_HOVER_STYLE);
105 
106             }
107 
108         });*/
109 
110         this.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
111         @Override
112 
113             public void onValueChange(ValueChangeEvent<Boolean> event) {
114                 if(KSRadioButton.this.getValue()){
115                     KSRadioButton.this.addStyleName("KS-Radio-Selected");
116                 }
117                 else{
118                     KSRadioButton.this.removeStyleName("KS-Radio-Selected");
119                     KSRadioButton.this.setFocus(false);
120                 }
121 
122             }
123         });
124 
125     }
126 
127 
128 }
129 
130