GridLayout() bugfix -- exclude MenuBar when 0'th component
Giles Lean
giles at nemeton.com.au
Sat Aug 1 08:44:07 PDT 1998
>Submitter-Id: kaffe-user
>Originator: Giles Lean
>Organization: Giles Lean <giles at nemeton.com.au> +61 3 9480 2118
Nemeton Pty. Ltd. fax +61 3 9480 1771
PGP Fingerprint (DA68EE41) 9F FB 28 37 81 F2 AC F3 8A B0 37 E5 73 CF 39 E7
>Confidential: no
>Synopsis: GridLayout() bugfix -- exclude MenuBar when 0'th component
>Severity: serious
>Priority: medium
>Category:
>Class: sw-bug
>Release:
>Environment:
System: NetBSD topaz.nemeton.com.au 1.3E NetBSD 1.3E (TOPAZ) #1: Sun May 17 17:02:53 EST 1998 giles at topaz.nemeton.com.au:/a/NetBSD/current-build/src/sys/arch/i386/compile/TOPAZ i386
Architecture: Unknown
Machine: Unknown
>Description:
When a menu bar is added to a frame, GridLayout() includes it in
layout calculations. This deleteriously effects both the layout
of the components being laid out (a blank allocation is made for
the menubar where the first component should be) and the sizing
of the components is distorted.
This fix eliminates the incorrect blank component.
>How-To-Repeat:
Create a Frame, add a menu bar and then set GridLayout as the
layout manager. Observe that the first space in the grid is
empty.
>Fix:
This fix includes:
(i) using parent.getComponentCount() rather than parent.nChildren
directly;
(ii) two other PRs I've sent for GridLayout() (#s unknown)
(a) a use of 'hgap' that should be 'vgap'
(b) addition of functionality for rows == 0 or cols == 0
A diff without (ii) will be provided if requested, but applying
this diff to get all three PRs fixed seems good value! :-)
Index: libraries/javalib/java/awt/GridLayout.java
===================================================================
RCS file: /a/Kaffe/CVS/kaffe/libraries/javalib/java/awt/GridLayout.java,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 GridLayout.java
*** GridLayout.java 1998/08/01 03:01:03 1.1.1.1
--- GridLayout.java 1998/08/01 15:28:53
***************
*** 29,34 ****
--- 29,36 ----
}
public GridLayout (int rows, int cols, int hgap, int vgap) {
+ if ( rows == 0 && cols == 0)
+ throw new IllegalArgumentException("GridLayout rows and cols cannot both be zero");
this.rows = rows;
this.cols = cols;
this.hgap = hgap;
***************
*** 40,53 ****
Dimension adjustDim ( Container parent) {
Dimension d = new Dimension( cols, rows);
!
! boolean extCol = true;
! while ( parent.nChildren > d.width * d.height ) {
! if ( extCol ) d.width++;
! else d.height++;
! extCol = !extCol;
}
!
return d;
}
--- 42,72 ----
Dimension adjustDim ( Container parent) {
Dimension d = new Dimension( cols, rows);
! int nChildren = parent.getComponentCount();
!
! if ( rows == 0 ) {
! d.width = cols;
! d.height = nChildren / cols;
! if (nChildren % cols != 0)
! d.height++;
}
! else if ( cols == 0 ) {
! d.height = rows;
! d.width = nChildren / rows;
! if (nChildren % rows != 0)
! d.width++;
! }
! else {
! boolean extCol = true;
! while ( nChildren > d.width * d.height ) {
! if ( extCol )
! d.width++;
! else
! d.height++;
! extCol = !extCol;
! }
! }
!
return d;
}
***************
*** 64,72 ****
int maxH = 0;
Dimension d = adjustDim( parent);
! for ( int i=0; i<parent.nChildren; i++) {
! Component c = parent.children[i];
Dimension cd = preferred ? c.getPreferredSize() : c.getMinimumSize();
maxW = Math.max( maxW, cd.width);
maxH = Math.max( maxH, cd.height );
--- 83,92 ----
int maxH = 0;
Dimension d = adjustDim( parent);
+ int nChildren = parent.getComponentCount();
! for ( int i=0; i<nChildren; i++) {
! Component c = parent.getComponent(i);
Dimension cd = preferred ? c.getPreferredSize() : c.getMinimumSize();
maxW = Math.max( maxW, cd.width);
maxH = Math.max( maxH, cd.height );
***************
*** 91,96 ****
--- 111,117 ----
int th = parent.height - in.top - in.bottom - vgap;
Dimension d = adjustDim( parent);
+ int nChildren = parent.getComponentCount();
int cw = tw / d.width;
int ch = th / d.height;
***************
*** 100,108 ****
int y = in.top + vgap;
int ix = 0;
! for ( int i=0; i<parent.nChildren; i++) {
! Component c = parent.children[i];
! c.setBounds( x, y, cw-hgap, ch-hgap);
if ( ix == d.width-1 ){
ix = 0;
x = x0;
--- 121,129 ----
int y = in.top + vgap;
int ix = 0;
! for ( int i=0; i<nChildren; i++) {
! Component c = parent.getComponent(i);
! c.setBounds( x, y, cw-hgap, ch-vgap);
if ( ix == d.width-1 ){
ix = 0;
x = x0;
More information about the kaffe
mailing list