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