001package gwt.material.design.client.ui;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 - 2016 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
023
024import com.google.gwt.dom.client.Style.Unit;
025import com.google.gwt.user.client.ui.HasText;
026import gwt.material.design.client.base.HasIcon;
027import gwt.material.design.client.base.mixin.TextMixin;
028import gwt.material.design.client.constants.IconPosition;
029import gwt.material.design.client.constants.IconSize;
030import gwt.material.design.client.constants.IconType;
031import gwt.material.design.client.ui.html.Div;
032
033public class MaterialHelpBlock extends Div implements HasText, HasIcon {
034
035    private MaterialIcon icon = new MaterialIcon();
036    private TextMixin<MaterialHelpBlock> textMixin = new TextMixin<>(this);
037
038    @Override
039    public String getText() {
040        return textMixin.getText();
041    }
042
043    @Override
044    public void setText(String text) {
045        textMixin.setText(text);
046    }
047
048    @Override
049    public MaterialIcon getIcon() {
050        return icon;
051    }
052
053    @Override
054    public void setIconType(IconType iconType) {
055        icon.setIconType(iconType);
056
057        if(!icon.isAttached()) {
058            insert(icon, 0);
059        }
060    }
061
062    @Override
063    public void setIconPosition(IconPosition position) {
064        icon.setIconPosition(position);
065    }
066
067    @Override
068    public void setIconSize(IconSize size) {
069        icon.setIconSize(size);
070    }
071
072    @Override
073    public void setIconFontSize(double size, Unit unit) {
074        icon.setIconFontSize(size, unit);
075    }
076
077    @Override
078    public void setIconColor(String iconColor) {
079        icon.setIconColor(iconColor);
080    }
081
082    @Override
083    public void setIconPrefix(boolean prefix) {
084        icon.setIconPrefix(prefix);
085    }
086
087    @Override
088    public boolean isIconPrefix() {
089        return icon.isIconPrefix();
090    }
091
092    public void clear() {
093        setText("");
094    }
095}