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.editor.client.IsEditor;
032    import com.google.gwt.editor.client.LeafValueEditor;
033    import com.google.gwt.editor.ui.client.adapters.HasTextEditor;
034    import com.google.gwt.user.client.ui.HasHTML;
035    import com.google.gwt.user.client.ui.Widget;
036    
037    /**
038     * Base class for {@link Widget} that just contains text.
039     *
040     * @author Sven Jacobs
041     * @author Joshua Godi
042     */
043    public abstract class AbstractTextWidget extends Widget implements HasId, HasHTML, HasResponsiveness, HasInlineStyle, IsEditor<LeafValueEditor<String>>, HasPull {
044        private final PullMixin<AbstractTextWidget> pullMixin = new PullMixin<AbstractTextWidget>(this);
045        private final IdMixin<AbstractTextWidget> idMixin = new IdMixin<AbstractTextWidget>(this);
046        private LeafValueEditor<String> editor;
047    
048        protected AbstractTextWidget(final Element element) {
049            setElement(element);
050        }
051    
052        @Override
053        public void setId(final String id) {
054            idMixin.setId(id);
055        }
056    
057        @Override
058        public String getId() {
059            return idMixin.getId();
060        }
061    
062        @Override
063        public void setText(final String text) {
064            getElement().setInnerText(text);
065        }
066    
067        @Override
068        public String getText() {
069            return getElement().getInnerText();
070        }
071    
072        @Override
073        public String getHTML() {
074            return getElement().getInnerHTML();
075        }
076    
077        @Override
078        public void setHTML(final String html) {
079            getElement().setInnerHTML(html);
080        }
081    
082        @Override
083        public void setVisibleOn(final DeviceSize deviceSize) {
084            StyleHelper.setVisibleOn(this, deviceSize);
085        }
086    
087        @Override
088        public void setHiddenOn(final DeviceSize deviceSize) {
089            StyleHelper.setHiddenOn(this, deviceSize);
090        }
091    
092        @Override
093        public void setMarginTop(final double margin) {
094            getElement().getStyle().setMarginTop(margin, Style.Unit.PX);
095        }
096    
097        @Override
098        public void setMarginLeft(final double margin) {
099            getElement().getStyle().setMarginLeft(margin, Style.Unit.PX);
100        }
101    
102        @Override
103        public void setMarginRight(final double margin) {
104            getElement().getStyle().setMarginRight(margin, Style.Unit.PX);
105        }
106    
107        @Override
108        public void setMarginBottom(final double margin) {
109            getElement().getStyle().setMarginBottom(margin, Style.Unit.PX);
110        }
111    
112        @Override
113        public void setPaddingTop(final double padding) {
114            getElement().getStyle().setPaddingTop(padding, Style.Unit.PX);
115        }
116    
117        @Override
118        public void setPaddingLeft(final double padding) {
119            getElement().getStyle().setPaddingLeft(padding, Style.Unit.PX);
120        }
121    
122        @Override
123        public void setPaddingRight(final double padding) {
124            getElement().getStyle().setPaddingRight(padding, Style.Unit.PX);
125        }
126    
127        @Override
128        public void setPaddingBottom(final double padding) {
129            getElement().getStyle().setPaddingBottom(padding, Style.Unit.PX);
130        }
131    
132        /**
133         * {@inheritDoc}
134         */
135        @Override
136        public void setColor(String color) {
137            getElement().getStyle().setColor(color);
138        }
139    
140        @Override
141        public LeafValueEditor<String> asEditor() {
142            if (editor == null) {
143                editor = HasTextEditor.of(this);
144            }
145            return editor;
146        }
147    
148        /**
149         * {@inheritDoc}
150         */
151        @Override
152        public void setPull(final Pull pull) {
153            pullMixin.setPull(pull);
154        }
155    
156        /**
157         * {@inheritDoc}
158         */
159        @Override
160        public Pull getPull() {
161            return pullMixin.getPull();
162        }
163    }