[Patch] javax.swing.JTextArea

Michael Koch konqueror@gmx.de
Mon Sep 27 19:05:00 GMT 2004


Hi list,


I just merged the attached patch from GNU classpath.


Michael


2004-09-27  Andrew John Hughes  <address@hidden>

	* javax/swing/JTextArea.java: Added additional
	documentation.

-------------- next part --------------
Index: javax/swing/JTextArea.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextArea.java,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 JTextArea.java
--- javax/swing/JTextArea.java	13 Sep 2004 10:26:19 -0000	1.1.2.6
+++ javax/swing/JTextArea.java	27 Sep 2004 06:46:16 -0000
@@ -45,14 +45,73 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.PlainDocument;
 
+/**
+ * The <code>JTextArea</code> component provides a multi-line area for displaying
+ * and editing plain text.  The component is designed to act as a lightweight
+ * replacement for the heavyweight <code>java.awt.TextArea</code> component,
+ * which provides similar functionality using native widgets.
+ * <p>
+ *
+ * This component has additional functionality to the AWT class.  It follows
+ * the same design pattern as seen in other text components, such as
+ * <code>JTextField</code>, <code>JTextPane</code> and <code>JEditorPane</code>,
+ * and embodied in <code>JTextComponent</code>.  These classes separate the text
+ * (the model) from its appearance within the onscreen component (the view).  The
+ * text is held within a <code>javax.swing.text.Document</code> object, which can
+ * also maintain relevant style information where necessary.  As a result, it is the
+ * document that should be monitored for textual changes, via
+ * <code>DocumentEvent</code>s delivered to registered
+ * <code>DocumentListener</code>s, rather than this component.
+ * <p>
+ *
+ * Unlike <code>java.awt.TextArea</code>, <code>JTextArea</code> does not
+ * handle scrolling.  Instead, this functionality is delegated to a
+ * <code>JScrollPane</code>, which can contain the text area and handle
+ * scrolling when required.  Likewise, the word wrapping functionality
+ * of the AWT component is converted to a property of this component
+ * and the <code>rows</code> and <code>columns</code> properties
+ * are used in calculating the preferred size of the scroll pane's
+ * view port.
+ *
+ * @author Michael Koch  <konqueror@gmx.de>
+ * @author Andrew John Hughes  <gnu_andrew@member.fsf.org>
+ * @see java.awt.TextArea
+ * @see javax.swing.JTextComponent
+ * @see javax.swing.JTextField
+ * @see javax.swing.JTextPane
+ * @see javax.swing.JEditorPane
+ * @see javax.swing.text.Document
+ * @see javax.swing.text.DocumentEvent
+ * @see javax.swing.text.DocumentListener
+ */
+
 public class JTextArea extends JTextComponent
 {
+  /**
+   * Compatible with Sun's JDK
+   */
   private static final long serialVersionUID = -6141680179310439825L;
   
+  /**
+   * The number of rows used by the component.
+   */
   private int rows;
+
+  /**
+   * The number of columns used by the component.
+   */
   private int columns;
+
+  /**
+   * Whether line wrapping is enabled or not.
+   */
   private boolean lineWrap;
+
+  /**
+   * The number of characters equal to a tab within the text.
+   */
   private int tabSize = 8;
+
   private boolean wrapStyleWord;
 
   /**
@@ -129,7 +188,8 @@
   }
 
   /**
-   * Appends some text.
+   * Appends the supplied text to the current contents
+   * of the document model.
    *
    * @param toAppend the text to append
    */
@@ -148,7 +208,13 @@
     return new PlainDocument();
   }
 
-
+  /**
+   * Returns true if the width of this component should be forced
+   * to match the width of a surrounding view port.  When line wrapping
+   * is turned on, this method returns true.
+   *
+   * @return true if lines are wrapped.
+   */
   public boolean getScrollableTracksViewportWidth()
   {
     return lineWrap ? true : super.getScrollableTracksViewportWidth();
@@ -251,7 +317,7 @@
   {
     return wrapStyleWord;
   }
-
+  
   /**
    * Enables/Disables word style wrapping.
    *
@@ -262,17 +328,31 @@
   {
     if (wrapStyleWord == flag)
       return;
-
+    
     boolean oldValue = wrapStyleWord;
     wrapStyleWord = flag;
     firePropertyChange("wrapStyleWord", oldValue, wrapStyleWord);
   }
-
+  
+  /**
+   * Returns the number of characters used for a tab.
+   * This defaults to 8.
+   *
+   * @return the current number of spaces used for a tab.
+   */
   public int getTabSize()
   {
     return tabSize;
   }
 
+  /**
+   * Sets the number of characters used for a tab to the
+   * supplied value.  If a change to the tab size property
+   * occurs (i.e. newSize != tabSize), a property change event
+   * is fired.
+   * 
+   * @param newSize The new number of characters to use for a tab.
+   */
   public void setTabSize(int newSize)
   {
     if (tabSize == newSize)
@@ -334,19 +414,29 @@
     return metrics.getHeight();
   }
 
-  public void insert(String text, int offset)
+  /**
+   * Inserts the supplied text at the specified position.  Nothing
+   * happens in the case that the model or the supplied string is null
+   * or of zero length.
+   *
+   * @param string The string of text to insert.
+   * @param position The position at which to insert the supplied text.
+   * @throws IllegalArgumentException if the position is < 0 or greater
+   *         than the length of the current text.
+   */
+  public void insert(String string, int position)
   {
-    if (offset < doc.getStartPosition().getOffset()
-	|| offset >= doc.getEndPosition().getOffset())
+    if (position < doc.getStartPosition().getOffset()
+	|| position >= doc.getEndPosition().getOffset())
       throw new IllegalArgumentException();
 
     try
       {
-	doc.insertString(offset, text, null);
+	doc.insertString(position, string, null);
       }
     catch (BadLocationException e)
       {
-	// This cannot happen as we check offset above.
+	// This cannot happen as we check position above.
       }
   }
 
@@ -367,4 +457,5 @@
 	// This cannot happen as we check offset above.
       }
   }
+
 }


More information about the Java-patches mailing list