Commit ed178abb by Tom Tromey Committed by Tom Tromey

FlowLayout.java (FlowLayout(), [...]): Set gaps to 5.

	* java/awt/FlowLayout.java (FlowLayout(), FlowLayout(int)): Set
	gaps to 5.
	(FlowLayout(int,int,int)): Use methods to set fields.
	(getSize): Skip invisible components.
	(layoutContainer): Skip invisible components.

From-SVN: r48182
parent 24ea750e
2001-12-19 Tom Tromey <tromey@redhat.com>
* java/awt/FlowLayout.java (FlowLayout(), FlowLayout(int)): Set
gaps to 5.
(FlowLayout(int,int,int)): Use methods to set fields.
(getSize): Skip invisible components.
(layoutContainer): Skip invisible components.
2001-12-19 Bryce McKinlay <bryce@waitaki.otago.ac.nz> 2001-12-19 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* include/jvm.h (_Jv_BuildGCDescr): Declare unconditionally. * include/jvm.h (_Jv_BuildGCDescr): Declare unconditionally.
......
// GridLayout.java - Grid-based layout engine // FlowLayout.java - Grid-based layout engine
/* Copyright (C) 2000 Free Software Foundation /* Copyright (C) 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -61,20 +61,20 @@ public class FlowLayout implements LayoutManager, Serializable ...@@ -61,20 +61,20 @@ public class FlowLayout implements LayoutManager, Serializable
} }
/** Create a new FlowLayout with center alignment. /** Create a new FlowLayout with center alignment.
* Both gaps are set to 0. * Both gaps are set to 5.
*/ */
public FlowLayout () public FlowLayout ()
{ {
this (CENTER, 0, 0); this (CENTER, 5, 5);
} }
/** Create a new FlowLayout with the alignment. /** Create a new FlowLayout with the alignment.
* columns. Both gaps are set to 0. * columns. Both gaps are set to 5.
* @param align Alignment * @param align Alignment
*/ */
public FlowLayout (int align) public FlowLayout (int align)
{ {
this (align, 0, 0); this (align, 5, 5);
} }
/** Create a new FlowLayout with the specified alignment and gaps. /** Create a new FlowLayout with the specified alignment and gaps.
...@@ -85,16 +85,11 @@ public class FlowLayout implements LayoutManager, Serializable ...@@ -85,16 +85,11 @@ public class FlowLayout implements LayoutManager, Serializable
*/ */
public FlowLayout (int align, int hgap, int vgap) public FlowLayout (int align, int hgap, int vgap)
{ {
if (hgap < 0) // Use methods to set fields so that we can have all the checking
throw new IllegalArgumentException ("horizontal gap must be nonnegative"); // in one place.
if (vgap < 0) setVgap (vgap);
throw new IllegalArgumentException ("vertical gap must be nonnegative"); setHgap (hgap);
if (align != LEFT && align != RIGHT && align != CENTER setAlignment (align);
&& align != LEADING && align != TRAILING)
throw new IllegalArgumentException ("invalid align: " + align);
this.align = align;
this.hgap = hgap;
this.vgap = vgap;
} }
/** Lay out the container's components based on current settings. /** Lay out the container's components based on current settings.
...@@ -120,22 +115,29 @@ public class FlowLayout implements LayoutManager, Serializable ...@@ -120,22 +115,29 @@ public class FlowLayout implements LayoutManager, Serializable
int new_w = ins.left + hgap + ins.right; int new_w = ins.left + hgap + ins.right;
int new_h = 0; int new_h = 0;
int j; int j;
for (j = i; j < num; ++j) boolean found_one = false;
for (j = i; j < num && ! found_one; ++j)
{ {
// FIXME: this is very inefficient. // FIXME: this is very inefficient.
Dimension c = comps[i].getPreferredSize (); Dimension c = comps[i].getPreferredSize ();
// Skip invisible items.
if (! comps[i].visible)
continue;
int next_w = new_w + hgap + c.width; int next_w = new_w + hgap + c.width;
if (next_w > d.width) if (next_w <= d.width || ! found_one)
{
new_w = next_w;
new_h = Math.max (new_h, c.height);
found_one = true;
}
else
{ {
// We must start a new row. // Must start a new row, and we already found an item
break; break;
} }
new_w = next_w;
new_h = Math.max (new_h, c.height);
} }
// We always need at least one item.
if (j == i)
++j;
// Set the location of each component for this row. // Set the location of each component for this row.
int x; int x;
...@@ -157,8 +159,11 @@ public class FlowLayout implements LayoutManager, Serializable ...@@ -157,8 +159,11 @@ public class FlowLayout implements LayoutManager, Serializable
{ {
// FIXME: this is very inefficient. // FIXME: this is very inefficient.
Dimension c = comps[i].getPreferredSize (); Dimension c = comps[i].getPreferredSize ();
comps[i].setLocation (x, y); if (comps[i].visible)
x += c.width + vgap; {
comps[i].setLocation (x, y);
x += c.width + vgap;
}
} }
// Advance to next row. // Advance to next row.
...@@ -241,6 +246,9 @@ public class FlowLayout implements LayoutManager, Serializable ...@@ -241,6 +246,9 @@ public class FlowLayout implements LayoutManager, Serializable
h = 0; h = 0;
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
{ {
if (! comps[i].visible)
continue;
// FIXME: can we just directly read the fields in Component? // FIXME: can we just directly read the fields in Component?
// Or will that not work with subclassing? // Or will that not work with subclassing?
Dimension d; Dimension d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment