package FIT.Menus;

import java.util.ArrayList;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

import FIT.AgentGUI;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ItemList extends org.eclipse.swt.widgets.Composite {
	private AgentGUI myParent;
	private ArrayList<Button> buttons = new ArrayList<Button>();
	private final int S = 5;
	
	public ItemList(Composite parent, int style, int num, int rows, String[] labels, String[] tasks) {
		super(parent, style);
		myParent = (AgentGUI)this.getParent();
		initGUI(num, rows, labels, tasks);
	}

	private void initGUI(int num, int rows, String[] labels, String[] tasks) {
		try {
			this.setLayout(new FormLayout());
			this.setSize(600, 350);
			initList(labels);
			this.layout();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void initList(String[] labels) {
		final List l = new List(this, SWT.BORDER);
		FormData Data = new FormData();
		Data.width = 150;
		Data.height = 250;
		Data.left =  new FormAttachment(0, 1000, 225);
		Data.top =  new FormAttachment(0, 1000, 50);
		l.setLayoutData(Data);
		for (int i = 0; i < labels.length; i++) {
			l.add(labels[i]);
			System.out.println(labels[i]);
		}
		l.setSelection(0);
	    l.addSelectionListener(new SelectionAdapter() {
	    	public void widgetSelected(SelectionEvent evt) {
				System.out.println("You selected " + l.getItem(l.getSelectionIndex()));
				myParent.handleButton(l.getItem(l.getSelectionIndex()));
			}
	    });
	}

	
}
