/*
 *	Modulname:	LayoutGroup
 *	Autor:		Eyer Leander
 *	Datum:		25.05.2006
 *
 *	(c) Copyright 2005
 */
package survey.gui;

import survey.model.Question;

import java.util.Vector;
import java.util.Iterator;

/**
 * A layout group will assure that all elements of the same layout group
 * are aligned along the same lignes
 */
public class LayoutGroup {

	/** A vector of questions belonging to the layout group */
	private Vector<Renderer> members = new Vector<Renderer>();

	/** Constructor */
	public LayoutGroup() {}

	/**
	 * Add a question to the renderer
	 */
	public void addMember(Renderer question) {
		members.add(question);
	}

	/** Layout the group */
	public void layout() {
		//determine the target size
		double labelWidth = 0;
		double answerWidth = 0;
		for (Renderer rend:members) {
			double cLabelWidth = rend.getLabelWidth();
			if (cLabelWidth > labelWidth) {
				labelWidth = cLabelWidth;
			}
			double cAnswerWidth = rend.getAnswerSpaceWidth();
			if (cAnswerWidth > answerWidth) {
				answerWidth = cAnswerWidth;
			}
		}

		//perform the resizing
		for (Renderer rend:members) {
			rend.setLabelWidth(labelWidth);
			rend.setAnswerSpaceWdith(answerWidth);
		}
	}

}

