[kaffe] CVS kaffe (dalibor): Switched java.awt.GridBadLayout over to GNU Classpath

Kaffe CVS cvs-commits at kaffe.org
Sun Jan 11 18:15:03 PST 2004


PatchSet 4325 
Date: 2004/01/12 02:11:39
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Switched java.awt.GridBadLayout over to GNU Classpath

2004-01-12  Dalibor Topic <robilad at kaffe.org>

        * libraries/javalib/java/awt/GridBagLayout.java:
        Replaced by implementation from GNU Classpath.

        This fixes a bug with the Babylon Chat Server client.

Members: 
	ChangeLog:1.1912->1.1913 
	libraries/javalib/java/awt/GridBagLayout.java:1.13->1.14 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1912 kaffe/ChangeLog:1.1913
--- kaffe/ChangeLog:1.1912	Sun Jan 11 22:06:46 2004
+++ kaffe/ChangeLog	Mon Jan 12 02:11:39 2004
@@ -1,3 +1,10 @@
+2004-01-12  Dalibor Topic <robilad at kaffe.org>
+
+	* libraries/javalib/java/awt/GridBagLayout.java:
+	Replaced by implementation from GNU Classpath. 
+
+	This fixes a bug with the Babylon Chat Server client.
+
 2004-01-11  Jim Pick  <jim at kaffe.org>
 
 	* m4/alsa.m4:
Index: kaffe/libraries/javalib/java/awt/GridBagLayout.java
diff -u kaffe/libraries/javalib/java/awt/GridBagLayout.java:1.13 kaffe/libraries/javalib/java/awt/GridBagLayout.java:1.14
--- kaffe/libraries/javalib/java/awt/GridBagLayout.java:1.13	Wed Jun 20 22:49:43 2001
+++ kaffe/libraries/javalib/java/awt/GridBagLayout.java	Mon Jan 12 02:11:41 2004
@@ -1,687 +1,688 @@
+/* GridBagLayout - Layout manager for components according to GridBagConstraints
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
 package java.awt;
 
+import java.io.Serializable;
 import java.util.Hashtable;
 
 /**
- * class GridBagLayout -
- *
- * Copyright (c) 1998
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- *
- * @author J.Mehlitz
+ * @author Michael Koch <konqueror at gmx.de>
+ * @author Jeroen Frijters <jeroen at frijters.net>
  */
 public class GridBagLayout
-  implements LayoutManager2, java.io.Serializable
+    implements Serializable, LayoutManager2
 {
-	final protected static int MINSIZE = 1;
-	final protected static int PREFERREDSIZE = 2;
-	final protected static int ACTUALSIZE = 3;
-	final protected static int MAXGRIDSIZE = 100;
-/* NB: Sun doesn't hardcode */
-	final private static long serialVersionUID = 8838754796412211005L;
-/** @serial */
-	protected Hashtable comptable = new Hashtable();
-/** @serial */
-	protected GridBagConstraints defaultConstraints = new GridBagConstraints();
-// XXX fix serial form! /** @serial */
-//protected GridBagLayoutInfo layoutInfo;
-	/** @serial */
-	public int[] columnWidths;
-/** @serial */
-	public int[] rowHeights;
-/** @serial */
-	public double[] columnWeights;
-/** @serial */
-	public double[] rowWeights;
-	transient Point offset = new Point();
-	private static Component[][] defGrid = new Component[MAXGRIDSIZE][MAXGRIDSIZE];
-
-protected void AdjustForGravity(GridBagConstraints cons, Rectangle display) {
-	throw new kaffe.util.NotImplemented(GridBagLayout.class.getName() + ".AdjustForGravity()");
-}
-
-protected void ArrangeGrid(Container container) {
-	layoutContainer(container);
-}
-
-public GridBagLayout() {
-}
-
-public void addLayoutComponent( Component c, Object constraints) {
-	try {
-		if (constraints != null) {
-			setConstraints(c, (GridBagConstraints)constraints);
-		}
-	}
-	catch (ClassCastException _) {
-		throw new IllegalArgumentException("not GridBagConstraints");
-	}
-}
-
-public void addLayoutComponent( String name, Component c) {
-}
-
-void adjustWeightsRelative( Container parent) {
-	Insets pin = parent.getInsets();
-	int i;
-	int nxw = 0;
-	int nyw = 0;
-	int sw = sumWidths();
-	int sh = sumHeights();
-	double dd;
-	double twx = 0;
-	double twy = 0;
-
-	for ( i=0; i<columnWeights.length; i++) {
-		dd = columnWeights[i];
-		if ( dd > 0.0 ) {
-			twx += dd;
-			nxw++;
-		}
-	}
-	for ( i=0; i<rowWeights.length; i++) {
-		dd = rowWeights[i];
-		if ( dd > 0.0 ) {
-			twy += dd;
-			nyw++;
-		}
-	}
-
-	int piw = pin.left + pin.right;
-	int pih = pin.top + pin.bottom;
-
-	if ( nxw > 0 ) {
-		int dx = parent.width - sw - piw;
-		for ( i=0; i<columnWeights.length-1; i++){
-			double cw = columnWeights[i];
-			if ( cw > 0.0 ) {
-				int dcx = (int)(cw/twx*dx);
-				columnWidths[i] += dcx;
-				twx -= cw;
-				dx -= dcx;
-			}
-			if ( twx == 0)
-				break;
-		}
-
-		if ( dx > 0)
-			columnWidths[i] += dx;
-		offset.x = 0;
-	}
-	else {
-		offset.x = (parent.width - sw - piw) / 2;
-	}
-
-	if ( nyw > 0) {
-		int dy = parent.height - sh - pih;
-		for ( i=0; i<rowWeights.length-1; i++){
-			double rw = rowWeights[i];
-			if ( rw > 0.0 ) {
-				int dcy = (int)(rw/twy*dy);
-				rowHeights[i] += dcy;
-				twy -= rw;
-				dy -= dcy;
-			}
-			if ( twy == 0)
-				break;
-		}
-		if ( dy > 0)
-			rowHeights[i] += dy;
-		offset.y = 0;
-	}
-	else {
-		offset.y = (parent.height - sh - pih) / 2;
-	}
-}
-
-void clearDefGrid() {
-	for ( int y=0; y<MAXGRIDSIZE; y++) {
-		for ( int x=0; x<MAXGRIDSIZE; x++) {
-			defGrid[x][y] = null;
-		}
-	}
-}
-
-Component componentAt( Container parent, int x, int y) {
-	int nc = parent.getComponentCount();
-	for ( int i=0; i<nc; i++ ) {
-		Component c = parent.getComponent( i);
-		GridBagConstraints gbc = lookupConstraints( c);
-		if ( gbc.gridx <= x && gbc.gridy <= y &&
-			gbc.gridx + gbc.gridwidth > x &&
-			gbc.gridy + gbc.gridheight > y ) {
-			return c;
-		}
-	}
-
-	return null;
-}
-
-void dump() {
-	if ( (columnWidths == null) || (rowHeights == null ) ){
-		return;
-	}
-
-	int i;
-	System.out.print( "\t\t");
-	for ( i=0; i<columnWidths.length; i++) {
-		System.out.print( columnWidths[i] + "[" + columnWeights[i] + "]" );
-		System.out.print( '\t');
-	}
-	System.out.println();
-	for ( i=0; i<rowHeights.length; i++) {
-		System.out.print( rowHeights[i] + "[" + rowWeights[i] + "]" );
-		for ( int i2=0; i2<columnWidths.length; i2++ ) {
-			Component c = defGrid[i2][i];
-			System.out.print( '\t');
-			System.out.print( (c != null) ? Integer.toHexString( c.hashCode() ) : "-------" );
-			System.out.print( '\t');
-		}
-		System.out.println();
-	}
-
-	System.out.println();
-}
-
-void fillGrid( Container parent, int mxr, int myr, int mode ) {
-	int maxX = 0;
-	int maxY = 0;
-	int x, y, di;
-	GridBagConstraints cc;
-	Dimension cd = new Dimension();
-
-	// get max cell extends
-	for ( y=MAXGRIDSIZE-1; y>-1; y--) {
-		if ( defGrid[MAXGRIDSIZE-1][y] != null ) {
-			maxX = Math.max( maxX, mxr);
-		}
-		else {
-			for ( x=MAXGRIDSIZE-1; x>-1; x--) {
-				if ( defGrid[x][y] != null ) {
-					maxX = Math.max( maxX, x+1);
-					break;
-				}
-			}
-		}
-	}
-	for ( x=MAXGRIDSIZE-1; x>-1; x--) {
-		if ( defGrid[x][MAXGRIDSIZE-1] != null ) {
-			maxY = Math.max( maxY, myr);
-		}
-		else {
-			for ( y=MAXGRIDSIZE-1; y>-1; y--) {
-				if ( defGrid[x][y] != null ) {
-					maxY = Math.max( maxY, y+1);
-					break;
-				}
-			}
-		}
-	}
-
-	boolean allocNew = (columnWidths == null) || (rowHeights == null) ||
-	(columnWidths.length != maxX) || (rowHeights.length != maxY);
-
-	if ( allocNew ) {
-		columnWidths = new int[maxX];
-		columnWeights = new double[maxX];
-		rowHeights = new int[maxY];
-		rowWeights = new double[maxY];
-	}
-	else {
-		for ( x=0; x<maxX; x++ ) {
-			columnWidths[x] = 0;
-			columnWeights[x] = 0.0;
-		}
-		for ( y=0; y<maxY; y++ ) {
-			rowHeights[y] = 0;
-			rowWeights[y] = 0.0;
-		}
-	}
+    private static final long serialVersionUID = 8838754796412211005L;
 
-	// convert relatives and remainders to real values
-	updateConstraints( parent);
+    protected static final int MINSIZE = 1;
+    protected static final int PREFERREDSIZE = 2;
+    protected static final int MAXGRIDSIZE = 512;
+
+    protected Hashtable comptable;
+    protected GridBagLayoutInfo layoutInfo;
+    protected GridBagConstraints defaultConstraints;
+
+    public double[] columnWeights;
+    public int[] columnWidths;
+    public double[] rowWeights;
+    public int[] rowHeights;
+
+    public GridBagLayout ()
+    {
+	this.comptable = new Hashtable();
+	this.defaultConstraints= new GridBagConstraints();
+    }
+
+    /**
+     * Helper method to calc the sum of a range of elements in an int array.
+     */
+    private int sumIntArray (int[] array, int upto)
+    {
+	int result = 0;
+
+	for (int i = 0; i < upto; i++)
+	    result += array [i];
+
+	return result;
+    }
+
+    /**
+     * Helper method to calc the sum of all elements in an int array.
+     */
+    private int sumIntArray (int[] array)
+    {
+	return sumIntArray(array, array.length);
+    }
+
+    /**
+     * Helper method to calc the sum of all elements in an double array.
+     */
+    private double sumDoubleArray (double[] array)
+    {
+	double result = 0;
+
+	for (int i = 0; i < array.length; i++)
+	    result += array [i];
+
+	return result;
+    }
+
+    public void addLayoutComponent (String name, Component component)
+    {
+	// do nothing here.
+    }
+
+    public void removeLayoutComponent (Component component)
+    {
+	// do nothing here
+    }
+
+    public void addLayoutComponent (Component component, Object constraints)
+    {
+	if (constraints == null)
+	    return;
+
+	if (!(constraints instanceof GridBagConstraints))
+	    throw new IllegalArgumentException();
+
+	setConstraints (component, (GridBagConstraints) constraints);
+    }
+
+    public Dimension preferredLayoutSize (Container parent)
+    {
+	if (parent == null)
+	    return new Dimension (0, 0);
+    
+	GridBagLayoutInfo li = getLayoutInfo (parent, PREFERREDSIZE);
+	return getMinSize (parent, li);
+    }
+
+    public Dimension minimumLayoutSize (Container parent)
+    {
+	if (parent == null)
+	    return new Dimension (0, 0);
+    
+	GridBagLayoutInfo li = getLayoutInfo (parent, MINSIZE);
+	return getMinSize (parent, li);
+    }
+
+    public Dimension maximumLayoutSize (Container target)
+    {
+	return new Dimension (Integer.MAX_VALUE, Integer.MAX_VALUE);
+    }
+
+    public void layoutContainer (Container parent)
+    {
+	arrangeGrid (parent);
+    }
 
-	//fill widths and heights
-	Rectangle cRect = new Rectangle();
-	int nc = parent.getComponentCount();
-
-	for ( int idx=0; idx<nc; idx++) {
-		Component c = parent.getComponent( idx);
-		cc = lookupConstraints( c);
-		cRect.setBounds( cc.gridx, cc.gridy, cc.gridwidth, cc.gridheight);
-
-		if ( (cRect.width == 1) || (cRect.height == 1) ) {
-			getComponentExt( c, cc, mode, cd);
-
-			if ( cRect.width == 1) {
-				columnWidths[cRect.x] = Math.max( columnWidths[cRect.x], cd.width );
-			}
-			if ( cRect.height == 1) {
-				rowHeights[cRect.y] = Math.max( rowHeights[cRect.y], cd.height);
-			}
-		}
-
-		di = cRect.x + cRect.width - 1;
-		columnWeights[di] = Math.max( columnWeights[di] ,cc.weightx);
-		di = cRect.y + cRect.height - 1;
-		rowWeights[di] = Math.max( rowWeights[di] ,cc.weighty);
-	}
-
-	/* first call of getComponentExt() / getPreferredSize() could
-	*  scramble the defGrid array ( cascaded GridBagLayouts ).
-	*  Use the (updated) Constraints!!!
-	*/
-	for ( x=0; x<maxX; x++) {
-		if ( columnWidths[x] == 0 ) {
-			for ( y=0; y<maxY; y++ ) {
-				Component c = componentAt( parent, x, y);
-//				Component c = defGrid[x][y];
-				if ( c != null ) {
-					cc = lookupConstraints( c);
-					getComponentExt( c, cc, mode, cd);
-					cRect.setBounds( cc.gridx, cc.gridy, cc.gridwidth, cc.gridheight);
-					columnWidths[x] = Math.max( columnWidths[x], cd.width / cRect.width );
-				}
-			}
-		}
-	}
-
-	for ( y=0; y<maxY; y++) {
-		if ( rowHeights[y] == 0 ) {
-			for ( x=0; x<maxX; x++ ) {
-				Component c = componentAt(parent, x, y);
-//				Component c = defGrid[x][y];
-				if ( c != null ) {
-					cc = lookupConstraints( c);
-					getComponentExt( c, cc, mode, cd);
-					cRect.setBounds( cc.gridx, cc.gridy, cc.gridwidth, cc.gridheight);
-					rowHeights[y] = Math.max( rowHeights[y], cd.height / cRect.height );
-				}
-			}
-		}
-	}
-
-	if ( mode == ACTUALSIZE) {
-		adjustWeightsRelative( parent);
-	}
-}
-
-Dimension getComponentExt( Component c, GridBagConstraints cc, int mode, Dimension dim) {
-	dim.setSize( (mode == MINSIZE) ? c.getMinimumSize() : c.getPreferredSize());
-	dim.width += cc.insets.left + cc.insets.right + 2 * cc.ipadx;
-	dim.height += cc.insets.top + cc.insets.bottom + 2 * cc.ipady;
-	return dim;
-}
-
-public GridBagConstraints getConstraints( Component c) {
-	return ((GridBagConstraints)lookupConstraints(c).clone());
-}
-
-void getGrid( Container parent, int mode ) {
-	int x1 = 0;
-	int y1 = 0;
-	int cx, cy;
-	int mxr = -1;
-	int myr = -1;
-	GridBagConstraints lcc = null;
-	int nc = parent.getComponentCount();
-
-	synchronized( defGrid) {
-		clearDefGrid();
-
-		for ( int i=0; i<nc; i++){
-			Component c = parent.getComponent(i);
-			GridBagConstraints cc = lookupConstraints( c);
-
-			if ( cc.gridx == cc.RELATIVE) {
-				if ( lcc == null )
-					x1 = 0;
-				else if ( lcc.gridwidth > 0 )
-					x1 += lcc.gridwidth;
-				else
-					x1 = -1;
-			}
-			else {
-				x1 = cc.gridx;
-			}
-
-			if ( cc.gridy == cc.RELATIVE) {
-				if ( lcc == null )
-					y1 = 0;
-				else if ( lcc.gridheight == cc.REMAINDER )
-					y1 = -1;
-				else if ( lcc.gridwidth == cc.REMAINDER )
-					y1 += Math.max( lcc.gridheight, 1);
-				else
-					y1 = -1;
-			}
-			else {
-				y1 = cc.gridy;
-			}
-
-			if ( x1 == -1 ) {
-				for ( x1=0; defGrid[x1][y1] != null; x1++);
-			}
-			if ( y1 == -1 ) {
-				for ( y1=0; defGrid[x1][y1] != null; y1++);
-			}
-
-
-			cx = cc.gridwidth;
-			cy = cc.gridheight;
-
-			if ( cx == cc.REMAINDER ){
-				mxr = Math.max( mxr, x1);
-				cx = MAXGRIDSIZE - x1;
-			}
-			else if ( cx == cc.RELATIVE ) {
-				cx = 1;
-			}
-			if ( cy == cc.REMAINDER ) {
-				myr = Math.max( myr, y1);
-				cy = MAXGRIDSIZE - y1;
-			}
-			else if ( cy == cc.RELATIVE) {
-				cy = 1;
-			}
-
-			for( cy--; cy > -1; cy--) {
-				for ( int icx=cx-1; icx > -1; icx--) {
-					defGrid[x1+icx][y1+cy] = c;
-				}
-			}
-
-			lcc = cc;
-		}
-
-		fillGrid( parent, mxr+1, myr+1, mode);
-	}
-}
-
-public float getLayoutAlignmentX( Container parent) {
+    public float getLayoutAlignmentX (Container target)
+    {
 	return Component.CENTER_ALIGNMENT;
-}
+    }
 
-public float getLayoutAlignmentY( Container parent) {
+    public float getLayoutAlignmentY (Container target)
+    {
 	return Component.CENTER_ALIGNMENT;
-}
-
-public int[][] getLayoutDimensions() {
-	return (new int[][]{columnWidths, rowHeights});
-}
-
-public Point getLayoutOrigin() {
-	return offset;
-}
-
-public double[][] getLayoutWeights() {
-	return (new double[][]{columnWeights, rowWeights});
-}
+    }
 
-Rectangle gridToPels( Rectangle r ) {
-	int x, y, xp, yp, wp, hp;
-
-	for ( xp=0, x=0; x<r.x; x++) {
-		xp += columnWidths[x];
-	}
-	for ( wp=0; x<r.x+r.width; x++) {
-		wp += columnWidths[x];
-	}
-	for ( yp=0, y=0; y<r.y; y++) {
-		yp += rowHeights[y];
+    public void invalidateLayout (Container target)
+    {
+	this.layoutInfo = null;
+    }
+
+    public void setConstraints (Component component,
+	GridBagConstraints constraints)
+    {
+	GridBagConstraints clone = (GridBagConstraints) constraints.clone();
+
+	if (clone.gridx < 0)
+	    clone.gridx = GridBagConstraints.RELATIVE;
+    
+	if (clone.gridy < 0)
+	    clone.gridy = GridBagConstraints.RELATIVE;
+
+	if (clone.gridwidth == 0)
+	    clone.gridwidth = GridBagConstraints.REMAINDER;
+	else if (clone.gridwidth < 0
+	    && clone.gridwidth != GridBagConstraints.REMAINDER
+	    && clone.gridwidth != GridBagConstraints.RELATIVE)
+	    clone.gridwidth = 1;
+    
+	if (clone.gridheight == 0)
+	    clone.gridheight = GridBagConstraints.REMAINDER;
+	else if (clone.gridheight < 0
+	    && clone.gridheight != GridBagConstraints.REMAINDER
+	    && clone.gridheight != GridBagConstraints.RELATIVE)
+	    clone.gridheight = 1;
+    
+	comptable.put (component, clone);
+    }
+
+    public GridBagConstraints getConstraints (Component component)
+    {
+	return (GridBagConstraints) (lookupConstraints (component).clone());
+    }
+
+    protected GridBagConstraints lookupConstraints (Component component)
+    {
+	GridBagConstraints result = (GridBagConstraints) comptable.get (component);
+
+	if (result == null)
+	{
+	    setConstraints (component, defaultConstraints);
+	    result = (GridBagConstraints) comptable.get (component);
+	}
+    
+	return result;
+    }
+
+    /**
+     * @since 1.1
+     */
+    public Point getLayoutOrigin ()
+    {
+	if (layoutInfo == null)
+	    return new Point (0, 0);
+    
+	return new Point (layoutInfo.pos_x, layoutInfo.pos_y);
+    }
+
+    /**
+     * @since 1.1
+     */
+    public int[][] getLayoutDimensions ()
+    {
+	int[][] result = new int [2][];
+	if (layoutInfo == null)
+	  {
+	    result[0] = new int[0];
+	    result[1] = new int[0];
+
+	    return result;
+	  }
+
+	result [0] = new int [layoutInfo.cols];
+	System.arraycopy (layoutInfo.colWidths, 0, result [0], 0, layoutInfo.cols);
+	result [1] = new int [layoutInfo.rows];
+	System.arraycopy (layoutInfo.rowHeights, 0, result [1], 0, layoutInfo.rows);
+	return result;
+    }
+
+    public double[][] getLayoutWeights ()
+    {
+	double[][] result = new double [2][];
+	if (layoutInfo == null)
+	  {
+	    result[0] = new double[0];
+	    result[1] = new double[0];
+
+	    return result;
+	  }
+
+	result [0] = new double [layoutInfo.cols];
+	System.arraycopy (layoutInfo.colWeights, 0, result [0], 0, layoutInfo.cols);
+	result [1] = new double [layoutInfo.rows];
+	System.arraycopy (layoutInfo.rowWeights, 0, result [1], 0, layoutInfo.rows);
+	return result;
+    }
+
+    /**
+     * @since 1.1
+     */
+    public Point location (int x, int y)
+    {
+	if (layoutInfo == null)
+	    return new Point (0, 0);
+
+	int col;
+	int row;
+	int pixel_x = layoutInfo.pos_x;
+	int pixel_y = layoutInfo.pos_y;
+
+	for (col = 0; col < layoutInfo.cols; col++)
+	{
+	    int w = layoutInfo.colWidths [col];
+	    if (x < pixel_x + w)
+		break;
+
+	    pixel_x += w;
+	}
+
+	for (row = 0; row < layoutInfo.rows; row++)
+	{
+	    int h = layoutInfo.rowHeights [row];
+	    if (y < pixel_y + h)
+		break;
+
+	    pixel_y += h;
+	}
+
+	return new Point (col, row);
+    }
+
+    /**
+     * Obsolete.
+     */
+    protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect)
+    {
+	adjustForGravity (gbc, rect);
+    }
+
+    /**
+     * Obsolete.
+     */
+    protected void ArrangeGrid (Container parent)
+    {
+	arrangeGrid (parent);
+    }
+
+    /**
+     * Obsolete.
+     */
+    protected GridBagLayoutInfo GetLayoutInfo (Container parent, int sizeflag)
+    {
+	return getLayoutInfo (parent, sizeflag);
+    }
+
+    /**
+     * Obsolete.
+     */
+    protected Dimension GetMinSize (Container parent, GridBagLayoutInfo info)
+    {
+	return getMinSize (parent, info);
+    }
+
+    /**
+     * @since 1.4
+     */
+    protected Dimension getMinSize (Container parent, GridBagLayoutInfo info)
+    {
+	if (parent == null || info == null)
+	    return new Dimension (0, 0);
+
+	Insets insets = parent.getInsets();
+	int width = sumIntArray (info.colWidths) + insets.left + insets.right;
+	int height = sumIntArray (info.rowHeights) + insets.top + insets.bottom;
+	return new Dimension (width, height);
+    }
+
+    private void calcCellSizes (int[] sizes, double[] weights, int range)
+    {
+	int diff = range - sumIntArray (sizes);
+
+	if (diff == 0)
+	    return;
+    
+	double weight = sumDoubleArray (weights);
+
+	for (int i = 0; i < sizes.length; i++)
+	{
+	    sizes [i] += (int) (((double) diff) * weights [i] / weight );
+
+	    if (sizes [i] < 0)
+		sizes [i] = 0;
+	}
+    }
+
+    private void dumpLayoutInfo (GridBagLayoutInfo info)
+    {
+	System.out.println ("GridBagLayoutInfo:");
+	System.out.println ("cols: " + info.cols + ", rows: " + info.rows);
+	System.out.print ("colWidths: ");
+	dumpArray(info.colWidths);
+	System.out.print ("rowHeights: ");
+	dumpArray(info.rowHeights);
+	System.out.print ("colWeights: ");
+	dumpArray(info.colWeights);
+	System.out.print ("rowWeights: ");
+	dumpArray(info.rowWeights);
+    }
+
+    private void dumpArray(int[] array)
+    {
+	String sep = "";
+	for(int i = 0; i < array.length; i++)
+	{
+	    System.out.print(sep);
+	    System.out.print(array[i]);
+	    sep = ", ";
 	}
-	for ( hp=0; y<r.y+r.height; y++) {
-		hp += rowHeights[y];
-	}
-
-	r.setBounds( xp, yp, wp, hp);
-	return r;
-}
-
-public void invalidateLayout( Container parent) {
-}
-
-public void layoutContainer( Container parent) {
-	Insets pin = parent.getInsets();
-	Rectangle cRect = new Rectangle();
-	int nc = parent.getComponentCount();
-
-	getGrid( parent, ACTUALSIZE);
-
-	for ( int idx=0; idx<nc; idx++) {
-		Component c = parent.getComponent( idx);
-		GridBagConstraints cc = lookupConstraints( c);
-		Insets in = cc.insets;
-
-		cRect.setBounds( cc.gridx, cc.gridy, cc.gridwidth, cc.gridheight);
-		gridToPels( cRect);
-
-		Dimension cd = c.getPreferredSize();
-		int cx = cRect.x + pin.left + offset.x;
-		int cy = cRect.y + pin.top + offset.y;
-		int cw = Math.min( cd.width, cRect.width);
-		int ch = Math.min( cd.height, cRect.height);
+	System.out.println();
+    }
 
-		switch ( cc.fill ) {
-		case GridBagConstraints.BOTH:
-			cx += in.left + cc.ipadx;
-			cy += in.top + cc.ipady;
-			cw = cRect.width - (in.left + in.right + 2 * cc.ipadx);
-			ch = cRect.height - (in.top + in.bottom + 2 * cc.ipady);
-			break;
+    private void dumpArray(double[] array)
+    {
+	String sep = "";
+	for(int i = 0; i < array.length; i++)
+	{
+	    System.out.print(sep);
+	    System.out.print(array[i]);
+	    sep = ", ";
+	}
+	System.out.println();
+    }
+  
+    /**
+     * @since 1.4
+     */
+    protected void arrangeGrid (Container parent)
+    {
+	Component[] components = parent.getComponents();
+
+	if (components.length == 0)
+	    return;
+
+	GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE);
+	if (info.cols == 0 && info.rows == 0)
+	    return;
+	layoutInfo = info;
+
+	// DEBUG
+	//dumpLayoutInfo (layoutInfo);
+    
+	for(int i = 0; i < components.length; i++)
+	{
+	    Component component = components [i];
+		
+	    // If component is not visible we dont have to care about it.
+	    if (!component.isVisible())
+		continue;
+		
+	    GridBagConstraints constraints = lookupConstraints (component);
+
+	    int cellx = sumIntArray(layoutInfo.colWidths, constraints.gridx);
+	    int celly = sumIntArray(layoutInfo.rowHeights, constraints.gridy);
+	    int cellw = sumIntArray(layoutInfo.colWidths,
+		constraints.gridx + constraints.gridwidth) - cellx;
+	    int cellh = sumIntArray(layoutInfo.rowHeights,
+		constraints.gridy + constraints.gridheight) - celly;
+
+	    Insets insets = constraints.insets;
+	    if (insets != null)
+	    {
+		cellx += insets.left;
+		celly += insets.top;
+		cellw -= insets.left + insets.right;
+		cellh -= insets.top + insets.bottom;
+	    }
+
+	    Dimension dim = component.preferredSize();
+
+	    // Note: Documentation says that padding is added on both sides, but
+	    // visual inspection shows that the Sun implementation only adds it
+	    // once, so we do the same.
+	    dim.width += constraints.ipadx;
+	    dim.height += constraints.ipady;
 
+	    switch(constraints.fill)
+	    {
 		case GridBagConstraints.HORIZONTAL:
-			cx += in.left + cc.ipadx;
-			cw = cRect.width - (in.left + in.right + 2 * cc.ipadx);
-			switch ( cc.anchor ) {
-			case GridBagConstraints.WEST:
-			case GridBagConstraints.CENTER:
-			case GridBagConstraints.EAST:
-			default:
-				cy += (cRect.height - ch) / 2;
-				break;
-
-			case GridBagConstraints.NORTH:
-			case GridBagConstraints.NORTHEAST:
-			case GridBagConstraints.NORTHWEST:
-				cy += in.top + cc.ipady;
-				break;
-
-			case GridBagConstraints.SOUTHEAST:
-			case GridBagConstraints.SOUTH:
-			case GridBagConstraints.SOUTHWEST:
-				cy += cRect.height - (cd.height + in.bottom + cc.ipady);
-				break;
-			}
-			break;
-
+		    dim.width = cellw;
+		    break;
 		case GridBagConstraints.VERTICAL:
-			cy += in.top + cc.ipady;
-			ch = cRect.height - (in.top + in.bottom + 2 * cc.ipady);
-			switch ( cc.anchor ) {
-			case GridBagConstraints.NORTH:
-			case GridBagConstraints.CENTER:
-			case GridBagConstraints.SOUTH:
-			default:
-				cx += (cRect.width - cw) / 2;
-				break;
-
-			case GridBagConstraints.NORTHWEST:
-			case GridBagConstraints.WEST:
-			case GridBagConstraints.SOUTHWEST:
-				cx += in.left + cc.ipadx;
-				break;
-
-			case GridBagConstraints.NORTHEAST:
-			case GridBagConstraints.SOUTHEAST:
-			case GridBagConstraints.EAST:
-				cx += cRect.width - (cw + in.right + cc.ipadx);

*** Patch too long, truncated ***




More information about the kaffe mailing list