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