diff options
Diffstat (limited to 'java/awt/FlowLayout.java')
-rw-r--r-- | java/awt/FlowLayout.java | 194 |
1 files changed, 97 insertions, 97 deletions
diff --git a/java/awt/FlowLayout.java b/java/awt/FlowLayout.java index 70c98a29a..231d041b1 100644 --- a/java/awt/FlowLayout.java +++ b/java/awt/FlowLayout.java @@ -73,7 +73,7 @@ public class FlowLayout implements LayoutManager, Serializable * does nothing. * * @param name the name - * @param comp the component + * @param comp the component */ public void addLayoutComponent (String name, Component comp) { @@ -155,78 +155,78 @@ public class FlowLayout implements LayoutManager, Serializable { 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 (); - - 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; ++j) - { - // Skip invisible items. - if (! comps[j].visible) - continue; - - Dimension c = comps[j].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; - - int myalign = align; - if (align == LEADING) - myalign = left_to_right ? LEFT : RIGHT; - else if (align == TRAILING) - myalign = left_to_right ? RIGHT : LEFT; - - if (myalign == RIGHT) - x = ins.left + (d.width - new_w) + hgap; - else if (myalign == CENTER) - x = ins.left + (d.width - new_w) / 2 + hgap; - else // LEFT and all other values of align. - x = ins.left + hgap; - - for (int k = i; k < j; ++k) - { - if (comps[k].visible) - { - Dimension c = comps[k].getPreferredSize (); - comps[k].setBounds (x, y + (new_h - c.height) / 2, - c.width, c.height); - x += c.width + hgap; - } - } - - // Advance to next row. - i = j; - y += new_h + vgap; - } + 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) + { + // 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; ++j) + { + // Skip invisible items. + if (! comps[j].visible) + continue; + + Dimension c = comps[j].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; + + int myalign = align; + if (align == LEADING) + myalign = left_to_right ? LEFT : RIGHT; + else if (align == TRAILING) + myalign = left_to_right ? RIGHT : LEFT; + + if (myalign == RIGHT) + x = ins.left + (d.width - new_w) + hgap; + else if (myalign == CENTER) + x = ins.left + (d.width - new_w) / 2 + hgap; + else // LEFT and all other values of align. + x = ins.left + hgap; + + for (int k = i; k < j; ++k) + { + if (comps[k].visible) + { + Dimension c = comps[k].getPreferredSize (); + comps[k].setBounds (x, y + (new_h - c.height) / 2, + c.width, c.height); + x += c.width + hgap; + } + } + + // Advance to next row. + i = j; + y += new_h + vgap; + } } } @@ -278,7 +278,7 @@ public class FlowLayout implements LayoutManager, Serializable /** * Sets the horizontal gap between lines of components to the specified value. * No Exception is thrown if hgap < 0. - * + * * @param hgap The new horizontal gap between components. */ public void setHgap (int hgap) @@ -303,7 +303,7 @@ public class FlowLayout implements LayoutManager, Serializable public String toString () { return ("[" + getClass ().getName () + ",hgap=" + hgap + ",vgap=" + vgap - + ",align=" + align + "]"); + + ",align=" + align + "]"); } // This method is used to compute the various sizes. @@ -311,39 +311,39 @@ public class FlowLayout implements LayoutManager, Serializable { synchronized (parent.getTreeLock ()) { - int w, h, num = parent.getComponentCount (); - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; + 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; + 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; + // 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 (); + if (is_min) + d = comps[i].getMinimumSize (); + else + d = comps[i].getPreferredSize (); - w += d.width; - h = Math.max (d.height, h); - } + w += d.width; + h = Math.max (d.height, h); + } - Insets ins = parent.getInsets (); + Insets ins = parent.getInsets (); if (num == 0) w += 2 * hgap + ins.left + ins.right; else w += (num + 1) * hgap + ins.left + ins.right; - h += 2 * vgap + ins.top + ins.bottom; + h += 2 * vgap + ins.top + ins.bottom; - return new Dimension (w, h); + return new Dimension (w, h); } } |