source: trunk/src/gcc/libjava/java/awt/TextArea.java@ 1389

Last change on this file since 1389 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 14.0 KB
Line 
1/* TextArea.java -- A multi-line text entry widget
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt;
40
41import java.awt.peer.TextAreaPeer;
42import java.awt.peer.TextComponentPeer;
43import java.awt.peer.ComponentPeer;
44
45/**
46 * This implements a multi-line text entry widget.
47 *
48 * @author Aaron M. Renn ([email protected])
49 */
50public class TextArea extends TextComponent implements java.io.Serializable
51{
52
53/*
54 * Static Variables
55 */
56
57/**
58 * Use both horiztonal and vertical scroll bars.
59 */
60public static final int SCROLLBARS_BOTH = 0;
61
62/**
63 * Use vertical scroll bars only.
64 */
65public static final int SCROLLBARS_VERTICAL_ONLY = 1;
66
67/**
68 * Use horizatonal scroll bars only.
69 */
70public static final int SCROLLBARS_HORIZONTAL_ONLY = 2;
71
72/**
73 * Use no scrollbars.
74 */
75public static final int SCROLLBARS_NONE = 3;
76
77// Serialization constant
78private static final long serialVersionUID = 3692302836626095722L;
79
80/*************************************************************************/
81
82/*
83 * Instance Variables
84 */
85
86/**
87 * @serial The number of columns in this text area.
88 */
89private int columns;
90
91/**
92 * @serial The number of rows in this text area.
93 */
94private int rows;
95
96/**
97 * @serial The type of scrollbars to display, which will be one of
98 * the contstants from this class.
99 */
100private int scrollbarVisibility;
101
102/*************************************************************************/
103
104/*
105 * Constructors
106 */
107
108/**
109 * Initialize a new instance of <code>TextArea</code> that is empty
110 * and is one row and one column. Both horizontal and vertical
111 * scrollbars will be used.
112 */
113public
114TextArea()
115{
116 this("", 1, 1, SCROLLBARS_BOTH);
117}
118
119/*************************************************************************/
120
121/**
122 * Initializes a new instance of <code>TextArea</code> that
123 * contains the specified string. Both horizontal and veritcal
124 * scrollbars will be used.
125 *
126 * @param text The text to display in this text area.
127 */
128public
129TextArea(String text)
130{
131 this(text, 1, text.length(), SCROLLBARS_BOTH);
132}
133
134/*************************************************************************/
135
136/**
137 * Initializes a new instance of <code>TextArea</code> that is empty
138 * and has the specified number of rows and columns. Both
139 * horizontal and vertical scrollbars will be used.
140 *
141 * @param rows The number of rows in this text area.
142 * @param columns The number of columns in this text area.
143 */
144public
145TextArea(int rows, int columns)
146{
147 this("", rows, columns, SCROLLBARS_BOTH);
148}
149
150/*************************************************************************/
151
152/**
153 * Initializes a new instance of <code>TextArea</code> that is the
154 * specified size and has the specified text.
155 *
156 * @param text The text to display in this text area.
157 * @param rows The number of rows in this text area.
158 * @param columns The number of columns in this text area.
159 */
160public
161TextArea(String text, int rows, int columns)
162{
163 this(text, rows, columns, SCROLLBARS_BOTH);
164}
165
166/*************************************************************************/
167
168/**
169 * Initializes a new instance of <code>TextArea</code> with the
170 * specified values. The scrollbar visibility value must be one
171 * of the constants in this class.
172 *
173 * @param text The text to display in this text area.
174 * @param rows The number of rows in this text area.
175 * @param columns The number of columns in this text area.
176 * @param scrollbarVisibility Which scrollbars to display.
177 */
178public
179TextArea(String text, int rows, int columns, int scrollbarVisibility)
180{
181 super(text);
182
183 if ((rows < 1) || (columns < 0))
184 throw new IllegalArgumentException("Bad row or column value");
185
186 if ((scrollbarVisibility != SCROLLBARS_BOTH) &&
187 (scrollbarVisibility != SCROLLBARS_VERTICAL_ONLY) &&
188 (scrollbarVisibility != SCROLLBARS_HORIZONTAL_ONLY) &&
189 (scrollbarVisibility != SCROLLBARS_NONE))
190 throw new IllegalArgumentException("Bad scrollbar visibility value");
191
192 this.rows = rows;
193 this.columns = columns;
194 this.scrollbarVisibility = scrollbarVisibility;
195}
196
197/*************************************************************************/
198
199/*
200 * Instance Variables
201 */
202
203/**
204 * Returns the number of columns in the field.
205 *
206 * @return The number of columns in the field.
207 */
208public int
209getColumns()
210{
211 return(columns);
212}
213
214/*************************************************************************/
215
216/**
217 * Sets the number of columns in this field to the specified value.
218 *
219 * @param columns The new number of columns in the field.
220 *
221 * @exception IllegalArgumentException If columns is less than zero.
222 */
223public synchronized void
224setColumns(int columns)
225{
226 if (columns < 0)
227 throw new IllegalArgumentException("Value is less than zero: " +
228 columns);
229
230 this.columns = columns;
231 // FIXME: How to we communicate this to our peer?
232}
233
234/*************************************************************************/
235
236/**
237 * Returns the number of rows in the field.
238 *
239 * @return The number of rows in the field.
240 */
241public int
242getRows()
243{
244 return(rows);
245}
246
247/*************************************************************************/
248
249/**
250 * Sets the number of rows in this field to the specified value.
251 *
252 * @param rows The new number of rows in the field.
253 *
254 * @exception IllegalArgumentException If rows is less than zero.
255 */
256public synchronized void
257setRows(int rows)
258{
259 if (rows < 1)
260 throw new IllegalArgumentException("Value is less than one: " +
261 rows);
262
263 this.rows = rows;
264 // FIXME: How to we communicate this to our peer?
265}
266
267/*************************************************************************/
268
269/**
270 * Returns the minimum size for this text field.
271 *
272 * @return The minimum size for this text field.
273 */
274public Dimension
275getMinimumSize()
276{
277 return(getMinimumSize(getRows(), getColumns()));
278}
279
280/*************************************************************************/
281
282/**
283 * Returns the minimum size of a text field with the specified number
284 * of rows and columns.
285 *
286 * @param rows The number of rows to get the minimum size for.
287 * @param columns The number of columns to get the minimum size for.
288 */
289public Dimension
290getMinimumSize(int rows, int columns)
291{
292 TextAreaPeer tap = (TextAreaPeer)getPeer();
293 if (tap == null)
294 return(null); // FIXME: What do we do if there is no peer?
295
296 return(tap.getMinimumSize(rows, columns));
297}
298
299/*************************************************************************/
300
301/**
302 * Returns the minimum size for this text field.
303 *
304 * @return The minimum size for this text field.
305 *
306 * @deprecated This method is depcreated in favor of
307 * <code>getMinimumSize()</code>.
308 */
309public Dimension
310minimumSize()
311{
312 return(getMinimumSize(getRows(), getColumns()));
313}
314
315/*************************************************************************/
316
317/**
318 * Returns the minimum size of a text field with the specified number
319 * of rows and columns.
320 *
321 * @param rows The number of rows to get the minimum size for.
322 * @param columns The number of columns to get the minimum size for.
323 *
324 * @deprecated This method is deprecated in favor of
325 * <code>getMinimumSize(int)</code>.
326 */
327public Dimension
328minimumSize(int rows, int columns)
329{
330 return(getMinimumSize(rows, columns));
331}
332
333/*************************************************************************/
334
335/**
336 * Returns the preferred size for this text field.
337 *
338 * @return The preferred size for this text field.
339 */
340public Dimension
341getPreferredSize()
342{
343 return(getPreferredSize(getRows(), getColumns()));
344}
345
346/*************************************************************************/
347
348/**
349 * Returns the preferred size of a text field with the specified number
350 * of rows and columns.
351 *
352 * @param rows The number of rows to get the preferred size for.
353 * @param columns The number of columns to get the preferred size for.
354 */
355public Dimension
356getPreferredSize(int rows, int columns)
357{
358 TextAreaPeer tap = (TextAreaPeer)getPeer();
359 if (tap == null)
360 return(null); // FIXME: What do we do if there is no peer?
361
362 return(tap.getPreferredSize(rows, columns));
363}
364
365/*************************************************************************/
366
367/**
368 * Returns the preferred size for this text field.
369 *
370 * @return The preferred size for this text field.
371 *
372 * @deprecated This method is deprecated in favor of
373 * <code>getPreferredSize()</code>.
374 */
375public Dimension
376preferredSize()
377{
378 return(getPreferredSize(getRows(), getColumns()));
379}
380
381/*************************************************************************/
382
383/**
384 * Returns the preferred size of a text field with the specified number
385 * of rows and columns.
386 *
387 * @param rows The number of rows to get the preferred size for.
388 * @param columns The number of columns to get the preferred size for.
389 *
390 * @deprecated This method is deprecated in favor of
391 * <code>getPreferredSize(int)</code>.
392 */
393public Dimension
394preferredSize(int columns)
395{
396 return(getPreferredSize(rows, columns));
397}
398
399/*************************************************************************/
400
401/**
402 * Returns one of the constants from this class indicating which
403 * types of scrollbars this object uses, if any.
404 *
405 * @return The scrollbar type constant for this object.
406 */
407public int
408getScrollbarVisibility()
409{
410 return(scrollbarVisibility);
411}
412
413/*************************************************************************/
414
415/**
416 * Notify this object that it should create its native peer.
417 */
418public void
419addNotify()
420{
421 if (getPeer() != null)
422 return;
423
424 setPeer((ComponentPeer)getToolkit().createTextArea(this));
425}
426
427/*************************************************************************/
428
429/**
430 * Appends the specified text to the end of the current text.
431 *
432 * @param text The text to append.
433 */
434public void
435append(String str)
436{
437 TextAreaPeer tap = (TextAreaPeer)getPeer();
438 if (tap == null)
439 return;
440
441 tap.insert(str, tap.getText().length());
442}
443
444/*************************************************************************/
445
446/**
447 * Appends the specified text to the end of the current text.
448 *
449 * @param text The text to append.
450 *
451 * @deprecated This method is deprecated in favor of
452 * <code>append()</code>.
453 */
454public void
455appendText(String text)
456{
457 append(text);
458}
459
460/*************************************************************************/
461
462/**
463 * Inserts the specified text at the specified location.
464 *
465 * @param text The text to insert.
466 * @param pos The insert position.
467 */
468public void
469insert(String text, int pos)
470{
471 TextAreaPeer tap = (TextAreaPeer)getPeer();
472 if (tap == null)
473 return;
474
475 tap.insert(text, pos);
476}
477
478/*************************************************************************/
479
480/**
481 * Inserts the specified text at the specified location.
482 *
483 * @param text The text to insert.
484 * @param pos The insert position.
485 *
486 * @deprecated This method is depcreated in favor of <code>insert()</code>.
487 */
488public void
489insertText(String text, int pos)
490{
491 insert(text, pos);
492}
493
494/*************************************************************************/
495
496/**
497 * Replaces the text bounded by the specified start and end positions
498 * with the specified text.
499 *
500 * @param text The new text for the range.
501 * @param start The start position of the replacement range.
502 * @param end The end position of the replacement range.
503 */
504public void
505replaceRange(String text, int start, int end)
506{
507 TextAreaPeer tap = (TextAreaPeer)getPeer();
508 if (tap == null)
509 return;
510
511 tap.replaceRange(text, start, end);
512}
513
514/*************************************************************************/
515
516/**
517 * Replaces the text bounded by the specified start and end positions
518 * with the specified text.
519 *
520 * @param text The new text for the range.
521 * @param start The start position of the replacement range.
522 * @param end The end position of the replacement range.
523 *
524 * @deprecated This method is deprecated in favor of
525 * <code>replaceRange()</code>.
526 */
527public void
528replaceText(String text, int start, int end)
529{
530 replaceRange(text, start, end);
531}
532
533/*************************************************************************/
534
535/**
536 * Returns a debugging string for this text area.
537 *
538 * @return A debugging string for this text area.
539 */
540protected String
541paramString()
542{
543 return(getClass().getName() + "(rows=" + getRows() + ",columns=" +
544 getColumns() + ",scrollbars=" + getScrollbarVisibility() +
545 ")");
546}
547
548} // class TextArea
549
Note: See TracBrowser for help on using the repository browser.