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.dom.client.Document; 023import com.google.gwt.user.client.ui.HasText; 024import gwt.material.design.client.base.AbstractValueWidget; 025import gwt.material.design.client.base.mixin.TextMixin; 026import gwt.material.design.client.constants.Color; 027import gwt.material.design.client.constants.CssName; 028 029//@formatter:off 030 031/** 032 * Material Label will extend to GWT Label functionality with other material specifications. 033 * <p> 034 * <h3>UiBinder Usage:</h3> 035 * <pre> 036 * {@code <m:MaterialLabel text="I love material design" />} 037 * </pre> 038 * 039 * @author kevzlou7979 040 * @author Ben Dol 041 * @see <a href="https://material.io/guidelines/style/typography.html">Material Design Specification</a> 042 */ 043//@formatter:on 044public class MaterialLabel extends AbstractValueWidget<String> implements HasText { 045 046 private TextMixin<MaterialLabel> textMixin; 047 048 public MaterialLabel() { 049 super(Document.get().createSpanElement(), CssName.MATERIAL_LABEL); 050 } 051 052 public MaterialLabel(String text) { 053 this(); 054 setText(text); 055 } 056 057 public MaterialLabel(String text, Color textColor) { 058 this(text); 059 setTextColor(textColor); 060 } 061 062 @Override 063 public String getText() { 064 return getValue(); 065 } 066 067 @Override 068 public void setText(String text) { 069 setValue(text, true); 070 } 071 072 @Override 073 public void setValue(String value, boolean fireEvents) { 074 getTextMixin().setText(value); 075 super.setValue(value, fireEvents); 076 } 077 078 @Override 079 public String getValue() { 080 return getTextMixin().getText(); 081 } 082 083 protected TextMixin<MaterialLabel> getTextMixin() { 084 if (textMixin == null) { 085 textMixin = new TextMixin<>(this); 086 } 087 return textMixin; 088 } 089}