001 package org.gwtbootstrap3.client.ui;
002
003 /*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2014 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.constants.Styles;
024
025 import com.google.gwt.dom.client.Document;
026 import com.google.gwt.i18n.client.HasDirection.Direction;
027 import com.google.gwt.i18n.shared.DirectionEstimator;
028 import com.google.gwt.safehtml.shared.SafeHtml;
029 import com.google.gwt.user.client.DOM;
030
031 /**
032 * An inline check box widget.
033 *
034 * @author Sven Jacobs
035 * @see org.gwtbootstrap3.client.ui.CheckBox
036 */
037 public class InlineCheckBox extends CheckBox {
038
039 /**
040 * Creates a check box with the specified text label.
041 *
042 * @param label
043 * the check box's label
044 */
045 public InlineCheckBox(SafeHtml label) {
046 this(label.asString(), true);
047 }
048
049 /**
050 * Creates a check box with the specified text label.
051 *
052 * @param label
053 * the check box's label
054 * @param dir
055 * the text's direction. Note that {@code DEFAULT} means
056 * direction should be inherited from the widget's parent
057 * element.
058 */
059 public InlineCheckBox(SafeHtml label, Direction dir) {
060 this();
061 setHTML(label, dir);
062 }
063
064 /**
065 * Creates a check box with the specified text label.
066 *
067 * @param label
068 * the check box's label
069 * @param directionEstimator
070 * A DirectionEstimator object used for automatic direction
071 * adjustment. For convenience,
072 * {@link #DEFAULT_DIRECTION_ESTIMATOR} can be used.
073 */
074 public InlineCheckBox(SafeHtml label, DirectionEstimator directionEstimator) {
075 this();
076 setDirectionEstimator(directionEstimator);
077 setHTML(label.asString());
078 }
079
080 /**
081 * Creates a check box with the specified text label.
082 *
083 * @param label
084 * the check box's label
085 */
086 public InlineCheckBox(String label) {
087 this();
088 setText(label);
089 }
090
091 /**
092 * Creates a check box with the specified text label.
093 *
094 * @param label
095 * the check box's label
096 * @param dir
097 * the text's direction. Note that {@code DEFAULT} means
098 * direction should be inherited from the widget's parent
099 * element.
100 */
101 public InlineCheckBox(String label, Direction dir) {
102 this();
103 setText(label, dir);
104 }
105
106 /**
107 * Creates a label with the specified text and a default direction
108 * estimator.
109 *
110 * @param label
111 * the check box's label
112 * @param directionEstimator
113 * A DirectionEstimator object used for automatic direction
114 * adjustment. For convenience,
115 * {@link #DEFAULT_DIRECTION_ESTIMATOR} can be used.
116 */
117 public InlineCheckBox(String label, DirectionEstimator directionEstimator) {
118 this();
119 setDirectionEstimator(directionEstimator);
120 setText(label);
121 }
122
123 /**
124 * Creates a check box with the specified text label.
125 *
126 * @param label
127 * the check box's label
128 * @param asHTML
129 * <code>true</code> to treat the specified label as html
130 */
131 public InlineCheckBox(String label, boolean asHTML) {
132 this();
133 if (asHTML) {
134 setHTML(label);
135 } else {
136 setText(label);
137 }
138 }
139
140 public InlineCheckBox() {
141 super(DOM.createLabel(), Document.get().createCheckInputElement());
142 setStyleName(Styles.CHECKBOX_INLINE);
143
144 getElement().appendChild(inputElem);
145 getElement().appendChild(labelElem);
146 }
147
148 }