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;
017
018import com.github.gwtbootstrap.client.ui.base.HasAlternateSize;
019import com.github.gwtbootstrap.client.ui.base.HasId;
020import com.github.gwtbootstrap.client.ui.base.HasSize;
021import com.github.gwtbootstrap.client.ui.base.HasStyle;
022import com.github.gwtbootstrap.client.ui.base.InlineLabel;
023import com.github.gwtbootstrap.client.ui.base.IsResponsive;
024import com.github.gwtbootstrap.client.ui.base.IsSearchQuery;
025import com.github.gwtbootstrap.client.ui.base.ResponsiveHelper;
026import com.github.gwtbootstrap.client.ui.base.SearchQueryStyleHelper;
027import com.github.gwtbootstrap.client.ui.base.SizeHelper;
028import com.github.gwtbootstrap.client.ui.base.Style;
029import com.github.gwtbootstrap.client.ui.base.StyleHelper;
030import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
031import com.github.gwtbootstrap.client.ui.constants.Constants;
032import com.github.gwtbootstrap.client.ui.constants.Device;
033import com.google.gwt.dom.client.Element;
034import com.google.gwt.i18n.shared.DirectionEstimator;
035import com.google.gwt.user.client.ui.Label;
036
037
038
039/**
040 * Uneditable style text input.
041 * 
042 * @since 2.0.4.0
043 * @author ohashi keisuke
044 */
045public class UneditableInput extends InlineLabel implements HasAlternateSize, IsSearchQuery, HasSize, HasId, HasStyle, IsResponsive {
046
047        /**
048         * Creates an empty widget.
049         */
050        public UneditableInput() {
051                super();
052                setStyleName(Constants.UNEDITABLE_INPUT);
053        }
054
055        /**
056         * This constructor may be used by subclasses to explicitly use an existing
057         * element. This element must be either a <div> <span> element.
058         * 
059         * @param element
060         *            the element to be used
061         */
062        protected UneditableInput(Element element) {
063                super(element);
064        }
065
066        /**
067         * Creates a label with the specified text and direction.
068         * 
069         * @param text
070         *            the new label's text
071         * @param dir
072         *            the text's direction. Note: {@code Direction.DEFAULT} means
073         *            direction should be inherited from the widget's parent
074         *            element.
075         */
076        public UneditableInput(String text, Direction dir) {
077                super(text, dir);
078        }
079
080        /**
081         * Creates a label with the specified text and a default direction
082         * estimator.
083         * 
084         * @param text
085         *            the new label's text
086         * @param directionEstimator
087         *            A DirectionEstimator object used for automatic direction
088         *            adjustment. For convenience,
089         *            {@link Label#DEFAULT_DIRECTION_ESTIMATOR} can be used.
090         */
091        public UneditableInput(String text, DirectionEstimator directionEstimator) {
092                super(text, directionEstimator);
093        }
094
095        /**
096         * Creates a widget with the specified text.
097         * 
098         * @param text
099         *            the new widget's text
100         */
101        public UneditableInput(String text) {
102                super(text);
103        }
104
105        /**
106         * {@inheritDoc}
107         */
108        @Override
109        public void setSearchQuery(boolean searchQuery) {
110                SearchQueryStyleHelper.setSearchQuery(this, searchQuery);
111        }
112
113        /**
114         * {@inheritDoc}
115         */
116        @Override
117        public boolean isSearchQuery() {
118                return SearchQueryStyleHelper.isSearchQuery(this);
119        }
120
121        /**
122         * {@inheritDoc}
123         */
124        @Override
125        public void setAlternateSize(AlternateSize size) {
126                StyleHelper.changeStyle(this, size, AlternateSize.class);
127        }
128
129        /**
130         * {@inheritDoc}
131         */
132        @Override
133        public void setSize(int size) {
134                SizeHelper.setSize(this, size);
135        }
136        
137        /**
138         * {@inheritDoc}
139         */
140        @Override
141        public String getId() {
142                return getElement().getId();
143        }
144
145        /**
146         * {@inheritDoc}
147         */
148        @Override
149        public void setId(String id) {
150                getElement().setId(id);
151        }
152        
153
154        /**
155         * {@inheritDoc}
156         */
157        @Override
158        public void setShowOn(Device device) {
159                ResponsiveHelper.setShowOn(this, device);
160        }
161
162        /**
163         * {@inheritDoc}
164         */
165        @Override
166        public void setHideOn(Device device) {
167                ResponsiveHelper.setHideOn(this, device);
168                
169        }
170
171        /**
172         * {@inheritDoc}
173         */
174        @Override
175        public void setStyle(Style style) {
176                StyleHelper.setStyle(this, style);
177        }
178
179        /**
180         * {@inheritDoc}
181         */
182        @Override
183        public void addStyle(Style style) {
184                StyleHelper.addStyle(this, style);
185        }
186
187        /**
188         * {@inheritDoc}
189         */
190        @Override
191        public void removeStyle(Style style) {
192                StyleHelper.removeStyle(this, style);
193                
194        }
195}