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.HasDataTarget;
026    import org.gwtbootstrap3.client.ui.base.HasPull;
027    import org.gwtbootstrap3.client.ui.base.HasResponsiveness;
028    import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
029    import org.gwtbootstrap3.client.ui.base.mixin.PullMixin;
030    import org.gwtbootstrap3.client.ui.constants.DeviceSize;
031    import org.gwtbootstrap3.client.ui.constants.Pull;
032    import org.gwtbootstrap3.client.ui.constants.Styles;
033    import org.gwtbootstrap3.client.ui.constants.Toggle;
034    import org.gwtbootstrap3.client.ui.html.Span;
035    
036    import com.google.gwt.user.client.ui.Composite;
037    import com.google.gwt.user.client.ui.Widget;
038    
039    /**
040     * Special button to toggle collapsible area of {@link Navbar}.
041     *
042     * @author Sven Jacobs
043     * @author Joshua Godi
044     * @see NavbarCollapse
045     */
046    public class NavbarCollapseButton extends Composite implements HasDataTarget, HasResponsiveness, HasPull {
047    
048        private final PullMixin<NavbarCollapseButton> pullMixin = new PullMixin<NavbarCollapseButton>(this);
049        private final Button button;
050    
051        public NavbarCollapseButton() {
052            button = new Button();
053            button.setStyleName(Styles.NAVBAR_TOGGLE);
054            button.setDataToggle(Toggle.COLLAPSE);
055    
056            button.add(newBarIcon());
057            button.add(newBarIcon());
058            button.add(newBarIcon());
059    
060            initWidget(button);
061        }
062    
063        @Override
064        public void setDataTargetWidgets(final List<Widget> widgets) {
065            button.setDataTargetWidgets(widgets);
066        }
067    
068        @Override
069        public void setDataTargetWidget(final Widget widget) {
070            button.setDataTargetWidget(widget);
071        }
072    
073        @Override
074        public void setDataTarget(final String dataTarget) {
075            button.setDataTarget(dataTarget);
076        }
077    
078        @Override
079        public String getDataTarget() {
080            return button.getDataTarget();
081        }
082    
083        @Override
084        public void setVisibleOn(final DeviceSize deviceSize) {
085            StyleHelper.setVisibleOn(this, deviceSize);
086        }
087    
088        @Override
089        public void setHiddenOn(final DeviceSize deviceSize) {
090            StyleHelper.setHiddenOn(this, deviceSize);
091        }
092    
093        @Override
094        public void setPull(final Pull pull) {
095            pullMixin.setPull(pull);
096        }
097    
098        @Override
099        public Pull getPull() {
100            return pullMixin.getPull();
101        }
102    
103        private Span newBarIcon() {
104            final Span span = new Span();
105            span.setStyleName(Styles.ICON_BAR);
106            return span;
107        }
108    }