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 com.google.gwt.user.client.ui.Panel; 024import com.google.gwt.user.client.ui.RootPanel; 025import gwt.material.design.client.ui.html.Div; 026 027//@formatter:off 028 029/** 030 * 031 * <p>If you have content that will take a long time to load, you should give the user feedback. For this reason we provide a number activity + progress indicators. 032 * <h3>Java Usage:</h3> 033 * 034 * <pre> 035 * {@code 036// FOR CIRCULAR LOADER 037MaterialLoader.showLoading(true); 038// FOR PROGRESS LOADER 039MaterialLoader.showProgress(true); 040 041</pre> 042 * </p> 043 * 044 * @author kevzlou7979 045 * @author Ben Dol 046 * @see <a href="http://gwt-material-demo.herokuapp.com/#loaders">Material Loaders</a> 047 */ 048//@formatter:on 049public class MaterialLoader { 050 private static Div div = new Div(); 051 private static MaterialPreLoader preLoader = new MaterialPreLoader(); 052 private static MaterialProgress progress = new MaterialProgress(); 053 054 static { 055 div.setStyleName("valign-wrapper loader-wrapper"); 056 preLoader.getElement().getStyle().setProperty("margin", "auto"); 057 preLoader.add(new MaterialSpinner("blue")); 058 preLoader.add(new MaterialSpinner("red")); 059 preLoader.add(new MaterialSpinner("yellow")); 060 preLoader.add(new MaterialSpinner("green")); 061 } 062 063 /** 064 * Show a circular loader. 065 */ 066 public static void showLoading(boolean isShow) { 067 showLoading(isShow, RootPanel.get()); 068 } 069 070 public static void showLoading(boolean isShow, Panel con) { 071 if (isShow) { 072 if(!(con instanceof RootPanel)) { 073 div.getElement().getStyle().setProperty("position", "absolute"); 074 } 075 div.setStyleName("valign-wrapper loader-wrapper"); 076 div.add(preLoader); 077 con.add(div); 078 } else { 079 div.removeFromParent(); 080 preLoader.removeFromParent(); 081 } 082 } 083 084 /** 085 * Show a progress loader. 086 */ 087 public static void showProgress(boolean isShow) { 088 if (isShow) { 089 div.setStyleName("valign-wrapper progress-wrapper"); 090 progress.getElement().getStyle().setProperty("margin", "auto"); 091 div.add(progress); 092 RootPanel.get().add(div); 093 } else { 094 div.removeFromParent(); 095 progress.removeFromParent(); 096 } 097 } 098}