gwt.material.design.client.ui.MaterialRadioButton Maven / Gradle / Ivy
/*
* #%L
* GwtMaterial
* %%
* Copyright (C) 2015 - 2017 GwtMaterialDesign
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package gwt.material.design.client.ui;
import com.google.gwt.i18n.client.HasDirection.Direction;
import com.google.gwt.i18n.shared.DirectionEstimator;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RadioButton;
import gwt.material.design.client.base.HasType;
import gwt.material.design.client.base.TypeWidget;
import gwt.material.design.client.base.SelectionToggleHandler;
import gwt.material.design.client.base.mixin.CssTypeMixin;
import gwt.material.design.client.constants.RadioButtonType;
import static gwt.material.design.jquery.client.api.JQuery.$;
//@formatter:off
/**
* Material Radio button has two types
* - NO-GAP
* - GAP
* UiBinder Usage:
*
*
* {@code
*
*
* }
*
*
* @author kevzlou7979
* @see Material Radio Button
* @see Material Design Specification
*/
public class MaterialRadioButton extends RadioButton implements HasType {
private CssTypeMixin> typeMixin;
private SelectionToggleHandler selectionToggleHandler = new SelectionToggleHandler<>(this);
public MaterialRadioButton() {
super("");
}
public MaterialRadioButton(String name, SafeHtml label, Direction dir) {
super(name, label, dir);
}
public MaterialRadioButton(String name, SafeHtml label, DirectionEstimator directionEstimator) {
super(name, label, directionEstimator);
}
public MaterialRadioButton(String name, SafeHtml label) {
super(name, label);
}
public MaterialRadioButton(String name, String label, boolean asHTML) {
super(name, label, asHTML);
}
public MaterialRadioButton(String name, String label, Direction dir) {
super(name, label, dir);
}
public MaterialRadioButton(String name, String label, DirectionEstimator directionEstimator) {
super(name, label, directionEstimator);
}
public MaterialRadioButton(String name, String label) {
super(name, label);
}
public MaterialRadioButton(String name) {
super(name);
}
@Override
protected void onLoad() {
super.onLoad();
selectionToggleHandler.load();
}
@Override
protected void onUnload() {
super.onUnload();
selectionToggleHandler.unload();
}
@Override
public RadioButtonType getType() {
return getTypeMixin().getType();
}
@Override
public void setType(RadioButtonType type) {
getTypeMixin().setType(type);
}
@Override
public void setTabIndex(int index) {
getElement().setTabIndex(index);
}
protected CssTypeMixin> getTypeMixin() {
if (typeMixin == null) {
typeMixin = new CssTypeMixin<>(new TypeWidget<>(DOM.getChild(getElement(), 0)));
}
return typeMixin;
}
}