001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.ui.client.widgets;
017    
018    import com.google.gwt.event.dom.client.BlurEvent;
019    import com.google.gwt.event.dom.client.BlurHandler;
020    import com.google.gwt.event.dom.client.FocusEvent;
021    import com.google.gwt.event.dom.client.FocusHandler;
022    import com.google.gwt.event.logical.shared.ValueChangeEvent;
023    import com.google.gwt.event.logical.shared.ValueChangeHandler;
024    import com.google.gwt.user.client.ui.RadioButton;
025    
026    /**
027     * KSRadioButton wraps gwt RadioButton.  This class provides most of the same functionality, but sets KS css styles
028     * for its default look and a variety of RadioButton events (for improved browser compatibility and customizability).
029     *
030     * @author Kuali Student Team
031     *
032     */
033    public class KSRadioButton extends RadioButton{
034    
035        /**
036         * Creates a new radio button associated with a particular group name, and initialized with the given label (optionally treated as HTML).
037         *
038         * @param name the name of the radio button group
039         * @param label the text to appear in the label
040         * @param asHTML true to treat the label as HTML, false otherwise.
041         */
042        public KSRadioButton(String group, String label, boolean asHTML) {
043            super(group, label, asHTML);
044            setupDefaultStyle();
045        }
046    
047        /**
048         * Creates a new radio associated with a particular group name, and initialized with the given HTML label.
049         *
050         * @param name the name of the radio button group
051         * @param label the text to appear in the label
052         */
053        public KSRadioButton(String group, String label) {
054            super(group, label);
055            setupDefaultStyle();
056        }
057    
058        /**
059         * Creates a new radio associated with a particular group name.
060         *
061         * @param name the name of the radio button group
062         */
063        public KSRadioButton(String group) {
064            super(group);
065            setupDefaultStyle();
066        }
067    
068        /**
069         * This method sets the default style for the radio button and radio button events.
070         *
071         */
072        private void setupDefaultStyle() {
073            addStyleName("KS-Radio");
074    
075            this.addBlurHandler(new BlurHandler(){
076                public void onBlur(BlurEvent event) {
077                    KSRadioButton.this.removeStyleName("KS-Radio-Focus");
078    
079                }
080            });
081    
082            this.addFocusHandler(new FocusHandler(){
083                public void onFocus(FocusEvent event) {
084                    KSRadioButton.this.addStyleName("KS-Radio-Focus");
085    
086                }
087            });
088    
089            //hover does not function correctly on radio buttons
090    /*        this.addMouseOverHandler(new MouseOverHandler(){
091                public void onMouseOver(MouseOverEvent event) {
092                    KSRadioButton.this.addStyleName(KSStyles.KS_RADIO_HOVER_STYLE);
093    
094                }
095            });
096    
097            this.addMouseOutHandler(new MouseOutHandler(){
098    
099                public void onMouseOut(MouseOutEvent event) {
100                    KSRadioButton.this.removeStyleName(KSStyles.KS_RADIO_HOVER_STYLE);
101    
102                }
103    
104            });*/
105    
106            this.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
107            @Override
108    
109                public void onValueChange(ValueChangeEvent<Boolean> event) {
110                    if(KSRadioButton.this.getValue()){
111                        KSRadioButton.this.addStyleName("KS-Radio-Selected");
112                    }
113                    else{
114                        KSRadioButton.this.removeStyleName("KS-Radio-Selected");
115                        KSRadioButton.this.setFocus(false);
116                    }
117    
118                }
119            });
120    
121        }
122    
123    
124    }
125    
126