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

package lt.ktu.gmj;

import lt.ktu.gmj.propertySheet.ArrayElementProvider;
import lt.ktu.gmj.propertySheet.FunctionEditor;
import lt.ktu.gmj.propertySheet.Header;
import lt.ktu.gmj.propertySheet.PropertyManager;
import lt.ktu.gmj.propertySheet.SimpleProperty;
import lt.monarch.function.Function;
import lt.monarch.function.FunctionParser;
import lt.monarch.function.parser.ParseException;

// Referenced classes of package lt.ktu.gmj:
//            Domain, Point

public abstract class DomainWithConstraint extends Domain
{

    public void customize(PropertyManager propertymanager)
    {
        super.customize(propertymanager);
        propertymanager.add(new Header("Contraint", "Function expression"));
        for (int i = 0; i < dimensions().length; i++)
            propertymanager.add(new SimpleProperty("Contstr" + (i + 1) + " (x1..xn)=", new FunctionEditor(new ArrayElementProvider(constraint, i))));

    }

    public double constraintAt(int i, Point point)
    {
        return constraint[i].evaluate(point.x);
    }

    public DomainWithConstraint()
    {
        StringBuffer stringbuffer = new StringBuffer();
        stringbuffer.append("(");
        for (int i = 0; i < dimensions().length; i++)
        {
            stringbuffer.append(i != 0 ? ", " : "");
            stringbuffer.append("x" + (i + 1));
        }

        stringbuffer.append(") = 1.0");
        constraint = new Function[dimensions().length];
        for (int j = 0; j < constraint.length; j++)
        {
            try
            {
                constraint[j] = (new FunctionParser()).parseDefinition("c" + j + stringbuffer.toString());
            }
            catch (ParseException parseexception) { }
        }

    }

    public Function constraint[];
}
