001package org.gwtbootstrap3.client.ui;
002
003/*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2016 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
023import org.gwtbootstrap3.client.ui.base.ComplexWidget;
024import org.gwtbootstrap3.client.ui.base.HasHref;
025import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
026import org.gwtbootstrap3.client.ui.constants.Attributes;
027import org.gwtbootstrap3.client.ui.constants.IconType;
028import org.gwtbootstrap3.client.ui.constants.Styles;
029import org.gwtbootstrap3.client.ui.html.Span;
030
031import com.google.gwt.dom.client.AnchorElement;
032import com.google.gwt.dom.client.Document;
033import com.google.gwt.user.client.ui.HasText;
034
035/**
036 * @author Joshua Godi
037 */
038public class CarouselControl extends ComplexWidget implements HasHref, HasText {
039
040    private static final String BUTTON = "button";
041
042    private final AnchorElement anchorElem;
043    private final Icon icon;
044    private final Span span;
045
046    public CarouselControl() {
047
048        // Anchor
049        this.anchorElem = Document.get().createAnchorElement();
050        setElement(anchorElem);
051        setStyleName(Styles.CAROUSEL_CONTROL);
052        anchorElem.setAttribute(Attributes.ROLE, BUTTON);
053
054        // Icon
055        icon = new Icon();
056        add(icon);
057
058        // Span (SR_ONLY)
059        span = new Span();
060        span.setStyleName(Styles.SR_ONLY);
061        add(span);
062    }
063
064    public void setIconType(final IconType iconType) {
065        icon.setType(iconType);
066    }
067
068    public void setPrev(final boolean prev) {
069        getElement().removeAttribute(Attributes.DATA_SLIDE);
070        getElement().setAttribute(Attributes.DATA_SLIDE, Carousel.PREV);
071        StyleHelper.toggleStyleName(this, prev, Styles.LEFT);
072        icon.addStyleName(Styles.ICON_PREV);
073    }
074
075    public void setNext(final boolean next) {
076        getElement().removeAttribute(Attributes.DATA_SLIDE);
077        getElement().setAttribute(Attributes.DATA_SLIDE, Carousel.NEXT);
078        StyleHelper.toggleStyleName(this, next, Styles.RIGHT);
079        icon.addStyleName(Styles.ICON_NEXT);
080    }
081
082    @Override
083    public void setHref(String href) {
084        anchorElem.setHref(href);
085    }
086
087    @Override
088    public String getHref() {
089        return anchorElem.getHref();
090    }
091
092    @Override
093    public String getText() {
094        return span.getText();
095    }
096
097    @Override
098    public void setText(String text) {
099        span.setText(text);
100    }
101}