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 gwt.material.design.client.base.HasHref; 024import gwt.material.design.client.base.HasNoSideNavSelection; 025import gwt.material.design.client.base.HasPosition; 026import gwt.material.design.client.base.MaterialWidget; 027import gwt.material.design.client.base.mixin.CssNameMixin; 028import gwt.material.design.client.constants.Color; 029import gwt.material.design.client.constants.CssName; 030import gwt.material.design.client.constants.Position; 031import gwt.material.design.client.ui.html.Div; 032 033//@formatter:off 034 035/** 036 * <p>Material NavBrand is a child of MaterialNavBar that will contain text or image logo 037 * <h3>UiBinder Usage:</h3> 038 * <p> 039 * <pre> 040 * {@code 041 * <m:MaterialNavBrand href="#Test" position="LEFT" text="Title"/> 042 * } 043 * </pre> 044 * </p> 045 * 046 * @author kevzlou7979 047 * @author Ben Dol 048 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#navbar">Material NavBrand</a> 049 * @see <a href="https://material.io/guidelines/components/toolbars.html#">Material Design Specification</a> 050 */ 051//@formatter:on 052public class MaterialNavBrand extends MaterialWidget implements HasHref, HasPosition, HasNoSideNavSelection { 053 054 private Div container = new Div(); 055 private CssNameMixin<MaterialNavBrand, Position> positionMixin; 056 057 /** 058 * Material NavBrand is a component wherein you can pass a text / logo branding of your app 059 */ 060 public MaterialNavBrand() { 061 super(Document.get().createAnchorElement(), CssName.BRAND_LOGO); 062 } 063 064 public MaterialNavBrand(String text) { 065 this(); 066 setText(text); 067 } 068 069 public MaterialNavBrand(String text, Color textColor) { 070 this(text); 071 setTextColor(textColor); 072 } 073 074 public void setText(String text) { 075 add(container); 076 container.getElement().setInnerText(text); 077 } 078 079 public String getText() { 080 return container.getElement().getInnerText(); 081 } 082 083 @Override 084 public String getHref() { 085 return getElement().getAttribute("href"); 086 } 087 088 @Override 089 public void setHref(String href) { 090 getElement().setAttribute("href", href); 091 } 092 093 @Override 094 public String getTarget() { 095 return getElement().getAttribute("target"); 096 } 097 098 @Override 099 public void setTarget(String target) { 100 getElement().setAttribute("target", target); 101 } 102 103 @Override 104 public Position getPosition() { 105 return getPositionMixin().getCssName(); 106 } 107 108 @Override 109 public void setPosition(Position position) { 110 getPositionMixin().setCssName(position); 111 } 112 113 public Div getContainer() { 114 return container; 115 } 116 117 protected CssNameMixin<MaterialNavBrand, Position> getPositionMixin() { 118 if (positionMixin == null) { 119 positionMixin = new CssNameMixin<>(this); 120 } 121 return positionMixin; 122 } 123}