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