KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > JTextArea


1 /*
2  * @(#)JTextArea.java 1.92 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing;
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.text.*;
12 import javax.swing.plaf.*;
13 import javax.accessibility.*;
14
15 import java.util.Collections JavaDoc;
16 import java.util.Set JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
18 import java.util.TreeSet JavaDoc;
19
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.ObjectInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 /**
25  * A <code>JTextArea</code> is a multi-line area that displays plain text.
26  * It is intended to be a lightweight component that provides source
27  * compatibility with the <code>java.awt.TextArea</code> class where it can
28  * reasonably do so.
29  * You can find information and examples of using all the text components in
30  * <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/components/text.html">Using Text Components</a>,
31  * a section in <em>The Java Tutorial.</em>
32  *
33  * <p>
34  * This component has capabilities not found in the
35  * <code>java.awt.TextArea</code> class. The superclass should be
36  * consulted for additional capabilities.
37  * Alternative multi-line text classes with
38  * more capabilities are <code>JTextPane</code> and <code>JEditorPane</code>.
39  * <p>
40  * The <code>java.awt.TextArea</code> internally handles scrolling.
41  * <code>JTextArea</code> is different in that it doesn't manage scrolling,
42  * but implements the swing <code>Scrollable</code> interface. This allows it
43  * to be placed inside a <code>JScrollPane</code> if scrolling
44  * behavior is desired, and used directly if scrolling is not desired.
45  * <p>
46  * The <code>java.awt.TextArea</code> has the ability to do line wrapping.
47  * This was controlled by the horizontal scrolling policy. Since
48  * scrolling is not done by <code>JTextArea</code> directly, backward
49  * compatibility must be provided another way. <code>JTextArea</code> has
50  * a bound property for line wrapping that controls whether or
51  * not it will wrap lines. By default, the line wrapping property
52  * is set to false (not wrapped).
53  * <p>
54  * <code>java.awt.TextArea</code> has two properties <code>rows</code>
55  * and <code>columns</code> that are used to determine the preferred size.
56  * <code>JTextArea</code> uses these properties to indicate the
57  * preferred size of the viewport when placed inside a <code>JScrollPane</code>
58  * to match the functionality provided by <code>java.awt.TextArea</code>.
59  * <code>JTextArea</code> has a preferred size of what is needed to
60  * display all of the text, so that it functions properly inside of
61  * a <code>JScrollPane</code>. If the value for <code>rows</code>
62  * or <code>columns</code> is equal to zero,
63  * the preferred size along that axis is used for
64  * the viewport preferred size along the same axis.
65  * <p>
66  * The <code>java.awt.TextArea</code> could be monitored for changes by adding
67  * a <code>TextListener</code> for <code>TextEvent</code>s.
68  * In the <code>JTextComponent</code> based
69  * components, changes are broadcasted from the model via a
70  * <code>DocumentEvent</code> to <code>DocumentListeners</code>.
71  * The <code>DocumentEvent</code> gives
72  * the location of the change and the kind of change if desired.
73  * The code fragment might look something like:
74  * <pre>
75  * DocumentListener myListener = ??;
76  * JTextArea myArea = ??;
77  * myArea.getDocument().addDocumentListener(myListener);
78  * </pre>
79  * <p>
80  * <dt><b><font size=+1>Newlines</font></b>
81  * <dd>
82  * For a discussion on how newlines are handled, see
83  * <a HREF="text/DefaultEditorKit.html">DefaultEditorKit</a>.
84  * </dl>
85  *
86  * <p>
87  * <strong>Warning:</strong>
88  * Serialized objects of this class will not be compatible with
89  * future Swing releases. The current serialization support is
90  * appropriate for short term storage or RMI between applications running
91  * the same version of Swing. As of 1.4, support for long term storage
92  * of all JavaBeans<sup><font size="-2">TM</font></sup>
93  * has been added to the <code>java.beans</code> package.
94  * Please see {@link java.beans.XMLEncoder}.
95  *
96  * @beaninfo
97  * attribute: isContainer false
98  * description: A multi-line area that displays plain text.
99  *
100  * @author Timothy Prinzing
101  * @version 1.92 12/19/03
102  * @see JTextPane
103  * @see JEditorPane
104  */

105 public class JTextArea extends JTextComponent {
106
107     /**
108      * @see #getUIClassID
109      * @see #readObject
110      */

111     private static final String JavaDoc uiClassID = "TextAreaUI";
112
113     /**
114      * Constructs a new TextArea. A default model is set, the initial string
115      * is null, and rows/columns are set to 0.
116      */

117     public JTextArea() {
118         this(null, null, 0, 0);
119     }
120
121     /**
122      * Constructs a new TextArea with the specified text displayed.
123      * A default model is created and rows/columns are set to 0.
124      *
125      * @param text the text to be displayed, or null
126      */

127     public JTextArea(String JavaDoc text) {
128         this(null, text, 0, 0);
129     }
130
131     /**
132      * Constructs a new empty TextArea with the specified number of
133      * rows and columns. A default model is created, and the initial
134      * string is null.
135      *
136      * @param rows the number of rows >= 0
137      * @param columns the number of columns >= 0
138      * @exception IllegalArgumentException if the rows or columns
139      * arguments are negative.
140      */

141     public JTextArea(int rows, int columns) {
142         this(null, null, rows, columns);
143     }
144
145     /**
146      * Constructs a new TextArea with the specified text and number
147      * of rows and columns. A default model is created.
148      *
149      * @param text the text to be displayed, or null
150      * @param rows the number of rows >= 0
151      * @param columns the number of columns >= 0
152      * @exception IllegalArgumentException if the rows or columns
153      * arguments are negative.
154      */

155     public JTextArea(String JavaDoc text, int rows, int columns) {
156         this(null, text, rows, columns);
157     }
158
159     /**
160      * Constructs a new JTextArea with the given document model, and defaults
161      * for all of the other arguments (null, 0, 0).
162      *
163      * @param doc the model to use
164      */

165     public JTextArea(Document doc) {
166         this(doc, null, 0, 0);
167     }
168
169     /**
170      * Constructs a new JTextArea with the specified number of rows
171      * and columns, and the given model. All of the constructors
172      * feed through this constructor.
173      *
174      * @param doc the model to use, or create a default one if null
175      * @param text the text to be displayed, null if none
176      * @param rows the number of rows >= 0
177      * @param columns the number of columns >= 0
178      * @exception IllegalArgumentException if the rows or columns
179      * arguments are negative.
180      */

181     public JTextArea(Document doc, String JavaDoc text, int rows, int columns) {
182         super();
183         this.rows = rows;
184         this.columns = columns;
185         if (doc == null) {
186             doc = createDefaultModel();
187         }
188         setDocument(doc);
189         if (text != null) {
190             setText(text);
191             select(0, 0);
192         }
193     if (rows < 0) {
194         throw new IllegalArgumentException JavaDoc("rows: " + rows);
195     }
196     if (columns < 0) {
197         throw new IllegalArgumentException JavaDoc("columns: " + columns);
198     }
199         LookAndFeel.installProperty(this,
200                                     "focusTraversalKeysForward",
201                                     JComponent.
202                                     getManagingFocusForwardTraversalKeys());
203         LookAndFeel.installProperty(this,
204                                     "focusTraversalKeysBackward",
205                                     JComponent.
206                                     getManagingFocusBackwardTraversalKeys());
207     }
208
209     /**
210      * Returns the class ID for the UI.
211      *
212      * @return the ID ("TextAreaUI")
213      * @see JComponent#getUIClassID
214      * @see UIDefaults#getUI
215      */

216     public String JavaDoc getUIClassID() {
217         return uiClassID;
218     }
219
220     /**
221      * Creates the default implementation of the model
222      * to be used at construction if one isn't explicitly
223      * given. A new instance of PlainDocument is returned.
224      *
225      * @return the default document model
226      */

227     protected Document createDefaultModel() {
228         return new PlainDocument();
229     }
230
231     /**
232      * Sets the number of characters to expand tabs to.
233      * This will be multiplied by the maximum advance for
234      * variable width fonts. A PropertyChange event ("tabSize") is fired
235      * when the tab size changes.
236      *
237      * @param size number of characters to expand to
238      * @see #getTabSize
239      * @beaninfo
240      * preferred: true
241      * bound: true
242      * description: the number of characters to expand tabs to
243      */

244     public void setTabSize(int size) {
245         Document doc = getDocument();
246         if (doc != null) {
247             int old = getTabSize();
248             doc.putProperty(PlainDocument.tabSizeAttribute, new Integer JavaDoc(size));
249             firePropertyChange("tabSize", old, size);
250         }
251     }
252
253     /**
254      * Gets the number of characters used to expand tabs. If the document is
255      * null or doesn't have a tab setting, return a default of 8.
256      *
257      * @return the number of characters
258      */

259     public int getTabSize() {
260         int size = 8;
261         Document doc = getDocument();
262         if (doc != null) {
263             Integer JavaDoc i = (Integer JavaDoc) doc.getProperty(PlainDocument.tabSizeAttribute);
264             if (i != null) {
265                 size = i.intValue();
266             }
267         }
268         return size;
269     }
270
271     /**
272      * Sets the line-wrapping policy of the text area. If set
273      * to true the lines will be wrapped if they are too long
274      * to fit within the allocated width. If set to false,
275      * the lines will always be unwrapped. A <code>PropertyChange</code>
276      * event ("lineWrap") is fired when the policy is changed.
277      * By default this property is false.
278      *
279      * @param wrap indicates if lines should be wrapped
280      * @see #getLineWrap
281      * @beaninfo
282      * preferred: true
283      * bound: true
284      * description: should lines be wrapped
285      */

286     public void setLineWrap(boolean wrap) {
287         boolean old = this.wrap;
288         this.wrap = wrap;
289         firePropertyChange("lineWrap", old, wrap);
290     }
291
292     /**
293      * Gets the line-wrapping policy of the text area. If set
294      * to true the lines will be wrapped if they are too long
295      * to fit within the allocated width. If set to false,
296      * the lines will always be unwrapped.
297      *
298      * @return if lines will be wrapped
299      */

300     public boolean getLineWrap() {
301         return wrap;
302     }
303
304     /**
305      * Sets the style of wrapping used if the text area is wrapping
306      * lines. If set to true the lines will be wrapped at word
307      * boundaries (whitespace) if they are too long
308      * to fit within the allocated width. If set to false,
309      * the lines will be wrapped at character boundaries.
310      * By default this property is false.
311      *
312      * @param word indicates if word boundaries should be used
313      * for line wrapping
314      * @see #getWrapStyleWord
315      * @beaninfo
316      * preferred: false
317      * bound: true
318      * description: should wrapping occur at word boundaries
319      */

320     public void setWrapStyleWord(boolean word) {
321         boolean old = this.word;
322         this.word = word;
323         firePropertyChange("wrapStyleWord", old, word);
324     }
325
326     /**
327      * Gets the style of wrapping used if the text area is wrapping
328      * lines. If set to true the lines will be wrapped at word
329      * boundaries (ie whitespace) if they are too long
330      * to fit within the allocated width. If set to false,
331      * the lines will be wrapped at character boundaries.
332      *
333      * @return if the wrap style should be word boundaries
334      * instead of character boundaries
335      * @see #setWrapStyleWord
336      */

337     public boolean getWrapStyleWord() {
338         return word;
339     }
340
341     /**
342      * Translates an offset into the components text to a
343      * line number.
344      *
345      * @param offset the offset >= 0
346      * @return the line number >= 0
347      * @exception BadLocationException thrown if the offset is
348      * less than zero or greater than the document length.
349      */

350     public int getLineOfOffset(int offset) throws BadLocationException {
351         Document doc = getDocument();
352         if (offset < 0) {
353             throw new BadLocationException("Can't translate offset to line", -1);
354         } else if (offset > doc.getLength()) {
355             throw new BadLocationException("Can't translate offset to line", doc.getLength()+1);
356         } else {
357             Element map = getDocument().getDefaultRootElement();
358             return map.getElementIndex(offset);
359         }
360     }
361
362     /**
363      * Determines the number of lines contained in the area.
364      *
365      * @return the number of lines > 0
366      */

367     public int getLineCount() {
368         Element map = getDocument().getDefaultRootElement();
369         return map.getElementCount();
370     }
371
372     /**
373      * Determines the offset of the start of the given line.
374      *
375      * @param line the line number to translate >= 0
376      * @return the offset >= 0
377      * @exception BadLocationException thrown if the line is
378      * less than zero or greater or equal to the number of
379      * lines contained in the document (as reported by
380      * getLineCount).
381      */

382     public int getLineStartOffset(int line) throws BadLocationException {
383         int lineCount = getLineCount();
384         if (line < 0) {
385             throw new BadLocationException("Negative line", -1);
386         } else if (line >= lineCount) {
387             throw new BadLocationException("No such line", getDocument().getLength()+1);
388         } else {
389             Element map = getDocument().getDefaultRootElement();
390             Element lineElem = map.getElement(line);
391             return lineElem.getStartOffset();
392         }
393     }
394
395     /**
396      * Determines the offset of the end of the given line.
397      *
398      * @param line the line >= 0
399      * @return the offset >= 0
400      * @exception BadLocationException Thrown if the line is
401      * less than zero or greater or equal to the number of
402      * lines contained in the document (as reported by
403      * getLineCount).
404      */

405     public int getLineEndOffset(int line) throws BadLocationException {
406         int lineCount = getLineCount();
407         if (line < 0) {
408             throw new BadLocationException("Negative line", -1);
409         } else if (line >= lineCount) {
410             throw new BadLocationException("No such line", getDocument().getLength()+1);
411         } else {
412             Element map = getDocument().getDefaultRootElement();
413             Element lineElem = map.getElement(line);
414             int endOffset = lineElem.getEndOffset();
415             // hide the implicit break at the end of the document
416
return ((line == lineCount - 1) ? (endOffset - 1) : endOffset);
417         }
418     }
419
420     // --- java.awt.TextArea methods ---------------------------------
421

422     /**
423      * Inserts the specified text at the specified position. Does nothing
424      * if the model is null or if the text is null or empty.
425      * <p>
426      * This method is thread safe, although most Swing methods
427      * are not. Please see
428      * <A HREF="http://java.sun.com/products/jfc/swingdoc-archive/threads.html">Threads
429      * and Swing</A> for more information.
430      *
431      * @param str the text to insert
432      * @param pos the position at which to insert >= 0
433      * @exception IllegalArgumentException if pos is an
434      * invalid position in the model
435      * @see TextComponent#setText
436      * @see #replaceRange
437      */

438     public void insert(String JavaDoc str, int pos) {
439         Document doc = getDocument();
440         if (doc != null) {
441             try {
442                 doc.insertString(pos, str, null);
443             } catch (BadLocationException e) {
444                 throw new IllegalArgumentException JavaDoc(e.getMessage());
445             }
446         }
447     }
448
449     /**
450      * Appends the given text to the end of the document. Does nothing if
451      * the model is null or the string is null or empty.
452      * <p>
453      * This method is thread safe, although most Swing methods
454      * are not. Please see
455      * <A HREF="http://java.sun.com/products/jfc/swingdoc-archive/threads.html">Threads
456      * and Swing</A> for more information.
457      *
458      * @param str the text to insert
459      * @see #insert
460      */

461     public void append(String JavaDoc str) {
462         Document doc = getDocument();
463         if (doc != null) {
464             try {
465                 doc.insertString(doc.getLength(), str, null);
466             } catch (BadLocationException e) {
467             }
468         }
469     }
470
471     /**
472      * Replaces text from the indicated start to end position with the
473      * new text specified. Does nothing if the model is null. Simply
474      * does a delete if the new string is null or empty.
475      * <p>
476      * This method is thread safe, although most Swing methods
477      * are not. Please see
478      * <A HREF="http://java.sun.com/products/jfc/swingdoc-archive/threads.html">Threads
479      * and Swing</A> for more information.
480      *
481      * @param str the text to use as the replacement
482      * @param start the start position >= 0
483      * @param end the end position >= start
484      * @exception IllegalArgumentException if part of the range is an
485      * invalid position in the model
486      * @see #insert
487      * @see #replaceRange
488      */

489     public void replaceRange(String JavaDoc str, int start, int end) {
490         if (end < start) {
491             throw new IllegalArgumentException JavaDoc("end before start");
492         }
493         Document doc = getDocument();
494         if (doc != null) {
495             try {
496                 if (doc instanceof AbstractDocument) {
497                     ((AbstractDocument)doc).replace(start, end - start, str,
498                                                     null);
499                 }
500                 else {
501                     doc.remove(start, end - start);
502                     doc.insertString(start, str, null);
503                 }
504             } catch (BadLocationException e) {
505                 throw new IllegalArgumentException JavaDoc(e.getMessage());
506             }
507         }
508     }
509
510     /**
511      * Returns the number of rows in the TextArea.
512      *
513      * @return the number of rows >= 0
514      */

515     public int getRows() {
516         return rows;
517     }
518
519     /**
520      * Sets the number of rows for this TextArea. Calls invalidate() after
521      * setting the new value.
522      *
523      * @param rows the number of rows >= 0
524      * @exception IllegalArgumentException if rows is less than 0
525      * @see #getRows
526      * @beaninfo
527      * description: the number of rows preferred for display
528      */

529     public void setRows(int rows) {
530         int oldVal = this.rows;
531         if (rows < 0) {
532             throw new IllegalArgumentException JavaDoc("rows less than zero.");
533         }
534         if (rows != oldVal) {
535             this.rows = rows;
536             invalidate();
537         }
538     }
539
540     /**
541      * Defines the meaning of the height of a row. This defaults to
542      * the height of the font.
543      *
544      * @return the height >= 1
545      */

546     protected int getRowHeight() {
547         if (rowHeight == 0) {
548             FontMetrics metrics = getFontMetrics(getFont());
549             rowHeight = metrics.getHeight();
550         }
551         return rowHeight;
552     }
553
554     /**
555      * Returns the number of columns in the TextArea.
556      *
557      * @return number of columns >= 0
558      */

559     public int getColumns() {
560         return columns;
561     }
562
563     /**
564      * Sets the number of columns for this TextArea. Does an invalidate()
565      * after setting the new value.
566      *
567      * @param columns the number of columns >= 0
568      * @exception IllegalArgumentException if columns is less than 0
569      * @see #getColumns
570      * @beaninfo
571      * description: the number of columns preferred for display
572      */

573     public void setColumns(int columns) {
574         int oldVal = this.columns;
575         if (columns < 0) {
576             throw new IllegalArgumentException JavaDoc("columns less than zero.");
577         }
578         if (columns != oldVal) {
579             this.columns = columns;
580             invalidate();
581         }
582     }
583
584     /**
585      * Gets column width.
586      * The meaning of what a column is can be considered a fairly weak
587      * notion for some fonts. This method is used to define the width
588      * of a column. By default this is defined to be the width of the
589      * character <em>m</em> for the font used. This method can be
590      * redefined to be some alternative amount.
591      *
592      * @return the column width >= 1
593      */

594     protected int getColumnWidth() {
595         if (columnWidth == 0) {
596             FontMetrics metrics = getFontMetrics(getFont());
597             columnWidth = metrics.charWidth('m');
598         }
599         return columnWidth;
600     }
601
602     // --- Component methods -----------------------------------------
603

604     /**
605      * Returns the preferred size of the TextArea. This is the
606      * maximum of the size needed to display the text and the
607      * size requested for the viewport.
608      *
609      * @return the size
610      */

611     public Dimension getPreferredSize() {
612     Dimension d = super.getPreferredSize();
613         d = (d == null) ? new Dimension(400,400) : d;
614         Insets insets = getInsets();
615
616         if (columns != 0) {
617             d.width = Math.max(d.width, columns * getColumnWidth() +
618                     insets.left + insets.right);
619         }
620     if (rows != 0) {
621         d.height = Math.max(d.height, rows * getRowHeight() +
622                                 insets.top + insets.bottom);
623     }
624     return d;
625     }
626
627     /**
628      * Sets the current font. This removes cached row height and column
629      * width so the new font will be reflected, and calls revalidate().
630      *
631      * @param f the font to use as the current font
632      */

633     public void setFont(Font f) {
634         super.setFont(f);
635         rowHeight = 0;
636         columnWidth = 0;
637     }
638
639
640     /**
641      * Returns a string representation of this JTextArea. This method
642      * is intended to be used only for debugging purposes, and the
643      * content and format of the returned string may vary between
644      * implementations. The returned string may be empty but may not
645      * be <code>null</code>.
646      *
647      * @return a string representation of this JTextArea.
648      */

649     protected String JavaDoc paramString() {
650         String JavaDoc wrapString = (wrap ?
651                  "true" : "false");
652         String JavaDoc wordString = (word ?
653                  "true" : "false");
654
655         return super.paramString() +
656         ",colums=" + columns +
657         ",columWidth=" + columnWidth +
658         ",rows=" + rows +
659         ",rowHeight=" + rowHeight +
660         ",word=" + wordString +
661         ",wrap=" + wrapString;
662     }
663
664     // --- Scrollable methods ----------------------------------------
665

666     /**
667      * Returns true if a viewport should always force the width of this
668      * Scrollable to match the width of the viewport. This is implemented
669      * to return true if the line wrapping policy is true, and false
670      * if lines are not being wrapped.
671      *
672      * @return true if a viewport should force the Scrollables width
673      * to match its own.
674      */

675     public boolean getScrollableTracksViewportWidth() {
676         return (wrap) ? true : super.getScrollableTracksViewportWidth();
677     }
678
679     /**
680      * Returns the preferred size of the viewport if this component
681      * is embedded in a JScrollPane. This uses the desired column
682      * and row settings if they have been set, otherwise the superclass
683      * behavior is used.
684      *
685      * @return The preferredSize of a JViewport whose view is this Scrollable.
686      * @see JViewport#getPreferredSize
687      */

688     public Dimension getPreferredScrollableViewportSize() {
689         Dimension size = super.getPreferredScrollableViewportSize();
690         size = (size == null) ? new Dimension(400,400) : size;
691         size.width = (columns == 0) ? size.width : columns * getColumnWidth();
692         size.height = (rows == 0) ? size.height : rows * getRowHeight();
693         return size;
694     }
695
696     /**
697      * Components that display logical rows or columns should compute
698      * the scroll increment that will completely expose one new row
699      * or column, depending on the value of orientation. This is implemented
700      * to use the values returned by the <code>getRowHeight</code> and
701      * <code>getColumnWidth</code> methods.
702      * <p>
703      * Scrolling containers, like JScrollPane, will use this method
704      * each time the user requests a unit scroll.
705      *
706      * @param visibleRect the view area visible within the viewport
707      * @param orientation Either SwingConstants.VERTICAL or
708      * SwingConstants.HORIZONTAL.
709      * @param direction Less than zero to scroll up/left,
710      * greater than zero for down/right.
711      * @return The "unit" increment for scrolling in the specified direction
712      * @exception IllegalArgumentException for an invalid orientation
713      * @see JScrollBar#setUnitIncrement
714      * @see #getRowHeight
715      * @see #getColumnWidth
716      */

717     public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
718         switch (orientation) {
719         case SwingConstants.VERTICAL:
720             return getRowHeight();
721         case SwingConstants.HORIZONTAL:
722             return getColumnWidth();
723         default:
724             throw new IllegalArgumentException JavaDoc("Invalid orientation: " + orientation);
725         }
726     }
727
728     /**
729      * See readObject() and writeObject() in JComponent for more
730      * information about serialization in Swing.
731      */

732     private void writeObject(ObjectOutputStream JavaDoc s) throws IOException JavaDoc {
733         s.defaultWriteObject();
734         if (getUIClassID().equals(uiClassID)) {
735             byte count = JComponent.getWriteObjCounter(this);
736             JComponent.setWriteObjCounter(this, --count);
737             if (count == 0 && ui != null) {
738                 ui.installUI(this);
739             }
740         }
741     }
742
743 /////////////////
744
// Accessibility support
745
////////////////
746

747
748     /**
749      * Gets the AccessibleContext associated with this JTextArea.
750      * For JTextAreas, the AccessibleContext takes the form of an
751      * AccessibleJTextArea.
752      * A new AccessibleJTextArea instance is created if necessary.
753      *
754      * @return an AccessibleJTextArea that serves as the
755      * AccessibleContext of this JTextArea
756      */

757     public AccessibleContext getAccessibleContext() {
758         if (accessibleContext == null) {
759             accessibleContext = new AccessibleJTextArea();
760         }
761         return accessibleContext;
762     }
763
764     /**
765      * This class implements accessibility support for the
766      * <code>JTextArea</code> class. It provides an implementation of the
767      * Java Accessibility API appropriate to text area user-interface
768      * elements.
769      * <p>
770      * <strong>Warning:</strong>
771      * Serialized objects of this class will not be compatible with
772      * future Swing releases. The current serialization support is
773      * appropriate for short term storage or RMI between applications running
774      * the same version of Swing. As of 1.4, support for long term storage
775      * of all JavaBeans<sup><font size="-2">TM</font></sup>
776      * has been added to the <code>java.beans</code> package.
777      * Please see {@link java.beans.XMLEncoder}.
778      */

779     protected class AccessibleJTextArea extends AccessibleJTextComponent {
780
781         /**
782          * Gets the state set of this object.
783          *
784          * @return an instance of AccessibleStateSet describing the states
785          * of the object
786          * @see AccessibleStateSet
787          */

788         public AccessibleStateSet getAccessibleStateSet() {
789             AccessibleStateSet states = super.getAccessibleStateSet();
790             states.add(AccessibleState.MULTI_LINE);
791             return states;
792         }
793     }
794
795     // --- variables -------------------------------------------------
796

797     private int rows;
798     private int columns;
799     private int columnWidth;
800     private int rowHeight;
801     private boolean wrap;
802     private boolean word;
803
804 }
805
Popular Tags