001    /*
002     *  Copyright 2012 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     */
016    package com.github.gwtbootstrap.client.ui;
017    
018    import com.github.gwtbootstrap.client.ui.base.StyleHelper;
019    import com.github.gwtbootstrap.client.ui.constants.IconSize;
020    import com.github.gwtbootstrap.client.ui.constants.IconType;
021    import com.google.gwt.uibinder.client.UiConstructor;
022    import com.google.gwt.user.client.DOM;
023    import com.google.gwt.user.client.ui.Widget;
024    
025    //@formatter:off
026    
027    /**
028     * Widget with a black or white icon.
029     * <p>
030     * The icons are provided by <a href="http://glyphicons.com/">Glyphicons</a>
031     * and <a href="http://fortawesome.github.com/Font-Awesome/">Font Awesome</a>.
032     *
033     * <p/>
034     * <p>
035     * <h3>UiBinder Usage:</h3>
036     * <p/>
037     * <pre>
038     * {@code
039     * <b:Icon type="PLANE" />
040     * }
041     * </pre>
042     * </p>
043     *
044     * @author Carlos Alexandro Becker
045     * @author Dominik Mayer
046     * @see <a href="http://twitter.github.com/bootstrap/base-css.html#icons">Bootstrap documentation</a>
047     * @see <a href="http://fortawesome.github.com/Font-Awesome/">Font Awesome page</a>
048     * @since 2.0.4.0
049     */
050    //@formatter:on
051    public class Icon extends Widget {
052    
053        private IconType type;
054    
055        /**
056         * Creates a widget but doesn't set an icon yet.
057         * <p/>
058         * (This is probably not what you want to do most of the time.)
059         */
060        public Icon() {
061            setElement(DOM.createElement("i"));
062        }
063    
064        /**
065         * Creates a black icon of given type.
066         *
067         * @param type the icon type
068         */
069        @UiConstructor
070        public Icon(IconType type) {
071            this();
072            setType(type);
073        }
074    
075        /**
076         * Sets the icon type.
077         *
078         * @param type the icon type
079         */
080        public void setType(IconType type) {
081            this.type = type;
082            StyleHelper.changeStyle(this, type, IconType.class);
083        }
084    
085        /**
086         * Sets the icon size.
087         *
088         * @param size the icon size
089         */
090        public void setIconSize(IconSize size) {
091            StyleHelper.changeStyle(this, size, IconSize.class);
092        }
093        
094        /**
095         * Get the icon type
096         * 
097         * @return icon type.
098         */
099        public IconType getIconType() {
100            return type;
101        }
102    
103    }