
package polarDust.calculator;

/*
 * Copyright (c) 1996 Sorin Lazareanu, All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies.
 *
 */

import java.awt.*;

/**
 * GridBagLayoutHelper is used in conjunction with class GridBagLayout in
 * providing compact and simplified GridBagConstraints specification.
 *
 * <br><br><a href=../source/polarDust/calculator/GridBagLayoutHelper.java>
 * The source code.</a>
 *
 * @version 0.9, 1996.06.04
 * @author Sorin Lazareanu
 */

public class GridBagLayoutHelper {
	int iTotRows, iTotCols;
	Container aContainer;
	GridBagLayout aLayout;
	GridBagConstraints aConstraint;

	/**
	* Constructs a new object.
	*/
	public GridBagLayoutHelper(
		Container aContainer,
		GridBagLayout aLayout,
		GridBagConstraints aConstraint,
		int iTotRows,
		int iTotCols
		) {
		this.aLayout = aLayout;
		this.aConstraint = aConstraint;
		this.aContainer = aContainer;
		this.iTotRows = iTotRows;
		this.iTotCols = iTotCols;
	}

	/**
	* Adds a component to the layout.
	*/
	public void addComponent( int iGridX, int iGridY, int iRows, int iCols, Component aComponent) {
		aConstraint.gridy = iGridY;
		aConstraint.weightx = (double)iRows / iTotRows;
		aConstraint.gridwidth = iRows;
		aConstraint.gridx = iGridX;
		aConstraint.weighty = (double)iCols / iTotCols;
		aConstraint.gridheight = iCols;
		aLayout.setConstraints(aComponent, aConstraint);
		aContainer.add(aComponent);
	}

}


