gwt.material.design.client.ui.MaterialCheckBox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gwt-material Show documentation
Show all versions of gwt-material Show documentation
A Material Design look and feel for GWT Applications
/*
* #%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.dom.client.Element;
import com.google.gwt.dom.client.Style.Display;
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 gwt.material.design.client.base.BaseCheckBox;
import gwt.material.design.client.base.HasGrid;
import gwt.material.design.client.base.mixin.GridMixin;
import gwt.material.design.client.base.mixin.ToggleStyleMixin;
import gwt.material.design.client.constants.CheckBoxType;
import gwt.material.design.client.constants.CssName;
//@formatter:off
/**
* Checkbox component provides two types
* - FILLED
* - INTERMEDIATE
*
*
UiBinder Usage:
*
* {@code
* // Default
*
*
* // Filled
*
* }
*
*
*
* @author kevzlou7979
* @author Ben Dol
* @see CheckBox
* @see Material Design Specification
*/
public class MaterialCheckBox extends BaseCheckBox implements HasGrid {
private Object object;
private GridMixin gridMixin;
private ToggleStyleMixin toggleOldMixin;
private CheckBoxType type;
public MaterialCheckBox() {
super();
}
public MaterialCheckBox(Element elem) {
super(elem);
}
public MaterialCheckBox(SafeHtml label, Direction dir) {
super(label, dir);
}
public MaterialCheckBox(SafeHtml label, DirectionEstimator directionEstimator) {
super(label, directionEstimator);
}
public MaterialCheckBox(SafeHtml label) {
super(label);
}
public MaterialCheckBox(String label, boolean asHTML) {
super(label, asHTML);
}
public MaterialCheckBox(String label, Direction dir) {
super(label, dir);
}
public MaterialCheckBox(String label, DirectionEstimator directionEstimator) {
super(label, directionEstimator);
}
public MaterialCheckBox(String label) {
super(label);
}
public MaterialCheckBox(String label, CheckBoxType type) {
super(label);
setType(type);
}
@Override
protected void onLoad() {
super.onLoad();
getElement().getStyle().setDisplay(isVisible() ? Display.BLOCK : Display.NONE);
}
@Override
public void setGrid(String grid) {
getGridMixin().setGrid(grid);
}
@Override
public void setOffset(String offset) {
getGridMixin().setOffset(offset);
}
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
/**
* Used the old checkbox.
*/
public void setOld(boolean old) {
getToggleOldMixin().setOn(old);
}
public boolean isOld() {
return getToggleOldMixin().isOn();
}
/**
* Setting the type of Checkbox.
*/
public void setType(CheckBoxType type) {
this.type = type;
switch (type) {
case FILLED:
Element input = DOM.getChild(getElement(), 0);
input.setAttribute("class", CssName.FILLED_IN);
break;
case INTERMEDIATE:
addStyleName(type.getCssName() + "-checkbox");
break;
default:
addStyleName(type.getCssName());
break;
}
}
public CheckBoxType getType() {
return type;
}
public GridMixin getGridMixin() {
if (gridMixin == null) {
gridMixin = new GridMixin<>(this);
}
return gridMixin;
}
public ToggleStyleMixin getToggleOldMixin() {
if (toggleOldMixin == null) {
toggleOldMixin = new ToggleStyleMixin<>(this, CssName.OLD_CHECKBOX);
}
return toggleOldMixin;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy