001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.wings.plaf.TextAreaCG;
016: import org.wings.text.SDocument;
017:
018: /**
019: * Multilined input text area which requires a surrounding {@link SForm} element.
020: * Can be also used as linebreaking label in disabled forms.
021: *
022: * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
023: */
024: public class STextArea extends STextComponent {
025:
026: /**
027: * Text wrapping behaviour for {@link STextArea#setLineWrap(int)}: Don't wrap.
028: */
029: public final static int NO_WRAP = 0;
030: /**
031: * Text wrapping behaviour for {@link STextArea#setLineWrap(int)}: Wrap at width.
032: */
033: public final static int VIRTUAL_WRAP = 1;
034: /**
035: * Text wrapping behaviour for {@link STextArea#setLineWrap(int)}: Wrap at physical input box borders.
036: */
037: public final static int PHYSICAL_WRAP = 2;
038:
039: private int rows = 0;
040:
041: private int columns = 0;
042:
043: /**
044: * allowed parameters
045: * are off(0), virtual(1), physical(2)
046: * default value is off
047: */
048: private int lineWrap = NO_WRAP;
049:
050: /**
051: * Creates a TextArea with defaults
052: */
053: public STextArea() {
054: this (null, 0, 0);
055: }
056:
057: /**
058: * Creates a textArea with the given text
059: * default values, no rows no columns no warp
060: * @param text the text to display
061: **/
062: public STextArea(String text) {
063: this (text, 0, 0);
064: }
065:
066: /**
067: * Creates a new empty TextArea with the specified number of rows and columns.
068: * @param rows is the number of rows to display
069: * @param columns is the number of columns to display
070: **/
071: public STextArea(int rows, int columns) {
072: this (null, rows, columns);
073: }
074:
075: /**
076: * Creates a new TextArea with the specified text and number of rows and columns.
077: * @param text is the text to display
078: * @param rows is the number of rows to display
079: * @param columns is the number of columns to display
080: **/
081: public STextArea(String text, int rows, int columns) {
082: this (null, text, rows, columns);
083: }
084:
085: /**
086: * Constructs a new STextArea with the given document model, and defaults
087: * for all of the other arguments (null, 0, 0).
088: *
089: * @param doc the model to use
090: */
091: public STextArea(SDocument doc) {
092: this (doc, null, 0, 0);
093: }
094:
095: /**
096: * Constructs a new STextArea with the specified number of rows
097: * and columns, and the given model. All of the constructors
098: * feed through this constructor.
099: *
100: * @param doc the model to use, or create a default one if null
101: * @param text the text to be displayed, null if none
102: * @param rows the number of rows >= 0
103: * @param columns the number of columns >= 0
104: * @exception IllegalArgumentException if the rows or columns
105: * arguments are negative.
106: */
107: public STextArea(SDocument doc, String text, int rows, int columns) {
108: super ();
109: this .setText(text);
110: this .setRows(rows);
111: this .setColumns(columns);
112: if (doc != null) {
113: setDocument(doc);
114: }
115: }
116:
117: /**
118: * Set the number of visble rows
119: * @param r the number of visble rows
120: */
121: public void setRows(int r) {
122: int oldRows = rows;
123: rows = r;
124: if (oldRows != rows)
125: reload();
126: }
127:
128: /**
129: * Get the number of visble rows
130: * @return number of visble rows
131: */
132: public int getRows() {
133: return rows;
134: }
135:
136: /**
137: * sets the Number of visible columns
138: * @param c the number of columns
139: */
140: public void setColumns(int c) {
141: int oldColumns = columns;
142: columns = c;
143: if (columns != oldColumns)
144: reload();
145: }
146:
147: /**
148: * Current number of columns to display
149: * @return the number of columns
150: */
151: public int getColumns() {
152: return columns;
153: }
154:
155: /**
156: * Valid values are {@link #NO_WRAP} {@link #VIRTUAL_WRAP} and {@link #PHYSICAL_WRAP}
157: * @param lw
158: */
159: public void setLineWrap(int lw) {
160: if (lw >= 0 && lw < 3)
161: lineWrap = lw;
162: }
163:
164: /**
165: * @return one of the LineWraps, NO_WRAP, VIRTUAL_WRAP, PHYSICAL_WRAP
166: */
167: public int getLineWrap() {
168: return lineWrap;
169: }
170:
171: public void setCG(TextAreaCG cg) {
172: super.setCG(cg);
173: }
174: }
|