001package gwt.material.design.addins.client.iconmorph; 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 gwt.material.design.addins.client.MaterialAddins; 025import gwt.material.design.client.MaterialDesignBase; 026import gwt.material.design.client.base.MaterialWidget; 027import gwt.material.design.client.base.mixin.CssNameMixin; 028import gwt.material.design.client.constants.IconSize; 029import gwt.material.design.client.ui.MaterialIcon; 030import gwt.material.design.client.ui.MaterialToast; 031 032//@formatter:off 033/** 034 * Provides visual continuity by morphing two material icons. 035 * 036 * <h3>XML Namespace Declaration</h3> 037 * <pre> 038 * {@code 039 * xmlns:ma='urn:import:gwt.material.design.addins.client' 040 * } 041 * </pre> 042 * 043 * <h3>UiBinder Usage:</h3> 044 * <pre> 045 * {@code 046 * <ma:iconmorph.MaterialIconMorph iconSize="SMALL"> 047 * <m:MaterialIcon iconType="POLYMER"/> 048 * <m:MaterialIcon iconType="DONE"/> 049 * </ma:iconmorph.MaterialIconMorph> 050 * } 051 * </pre> 052 * 053 * @author kevzlou7979 054 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/snapshot/#morphingIcons">Material Icon Morph</a> 055 */ 056//@formatter:on 057public class MaterialIconMorph extends MaterialWidget { 058 059 static { 060 if(MaterialAddins.isDebug()) { 061 MaterialDesignBase.injectCss(MaterialIconMorphDebugClientBundle.INSTANCE.morphCssDebug()); 062 } else { 063 MaterialDesignBase.injectCss(MaterialIconMorphClientBundle.INSTANCE.morphCss()); 064 } 065 } 066 067 private final CssNameMixin<MaterialIconMorph, IconSize> sizeMixin = new CssNameMixin<>(this); 068 069 public MaterialIconMorph() { 070 super(Document.get().createDivElement(), "anim-container"); 071 getElement().setAttribute("onclick", "this.classList.toggle('morphed')"); 072 } 073 074 @Override 075 protected void onLoad() { 076 super.onLoad(); 077 if (getWidgetCount() >= 2) { 078 MaterialIcon source = (MaterialIcon) getWidget(0); 079 source.addStyleName("icons source"); 080 MaterialIcon target = (MaterialIcon) getWidget(1); 081 target.addStyleName("icons target"); 082 }else{ 083 MaterialToast.fireToast("Nothing"); 084 } 085 } 086 087 public void setIconSize(IconSize size) { 088 sizeMixin.setCssName(size); 089 } 090}