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.addins.client.subheader;
021
022import com.google.gwt.dom.client.Document;
023import com.google.gwt.dom.client.Element;
024import gwt.material.design.addins.client.MaterialAddins;
025import gwt.material.design.addins.client.base.constants.AddinsCssName;
026import gwt.material.design.client.MaterialDesignBase;
027import gwt.material.design.client.base.AbstractIconButton;
028import gwt.material.design.client.constants.Color;
029
030//@formatter:off
031
032/**
033 * SubHeaders are special list tiles that delineate distinct sections of a list or grid list and are typically related
034 * to the current filtering or sorting criteria. Subheader tiles are either displayed inline with tiles or can be
035 * associated with content, for example, in an adjacent column.
036 * <p>
037 * <h3>XML Namespace Declaration</h3>
038 * <pre>
039 * {@code
040 * xmlns:ma='urn:import:gwt.material.design.addins.client'
041 * }
042 * </pre>
043 * <p>
044 * <h3>UiBinder Usage:</h3>
045 * <pre>
046 * {@code
047 *      <ma:subheader.MaterialSubHeader text="Subheader" textColor="pink" />
048 * }
049 * </pre>
050 *
051 * @author kevzlou7979
052 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#subheaders">Material Subheader</a>
053 * @see <a href="https://material.io/guidelines/components/subheaders.html">Material Design Specification</a>
054 */
055//@formatter:on
056public class MaterialSubHeader extends AbstractIconButton {
057
058    private static boolean resourcesLoaded = false;
059
060    static {
061        loadResources();
062    }
063
064    static void loadResources() {
065        if (!resourcesLoaded) {
066            if (MaterialAddins.isDebug()) {
067                MaterialDesignBase.injectDebugJs(MaterialSubHeaderDebugClientBundle.INSTANCE.subheaderJsDebug());
068                MaterialDesignBase.injectCss(MaterialSubHeaderDebugClientBundle.INSTANCE.subheaderCssDebug());
069            } else {
070                MaterialDesignBase.injectJs(MaterialSubHeaderClientBundle.INSTANCE.subheaderJs());
071                MaterialDesignBase.injectCss(MaterialSubHeaderClientBundle.INSTANCE.subheaderCss());
072            }
073            resourcesLoaded = true;
074        }
075    }
076
077    public MaterialSubHeader() {
078        super(AddinsCssName.SUBHEADER);
079    }
080
081    public MaterialSubHeader(String text) {
082        this();
083        setText(text);
084    }
085
086    public MaterialSubHeader(String text, Color textColor) {
087        this(text);
088        setTextColor(textColor);
089    }
090
091    @Override
092    protected Element createElement() {
093        return Document.get().createDivElement();
094    }
095}