package FIT;
import FIT.Menus.Buttons;
import FIT.Menus.TextIn;

import com.cloudgarden.resource.SWTResourceManager;

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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* 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 AgentGUI extends org.eclipse.swt.widgets.Composite {

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}
	
	private Agent agent;
	private final static Display display = Display.getDefault();
	private final static Shell shell = new Shell(display);
	private Button AskNext;
	private StyledText AgentDialog;
	private Button AskWhy;
	private final static AgentGUI inst = new AgentGUI(shell, SWT.NULL);
	private Buttons Main;
	private TextIn Text;

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static void main(String[] args) {
		inst.showGUI();
	}
		
	
	public static AgentGUI getInstance(Agent agt) {
		inst.agent = agt;
		return inst;
	}
	
	public Display getDisplay () {
		return display;
	}
	
	/**
	* Auto-generated method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public void showGUI() {
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		
	}
	
	public void loop() {
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	public AgentGUI(org.eclipse.swt.widgets.Composite parent, int style) {
		super(parent, style);
		initGUI();
	}

	private void initGUI() {
		this.setLayout(new FormLayout());
		this.setSize(600, 400);
		{
			AgentDialog = new StyledText(this, SWT.BORDER + SWT.READ_ONLY + SWT.WRAP);
			FormData AgentDialogLData = new FormData();
			AgentDialogLData.width = 419;
			AgentDialogLData.height = 32;
			AgentDialogLData.left =  new FormAttachment(0, 1000, 19);
			AgentDialogLData.top =  new FormAttachment(0, 1000, 352);
			AgentDialog.setLayoutData(AgentDialogLData);
		}
		{
			AskNext = new Button(this, SWT.PUSH | SWT.CENTER);
			FormData AskNextLData = new FormData();
			AskNextLData.width = 78;
			AskNextLData.height = 32;
			AskNextLData.left =  new FormAttachment(0, 1000, 454);
			AskNextLData.top =  new FormAttachment(0, 1000, 354);
			AskNext.setLayoutData(AskNextLData);
			AskNext.setText("What's next?");
			AskNext.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					AskNextWidgetSelected(evt);
				}
			});
		}
		{
			AskWhy = new Button(this, SWT.PUSH | SWT.CENTER);
			FormData AskWhyLData = new FormData();
			AskWhyLData.width = 41;
			AskWhyLData.height = 32;
			AskWhyLData.left =  new FormAttachment(0, 1000, 544);
			AskWhyLData.top =  new FormAttachment(0, 1000, 354);
			AskWhy.setLayoutData(AskWhyLData);
			AskWhy.setText("Why?");
			AskWhy.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					AskWhyWidgetSelected(evt);
				}
			});
		}
	}
	
	public void showResponse (String resp) {
		AgentDialog.setText(resp);
	}
	
	private void AskNextWidgetSelected(SelectionEvent evt) {
		agent.next();
	}
	
	private void AskWhyWidgetSelected(SelectionEvent evt) {
		agent.why();
	}


	public void handleText(String text) {
		agent.handleText(text);
	}
	
	public Composite getTextMenu () {
		return this.Text;
	}


	public void handleButton(String task) {
		agent.handleButton(task);
	}




}
