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.safehtml.shared.SafeHtmlUtils; 024import com.google.gwt.user.client.DOM; 025import gwt.material.design.client.base.AbstractValueWidget; 026import gwt.material.design.client.base.HasTitle; 027import gwt.material.design.client.constants.HeadingSize; 028import gwt.material.design.client.ui.html.Div; 029import gwt.material.design.client.ui.html.Heading; 030import gwt.material.design.client.ui.html.Paragraph; 031 032//@formatter:off 033 034/** 035 * Title is a component that will easily add Title and description widgets 036 * <p> 037 * <p> 038 * <h3>UiBinder Usage:</h3> 039 * <pre> 040 * {@code 041 * <m:MaterialTitle title="I love Material Design" description="This is sample description" /> 042 * } 043 * </pre> 044 * </p> 045 * 046 * @author kevzlou7979 047 * @author Ben Dol 048 */ 049//@formatter:on 050public class MaterialTitle extends AbstractValueWidget<String> implements HasTitle { 051 052 private Heading header = new Heading(HeadingSize.H4); 053 private Paragraph paragraph = new Paragraph(); 054 055 public MaterialTitle(String title, String description) { 056 this(); 057 setTitle(title); 058 setDescription(description); 059 } 060 061 public MaterialTitle(String title) { 062 this(); 063 setTitle(title); 064 } 065 066 public MaterialTitle() { 067 super(DOM.createDiv()); 068 } 069 070 @Override 071 protected void onLoad() { 072 super.onLoad(); 073 074 header.setFontWeight(300); 075 header.getElement().getStyle().setMarginTop(60, Unit.PX); 076 add(header); 077 add(paragraph); 078 } 079 080 @Override 081 public void setDescription(String description) { 082 paragraph.setText(description); 083 } 084 085 @Override 086 public void setTitle(String title) { 087 setValue(title, true); 088 } 089 090 @Override 091 public String getTitle() { 092 return getValue(); 093 } 094 095 public Heading getHeader() { 096 return header; 097 } 098 099 public Paragraph getParagraph() { 100 return paragraph; 101 } 102 103 @Override 104 public void setValue(String value, boolean fireEvents) { 105 header.getElement().setInnerSafeHtml(SafeHtmlUtils.fromString(value)); 106 super.setValue(value, fireEvents); 107 } 108 109 @Override 110 public String getValue() { 111 return header.getElement().getInnerHTML(); 112 } 113}