// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   Convergence.java

package lt.ktu.gmj.analysis;

import java.awt.Container;
import java.awt.Window;
import javax.swing.JFrame;
import lt.ktu.gmj.*;
import lt.ktu.gmj.tasks.ChannelProperties;
import lt.ktu.gmj.tasks.Model;
import lt.ktu.gmj.tasks.ModelTask;
import lt.monarch.chart.*;
import lt.monarch.chart.chart2D.*;
import lt.monarch.swing.JChartPanel;

// Referenced classes of package lt.ktu.gmj.analysis:
//            ResultFrame

public class Test extends ResultFrame
{
    class Provider extends AbstractChartPointProvider
    {
    	ModelTask task;
    	
        public void newResult(ResultRepository result)
        {        	
        	task=(ModelTask)result.task();                          
        }

        public ChartPoint point(int i)
        {
            return new InvisibleDot(task.v[i],task.g[i]);
        }

        public int pointCount()
        {
            return task.v.length;
        }

        Provider()
        {
        }
    }
    
    class Provider1 extends AbstractChartPointProvider
    {
    	double r[][];
    	
        public void newResult(ResultRepository result)
        {   
        	ModelTask task=(ModelTask)result.task();
        	
        	Model model=new Model();
        	Point point=result.lastResult().point;
        	
        	model.getProperties().getA().setGc(point.x[0]);
        	model.getProperties().getA().setGo(point.x[1]);
        	model.getProperties().getA().setA(point.x[2]);
        	model.getProperties().getA().setV0(point.x[3]);
        	model.getProperties().getB().setGc(point.x[4]);
        	model.getProperties().getB().setGo(point.x[5]);
        	model.getProperties().getB().setA(point.x[6]);
        	model.getProperties().getB().setV0(point.x[7]);
        	model.getProperties().setX(task.x);
        	
        	r=model.Run();    
        }

        public ChartPoint point(int i)
        {
            return new InvisibleDot(r[0][i],r[1][i]);
        }

        public int pointCount()
        {
            return r[0].length;
        }

        Provider1()
        {
        }
    }


    public Test()
    {
        super("Test");
        chart = new Chart2D();
        getContentPane().add("Center", new JChartPanel(chart));
    }

    public void finalResult(ResultRepository resultrepository)
    {
        newProgressResult(resultrepository);
    }

    public void newProgressResult(ResultRepository resultrepository)
    {
        provider.newResult(resultrepository);
    }

    public void newResult(ResultRepository resultrepository)
    {
    }

    public void prepare(ResultRepository resultrepository)
    {
        super.prepare(resultrepository);
        setupChart();
        show();
        resultrepository.addObserver(this);
    }

    protected void setupChart()
    {
        provider = new Provider();
        provider.newResult(super.results);
        
        Provider1 provider1 = new Provider1();
        provider1.newResult(super.results);
        
        MathAxisMapper mathaxismapper = new MathAxisMapper();
        MathAxisMapper mathaxismapper1 = new MathAxisMapper();
        Axis2DX axis2dx = new Axis2DX(mathaxismapper1);
        Axis2DY axis2dy = new Axis2DY(mathaxismapper);
        series = new ConnectedSeries(provider, axis2dx, axis2dy);
        
        ConnectedSeries series1 = new ConnectedSeries(provider1, axis2dx, axis2dy);
        
        Grid grid = new Grid(axis2dx, axis2dy);
        axis2dy.setLabel("f(x)");
        axis2dx.setLabel("Iteration");
        mathaxismapper.range.setRange(0,1);
        mathaxismapper1.range.setRange(-120,120);
        chart.reset();
        chart.setLAxis(axis2dy);
        chart.setXAxis(axis2dx);
        chart.setObjects(new ChartObject[] {
            grid, axis2dx, axis2dy, series,series1
        });              
        chart.invalidate();
    }

    protected Chart2D chart;
    protected ConnectedSeries series;
    protected Provider provider;
}
