Package org.jsurveylib

Source Code of org.jsurveylib.TestBench

/**
* This file is part of JSurveyLib.
*
* JSurveyLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSurveyLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JSurveyLib.  If not, see <http://www.gnu.org/licenses/>.
**/

/*
*  Modulname:  Testbench
*  Autor:    Eyer Leander
*  Datum:    08.05.2006
*
*  (c) Copyright 2005
*/
package org.jsurveylib;

import org.jsurveylib.gui.swing.SurveyPanel;
import org.jsurveylib.gui.swing.SurveyMenu;

import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;

/**
* <u><b><font color="red">FOR INTERNAL USE ONLY.</font></b></u>
* <p/>
* A simple main window to host the testing
*/
public class TestBench extends JFrame implements SurveyListener {


    public TestBench(String xmlConfigFile) {
        super("Survey Testbench");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        try {
            ClientSurvey survey = new Survey(xmlConfigFile);
            SurveyPanel surveyPanel = new SurveyPanel(survey);
            survey.addSurveyListener(this);
            if (xmlConfigFile.contains("surveyLoadAnswers.xml")) {
                survey.loadXMLAnswers(new InputStreamReader(new FileInputStream("resultLoadAnswers.xml"), "UTF-8"));
            }
            setLayout(new BorderLayout());
            add(surveyPanel, BorderLayout.CENTER);
            setJMenuBar(new SurveyMenu(survey, this));           
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }

        pack();
        setVisible(true);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    public static void main(String[] args) {
        String fileName = (args.length == 0) ? "surveyLoadAnswers.xml" : args[0];
        new TestBench(fileName);
    }

    public void surveyFinished(Survey survey) {
        try {
            survey.saveXMLAnswers("result.xml");

        } catch (IOException e) {
            e.printStackTrace();
        }

        System.exit(0);
    }

}
TOP

Related Classes of org.jsurveylib.TestBench

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.