From ed178abb75b2e01875075bbdcf7689c5047951fc Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 19 Dec 2001 19:38:25 +0000 Subject: [PATCH] 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 --- libjava/ChangeLog | 8 +++++ libjava/java/awt/FlowLayout.java | 60 ++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index cf601a26a9a..3513b273f6e 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2001-12-19 Tom Tromey + + * 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 * include/jvm.h (_Jv_BuildGCDescr): Declare unconditionally. diff --git a/libjava/java/awt/FlowLayout.java b/libjava/java/awt/FlowLayout.java index 95cb6e65521..d33059bf252 100644 --- a/libjava/java/awt/FlowLayout.java +++ b/libjava/java/awt/FlowLayout.java @@ -1,6 +1,6 @@ -// 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. @@ -61,20 +61,20 @@ public class FlowLayout implements LayoutManager, Serializable } /** Create a new FlowLayout with center alignment. - * Both gaps are set to 0. + * Both gaps are set to 5. */ public FlowLayout () { - this (CENTER, 0, 0); + this (CENTER, 5, 5); } /** Create a new FlowLayout with the alignment. - * columns. Both gaps are set to 0. + * columns. Both gaps are set to 5. * @param align Alignment */ public FlowLayout (int align) { - this (align, 0, 0); + this (align, 5, 5); } /** Create a new FlowLayout with the specified alignment and gaps. @@ -85,16 +85,11 @@ public class FlowLayout implements LayoutManager, Serializable */ public FlowLayout (int align, int hgap, int vgap) { - if (hgap < 0) - throw new IllegalArgumentException ("horizontal gap must be nonnegative"); - if (vgap < 0) - throw new IllegalArgumentException ("vertical gap must be nonnegative"); - if (align != LEFT && align != RIGHT && align != CENTER - && align != LEADING && align != TRAILING) - throw new IllegalArgumentException ("invalid align: " + align); - this.align = align; - this.hgap = hgap; - this.vgap = vgap; + // Use methods to set fields so that we can have all the checking + // in one place. + setVgap (vgap); + setHgap (hgap); + setAlignment (align); } /** Lay out the container's components based on current settings. @@ -120,22 +115,29 @@ public class FlowLayout implements LayoutManager, Serializable int new_w = ins.left + hgap + ins.right; int new_h = 0; 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. Dimension c = comps[i].getPreferredSize (); + + // Skip invisible items. + if (! comps[i].visible) + continue; + int next_w = new_w + hgap + c.width; - if (next_w > d.width) + if (next_w <= d.width || ! found_one) { - // We must start a new row. + 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; } - 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. int x; @@ -157,8 +159,11 @@ public class FlowLayout implements LayoutManager, Serializable { // FIXME: this is very inefficient. Dimension c = comps[i].getPreferredSize (); - comps[i].setLocation (x, y); - x += c.width + vgap; + if (comps[i].visible) + { + comps[i].setLocation (x, y); + x += c.width + vgap; + } } // Advance to next row. @@ -241,6 +246,9 @@ public class FlowLayout implements LayoutManager, Serializable 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;