[cp-patches]: RFA: TextArea and TextComponent fixes

Thomas Fitzsimmons fitzsim at redhat.com
Fri Jun 30 20:10:08 UTC 2006


Tania Bento wrote:
> Hey,
> 
> Based on David Gilbert's comments and suggestions, I have made these
> modifcations.  I have also committed mauve tests for these changes.
> 
> If someone could please approve/comment on this patch, that would be
> great.

Looks good, please commit.

Thanks,
Tom

> 
> Thanks,
> Tania
> 
> 2006-06-30  Tania Bento  <tbento at redhat.com>
> 
> 	* java/awt/TextArea.java:
> 	(TextArea(String, int, int, int)): No longer throws
> IllegalArgumentException if rows, columns, or scrollbarVisibility values
> are invalid.  
> 	(TextArea(String, int, int, int)): If rows or columns are < 0, they get
> set to 0.  If scrollbarVisibility is < 0 or > 4, it gets set to the
> default value of 0 (SCROLLBARS_BOTH).
> 	(appendText): Added case when peer = null.
> 	(insertText): Added case when peer == null.
> 	(replaceText): Added case when peer == null.
> 	* java/awt/TextComponent.java:
> 	(TextComponent(String)): If text == null, set it to "".
> 
> 
> ------------------------------------------------------------------------
> 
> Index: java/awt/Component.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
> retrieving revision 1.127
> diff -u -r1.127 Component.java
> --- java/awt/Component.java	27 Jun 2006 19:59:14 -0000	1.127
> +++ java/awt/Component.java	30 Jun 2006 18:29:57 -0000
> @@ -4697,7 +4697,7 @@
>                                      Object newValue)
>    {
>      if (changeSupport != null)
> -      changeSupport.firePropertyChange(propertyName, oldValue, newValue);
> +      changeSupport.firePropertyChange(propertyName, oldValue, newValue);  
>    }
>  
>    /**
> Index: java/awt/TextArea.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/awt/TextArea.java,v
> retrieving revision 1.20
> diff -u -r1.20 TextArea.java
> --- java/awt/TextArea.java	20 Sep 2005 01:05:28 -0000	1.20
> +++ java/awt/TextArea.java	30 Jun 2006 18:29:57 -0000
> @@ -125,9 +125,11 @@
>     * the specified text.  Conceptually the <code>TextArea</code> has 0
>     * rows and 0 columns but its initial bounds are defined by its peer
>     * or by the container in which it is packed.  Both horizontal and
> -   * veritcal scrollbars will be displayed.
> +   * veritcal scrollbars will be displayed.  The TextArea initially contains
> +   * the specified text.  If text specified as <code>null<code>, it will
> +   * be set to "".
>     *
> -   * @param text The text to display in this text area.
> +   * @param text The text to display in this text area (<code>null</code> permitted).
>     *
>     * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
>     */
> @@ -156,9 +158,10 @@
>     * Initialize a new instance of <code>TextArea</code> that can
>     * display the specified number of rows and columns of text, without
>     * the need to scroll.  The TextArea initially contains the
> -   * specified text.
> +   * specified text.  If text specified as <code>null<code>, it will
> +   * be set to "".
>     *
> -   * @param text The text to display in this text area.
> +   * @param text The text to display in this text area (<code>null</code> permitted).
>     * @param rows The number of rows in this text area.
>     * @param columns The number of columns in this text area.
>     *
> @@ -174,9 +177,10 @@
>     * contains the specified text.  The TextArea can display the
>     * specified number of rows and columns of text, without the need to
>     * scroll.  This constructor allows specification of the scroll bar
> -   * display policy.
> +   * display policy.  The TextArea initially contains the specified text.  
> +   * If text specified as <code>null<code>, it will be set to "". 
>     *
> -   * @param text The text to display in this text area.
> +   * @param text The text to display in this text area (<code>null</code> permitted).
>     * @param rows The number of rows in this text area.
>     * @param columns The number of columns in this text area.
>     * @param scrollbarVisibility The scroll bar display policy. One of
> @@ -192,18 +196,20 @@
>      if (GraphicsEnvironment.isHeadless ())
>        throw new HeadlessException ();
>  
> -    if (rows < 0 || columns < 0)
> -      throw new IllegalArgumentException ("Bad row or column value");
> -
> -    if (scrollbarVisibility != SCROLLBARS_BOTH
> -        && scrollbarVisibility != SCROLLBARS_VERTICAL_ONLY
> -        && scrollbarVisibility != SCROLLBARS_HORIZONTAL_ONLY
> -        && scrollbarVisibility != SCROLLBARS_NONE)
> -      throw new IllegalArgumentException ("Bad scrollbar visibility value");
> -
> -    this.rows = rows;
> -    this.columns = columns;
> -    this.scrollbarVisibility = scrollbarVisibility;
> +    if (rows < 0)
> +      this.rows = 0;
> +    else
> +      this.rows = rows;
> +    
> +    if (columns < 0)
> +      this.columns = 0;
> +    else
> +      this.columns = columns;
> +
> +    if (scrollbarVisibility < 0 || scrollbarVisibility > 4)
> +      this.scrollbarVisibility = SCROLLBARS_BOTH;
> +    else
> +      this.scrollbarVisibility = scrollbarVisibility;
>  
>      // TextAreas need to receive tab key events so we override the
>      // default forward and backward traversal key sets.
> @@ -478,6 +484,8 @@
>  
>      if (peer != null)
>        peer.insert (str, peer.getText().length ());
> +    else
> +      setText(getText() + str);   
>    }
>  
>    /**
> @@ -504,10 +512,19 @@
>     */
>    public void insertText (String str, int pos)
>    {
> +    String tmp1 = null;
> +    String tmp2 = null;
> +    
>      TextAreaPeer peer = (TextAreaPeer) getPeer ();
>  
>      if (peer != null)
>        peer.insert (str, pos);
> +    else
> +      {
> +        tmp1 = getText().substring(0, pos);
> +        tmp2 = getText().substring(pos, getText().length());
> +        setText(tmp1 + str + tmp2);
> +      }
>    }
>  
>    /**
> @@ -544,10 +561,19 @@
>     */
>    public void replaceText (String str, int start, int end)
>    {
> -    TextAreaPeer peer = (TextAreaPeer) getPeer ();
> +    String tmp1 = null;
> +    String tmp2 = null;
> +
> +    TextAreaPeer peer = (TextAreaPeer) getPeer();
>  
>      if (peer != null)
> -      peer.replaceRange (str, start, end);
> +      peer.replaceRange(str, start, end);
> +    else
> +      {
> +        tmp1 = getText().substring(0, start);
> +        tmp2 = getText().substring(end, getText().length());
> +        setText(tmp1 + str + tmp2);
> +      }
>    }
>  
>    /**
> Index: java/awt/TextComponent.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/awt/TextComponent.java,v
> retrieving revision 1.24
> diff -u -r1.24 TextComponent.java
> --- java/awt/TextComponent.java	30 Jun 2006 09:32:21 -0000	1.24
> +++ java/awt/TextComponent.java	30 Jun 2006 18:29:57 -0000
> @@ -312,7 +312,11 @@
>  
>    TextComponent(String text)
>    {
> -    this.text = text;
> +    if (text == null)
> +      this.text = "";
> +    else
> +      this.text = text;
> +    
>      this.editable = true;
>    }
>  




More information about the Classpath-patches mailing list