// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:22
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/commands/PlotMovieClipCommand

package com.macromedia.generator.commands;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import com.macromedia.generator.utils.PropertyParser;
import java.util.Properties;

public class PlotMovieClipCommand extends GenericCommand
{

    public PlotMovieClipCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        _fld0109 = new GenVector(16);
        Script script1 = (Script)_fld0109.add(script.getCommandScript(i));
        if(script1 == null)
            throw new FlashCommandException("movie clip missing");
        String s = properties.getProperty("datasource", "");
        String s1 = properties.getProperty("xmin", "");
        String s2 = properties.getProperty("ymin", "");
        String s3 = properties.getProperty("xmax", "");
        String s4 = properties.getProperty("ymax", "");
        String s5 = properties.getProperty("instancename", "");
        s = context.apply(s);
        s1 = context.apply(s1);
        s2 = context.apply(s2);
        s3 = context.apply(s3);
        s4 = context.apply(s4);
        s5 = context.apply(s5);
        int j;
        int k;
        int l;
        int i1;
        try
        {
            j = Integer.valueOf(s1).intValue();
            k = Integer.valueOf(s3).intValue();
            l = Integer.valueOf(s2).intValue();
            i1 = Integer.valueOf(s4).intValue();
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "MinMaxMustBeNumbers", null);
            return;
        }
        if(j >= k)
            logError(flashenvironment, "XMinGreaterThanXMax", null);
        if(l >= i1)
            logError(flashenvironment, "YMinGreaterThanYMax", null);
        if(j >= k || l >= i1)
        {
            logError(flashenvironment, "MinMaxInvalid", null);
            return;
        }
        UrlDataSource urldatasource = new UrlDataSource();
        urldatasource.setEnvironment(flashenvironment);
        String as[][] = urldatasource.getData(s);
        if(as == null)
        {
            logError(flashenvironment, "DataSourceError", s);
            return;
        }
        if(as.length < 2)
        {
            logError(flashenvironment, "DataSourceFormatError", s);
            return;
        }
        int j2 = findColumn(context, as, getStringParam(context, properties, "x", "x"));
        int k2 = findColumn(context, as, getStringParam(context, properties, "y", "y"));
        int l2 = findColumn(context, as, getStringParam(context, properties, "xs", "xscale"));
        int i3 = findColumn(context, as, getStringParam(context, properties, "ys", "yscale"));
        int j3 = findColumn(context, as, getStringParam(context, properties, "rotate", "rotate"));
        int k3 = findColumn(context, as, getStringParam(context, properties, "clip", "clip"));
        int l3 = findColumn(context, as, getStringParam(context, properties, "instance", "instancename"));
        if(k3 == -1)
        {
            logError(flashenvironment, "ClipColumnNotFound", s);
            return;
        }
        if(j2 == -1)
        {
            logError(flashenvironment, "XColumnNotFound", s);
            return;
        }
        if(k2 == -1)
        {
            logError(flashenvironment, "YColumnNotFound", s);
            return;
        }
        int j1;
        int k1;
        int l1;
        int i2;
        Rect rect;
        try
        {
            rect = (Rect)_fld0109.add(script.getCommandRect(i));
            j1 = rect.getXMin();
            k1 = rect.getYMin();
            l1 = rect.getXMax();
            i2 = rect.getYMax();
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToInsertSymbol", null);
            return;
        }
        boolean flag = false;
        int i4 = 0;
        String s6 = null;
        PropertyParser propertyparser = new PropertyParser(getClass().getName(), flashenvironment, context, properties);
        if(propertyparser.HasParam("borders"))
            if(propertyparser.ParamEquals("borders", "on"))
                flag = true;
            else
            if(!propertyparser.ParamEquals("borders", "off"))
                logError(flashenvironment, "badBorderParam", propertyparser.GetStringParam("borders"));
        if(flag)
        {
            if(propertyparser.HasParam("bordercolor"))
            {
                s6 = propertyparser.GetStringParam("bordercolor");
                int j4;
                try
                {
                    j4 = Color.getRGBValue(s6);
                }
                catch(GeneratorApiException _ex)
                {
                    logError(flashenvironment, "borderColorErr", propertyparser.GetStringParam("bordercolor"));
                    s6 = "black";
                }
            } else
            {
                s6 = "black";
            }
            if(propertyparser.HasParam("borderthickness"))
            {
                i4 = propertyparser.GetIntParam("borderthickness", 20);
                if(i4 <= 0)
                    flag = false;
            }
        }
        if(flag)
            try
            {
                Shape shape = _mth014A(rect, s6, i4);
                Matrix matrix = (Matrix)_fld0109.add(new Matrix());
                int l4 = script.getCommandFrameCount(i);
                script1.insertShape(shape, 0, 0, matrix, l4, matrix);
            }
            catch(GeneratorApiException _ex)
            {
                logError(flashenvironment, "plotError", "");
                _fld0109.release();
                return;
            }
        for(int k4 = 1; k4 < as.length; k4++)
        {
            Context context1 = (Context)_fld0109.add(new Context());
            context1.setParent(context);
            for(int i5 = 0; i5 < as[k4].length; i5++)
                context1.setValue(as[0][i5], as[k4][i5]);

            try
            {
                int j5 = 0;
                int k5 = 0;
                float f = 1.0F;
                float f1 = 1.0F;
                float f2 = 0.0F;
                Object obj = null;
                Script script2 = (Script)_fld0109.add(script.findScript(as[k4][k3]));
                if(script2 == null)
                    script2 = (Script)_fld0109.add(flashenvironment.getTemplate().findScript(as[k4][k3]));
                if(script2 != null)
                {
                    boolean flag1 = true;
                    try
                    {
                        j5 = Integer.valueOf(as[k4][j2]).intValue();
                    }
                    catch(NumberFormatException _ex)
                    {
                        logError(flashenvironment, "xposInvalid", null);
                        flag1 = false;
                    }
                    if(flag1)
                        try
                        {
                            k5 = Integer.valueOf(as[k4][k2]).intValue();
                        }
                        catch(NumberFormatException _ex)
                        {
                            logError(flashenvironment, "yposInvalid", null);
                            flag1 = false;
                        }
                    if(flag1)
                        try
                        {
                            f = l2 == -1 ? 1.0F : Float.valueOf(as[k4][l2]).floatValue();
                        }
                        catch(NumberFormatException _ex)
                        {
                            logError(flashenvironment, "xscaleInvalid", null);
                            flag1 = false;
                        }
                    if(flag1)
                        try
                        {
                            f1 = i3 == -1 ? 1.0F : Float.valueOf(as[k4][i3]).floatValue();
                        }
                        catch(NumberFormatException _ex)
                        {
                            logError(flashenvironment, "yscaleInvalid", null);
                            flag1 = false;
                        }
                    if(flag1)
                        try
                        {
                            f2 = j3 == -1 ? 0.0F : Float.valueOf(as[k4][j3]).floatValue();
                        }
                        catch(NumberFormatException _ex)
                        {
                            logError(flashenvironment, "rotateInvalid", null);
                            flag1 = false;
                        }
                    String s7;
                    if(flag1)
                        s7 = l3 == -1 ? null : as[k4][l3];
                    if(!flag1)
                    {
                        j5 = 0;
                        k5 = 0;
                        f = 1.0F;
                        f1 = 1.0F;
                        f2 = 0.0F;
                    } else
                    {
                        Script script3 = (Script)_fld0109.add(script2.copyScript());
                        flashenvironment.processScript(script3, context1);
                        Matrix matrix1 = (Matrix)_fld0109.add(new Matrix());
                        int l5 = k - j;
                        int i6 = i1 - l;
                        j5 -= j;
                        k5 -= l;
                        j5 = (j5 * (l1 - j1)) / l5;
                        k5 = (k5 * (i2 - k1)) / i6;
                        j5 -= (l1 - j1) / 2;
                        k5 -= (i2 - k1) / 2;
                        matrix1.setXOffset(j5);
                        matrix1.setYOffset(k5);
                        matrix1.setXScale(f);
                        matrix1.setYScale(f1);
                        matrix1.setAngle(f2);
                        int j6 = script.getCommandFrameCount(i);
                        String s8 = null;
                        if(l3 != -1)
                            s8 = as[k4][l3];
                        else
                            s8 = as[k4][k3];
                        int k6 = script.getCommandFrameCount(i);
                        script1.insertObject(script3, 0, 0, matrix1, k6, matrix1, null, s8);
                        _fld0109.release(matrix1);
                        _fld0109.release(script3);
                    }
                } else
                {
                    logError(flashenvironment, "UnableToInsertSymbol", as[k4][k3]);
                }
            }
            catch(GeneratorApiException _ex)
            {
                logError(flashenvironment, "UnableToInsertSymbol", as[k4][k3]);
            }
            _fld0109.release(context1);
        }

        try
        {
            if(s5 != null)
                script.setCommandLabel(i, s5);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToSetInstanceName", s5);
        }
        _fld0109.release();
    }

    protected int findColumn(Context context, String as[][], String s)
    {
        for(int i = 0; i < as[0].length; i++)
            if(as[0][i].equalsIgnoreCase(s))
                return i;

        return -1;
    }

    private Shape _mth014A(Rect rect, String s, int i)
    {
        Shape shape = null;
        try
        {
            shape = (Shape)_fld0109.add(new Shape());
            Color color = (Color)_fld0109.add(new Color());
            color.setRGBValue(s);
            LineStyle linestyle = (LineStyle)_fld0109.add(new LineStyle());
            linestyle.setWidth(i);
            linestyle.setColor(color);
            shape.setLineStyle(linestyle);
            int j = rect.getXMin();
            int k = rect.getYMin();
            int l = rect.getXMax();
            int i1 = rect.getYMax();
            shape.moveTo(j, i1);
            shape.lineTo(l, i1);
            shape.lineTo(l, k);
            shape.lineTo(j, k);
            shape.lineTo(j, i1);
        }
        catch(GeneratorApiException _ex)
        {
            shape = null;
        }
        return shape;
    }

    GenVector _fld0109;
}