/*
 * @(#)ListBuilder.java	1.0 11-Apr-07
 *
 * IIT Bombay, 
 * Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
 */
package classes.main.components;

import interfaces.IAppletGUIBuilder;

import java.applet.Applet;
import java.awt.Component;
import java.awt.List;
import java.util.ArrayList;
import java.util.Iterator;

import types.Bounds;

/**
 * Builder class for List component
 *
 * @author  Prathab, Mukesh
 * @version 1.0, 11-Apr-07
 */
public class ListBuilder implements IAppletGUIBuilder {

	/** 
	 * Builds the respective component (control) and adds to Applet.
	 * @param bounds the coordinate bounds where the component to be placed
	 * @param component the component that need to be added
	 * @param applet the applet frame to which the component to be added
	 * @param object object required to intialize the component
	 * @see interfaces.IAppletGUIBuilder#build(types.Bounds, java.awt.Component, java.applet.Applet,java.lang.Object)
	 */
	public void build(Bounds bounds, Component component, Applet applet, Object object) {
		List list = (List) component;
		list.setBounds(bounds.x1,bounds.y1,bounds.x2,bounds.y2);
		applet.add(list);
		if(object != null) {
			ArrayList arrayList = (ArrayList) object;
			Iterator it = arrayList.iterator();
			while(it.hasNext()) {
				String str = (String) it.next();
				list.add(str);
			}
			if(!arrayList.isEmpty()) list.select(0);
		}
	}
}
