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]

Patch: FYI: layout -vs- tree lock


I'm checking this in.

This fixes the layout managers to use the tree lock.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* java/awt/GridLayout.java (layoutContainer): Use tree lock.
	(getSize): Likewise.
	* java/awt/FlowLayout.java (layoutContainer): Use tree lock.
	(getSize): Likewise.
	* java/awt/BorderLayout.java (layoutContainer): Use tree lock.
	(calcSize): Likewise.
	* java/awt/CardLayout.java (getSize): Use tree lock.
	(gotoComponent): Likewise.
	(layoutContainer): Likewise.

Index: java/awt/BorderLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/BorderLayout.java,v
retrieving revision 1.9
diff -u -r1.9 BorderLayout.java
--- java/awt/BorderLayout.java 9 Aug 2002 04:26:13 -0000 1.9
+++ java/awt/BorderLayout.java 10 Nov 2002 23:08:58 -0000
@@ -529,80 +529,83 @@
 public void
 layoutContainer(Container target)
 {
-  Insets i = target.getInsets();
+  synchronized (target.getTreeLock ())
+    {
+      Insets i = target.getInsets();
 
-  ComponentOrientation orient = target.getComponentOrientation ();
-  boolean left_to_right = orient.isLeftToRight ();
+      ComponentOrientation orient = target.getComponentOrientation ();
+      boolean left_to_right = orient.isLeftToRight ();
 
-  Component my_north = north;
-  Component my_east = east;
-  Component my_south = south;
-  Component my_west = west;
-
-  // Note that we currently don't handle vertical layouts.  Neither
-  // does JDK 1.3.
-  if (firstLine != null)
-    my_north = firstLine;
-  if (lastLine != null)
-    my_south = lastLine;
-  if (firstItem != null)
-    {
-      if (left_to_right)
-	my_west = firstItem;
-      else
-	my_east = firstItem;
-    }
-  if (lastItem != null)
-    {
-      if (left_to_right)
-	my_east = lastItem;
-      else
-	my_west = lastItem;
+      Component my_north = north;
+      Component my_east = east;
+      Component my_south = south;
+      Component my_west = west;
+
+      // Note that we currently don't handle vertical layouts.  Neither
+      // does JDK 1.3.
+      if (firstLine != null)
+	my_north = firstLine;
+      if (lastLine != null)
+	my_south = lastLine;
+      if (firstItem != null)
+	{
+	  if (left_to_right)
+	    my_west = firstItem;
+	  else
+	    my_east = firstItem;
+	}
+      if (lastItem != null)
+	{
+	  if (left_to_right)
+	    my_east = lastItem;
+	  else
+	    my_west = lastItem;
+	}
+
+      Dimension c = calcCompSize(center, PREF);
+      Dimension n = calcCompSize(my_north, PREF);
+      Dimension s = calcCompSize(my_south, PREF);
+      Dimension e = calcCompSize(my_east, PREF);
+      Dimension w = calcCompSize(my_west, PREF);
+      Dimension t = target.getSize();
+
+      /*
+	<-> hgap     <-> hgap
+	+----------------------------+          }
+	|t                           |          } i.top
+	|  +----------------------+  |  --- y1  }
+	|  |n                     |  |
+	|  +----------------------+  |          } vgap
+	|  +---+ +----------+ +---+  |  --- y2  }        }
+	|  |w  | |c         | |e  |  |                   } hh
+	|  +---+ +----------+ +---+  |          } vgap   }
+	|  +----------------------+  |  --- y3  }
+	|  |s                     |  |
+	|  +----------------------+  |          }
+	|                            |          } i.bottom
+	+----------------------------+          }
+	|x1   |x2          |x3
+	<---------------------->
+	<-->         ww           <-->
+	i.left                    i.right
+      */
+
+      int x1 = i.left;
+      int x2 = x1 + w.width + hgap;
+      int x3 = t.width - i.right - e.width;
+      int ww = t.width - i.right - i.left;
+
+      int y1 = i.top;
+      int y2 = y1 + n.height + vgap;
+      int y3 = t.height - i.bottom - s.height;
+      int hh = y3-y2-vgap;
+
+      setBounds(center, x2, y2, x3-x2-hgap, hh);
+      setBounds(my_north, x1, y1, ww, n.height);
+      setBounds(my_south, x1, y3, ww, s.height);
+      setBounds(my_west, x1, y2, w.width, hh);
+      setBounds(my_east, x3, y2, e.width, hh);
     }
-
-  Dimension c = calcCompSize(center, PREF);
-  Dimension n = calcCompSize(my_north, PREF);
-  Dimension s = calcCompSize(my_south, PREF);
-  Dimension e = calcCompSize(my_east, PREF);
-  Dimension w = calcCompSize(my_west, PREF);
-  Dimension t = target.getSize();
-
-    /*
-             <-> hgap     <-> hgap
-      +----------------------------+          }
-      |t                           |          } i.top
-      |  +----------------------+  |  --- y1  }
-      |  |n                     |  |
-      |  +----------------------+  |          } vgap
-      |  +---+ +----------+ +---+  |  --- y2  }        }
-      |  |w  | |c         | |e  |  |                   } hh
-      |  +---+ +----------+ +---+  |          } vgap   }
-      |  +----------------------+  |  --- y3  }
-      |  |s                     |  |
-      |  +----------------------+  |          }
-      |                            |          } i.bottom
-      +----------------------------+          }
-         |x1   |x2          |x3
-         <---------------------->
-      <-->         ww           <-->
-     i.left                    i.right
-    */
-
-  int x1 = i.left;
-  int x2 = x1 + w.width + hgap;
-  int x3 = t.width - i.right - e.width;
-  int ww = t.width - i.right - i.left;
-
-  int y1 = i.top;
-  int y2 = y1 + n.height + vgap;
-  int y3 = t.height - i.bottom - s.height;
-  int hh = y3-y2-vgap;
-
-  setBounds(center, x2, y2, x3-x2-hgap, hh);
-  setBounds(my_north, x1, y1, ww, n.height);
-  setBounds(my_south, x1, y3, ww, s.height);
-  setBounds(my_west, x1, y2, w.width, hh);
-  setBounds(my_east, x3, y2, e.width, hh);
 }
 
 /*************************************************************************/
@@ -648,59 +651,62 @@
 private Dimension
 calcSize(Container target, int what)
 {
-  Insets ins = target.getInsets();
+  synchronized (target.getTreeLock ())
+    {
+      Insets ins = target.getInsets();
 
-  ComponentOrientation orient = target.getComponentOrientation ();
-  boolean left_to_right = orient.isLeftToRight ();
+      ComponentOrientation orient = target.getComponentOrientation ();
+      boolean left_to_right = orient.isLeftToRight ();
 
-  Component my_north = north;
-  Component my_east = east;
-  Component my_south = south;
-  Component my_west = west;
-
-  // Note that we currently don't handle vertical layouts.  Neither
-  // does JDK 1.3.
-  if (firstLine != null)
-    my_north = firstLine;
-  if (lastLine != null)
-    my_south = lastLine;
-  if (firstItem != null)
-    {
-      if (left_to_right)
-	my_west = firstItem;
-      else
-	my_east = firstItem;
-    }
-  if (lastItem != null)
-    {
-      if (left_to_right)
-	my_east = lastItem;
-      else
-	my_west = lastItem;
-    }
+      Component my_north = north;
+      Component my_east = east;
+      Component my_south = south;
+      Component my_west = west;
+
+      // Note that we currently don't handle vertical layouts.  Neither
+      // does JDK 1.3.
+      if (firstLine != null)
+	my_north = firstLine;
+      if (lastLine != null)
+	my_south = lastLine;
+      if (firstItem != null)
+	{
+	  if (left_to_right)
+	    my_west = firstItem;
+	  else
+	    my_east = firstItem;
+	}
+      if (lastItem != null)
+	{
+	  if (left_to_right)
+	    my_east = lastItem;
+	  else
+	    my_west = lastItem;
+	}
       
-  Dimension ndim = calcCompSize(my_north, what);
-  Dimension sdim = calcCompSize(my_south, what);
-  Dimension edim = calcCompSize(my_east, what);
-  Dimension wdim = calcCompSize(my_west, what);
-  Dimension cdim = calcCompSize(center, what);
-
-  int width = edim.width + cdim.width + wdim.width + (hgap * 2);
-  if (ndim.width > width)
-    width = ndim.width;
-  if (sdim.width > width)
-    width = sdim.width;
-
-  width += (ins.left + ins.right);
-
-  int height = edim.height;
-  if (cdim.height > height)
-    height = cdim.height;
-  if (wdim.height > height)
-    height = wdim.height;
+      Dimension ndim = calcCompSize(my_north, what);
+      Dimension sdim = calcCompSize(my_south, what);
+      Dimension edim = calcCompSize(my_east, what);
+      Dimension wdim = calcCompSize(my_west, what);
+      Dimension cdim = calcCompSize(center, what);
+
+      int width = edim.width + cdim.width + wdim.width + (hgap * 2);
+      if (ndim.width > width)
+	width = ndim.width;
+      if (sdim.width > width)
+	width = sdim.width;
+
+      width += (ins.left + ins.right);
+
+      int height = edim.height;
+      if (cdim.height > height)
+	height = cdim.height;
+      if (wdim.height > height)
+	height = wdim.height;
 
-  height += (ndim.height + sdim.height + (vgap * 2) + ins.top + ins.bottom);
+      height += (ndim.height + sdim.height + (vgap * 2) + ins.top + ins.bottom);
 
-  return(new Dimension(width, height));
+      return(new Dimension(width, height));
+    }
 }
 } // class BorderLayout 
Index: java/awt/CardLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/CardLayout.java,v
retrieving revision 1.6
diff -u -r1.6 CardLayout.java
--- java/awt/CardLayout.java 10 Nov 2002 00:16:42 -0000 1.6
+++ java/awt/CardLayout.java 10 Nov 2002 23:08:58 -0000
@@ -165,21 +165,24 @@
    */ 
   public void layoutContainer (Container parent)
   {
-    int width = parent.width;
-    int height = parent.height;
+    synchronized (parent.getTreeLock ())
+      {
+	int width = parent.width;
+	int height = parent.height;
 
-    Insets ins = parent.getInsets ();
+	Insets ins = parent.getInsets ();
 
-    int num = parent.ncomponents;
-    Component[] comps = parent.component;
+	int num = parent.ncomponents;
+	Component[] comps = parent.component;
 
-    int x = ins.left + hgap;
-    int y = ins.top + vgap;
-    width = width - 2 * hgap - ins.left - ins.right;
-    height = height - 2 * vgap - ins.top - ins.bottom;
+	int x = ins.left + hgap;
+	int y = ins.top + vgap;
+	width = width - 2 * hgap - ins.left - ins.right;
+	height = height - 2 * vgap - ins.top - ins.bottom;
 
-    for (int i = 0; i < num; ++i)
-      comps[i].setBounds (x, y, width, height);
+	for (int i = 0; i < num; ++i)
+	  comps[i].setBounds (x, y, width, height);
+      }
   }
 
   /** Get the maximum layout size of the container.
@@ -287,91 +290,97 @@
   private void gotoComponent (Container parent, int what,
 			      Component target)
   {
-    int num = parent.ncomponents;
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-    int choice = -1;
-
-    if (what == FIRST)
-      choice = 0;
-    else if (what == LAST)
-      choice = num - 1;
-    else if (what >= 0)
-      choice = what;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-	// If TARGET is set then we are looking for a specific
-	// component.
-	if (target != null)
-	  {
-	    if (target == comps[i])
-	      choice = i;
-	  }
+	int num = parent.ncomponents;
+	// This is more efficient than calling getComponents().
+	Component[] comps = parent.component;
+	int choice = -1;
+
+	if (what == FIRST)
+	  choice = 0;
+	else if (what == LAST)
+	  choice = num - 1;
+	else if (what >= 0)
+	  choice = what;
 
-	if (comps[i].isVisible ())
+	for (int i = 0; i < num; ++i)
 	  {
-	    if (what == NEXT)
+	    // If TARGET is set then we are looking for a specific
+	    // component.
+	    if (target != null)
 	      {
-		choice = i + 1;
-		if (choice == num)
-		  choice = 0;
+		if (target == comps[i])
+		  choice = i;
 	      }
-	    else if (what == PREV)
-	      {
-		choice = i - 1;
-		if (choice < 0)
-		  choice = num - 1;
-	      }
-	    else if (choice == i)
+
+	    if (comps[i].isVisible ())
 	      {
-		// Do nothing if we're already looking at the right
-		// component.
-		return;
-	      }
-	    comps[i].setVisible (false);
+		if (what == NEXT)
+		  {
+		    choice = i + 1;
+		    if (choice == num)
+		      choice = 0;
+		  }
+		else if (what == PREV)
+		  {
+		    choice = i - 1;
+		    if (choice < 0)
+		      choice = num - 1;
+		  }
+		else if (choice == i)
+		  {
+		    // Do nothing if we're already looking at the right
+		    // component.
+		    return;
+		  }
+		comps[i].setVisible (false);
 
-	    if (choice >= 0)
-	      break;
+		if (choice >= 0)
+		  break;
+	      }
 	  }
-      }
 
-    if (choice >= 0 && choice < num)
-      comps[choice].setVisible (true);
+	if (choice >= 0 && choice < num)
+	  comps[choice].setVisible (true);
+      }
   }
 
   // Compute the size according to WHAT.
   private Dimension getSize (Container parent, int what)
   {
-    int w = 0, h = 0, num = parent.ncomponents;
-    Component[] comps = parent.component;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-	Dimension d;
+	int w = 0, h = 0, num = parent.ncomponents;
+	Component[] comps = parent.component;
 
-	if (what == MIN)
-	  d = comps[i].getMinimumSize ();
-	else if (what == MAX)
-	  d = comps[i].getMaximumSize ();
-	else
-	  d = comps[i].getPreferredSize ();
+	for (int i = 0; i < num; ++i)
+	  {
+	    Dimension d;
 
-	w = Math.max (d.width, w);
-	h = Math.max (d.height, h);
-      }
+	    if (what == MIN)
+	      d = comps[i].getMinimumSize ();
+	    else if (what == MAX)
+	      d = comps[i].getMaximumSize ();
+	    else
+	      d = comps[i].getPreferredSize ();
+
+	    w = Math.max (d.width, w);
+	    h = Math.max (d.height, h);
+	  }
 
-    Insets i = parent.getInsets ();
-    w += 2 * hgap + i.right + i.left;
-    h += 2 * vgap + i.bottom + i.top;
-
-    // Handle overflow.
-    if (w < 0)
-      w = Integer.MAX_VALUE;
-    if (h < 0)
-      h = Integer.MAX_VALUE;
+	Insets i = parent.getInsets ();
+	w += 2 * hgap + i.right + i.left;
+	h += 2 * vgap + i.bottom + i.top;
+
+	// Handle overflow.
+	if (w < 0)
+	  w = Integer.MAX_VALUE;
+	if (h < 0)
+	  h = Integer.MAX_VALUE;
 
-    return new Dimension (w, h);
+	return new Dimension (w, h);
+      }
   }
 
   /**
Index: java/awt/FlowLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/FlowLayout.java,v
retrieving revision 1.7
diff -u -r1.7 FlowLayout.java
--- java/awt/FlowLayout.java 29 Jan 2002 16:31:24 -0000 1.7
+++ java/awt/FlowLayout.java 10 Nov 2002 23:08:58 -0000
@@ -150,76 +150,79 @@
    */
   public void layoutContainer (Container parent)
   {
-    int num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    Dimension d = parent.getSize ();
-    Insets ins = parent.getInsets ();
-
-    ComponentOrientation orient = parent.getComponentOrientation ();
-    boolean left_to_right = orient.isLeftToRight ();
-
-    int y = ins.top + vgap;
-    int i = 0;
-    while (i < num)
+    synchronized (parent.getTreeLock ())
       {
-	// Find the components which go in the current row.
-	int new_w = ins.left + hgap + ins.right;
-	int new_h = 0;
-	int j;
-	boolean found_one = false;
-	for (j = i; j < num && ! found_one; ++j)
+	int num = parent.getComponentCount ();
+	// This is more efficient than calling getComponents().
+	Component[] comps = parent.component;
+
+	Dimension d = parent.getSize ();
+	Insets ins = parent.getInsets ();
+
+	ComponentOrientation orient = parent.getComponentOrientation ();
+	boolean left_to_right = orient.isLeftToRight ();
+
+	int y = ins.top + vgap;
+	int i = 0;
+	while (i < num)
 	  {
-	    // Skip invisible items.
-	    if (! comps[i].visible)
-	      continue;
-
-	    Dimension c = comps[i].getPreferredSize ();
-
-	    int next_w = new_w + hgap + c.width;
-	    if (next_w <= d.width || ! found_one)
-	      {
-		new_w = next_w;
-		new_h = Math.max (new_h, c.height);
-		found_one = true;
-	      }
-	    else
+	    // Find the components which go in the current row.
+	    int new_w = ins.left + hgap + ins.right;
+	    int new_h = 0;
+	    int j;
+	    boolean found_one = false;
+	    for (j = i; j < num && ! found_one; ++j)
 	      {
-		// Must start a new row, and we already found an item
-		break;
+		// Skip invisible items.
+		if (! comps[i].visible)
+		  continue;
+
+		Dimension c = comps[i].getPreferredSize ();
+
+		int next_w = new_w + hgap + c.width;
+		if (next_w <= d.width || ! found_one)
+		  {
+		    new_w = next_w;
+		    new_h = Math.max (new_h, c.height);
+		    found_one = true;
+		  }
+		else
+		  {
+		    // Must start a new row, and we already found an item
+		    break;
+		  }
 	      }
-	  }
 
-	// Set the location of each component for this row.
-	int x;
+	    // Set the location of each component for this row.
+	    int x;
 
-	int myalign = align;
-	if (align == LEADING)
-	  myalign = left_to_right ? LEFT : RIGHT;
-	else if (align == TRAILING)
-	  myalign = left_to_right ? RIGHT : LEFT;
-
-	if (myalign == LEFT)
-	  x = ins.left + hgap;
-	else if (myalign == CENTER)
-	  x = (d.width - new_w) / 2;
-	else
-	  x = d.width - new_w;
+	    int myalign = align;
+	    if (align == LEADING)
+	      myalign = left_to_right ? LEFT : RIGHT;
+	    else if (align == TRAILING)
+	      myalign = left_to_right ? RIGHT : LEFT;
+
+	    if (myalign == LEFT)
+	      x = ins.left + hgap;
+	    else if (myalign == CENTER)
+	      x = (d.width - new_w) / 2;
+	    else
+	      x = d.width - new_w;
 
-	for (int k = i; k < j; ++k)
-	  {
-	    if (comps[k].visible)
+	    for (int k = i; k < j; ++k)
 	      {
-		Dimension c = comps[k].getPreferredSize ();
-		comps[k].setBounds (x, y, c.width, new_h);
-		x += c.width + hgap;
+		if (comps[k].visible)
+		  {
+		    Dimension c = comps[k].getPreferredSize ();
+		    comps[k].setBounds (x, y, c.width, new_h);
+		    x += c.width + hgap;
+		  }
 	      }
-	  }
 
-	// Advance to next row.
-	i = j;
-	y += new_h + vgap;
+	    // Advance to next row.
+	    i = j;
+	    y += new_h + vgap;
+	  }
       }
   }
 
@@ -304,36 +307,39 @@
   // This method is used to compute the various sizes.
   private Dimension getSize (Container parent, boolean is_min)
   {
-    int w, h, num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    w = 0;
-    h = 0;
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-	if (! comps[i].visible)
-	  continue;
+	int w, h, num = parent.getComponentCount ();
+	// This is more efficient than calling getComponents().
+	Component[] comps = parent.component;
+
+	w = 0;
+	h = 0;
+	for (int i = 0; i < num; ++i)
+	  {
+	    if (! comps[i].visible)
+	      continue;
 
-	// FIXME: can we just directly read the fields in Component?
-	// Or will that not work with subclassing?
-	Dimension d;
-
-	if (is_min)
-	  d = comps[i].getMinimumSize ();
-	else
-	  d = comps[i].getPreferredSize ();
+	    // FIXME: can we just directly read the fields in Component?
+	    // Or will that not work with subclassing?
+	    Dimension d;
 
-	w += d.width;
-	h = Math.max (d.height, h);
-      }
+	    if (is_min)
+	      d = comps[i].getMinimumSize ();
+	    else
+	      d = comps[i].getPreferredSize ();
 
-    Insets ins = parent.getInsets ();
+	    w += d.width;
+	    h = Math.max (d.height, h);
+	  }
 
-    w += (num + 1) * hgap + ins.left + ins.right;
-    h += 2 * vgap + ins.top + ins.bottom;
+	Insets ins = parent.getInsets ();
 
-    return new Dimension (w, h);
+	w += (num + 1) * hgap + ins.left + ins.right;
+	h += 2 * vgap + ins.top + ins.bottom;
+
+	return new Dimension (w, h);
+      }
   }
 
   /**
Index: java/awt/GridLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/GridLayout.java,v
retrieving revision 1.9
diff -u -r1.9 GridLayout.java
--- java/awt/GridLayout.java 10 Nov 2002 17:35:13 -0000 1.9
+++ java/awt/GridLayout.java 10 Nov 2002 23:09:00 -0000
@@ -153,62 +153,65 @@
    */
   public void layoutContainer (Container parent)
   {
-    int num = parent.ncomponents;
+    synchronized (parent.getTreeLock ())
+      {
+	int num = parent.ncomponents;
 
-    // There's no point, and handling this would mean adding special
-    // cases.
-    if (num == 0)
-      return;
-
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    int real_rows = rows;
-    int real_cols = cols;
-    if (real_rows == 0)
-      real_rows = (num + real_cols - 1) / real_cols;
-    else
-      real_cols = (num + real_rows - 1) / real_rows;
-
-    // We might have less than a single row.  In this case we expand
-    // to fill.
-    if (num < real_cols)
-      real_cols = num;
-
-    Dimension d = parent.getSize ();
-    Insets ins = parent.getInsets ();
-
-    // Compute width and height of each cell in the grid.
-    int tw = d.width - ins.left - ins.right;
-    tw = (tw - (real_cols - 1) * hgap) / real_cols;
-    int th = d.height - ins.top - ins.bottom;
-    th = (th - (real_rows - 1) * vgap) / real_rows;
-
-    // If the cells are too small, still try to do something.
-    if (tw < 0)
-      tw = 1;
-    if (th < 0)
-      th = 1;
-
-    int x = ins.left;
-    int y = ins.top;
-    int i = 0;
-    int recount = 0;
+	// There's no point, and handling this would mean adding special
+	// cases.
+	if (num == 0)
+	  return;
+
+	// This is more efficient than calling getComponents().
+	Component[] comps = parent.component;
+
+	int real_rows = rows;
+	int real_cols = cols;
+	if (real_rows == 0)
+	  real_rows = (num + real_cols - 1) / real_cols;
+	else
+	  real_cols = (num + real_rows - 1) / real_rows;
 
-    while (i < num)
-      {
-	comps[i].setBounds (x, y, tw, th);
+	// We might have less than a single row.  In this case we expand
+	// to fill.
+	if (num < real_cols)
+	  real_cols = num;
+
+	Dimension d = parent.getSize ();
+	Insets ins = parent.getInsets ();
+
+	// Compute width and height of each cell in the grid.
+	int tw = d.width - ins.left - ins.right;
+	tw = (tw - (real_cols - 1) * hgap) / real_cols;
+	int th = d.height - ins.top - ins.bottom;
+	th = (th - (real_rows - 1) * vgap) / real_rows;
+
+	// If the cells are too small, still try to do something.
+	if (tw < 0)
+	  tw = 1;
+	if (th < 0)
+	  th = 1;
+
+	int x = ins.left;
+	int y = ins.top;
+	int i = 0;
+	int recount = 0;
 
-	++i;
-	++recount;
-	if (recount == real_cols)
+	while (i < num)
 	  {
-	    recount = 0;
-	    y += vgap + th;
-	    x = ins.left;
+	    comps[i].setBounds (x, y, tw, th);
+
+	    ++i;
+	    ++recount;
+	    if (recount == real_cols)
+	      {
+		recount = 0;
+		y += vgap + th;
+		x = ins.left;
+	      }
+	    else
+	      x += hgap + tw;
 	  }
-	else
-	  x += hgap + tw;
       }
   }
 
@@ -301,36 +304,39 @@
   // This method is used to compute the various sizes.
   private Dimension getSize (Container parent, boolean is_min)
   {
-    int w = 0, h = 0, num = parent.ncomponents;
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-	Dimension d;
+	int w = 0, h = 0, num = parent.ncomponents;
+	// This is more efficient than calling getComponents().
+	Component[] comps = parent.component;
 
-	if (is_min)
-	  d = comps[i].getMinimumSize ();
+	for (int i = 0; i < num; ++i)
+	  {
+	    Dimension d;
+
+	    if (is_min)
+	      d = comps[i].getMinimumSize ();
+	    else
+	      d = comps[i].getPreferredSize ();
+
+	    w = Math.max (d.width, w);
+	    h = Math.max (d.height, h);
+	  }
+
+	int real_rows = rows;
+	int real_cols = cols;
+	if (real_rows == 0)
+	  real_rows = (num + real_cols - 1) / real_cols;
 	else
-	  d = comps[i].getPreferredSize ();
+	  real_cols = (num + real_rows - 1) / real_rows;
 
-	w = Math.max (d.width, w);
-	h = Math.max (d.height, h);
+	Insets ins = parent.getInsets ();
+	// We subtract out an extra gap here because the gaps are only
+	// between cells.
+	w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
+	h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
+	return new Dimension (w, h);
       }
-
-    int real_rows = rows;
-    int real_cols = cols;
-    if (real_rows == 0)
-      real_rows = (num + real_cols - 1) / real_cols;
-    else
-      real_cols = (num + real_rows - 1) / real_rows;
-
-    Insets ins = parent.getInsets ();
-    // We subtract out an extra gap here because the gaps are only
-    // between cells.
-    w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
-    h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
-    return new Dimension (w, h);
   }
 
   /**


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