package applets;

import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.beans.*;

import iDSS.utils.*;
import iDSS.grids.*;
import iDSS.gridDisp.*;
import iDSS.disp.*;




public class VisualizationApplet extends JApplet implements PropertyChangeListener {


    private JDesktopPane desktopPane;




    public void init() {


        desktopPane = new JDesktopPane();

/**
        String simName = getParameter("simulationName");
        String timeStepHrs = getParameter("timeStepHrs");
        String simStartYear = getParameter("simStartYear");
        String simEndYear = getParameter("simEndYear");

        if(simName == null)
            simName = "FailedToReadSimulationName";

        if(simStartYear == null)
            simStartYear = "9999";

        if(simEndYear == null)
            simEndYear = "9999";

        if(timeStepHrs == null) {
            simName = "FailedToReadTimeStepHrs";
            timeStepHrs = "00";
        } //
**/

        try {

/**
            System.out.println("VisualizationApplet.init()");
            System.out.println("simStartYear : " + simStartYear);
            System.out.println("simEndYear : " + simEndYear);
            System.out.println("timeStepHrs : " + timeStepHrs);
            System.out.println("simName : " + simName);

            int simStartYearInt = Integer.parseInt(simStartYear);
            int timeStepHrsInt = Integer.parseInt(timeStepHrs);
            int simEndYearInt = Integer.parseInt(simEndYear);

            GridViewControlApplet gvc = new GridViewControlApplet(simName,
                                                                simStartYearInt,simEndYearInt,timeStepHrsInt);
**/

            GridViewControlApplet gvc = new GridViewControlApplet();
            gvc.addPropertyChangeListener(this);

            addToView(gvc);
            //gvc.resetYearCombo(simStartYearInt,simEndYearInt);

        } //try

        catch(NumberFormatException nfe) {

            System.out.println(nfe.toString());

        } //

    } //public void init()








    public void propertyChange(PropertyChangeEvent evt) {


        if (evt.getPropertyName().equals(IDSSAppConstants.addToModelView)) {

            DisplayFrame frame = (DisplayFrame)evt.getNewValue();

            if(frame != null) {

                addToView(frame);

            } //if(frame != null)

            else {

                if(IDSSAppConstants.debug)
                    System.out.println("ModelSetupTree.propertyChange(), " +
                            evt.getPropertyName() + " frame = null");

            } //else

        } //if (evt.getPropertyName().equals(IDSSAppConstants.addToModelView))

    } //public void propertyChange(PropertyChangeEvent evt)






    private void addToView(DisplayFrame f) {

        desktopPane.add(f);
        desktopPane.setPosition(f,0);
        setContentPane(desktopPane);

    } //private void addToView(DisplayFrame f)


} //public class VisualizationApplet extends JApplet
