001    package org.gwtbootstrap3.client.ui;
002    
003    /*
004     * #%L
005     * GwtBootstrap3
006     * %%
007     * Copyright (C) 2013 GwtBootstrap3
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    
023    import org.gwtbootstrap3.client.ui.base.AbstractTextWidget;
024    import org.gwtbootstrap3.client.ui.base.HasType;
025    import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
026    import org.gwtbootstrap3.client.ui.constants.LabelType;
027    import org.gwtbootstrap3.client.ui.constants.Styles;
028    
029    import com.google.gwt.dom.client.Document;
030    import com.google.gwt.event.dom.client.ClickEvent;
031    import com.google.gwt.event.dom.client.ClickHandler;
032    import com.google.gwt.event.dom.client.HasAllMouseHandlers;
033    import com.google.gwt.event.dom.client.HasClickHandlers;
034    import com.google.gwt.event.dom.client.MouseDownEvent;
035    import com.google.gwt.event.dom.client.MouseDownHandler;
036    import com.google.gwt.event.dom.client.MouseMoveEvent;
037    import com.google.gwt.event.dom.client.MouseMoveHandler;
038    import com.google.gwt.event.dom.client.MouseOutEvent;
039    import com.google.gwt.event.dom.client.MouseOutHandler;
040    import com.google.gwt.event.dom.client.MouseOverEvent;
041    import com.google.gwt.event.dom.client.MouseOverHandler;
042    import com.google.gwt.event.dom.client.MouseUpEvent;
043    import com.google.gwt.event.dom.client.MouseUpHandler;
044    import com.google.gwt.event.dom.client.MouseWheelEvent;
045    import com.google.gwt.event.dom.client.MouseWheelHandler;
046    import com.google.gwt.event.shared.HandlerRegistration;
047    
048    /**
049     * Bootstrap's label, see <a href="http://getbootstrap.com/components/#labels">documentation</a>.
050     * <p/>
051     * Not to be confused with {@code <label>} (see {@link FormLabel}) or GWT's {@link com.google.gwt.user.client.ui.Label}
052     *
053     * @author Sven Jacobs
054     * @see FormLabel
055     */
056    public class Label extends AbstractTextWidget implements HasType<LabelType>, HasClickHandlers, HasAllMouseHandlers {
057    
058        public Label() {
059            super(Document.get().createSpanElement());
060            setStyleName(Styles.LABEL);
061            setType(LabelType.DEFAULT);
062        }
063    
064        public Label(final LabelType type) {
065            this();
066            setType(type);
067        }
068    
069        public Label(final String text) {
070            this(LabelType.DEFAULT, text);
071        }
072    
073        public Label(final LabelType type, final String text) {
074            this(type);
075            setText(text);
076        }
077    
078        /**
079         * Sets type of label.
080         *
081         * @param type Type of label
082         */
083        @Override
084        public void setType(final LabelType type) {
085            StyleHelper.addUniqueEnumStyleName(this, LabelType.class, type);
086        }
087    
088        @Override
089        public LabelType getType() {
090            return LabelType.fromStyleName(getStyleName());
091        }
092    
093        @Override
094        public HandlerRegistration addClickHandler(final ClickHandler handler) {
095            return addDomHandler(handler, ClickEvent.getType());
096        }
097    
098        @Override
099        public HandlerRegistration addMouseDownHandler(final MouseDownHandler handler) {
100            return addDomHandler(handler, MouseDownEvent.getType());
101        }
102    
103        @Override
104        public HandlerRegistration addMouseMoveHandler(final MouseMoveHandler handler) {
105            return addDomHandler(handler, MouseMoveEvent.getType());
106        }
107    
108        @Override
109        public HandlerRegistration addMouseOutHandler(final MouseOutHandler handler) {
110            return addDomHandler(handler, MouseOutEvent.getType());
111        }
112    
113        @Override
114        public HandlerRegistration addMouseOverHandler(final MouseOverHandler handler) {
115            return addDomHandler(handler, MouseOverEvent.getType());
116        }
117    
118        @Override
119        public HandlerRegistration addMouseUpHandler(final MouseUpHandler handler) {
120            return addDomHandler(handler, MouseUpEvent.getType());
121        }
122    
123        @Override
124        public HandlerRegistration addMouseWheelHandler(final MouseWheelHandler handler) {
125            return addDomHandler(handler, MouseWheelEvent.getType());
126        }
127    }