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.base;
017    
018    import com.github.gwtbootstrap.client.ui.Dropdown;
019    import com.github.gwtbootstrap.client.ui.DropdownButton;
020    import com.github.gwtbootstrap.client.ui.constants.Constants;
021    import com.google.gwt.user.client.DOM;
022    
023    /**
024     * Icon used in Dropdowns to show the presence of a menu. Can point up- or
025     * downwards, depending on the context.
026     * <p>
027     * <h3>UiBinder Usage:</h3>
028     * {@code <b:Caret/>}
029     * </p>
030     * 
031     * @since 2.0.4.0
032     * 
033     * @author Dominik Mayer
034     * 
035     * @see DropdownBase
036     * @see Dropdown
037     * @see DropdownButton
038     * 
039     */
040    public class Caret extends AbstractTypography {
041    
042            /**
043             * Creates a visible widget.
044             */
045            public Caret() {
046                    this(true);
047            }
048    
049            /**
050             * Creates a widget that can initially be hidden.
051             * 
052             * @param visible
053             *            <code>false</code> if the caret should be hidden. Default:
054             *            <code>true</code>
055             */
056            public Caret(boolean visible) {
057                    setElement(DOM.createElement("span"));
058                    if (visible)
059                            show();
060            }
061    
062            /**
063             * Shows the widget.
064             */
065            public void show() {
066                    setStyleName(Constants.CARET);
067            }
068    
069            /**
070             * Hides the widget.
071             */
072            public void hide() {
073                    removeStyleName(Constants.CARET);
074            }
075    
076            /**
077             * Sets the visibility of the widget.
078             * 
079             * @param visible
080             *            <code>false</code> if the caret should be hidden. Default:
081             *            <code>true</code>
082             */
083            @Override
084            public void setVisible(boolean visible) {
085                    if (visible)
086                            show();
087                    else
088                            hide();
089            }
090    }