// 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:   ResultSheet.java

package lt.ktu.gmj.ui;

import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import lt.ktu.gmj.*;
import lt.ktu.gmj.propertySheet.*;

public class ResultSheet extends PropertySheet
    implements ResultObserver
{

    public void logStarted(ResultRepository resultrepository)
    {
        set = resultrepository;
        SwingUtilities.invokeLater(new _cls1());
    }

    public void logDisposed(ResultRepository resultrepository)
    {
        resultrepository.removeObserver(this);
        SwingUtilities.invokeLater(new _cls2());
    }

    public void newResult(ResultRepository resultrepository)
    {
        final Result r = resultrepository.lastResult();
        SwingUtilities.invokeLater(new _cls3(r));
    }

    private String format(double d)
    {
        String s = String.valueOf((double)Math.round(d * 1000D) / 1000D);
        if (s.length() > 7)
            s = s.substring(0, 7);
        return s;
    }

    private String format(int i)
    {
        return String.valueOf(i);
    }

    public void newProgressResult(ResultRepository resultrepository)
    {
        final Result r = resultrepository.lastResult();
        SwingUtilities.invokeLater(new _cls4(r));
    }

    public void finalResult(ResultRepository resultrepository)
    {
    }

    protected void setup()
    {
        removeAll();
        add(new Header("Property", "Value"));
        iteration = new JLabel("", 0);
        add(new SimpleProperty("Iteration", new ComponentPresenter(iteration)));
        value = new JLabel("", 0);
        add(new SimpleProperty("F(x)", new ComponentPresenter(value)));
        String as[] = set.task().domain().dimensions();
        dimensions = new JLabel[as.length];
        for (int i = 0; i < as.length; i++)
        {
            dimensions[i] = new JLabel("", 0);
            add(new SimpleProperty(as[i], new ComponentPresenter(dimensions[i])));
        }

        complete();
    }

    public ResultSheet()
    {
        set = null;
    }

    protected ResultRepository set;
    protected JLabel iteration;
    protected JLabel value;
    protected JLabel dimensions[];


    private class _cls1
        implements Runnable
    {

        public void run()
        {
            setup();
        }

        public void constructor$0(ResultSheet resultsheet)
        {
        }

        public _cls1()
        {
            constructor$0(ResultSheet.this);
        }
    }


    private class _cls2
        implements Runnable
    {

        public void run()
        {
            removeAll();
        }

        public void constructor$0(ResultSheet resultsheet)
        {
        }

        public _cls2()
        {
            constructor$0(ResultSheet.this);
        }
    }


    private class _cls3
        implements Runnable
    {

        private Result r;

		public void run()
        {
            iteration.setText(String.valueOf(r.iteration));
        }

        public void constructor$0(ResultSheet resultsheet)
        {
        }

        public _cls3(Result rr)
        {
        	r=rr;
            constructor$0(ResultSheet.this);
        }
    }


    private class _cls4
        implements Runnable
    {

        private Result r;
		

		public void run()
        {
            value.setText(format(r.value));
            for (int i = 0; i < r.point.x.length; i++)
                dimensions[i].setText(format(r.point.x[i]));

        }

        public void constructor$0(ResultSheet resultsheet)
        {
        }

        public _cls4(Result rr)
        {
        	r=rr;
            constructor$0(ResultSheet.this);
        }
    }

}
