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.MaterialWidget;
024import gwt.material.design.client.base.mixin.CssNameMixin;
025import gwt.material.design.client.constants.CssName;
026import gwt.material.design.client.constants.LoaderSize;
027
028//@formatter:off
029
030/**
031 * Material Preloader is a wrapper for Material Spinner which handle multiple flashing circular loaders
032 * <p>
033 * <h3>Java Usage:</h3>
034 * <pre>
035 * {@code
036 *
037 * MaterialLoader.loading(true);
038 *
039 * }
040 * <pre>
041 * @author kevzlou7979
042 * @author Ben Dol
043 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#loader">Material PreLoader</a>
044 * @see <a href="https://material.io/guidelines/components/progress-activity.html#">Material Design Specification</a>
045 */
046//@formatter:on
047public class MaterialPreLoader extends MaterialWidget {
048
049    private CssNameMixin<MaterialPreLoader, LoaderSize> sizeMixin;
050
051    public MaterialPreLoader() {
052        super(Document.get().createDivElement(), CssName.PRELOADER_WRAPPER, CssName.ACTIVE);
053    }
054
055    /**
056     * Sets the size of the pre loader.
057     */
058    public void setSize(LoaderSize size) {
059        getSizeMixin().setCssName(size);
060    }
061
062    /**
063     * Same as {@link #setSize(LoaderSize)}, but will not clash with {@link com.google.gwt.user.client.ui.UIObject#setSize(String, String)}
064     */
065    public void setLoaderSize(LoaderSize size) {
066        setSize(size);
067    }
068
069    public LoaderSize getSize() {
070        return getSizeMixin().getCssName();
071    }
072
073    public LoaderSize getLoaderSize() {
074        return getSize();
075    }
076
077    protected CssNameMixin<MaterialPreLoader, LoaderSize> getSizeMixin() {
078        if (sizeMixin == null) {
079            sizeMixin = new CssNameMixin<>(this);
080        }
081        return sizeMixin;
082    }
083}