001    package org.gwtbootstrap3.client.ui.base;
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 org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
024    import org.gwtbootstrap3.client.ui.base.mixin.IdMixin;
025    import org.gwtbootstrap3.client.ui.base.mixin.PullMixin;
026    import org.gwtbootstrap3.client.ui.constants.DeviceSize;
027    import org.gwtbootstrap3.client.ui.constants.Pull;
028    
029    import com.google.gwt.dom.client.Element;
030    import com.google.gwt.dom.client.Style;
031    import com.google.gwt.user.client.ui.ComplexPanel;
032    import com.google.gwt.user.client.ui.Widget;
033    
034    /**
035     * Base class for widgets that contain further widgets.
036     *
037     * @author Sven Jacobs
038     */
039    public class ComplexWidget extends ComplexPanel implements HasId, HasResponsiveness, HasInlineStyle, HasPull {
040        private final IdMixin<ComplexWidget> idMixin = new IdMixin<ComplexWidget>(this);
041        private final PullMixin<ComplexWidget> pullMixin = new PullMixin<ComplexWidget>(this);
042    
043        /**
044         * {@inheritDoc}
045         */
046        @Override
047        public void add(final Widget child) {
048            add(child, (Element) getElement());
049        }
050    
051        /**
052         * Inserts a widget at a specific index
053         *
054         * @param child       - widget to be inserted
055         * @param beforeIndex - index for the widget
056         */
057        public void insert(final Widget child, final int beforeIndex) {
058            insert(child, (Element) getElement(), beforeIndex, true);
059        }
060    
061        /**
062         * {@inheritDoc}
063         */
064        @Override
065        public void setId(final String id) {
066            idMixin.setId(id);
067        }
068    
069        /**
070         * {@inheritDoc}
071         */
072        @Override
073        public String getId() {
074            return idMixin.getId();
075        }
076    
077        /**
078         * {@inheritDoc}
079         */
080        @Override
081        public void setVisibleOn(final DeviceSize deviceSize) {
082            StyleHelper.setVisibleOn(this, deviceSize);
083        }
084    
085        /**
086         * {@inheritDoc}
087         */
088        @Override
089        public void setHiddenOn(final DeviceSize deviceSize) {
090            StyleHelper.setHiddenOn(this, deviceSize);
091        }
092    
093        /**
094         * {@inheritDoc}
095         */
096        @Override
097        public void setMarginTop(final double margin) {
098            getElement().getStyle().setMarginTop(margin, Style.Unit.PX);
099        }
100    
101        /**
102         * {@inheritDoc}
103         */
104        @Override
105        public void setMarginLeft(final double margin) {
106            getElement().getStyle().setMarginLeft(margin, Style.Unit.PX);
107        }
108    
109        /**
110         * {@inheritDoc}
111         */
112        @Override
113        public void setMarginRight(final double margin) {
114            getElement().getStyle().setMarginRight(margin, Style.Unit.PX);
115        }
116    
117        /**
118         * {@inheritDoc}
119         */
120        @Override
121        public void setMarginBottom(final double margin) {
122            getElement().getStyle().setMarginBottom(margin, Style.Unit.PX);
123        }
124    
125        /**
126         * {@inheritDoc}
127         */
128        @Override
129        public void setPaddingTop(final double padding) {
130            getElement().getStyle().setPaddingTop(padding, Style.Unit.PX);
131        }
132    
133        /**
134         * {@inheritDoc}
135         */
136        @Override
137        public void setPaddingLeft(final double padding) {
138            getElement().getStyle().setPaddingLeft(padding, Style.Unit.PX);
139        }
140    
141        /**
142         * {@inheritDoc}
143         */
144        @Override
145        public void setPaddingRight(final double padding) {
146            getElement().getStyle().setPaddingRight(padding, Style.Unit.PX);
147        }
148    
149        /**
150         * {@inheritDoc}
151         */
152        @Override
153        public void setPaddingBottom(final double padding) {
154            getElement().getStyle().setPaddingBottom(padding, Style.Unit.PX);
155        }
156    
157        /**
158         * {@inheritDoc}
159         */
160        @Override
161        public void setColor(String color) {
162            getElement().getStyle().setColor(color);
163        }
164    
165        /**
166         * {@inheritDoc}
167         */
168        @Override
169        public void setPull(final Pull pull) {
170            pullMixin.setPull(pull);
171        }
172    
173        /**
174         * {@inheritDoc}
175         */
176        @Override
177        public Pull getPull() {
178            return pullMixin.getPull();
179        }
180    }