001package gwt.material.design.client.ui;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 GwtMaterialDesign
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import com.google.gwt.i18n.client.HasDirection.Direction;
024import com.google.gwt.i18n.shared.DirectionEstimator;
025import com.google.gwt.safehtml.shared.SafeHtml;
026import com.google.gwt.user.client.DOM;
027import com.google.gwt.user.client.ui.RadioButton;
028import gwt.material.design.client.base.HasGrid;
029import gwt.material.design.client.base.HasType;
030import gwt.material.design.client.base.TypeWidget;
031import gwt.material.design.client.base.mixin.CssTypeMixin;
032import gwt.material.design.client.base.mixin.GridMixin;
033import gwt.material.design.client.constants.RadioButtonType;
034
035//@formatter:off
036
037/**
038 * Material Radio button has two types
039 * - NO-GAP <br>
040 * - GAP
041 * <h3>UiBinder Usage:</h3>
042 *
043 * <pre>
044 * {@code
045 * <m:MaterialRadioButton text="Sample"/>
046 * <m:MaterialRadioButton type="GAP"/>
047}
048 * </pre>
049 * @see <a href="http://gwt-material-demo.herokuapp.com/#forms">Material Radio Button</a>
050 * @author kevzlou7979
051 */
052public class MaterialRadioButton extends RadioButton implements HasGrid, HasType<RadioButtonType> {
053
054    private CssTypeMixin<RadioButtonType, TypeWidget<RadioButtonType>> typeMixin;
055    private final GridMixin<MaterialRadioButton> gridMixin = new GridMixin<>(this);
056
057    public MaterialRadioButton() {
058        super("");
059    }
060
061    public MaterialRadioButton(String name, SafeHtml label, Direction dir) {
062        super(name, label, dir);
063    }
064
065    public MaterialRadioButton(String name, SafeHtml label, DirectionEstimator directionEstimator) {
066        super(name, label, directionEstimator);
067    }
068
069    public MaterialRadioButton(String name, SafeHtml label) {
070        super(name, label);
071    }
072
073    public MaterialRadioButton(String name, String label, boolean asHTML) {
074        super(name, label, asHTML);
075    }
076
077    public MaterialRadioButton(String name, String label, Direction dir) {
078        super(name, label, dir);
079    }
080
081    public MaterialRadioButton(String name, String label, DirectionEstimator directionEstimator) {
082        super(name, label, directionEstimator);
083    }
084
085    public MaterialRadioButton(String name, String label) {
086        super(name, label);
087    }
088
089    public MaterialRadioButton(String name) {
090        super(name);
091    }
092
093    @Override
094    public RadioButtonType getType() {
095        return typeMixin.getType();
096    }
097
098    @Override
099    public void setType(RadioButtonType type) {
100        // Since the input element handles the type
101        // styles we need to override the mixin.
102        typeMixin = new CssTypeMixin<>(new TypeWidget<RadioButtonType>(DOM.getChild(getElement(), 0)));
103        typeMixin.setType(type);
104    }
105
106    @Override
107    public void setGrid(String grid) {
108        gridMixin.setGrid(grid);
109    }
110
111    @Override
112    public void setOffset(String offset) {
113        gridMixin.setOffset(offset);
114    }
115}