001package gwt.material.design.addins.client.sideprofile;
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 com.google.gwt.dom.client.Document;
024import com.google.gwt.resources.client.ImageResource;
025import gwt.material.design.addins.client.MaterialAddins;
026import gwt.material.design.client.MaterialDesignBase;
027import gwt.material.design.client.base.HasImage;
028import gwt.material.design.client.base.MaterialWidget;
029
030//@formatter:off
031/**
032 * SideProfile is a component that is attached on SideNav Component. Consists of
033 * Image , Label and link components.
034 *
035 * <h3>XML Namespace Declaration</h3>
036 * <pre>
037 * {@code
038 * xmlns:ma='urn:import:gwt.material.design.addins.client'
039 * }
040 * </pre>
041 *
042 * <h3>UiBinder Usage:</h3>
043 * <pre>
044 * {@code
045 * <m:MaterialSideNav type="OPEN" m:id="sideNav" closeOnClick="false" width="280">
046 *    <ma:sideprofile.MaterialSideProfile url="http://static1.squarespace.com/static/51609147e4b0715db61d32b6/521b97cee4b05f031fd12dde/5519e33de4b06a1002802805/1431718693701/?format=1500w">
047 *        <m:MaterialImage url="http://b.vimeocdn.com/ps/339/488/3394886_300.jpg" />
048 *        <m:MaterialLabel text="GWT Material" textColor="white"/>
049 *        <m:MaterialLink text="gwt-material@gmail.com" activates="dropProfile" iconType="ARROW_DROP_DOWN" iconPosition="RIGHT" textColor="white"/>
050 *    </ma:sideprofile.MaterialSideProfile>
051 * </m:MaterialSideNav>
052 * }
053 * </pre>
054 *
055 * @author kevzlou7979
056 * @author Ben Dol
057 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#!sidenavs">Material Side Profile</a>
058 */
059//@formatter:on
060public class MaterialSideProfile extends MaterialWidget implements HasImage {
061
062    static {
063        if(MaterialAddins.isDebug()) {
064            MaterialDesignBase.injectCss(MaterialSideProfileDebugClientBundle.INSTANCE.sideprofileCssDebug());
065        } else {
066            MaterialDesignBase.injectCss(MaterialSideProfileClientBundle.INSTANCE.sideprofileCss());
067        }
068    }
069
070    private String url;
071    private ImageResource resource;
072
073    public MaterialSideProfile() {
074        super(Document.get().createDivElement(), "side-profile");
075    }
076
077    @Override
078    public void setUrl(String url) {
079        this.url = url;
080        applyBackground(url);
081    }
082
083    protected void applyBackground(String url) {
084        getElement().setAttribute("style", "background-image: url(" + url + "); background-size: cover;");
085    }
086
087    @Override
088    public String getUrl() {
089        return url;
090    }
091
092    @Override
093    public void setResource(ImageResource resource) {
094        this.resource = resource;
095        applyBackground(resource.getSafeUri().asString());
096    }
097
098    @Override
099    public ImageResource getResource() {
100        return resource;
101    }
102}