001package gwt.material.design.client.ui; 002 003/* 004 * #%L 005 * GwtMaterial 006 * %% 007 * Copyright (C) 2015 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 023import gwt.material.design.client.base.MaterialWidget; 024import gwt.material.design.client.base.HasPosition; 025import gwt.material.design.client.base.mixin.CssNameMixin; 026import gwt.material.design.client.ui.html.Div; 027import gwt.material.design.client.base.HasHref; 028import gwt.material.design.client.constants.Position; 029 030import com.google.gwt.dom.client.Document; 031import com.google.gwt.uibinder.client.UiConstructor; 032import com.google.gwt.user.client.ui.HasText; 033 034//@formatter:off 035/** 036* 037* <p>Material NavBrand is a child of MaterialNavBar that will contain text or image logo 038* <h3>UiBinder Usage:</h3> 039* 040* <pre> 041* {@code 042<m:MaterialNavBrand href="#Test" position="LEFT">Title</m:MaterialNavBrand> 043} 044</pre> 045* </p> 046* 047* @author kevzlou7979 048* @author Ben Dol 049* @see <a href="http://gwt-material-demo.herokuapp.com/#navigations">Material NavBrand</a> 050*/ 051//@formatter:on 052public class MaterialNavBrand extends MaterialWidget implements HasText, HasHref, HasPosition { 053 054 private Div div = new Div(); 055 056 private final CssNameMixin<MaterialNavBrand, Position> posMixin = new CssNameMixin<>(this); 057 058 /** 059 * Material NavBrand is a component wherein you can pass a text / logo branding of your app 060 */ 061 @UiConstructor 062 public MaterialNavBrand() { 063 super(Document.get().createElement("a"), "brand-logo"); 064 065 } 066 067 @Override 068 public void setText(String text) { 069 add(div); 070 div.getElement().setInnerText(text); 071 } 072 073 @Override 074 public String getText() { 075 return div.getElement().getInnerText(); 076 } 077 078 @Override 079 public String getHref() { 080 return getElement().getAttribute("href"); 081 } 082 083 @Override 084 public void setHref(String href) { 085 getElement().setAttribute("href", href); 086 } 087 088 @Override 089 public String getTarget() { 090 return getElement().getAttribute("target"); 091 } 092 093 @Override 094 public void setTarget(String target) { 095 getElement().setAttribute("target", target); 096 } 097 098 @Override 099 public Position getPosition() { 100 return posMixin.getCssName(); 101 } 102 103 @Override 104 public void setPosition(Position position) { 105 posMixin.setCssName(position); 106 } 107}