/*
 * Copyright (C) 1999-2006 <a href="mailto:adrian.paschke@gmx.de">Adrian Paschke</a>
 * 
 * The RBSLM Environment is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library 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 2 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.environment;

import java.awt.Dimension;
import java.io.File;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import rbsla.wrapper.ProvaWrapper;

/**
 * Main Class.
 */
public class ECAEnvironment extends Object implements Runnable
{

    private ECAWindow window;

    private ProvaWrapper myProva = null;

    private Class thisClass = ECAEnvironment.class;

    private int windowWidth = 0;

    private int windowHeight = 0;

    private static Logger logger = Logger.getLogger(ECAEnvironment.class);

    public ECAEnvironment(String[] args)
    {
    	
        PropertyConfigurator.configure(ECAConstraints._FILE_BASE_PATH + "log.properties");

        logger.info("-------------------------------------------------------------------------------");
        logger.info("ECA Environment");
        logger.info("-------------------------------------------------------------------------------");

        //System.exit(0);

        if (args.length == 0)
        {
            System.out
                    .println("Please provide one argument while starting the ECA Runtime System. The main prova file is needed.");
            System.exit(1);
        }

        // create a new knowlege base instance
        /*
         * try { myProva = new ProvaWrapper(new String[] { args[0] }); } catch
         * (Exception E) { System.out.println("The Prova file " + args[0] + "
         * can not be loaded."); System.exit(1); }
         */

        // start view daemon
        StartViewDaemon startViewDaemon = StartViewDaemon.initialise();

        // Open the window
        window = new ECAWindow(new ECAPanel(args));

        // load project file
        if (args.length < 2)
            startViewDaemon.loadViews(window, "");
        else
            startViewDaemon.loadViews(window, args[1]);

        // Set the window width and height, if applicable
        Dimension tmpSize = window.getSize();
        if (windowWidth > 0)
            tmpSize.width = windowWidth;
        if (windowHeight > 0)
            tmpSize.height = windowHeight;
        window.setSize(tmpSize);

        window.setTitle("ECA Runtime Environment - " + args[0] + "");

        // Show the window
        window.show();

        return;
    }

    public void run()
    {
        // Nothing to do here.
        return;
    }

    private void usage()
    {
        System.out.println("\n" + "Usage:");
        System.out.println("java ECAEnvironment [" + "prova file"
                + " filename]");
        return;
    }

    public static void main(String[] args)
    {
    	ECAEnvironment firstInstance = new ECAEnvironment(args);
        firstInstance.run();
        return;
    }
}