// 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.monarch.chart.*;
import lt.monarch.chart.chart2D.*;
import lt.monarch.swing.JChartPanel;

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

public class Convergence extends ResultFrame
{
    class Provider extends AbstractChartPointProvider
    {

        public void newResult(Result result)
        {
            ChartPoint chartpoint = pointFromResult(result);
            if (chartpoint.registerOn(series))
                firePointsChanged();
            firePointAdded(chartpoint);
        }

        public ChartPoint point(int i)
        {
            return ((ChartPoint) (i == 0 ? new InvisibleDot(new Double(0.0D), new Double(results.maxValue())) : pointFromResult(results.progressResultAt(i - 1))));
        }

        public int pointCount()
        {
            return results.progressResultCount() + 1;
        }

        protected ChartPoint pointFromResult(Result result)
        {
            InvisibleDot invisibledot = new InvisibleDot(new Double(result.iteration), new Double(result.value));
            return invisibledot;
        }

        Provider()
        {
        }
    }


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

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

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

    public void newResult(ResultRepository resultrepository)
    {
    }

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

    protected void setupChart()
    {
        provider = new Provider();
        MathAxisMapper mathaxismapper = new MathAxisMapper();
        MathAxisMapper mathaxismapper1 = new MathAxisMapper();
        Axis2DX axis2dx = new Axis2DX(mathaxismapper1);
        Axis2DY axis2dy = new Axis2DY(mathaxismapper);
        series = new ConnectedSeries(provider, axis2dx, axis2dy);
        Grid grid = new Grid(axis2dx, axis2dy);
        axis2dy.setLabel("f(x)");
        axis2dx.setLabel("Iteration");
        mathaxismapper.range.setRange(super.results.minValue(), super.results.maxValue());
        mathaxismapper1.range.setRange(0.0D, super.results.method().iterations());
        chart.reset();
        chart.setLAxis(axis2dy);
        chart.setXAxis(axis2dx);
        chart.setObjects(new ChartObject[] {
            grid, axis2dx, axis2dy, series
        });
        chart.invalidate();
    }

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