001package gwt.material.design.client.base; 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.Style; 024import gwt.material.design.client.constants.ButtonType; 025import gwt.material.design.client.constants.IconPosition; 026import gwt.material.design.client.constants.IconSize; 027import gwt.material.design.client.constants.IconType; 028import gwt.material.design.client.ui.MaterialIcon; 029 030/** 031 * @author Ben Dol 032 */ 033public abstract class AbstractIconButton extends AbstractButton implements HasIcon { 034 035 private MaterialIcon icon = new MaterialIcon(); 036 037 public AbstractIconButton(ButtonType type, String text, MaterialIcon icon) { 038 super(type, text); 039 040 this.icon = icon; 041 ensureIconAttached(); 042 } 043 044 public AbstractIconButton(ButtonType type, String text) { 045 super(type, text); 046 setIconPosition(IconPosition.LEFT); 047 } 048 049 public AbstractIconButton(IconType iconType) { 050 super(); 051 setIconType(iconType); 052 setIconPosition(IconPosition.LEFT); 053 } 054 055 public AbstractIconButton(ButtonType type) { 056 super(type); 057 setIconPosition(IconPosition.LEFT); 058 } 059 060 public AbstractIconButton() { 061 super(); 062 setIconPosition(IconPosition.LEFT); 063 } 064 065 public AbstractIconButton(String... initialClass) { 066 super(); 067 setInitialClasses(initialClass); 068 } 069 070 @Override 071 public MaterialIcon getIcon() { 072 return icon; 073 } 074 075 @Override 076 public void setIconType(IconType iconType) { 077 icon.setIconType(iconType); 078 ensureIconAttached(); 079 } 080 081 @Override 082 public void setIconPosition(IconPosition position) { 083 icon.setIconPosition(position); 084 } 085 086 @Override 087 public void setIconSize(IconSize size) { 088 icon.setIconSize(size); 089 } 090 091 @Override 092 public void setIconFontSize(double size, Style.Unit unit) { 093 icon.setIconFontSize(size, unit); 094 } 095 096 @Override 097 public void setIconColor(String iconColor) { 098 icon.setIconColor(iconColor); 099 } 100 101 @Override 102 public void setIconPrefix(boolean prefix) { 103 icon.setIconPrefix(prefix); 104 } 105 106 @Override 107 public boolean isIconPrefix() { 108 return icon.isIconPrefix(); 109 } 110 111 public void ensureIconAttached() { 112 if(icon != null && !icon.isAttached()) { 113 insert(icon, 0); 114 } 115 } 116}