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 text box that allows multiple lines of text to be entered.
22: *
23: * <p>
24: * <img class='gallery' src='TextArea.png'/>
25: * </p>
26: *
27: * <h3>CSS Style Rules</h3>
28: * <ul class='css'>
29: * <li>.gwt-TextArea { primary style }</li>
30: * <li>.gwt-TextArea-readonly { dependent style set when the text area is read-only }</li>
31: * </ul>
32: *
33: * <p>
34: * <h3>Example</h3> {@example com.google.gwt.examples.TextBoxExample}
35: * </p>
36: */
37: public class TextArea extends TextBoxBase {
38:
39: /**
40: * Creates an empty text area.
41: */
42: public TextArea() {
43: super (DOM.createTextArea());
44: setStyleName("gwt-TextArea");
45: }
46:
47: /**
48: * Gets the requested width of the text box (this is not an exact value, as
49: * not all characters are created equal).
50: *
51: * @return the requested width, in characters
52: */
53: public int getCharacterWidth() {
54: return DOM.getElementPropertyInt(getElement(), "cols");
55: }
56:
57: @Override
58: public int getCursorPos() {
59: return getImpl().getTextAreaCursorPos(getElement());
60: }
61:
62: @Override
63: public int getSelectionLength() {
64: return getImpl().getSelectionLength(getElement());
65: }
66:
67: /**
68: * Gets the number of text lines that are visible.
69: *
70: * @return the number of visible lines
71: */
72: public int getVisibleLines() {
73: return DOM.getElementPropertyInt(getElement(), "rows");
74: }
75:
76: /**
77: * Sets the requested width of the text box (this is not an exact value, as
78: * not all characters are created equal).
79: *
80: * @param width the requested width, in characters
81: */
82: public void setCharacterWidth(int width) {
83: DOM.setElementPropertyInt(getElement(), "cols", width);
84: }
85:
86: /**
87: * Sets the number of text lines that are visible.
88: *
89: * @param lines the number of visible lines
90: */
91: public void setVisibleLines(int lines) {
92: DOM.setElementPropertyInt(getElement(), "rows", lines);
93: }
94: }
|