From 924af605fe5f1e5cfac29d369c3fa50b7bd603dd Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 10 Nov 2002 23:11:21 +0000 Subject: GridLayout.java (layoutContainer): Use tree lock. * 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. From-SVN: r58998 --- libjava/java/awt/FlowLayout.java | 166 ++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 80 deletions(-) (limited to 'libjava/java/awt/FlowLayout.java') diff --git a/libjava/java/awt/FlowLayout.java b/libjava/java/awt/FlowLayout.java index e328d63..1f9465e 100644 --- a/libjava/java/awt/FlowLayout.java +++ b/libjava/java/awt/FlowLayout.java @@ -150,76 +150,79 @@ public class FlowLayout implements LayoutManager, Serializable */ public void layoutContainer (Container parent) { - int num = parent.getComponentCount (); - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; + synchronized (parent.getTreeLock ()) + { + int num = parent.getComponentCount (); + // This is more efficient than calling getComponents(). + Component[] comps = parent.component; - Dimension d = parent.getSize (); - Insets ins = parent.getInsets (); + Dimension d = parent.getSize (); + Insets ins = parent.getInsets (); - ComponentOrientation orient = parent.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); + ComponentOrientation orient = parent.getComponentOrientation (); + boolean left_to_right = orient.isLeftToRight (); - int y = ins.top + vgap; - int i = 0; - while (i < num) - { - // 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 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) + // 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) { - new_w = next_w; - new_h = Math.max (new_h, c.height); - found_one = true; + // 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; + } } - 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; + 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; + 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 @@ public class FlowLayout implements LayoutManager, Serializable // 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; - // FIXME: can we just directly read the fields in Component? - // Or will that not work with subclassing? - Dimension d; + w = 0; + h = 0; + for (int i = 0; i < num; ++i) + { + if (! comps[i].visible) + continue; - 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); + } } /** -- cgit v1.1