KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > TextArea


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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   public int getCursorPos() {
58     return getImpl().getTextAreaCursorPos(getElement());
59   }
60
61   public int getSelectionLength() {
62     return getImpl().getSelectionLength(getElement());
63   }
64
65   /**
66    * Gets the number of text lines that are visible.
67    *
68    * @return the number of visible lines
69    */

70   public int getVisibleLines() {
71     return DOM.getElementPropertyInt(getElement(), "rows");
72   }
73
74   /**
75    * Sets the requested width of the text box (this is not an exact value, as
76    * not all characters are created equal).
77    *
78    * @param width the requested width, in characters
79    */

80   public void setCharacterWidth(int width) {
81     DOM.setElementPropertyInt(getElement(), "cols", width);
82   }
83
84   /**
85    * Sets the number of text lines that are visible.
86    *
87    * @param lines the number of visible lines
88    */

89   public void setVisibleLines(int lines) {
90     DOM.setElementPropertyInt(getElement(), "rows", lines);
91   }
92 }
93
Popular Tags