This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] TextArea and GtkTextAreaPeer fixes


Hi,

This patch fixes some problems with sizing TextAreas constructed without
row and column information.  They should be given row and column values
of zero, and their bounds should be set to sensible values by the peer. 
This patch also properly sets the peer's editable state.  I committed
this to java-gui-branch.

Tom

2004-06-12  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* gnu/java/awt/peer/gtk/GtkTextAreaPeer.java (DEFAULT_ROWS,
	DEFAULT_COLS): New variables.
	(create): Don't allow 0 rows or 0 columns.  Instead, set the
	values to DEFAULT_ROWS or DEFAULT_COLS.
	(getMinimumSize): Likewise.
	(getPreferredSize): Likewise.
	(minimumSize): Likewise.
	(preferredSize): Likewise.
	(create): Set peer's editable state.
	* java/awt/TextArea.java (TextArea()): Set rows and columns to
	zero.  Update javadocs.
	(TextArea(String)): Likewise.
	(TextArea(int,int)): Fix javadocs.
	(TextArea(String,int,int,int)): Only throw exception if one of
	rows or columns is zero.  Fix javadocs.

Index: gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java,v
retrieving revision 1.7.8.3
diff -u -r1.7.8.3 GtkTextAreaPeer.java
--- gnu/java/awt/peer/gtk/GtkTextAreaPeer.java	27 May 2004 18:40:16 -0000	1.7.8.3
+++ gnu/java/awt/peer/gtk/GtkTextAreaPeer.java	12 Jun 2004 04:39:40 -0000
@@ -47,6 +47,9 @@
 public class GtkTextAreaPeer extends GtkTextComponentPeer
   implements TextAreaPeer
 {
+  private static transient int DEFAULT_ROWS = 10;
+  private static transient int DEFAULT_COLS = 80;
+
   native void create (int width, int height, int scrollbarVisibility);
 
   native void gtkSetFont (String name, int style, int size);
@@ -72,13 +75,17 @@
       fm = new GdkFontMetrics (f);
 
     TextArea ta = ((TextArea) awtComponent);
-    int rows = ta.getRows ();
-    int cols = ta.getColumns ();
+    int sizeRows = ta.getRows ();
+    int sizeCols = ta.getColumns ();
+
+    sizeRows = sizeRows == 0 ? DEFAULT_ROWS : sizeRows;
+    sizeCols = sizeCols == 0 ? DEFAULT_COLS : sizeCols;
 
-    int width = cols * fm.getMaxAdvance ();
-    int height = rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+    int width = sizeCols * fm.getMaxAdvance ();
+    int height = sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
 
     create (width, height, ta.getScrollbarVisibility ());
+    setEditable (ta.isEditable ());
   }
 
   public GtkTextAreaPeer (TextArea ta)
@@ -91,12 +98,14 @@
 
   public Dimension getMinimumSize (int rows, int cols)
   {
-    return minimumSize (rows, cols);
+    return minimumSize (rows == 0 ? DEFAULT_ROWS : rows,
+                        cols == 0 ? DEFAULT_COLS : cols);
   }
 
   public Dimension getPreferredSize (int rows, int cols)
   {
-    return preferredSize (rows, cols);
+    return preferredSize (rows == 0 ? DEFAULT_ROWS : rows,
+                          cols == 0 ? DEFAULT_COLS : cols);
   }
 
   native int getHScrollbarHeight ();
@@ -129,8 +138,11 @@
     else
       fm = new GdkFontMetrics (f);
 
-    width += cols * fm.getMaxAdvance ();
-    height += rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+    int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
+    int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
+
+    width += sizeCols * fm.getMaxAdvance ();
+    height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
 
     return new Dimension (width, height);
   }
@@ -161,8 +173,11 @@
     else
       fm = new GdkFontMetrics (f);
 
-    width += cols * fm.getMaxAdvance ();
-    height += rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+    int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
+    int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
+
+    width += sizeCols * fm.getMaxAdvance ();
+    height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
 
     return new Dimension (width, height);
   }
Index: java/awt/TextArea.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/TextArea.java,v
retrieving revision 1.10.2.1
diff -u -r1.10.2.1 TextArea.java
--- java/awt/TextArea.java	6 May 2004 23:29:42 -0000	1.10.2.1
+++ java/awt/TextArea.java	12 Jun 2004 04:39:40 -0000
@@ -103,29 +103,33 @@
   private static transient long next_text_number = 0;
 
   /**
-   * Initialize a new instance of <code>TextArea</code> that is empty
-   * and is one row by one column.  Both horizontal and vertical
+   * Initialize a new instance of <code>TextArea</code> that is empty.
+   * 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 vertical
    * scrollbars will be displayed.
    *
-   * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true,
+   * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
    */
   public TextArea ()
   {
-    this ("", 1, 1, SCROLLBARS_BOTH);
+    this ("", 0, 0, SCROLLBARS_BOTH);
   }
 
   /**
-   * Initialize a new instance of <code>TextArea</code> that initially
-   * contains the specified text.  Both horizontal and veritcal
-   * scrollbars will be displayed.
+   * Initialize a new instance of <code>TextArea</code> that contains
+   * 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.
    *
    * @param text The text to display in this text area.
    *
-   * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true,
+   * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
    */
   public TextArea (String text)
   {
-    this (text, 1, text.length (), SCROLLBARS_BOTH);
+    this (text, 0, 0, SCROLLBARS_BOTH);
   }
 
   /**
@@ -137,7 +141,7 @@
    * @param rows The number of rows in this text area.
    * @param columns The number of columns in this text area.
    *
-   * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true,
+   * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
    */
   public TextArea (int rows, int columns)
   {
@@ -154,7 +158,7 @@
    * @param rows The number of rows in this text area.
    * @param columns The number of columns in this text area.
    *
-   * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true,
+   * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
    */
   public TextArea (String text, int rows, int columns)
   {
@@ -175,7 +179,7 @@
    * SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY,
    * SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE.
    *
-   * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true,
+   * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
    */
   public TextArea (String text, int rows, int columns, int scrollbarVisibility)
   {
@@ -184,7 +188,7 @@
     if (GraphicsEnvironment.isHeadless ())
       throw new HeadlessException ();
 
-    if (rows < 1 || columns < 0)
+    if (rows < 0 || columns < 0)
       throw new IllegalArgumentException ("Bad row or column value");
 
     if (scrollbarVisibility != SCROLLBARS_BOTH

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]