001/* 002 * Copyright 2013 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.client.ui; 017 018import com.github.gwtbootstrap.client.ui.constants.Constants; 019import com.google.gwt.user.client.DOM; 020import com.google.gwt.user.client.ui.ComplexPanel; 021import com.google.gwt.user.client.ui.Widget; 022 023/** 024 * An IconStack overlays multiple icons to "create" a new icon. 025 * <p/> 026 * <a href="http://fontawesome.io/">Font Awesome</a> offers some icons that can be used as a frame or background for 027 * other icons, for instance {@code CIRCLE}, {@code CHECK_EMPTY} or {@code SIGN_BLANK}. 028 * 029 * <pre> 030 * {@code 031 * <b:IconStack> 032 * <b:Icon type="CIRCLE" stackBase="true"/> 033 * <b:Icon type="FLAG" light="true"/> 034 * </b:IconStack> 035 * } 036 * </pre> 037 * <p/> 038 * See <a href="http://fontawesome.io/examples/#stacked">Font Awesome</a>. 039 * 040 * @author Sven Jacobs 041 * @see Icon 042 * @see Icon#setStackBase(boolean) 043 * @see com.github.gwtbootstrap.client.ui.constants.IconType 044 * @since 2.3.2.0 045 */ 046public class IconStack extends ComplexPanel { 047 048 public IconStack() { 049 setElement(DOM.createSpan()); 050 getElement().addClassName(Constants.ICON_STACK); 051 } 052 053 /** 054 * Adds an icon to the stack. 055 * 056 * @param icon Icon to be added to the stack 057 * @param stackBase Is this icon the base (bottom icon)? 058 */ 059 public void add(final Icon icon, final boolean stackBase) { 060 icon.setStackBase(stackBase); 061 add(icon); 062 } 063 064 @Override 065 public void add(final Widget child) { 066 if (!(child instanceof Icon)) { 067 throw new IllegalArgumentException("Only instances of Icon can be children of IconStack"); 068 } 069 070 add(child, getElement()); 071 } 072}