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 java.util.List;
024
025 import org.gwtbootstrap3.client.ui.base.ComplexWidget;
026 import org.gwtbootstrap3.client.ui.base.HasDataTarget;
027 import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
028 import org.gwtbootstrap3.client.ui.base.mixin.DataTargetMixin;
029 import org.gwtbootstrap3.client.ui.constants.Attributes;
030 import org.gwtbootstrap3.client.ui.constants.IconType;
031 import org.gwtbootstrap3.client.ui.constants.Styles;
032
033 import com.google.gwt.dom.client.Document;
034 import com.google.gwt.user.client.ui.Widget;
035
036 /**
037 * @author Joshua Godi
038 */
039 public class CarouselControl extends ComplexWidget implements HasDataTarget {
040 private final DataTargetMixin<CarouselControl> targetMixin = new DataTargetMixin<CarouselControl>(this);
041
042 private final Icon icon = new Icon();
043
044 public CarouselControl() {
045 setElement(Document.get().createAnchorElement());
046 setStyleName(Styles.CAROUSEL_CONTROL);
047
048 add(icon);
049 }
050
051 public void setIconType(final IconType iconType) {
052 icon.setType(iconType);
053 }
054
055 public void setPrev(final boolean prev) {
056 getElement().removeAttribute(Attributes.DATA_SLIDE);
057 getElement().setAttribute(Attributes.DATA_SLIDE, Carousel.PREV);
058 StyleHelper.toggleStyleName(this, prev, Styles.LEFT);
059 icon.addStyleName(Styles.ICON_PREV);
060 }
061
062 public void setNext(final boolean next) {
063 getElement().removeAttribute(Attributes.DATA_SLIDE);
064 getElement().setAttribute(Attributes.DATA_SLIDE, Carousel.NEXT);
065 StyleHelper.toggleStyleName(this, next, Styles.RIGHT);
066 icon.addStyleName(Styles.ICON_NEXT);
067 }
068
069 @Override
070 public void setDataTargetWidgets(final List<Widget> widgets) {
071 targetMixin.setDataTargetWidgets(widgets);
072 }
073
074 @Override
075 public void setDataTargetWidget(final Widget widget) {
076 targetMixin.setDataTargetWidget(widget);
077 }
078
079 @Override
080 public void setDataTarget(final String dataTarget) {
081 targetMixin.setDataTarget(dataTarget);
082 }
083
084 @Override
085 public String getDataTarget() {
086 return targetMixin.getDataTarget();
087 }
088 }