01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.user.client.DOM;
19:
20: /**
21: * A standard single-line text box.
22: *
23: * <p>
24: * <img class='gallery' src='TextBox.png'/>
25: * </p>
26: *
27: * <h3>CSS Style Rules</h3>
28: * <ul class='css'>
29: * <li>.gwt-TextBox { primary style }</li>
30: * <li>.gwt-TextBox-readonly { dependent style set when the text box is read-only }</li>
31: * </ul>
32: *
33: * <p>
34: * <h3>Example</h3>
35: * {@example com.google.gwt.examples.TextBoxExample}
36: * </p>
37: */
38: public class TextBox extends TextBoxBase {
39:
40: /**
41: * Creates an empty text box.
42: */
43: public TextBox() {
44: super (DOM.createInputText());
45: setStyleName("gwt-TextBox");
46: }
47:
48: /**
49: * Gets the maximum allowable length of the text box.
50: *
51: * @return the maximum length, in characters
52: */
53: public int getMaxLength() {
54: return DOM.getElementPropertyInt(getElement(), "maxLength");
55: }
56:
57: /**
58: * Gets the number of visible characters in the text box.
59: *
60: * @return the number of visible characters
61: */
62: public int getVisibleLength() {
63: return DOM.getElementPropertyInt(getElement(), "size");
64: }
65:
66: /**
67: * Sets the maximum allowable length of the text box.
68: *
69: * @param length the maximum length, in characters
70: */
71: public void setMaxLength(int length) {
72: DOM.setElementPropertyInt(getElement(), "maxLength", length);
73: }
74:
75: /**
76: * Sets the number of visible characters in the text box.
77: *
78: * @param length the number of visible characters
79: */
80: public void setVisibleLength(int length) {
81: DOM.setElementPropertyInt(getElement(), "size", length);
82: }
83: }
|