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 */
016package com.github.gwtbootstrap.client.ui.base;
017
018import com.github.gwtbootstrap.client.ui.constants.Alignment;
019import com.github.gwtbootstrap.client.ui.constants.Device;
020import 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 */
043public class DivWidget extends FlowPanel implements HasStyle, IsResponsive, HasId {
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        @Deprecated
066        public void pullRight(boolean pullRight) {
067                setPullRight(pullRight);
068        }
069
070    /**
071     * Pulls the widget to the right side.
072     *
073     * @param pullRight
074     *            <code>true</code> if the widget should be aligned right.
075     */
076    public void setPullRight(boolean pullRight) {
077        if (pullRight)
078            addStyle(Alignment.RIGHT);
079        else
080            removeStyle(Alignment.RIGHT);
081    }
082
083        /**
084         * {@inheritDoc}
085         */
086        public void setStyle(Style style) {
087                StyleHelper.setStyle(this, style);
088        }
089
090        /**
091         * {@inheritDoc}
092         */
093        public void addStyle(Style style) {
094                StyleHelper.addStyle(this, style);
095        }
096
097        /**
098         * {@inheritDoc}
099         */
100        public void removeStyle(Style style) {
101                StyleHelper.removeStyle(this, style);
102        }
103
104        /**
105         * {@inheritDoc}
106         */
107        public void setShowOn(Device device) {
108                ResponsiveHelper.setShowOn(this, device);
109        }
110
111        /**
112         * {@inheritDoc}
113         */
114        public void setHideOn(Device device) {
115                ResponsiveHelper.setHideOn(this, device);
116        }
117
118    /**
119     * {@inheritDoc}
120     */
121    @Override
122    public String getId() {
123        return getElement().getId();
124    }
125
126    /**
127     * {@inheritDoc}
128     */
129    @Override
130    public void setId(String id) {
131        getElement().setId(id);
132    }
133}