001package gwt.material.design.addins.client.waterfall; 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.user.client.ui.Widget; 025import gwt.material.design.addins.client.MaterialAddins; 026import gwt.material.design.client.MaterialDesignBase; 027import gwt.material.design.client.base.MaterialWidget; 028 029//@formatter:off 030/** 031 * Material Waterfall - Act like a collapsible header below the nav bar component when scrolling up / down to provide delightful transition of components. 032 * 033 * <h3>XML Namespace Declaration</h3> 034 * <pre> 035 * {@code 036 * xmlns:ma='urn:import:gwt.material.design.addins.client' 037 * } 038 * </pre> 039 * 040 * <h3>UiBinder Usage:</h3> 041 * <pre> 042 * {@code 043 * 044 * <ma:waterfall.MaterialWaterfall backgroundColor="blue" textColor="white" height="280px"> 045 * <m:MaterialPanel addStyleNames="container" paddingTop="20"> 046 * <m:MaterialTitle title="GWT Material" description="Google Material Design UI / UX for GWT Applications."/> 047 * <m:MaterialAnchorButton text="Get Started" size="LARGE" backgroundColor="blue lighten-2" textColor="white"/> 048 * </m:MaterialPanel> 049 * </ma:waterfall.MaterialWaterfall> 050 * 051 * </pre> 052 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#waterfall">Material Waterfall</a> 053 * @author kevzlou7979 054 */ 055//@formatter:on 056public class MaterialWaterfall extends MaterialWidget { 057 058 static { 059 if(MaterialAddins.isDebug()) { 060 MaterialDesignBase.injectDebugJs(MaterialWaterfallDebugClientBundle.INSTANCE.waterfallJsDebug()); 061 MaterialDesignBase.injectCss(MaterialWaterfallDebugClientBundle.INSTANCE.waterfallCssDebug()); 062 } else { 063 MaterialDesignBase.injectJs(MaterialWaterfallClientBundle.INSTANCE.waterfallJs()); 064 MaterialDesignBase.injectCss(MaterialWaterfallClientBundle.INSTANCE.waterfallCss()); 065 } 066 } 067 068 private Runnable openCallback; 069 private Runnable closeCallback; 070 private double offset; 071 072 public MaterialWaterfall() { 073 super(Document.get().createDivElement(), "waterfall"); 074 setShadow(1); 075 } 076 077 @Override 078 protected void onLoad() { 079 super.onLoad(); 080 if(openCallback == null && closeCallback == null) { 081 openCallback = new Runnable() { 082 @Override 083 public void run() { 084 for(Widget w : getChildren()){ 085 w.getElement().getStyle().setOpacity(1); 086 } 087 } 088 }; 089 closeCallback = new Runnable() { 090 @Override 091 public void run() { 092 for(Widget w : getChildren()){ 093 w.getElement().getStyle().setOpacity(0); 094 } 095 } 096 }; 097 } 098 if(offset == 0){ 099 offset = getOffsetHeight(); 100 } 101 initWaterfall(getElement().getOffsetHeight(), openCallback, closeCallback, offset); 102 } 103 104 public void setCallbacks(Runnable openCallback, Runnable closeCallback) { 105 this.openCallback = openCallback; 106 this.closeCallback = closeCallback; 107 } 108 109 protected native void initWaterfall(double height, Runnable openCallback, Runnable closeCallback, double offset) /*-{ 110 $wnd.jQuery(document).ready(function() { 111 112 var openCallbackFn = $entry(function() { 113 openCallback.@java.lang.Runnable::run()(); 114 }); 115 116 var closeCallbackFn = $entry(function() { 117 closeCallback.@java.lang.Runnable::run()(); 118 }); 119 120 $wnd.initWaterfall(height, openCallbackFn, closeCallbackFn, offset); 121 }); 122 }-*/; 123 124 public double getOffset() { 125 return offset; 126 } 127 128 public void setOffset(double offset) { 129 this.offset = offset; 130 } 131}