/*
 *	Modulname:	Testbench
 *	Autor:		Eyer Leander
 *	Datum:		08.05.2006
 *
 *	(c) Copyright 2005
 */
package survey;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 * A simple main window to host the testing
 */
public class Testbench extends JFrame implements SurveyListener {

	private Survey survey;

	/**
	 * Constructor
	 */
	public Testbench(String surveyConfigFileName) {
		super("Survey Testbench");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		try {
			survey = new Survey(surveyConfigFileName);
			survey.addListener(this);
			getContentPane().setLayout(new BorderLayout());
			getContentPane().add(survey, BorderLayout.CENTER);
		} catch (Exception e) {
			e.printStackTrace();
		}


		/*
		survey.setAnswer("partnumber", "John Doe");
		survey.setEditable("partnumber", false);
		survey.setAnswer("experimentnumber", "123");
		survey.setEditable("experimentnumber", false);
		survey.gotoPage(1);
		*/

		pack();
		setVisible(true);
		setExtendedState(JFrame.MAXIMIZED_BOTH);
	}

	/** Program Entry Point */
	public static void main(String [] args) {
	    String fileName = (args.length == 0) ? "preSurveyConfig.xml"/*"surveyTestConfig.xml"*/ : args[0];
        new Testbench(fileName);
	}

	public void surveyFinished() {
		try {
			survey.saveResult("result.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.exit(0);
	}

}

