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.constants.Alignment;
019    import com.github.gwtbootstrap.client.ui.constants.Device;
020    import com.google.gwt.user.client.ui.FlowPanel;
021    
022    /**
023     * A simple <code>div</code> widget with support for child widgets.
024     * 
025     * <p>
026     * <h3>UiBinder Usage:</h3>
027     * 
028     * <pre>
029     * {@code
030     * <b:DivWidget>
031     *     <b:SomeChildWidget />
032     *     <b:AnotherChildWidget />
033     * </b:DivWidget>}
034     * </pre>
035     * 
036     * </p>
037     * 
038     * @since 2.0.4.0
039     * 
040     * @author Carlos Alexandro Becker
041     * @author Dominik Mayer
042     */
043    public class DivWidget extends FlowPanel implements HasStyle, IsResponsive {
044    
045            /**
046             * Creates an empty widget.
047             */
048            public DivWidget() {
049                    super();
050            }
051    
052            /**
053             * Creates a widget and sets the provided style name. Technically it
054             * replaces the <code>div<code>s <code>class</code> property with the
055             * provided String.
056             * 
057             * @param styleName
058             *            the class to be added to the <code>div</code>
059             */
060            public DivWidget(String styleName) {
061                    super();
062                    setStyleName(styleName);
063            }
064    
065            /**
066             * Pulls the widget to the right side.
067             * 
068             * @param pullRight
069             *            <code>true</code> if the widget should be aligned right.
070             */
071            public void pullRight(boolean pullRight) {
072                    if (pullRight)
073                            addStyle(Alignment.RIGHT);
074                    else
075                            removeStyle(Alignment.RIGHT);
076            }
077    
078            /**
079             * {@inheritDoc}
080             */
081            public void setStyle(Style style) {
082                    StyleHelper.setStyle(this, style);
083            }
084    
085            /**
086             * {@inheritDoc}
087             */
088            public void addStyle(Style style) {
089                    StyleHelper.addStyle(this, style);
090            }
091    
092            /**
093             * {@inheritDoc}
094             */
095            public void removeStyle(Style style) {
096                    StyleHelper.removeStyle(this, style);
097            }
098    
099            /**
100             * {@inheritDoc}
101             */
102            public void setShowOn(Device device) {
103                    ResponsiveHelper.setShowOn(this, device);
104            }
105    
106            /**
107             * {@inheritDoc}
108             */
109            public void setHideOn(Device device) {
110                    ResponsiveHelper.setHideOn(this, device);
111            }
112    }