// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:39
// 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/TickerCommand

package com.macromedia.generator.commands;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import java.util.*;

public class TickerCommand extends GenericCommand
{

    public TickerCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        _fld0144 = context;
        _fld0145 = properties;
        _fld0109 = new GenVector(16);
        try
        {
            Script script1 = (Script)_fld0109.add(script.getCommandScript(i));
            if(script1 == null)
                throw new FlashCommandException("movie clip missing");
            String s = getStringParamEmpty(_fld0144, _fld0145, "datasource");
            String s1 = getStringParamEmpty(_fld0144, _fld0145, "stepsize");
            boolean flag = getStringParamEmpty(_fld0144, _fld0145, "orient").equalsIgnoreCase(getResourceString(flashenvironment, "horizontal"));
            boolean flag1 = getStringParamEmpty(_fld0144, _fld0145, "spacing").equalsIgnoreCase(getResourceString(flashenvironment, "auto"));
            String s2 = getStringParamEmpty(_fld0144, _fld0145, "halign");
            String s3 = getStringParamEmpty(_fld0144, _fld0145, "valign");
            int j = getIntParam(_fld0144, _fld0145, "itemspace", 0) * 20;
            boolean flag2 = getBoolParam(_fld0144, _fld0145, "mask");
            int k = getIntParam(_fld0144, _fld0145, "stepsize", 0) * 20;
            if(k < 10)
            {
                logWarning(flashenvironment, "StepError", null);
                k = 10;
            }
            String s4 = getStringParamEmpty(_fld0144, _fld0145, "instancename");
            UrlDataSource urldatasource = new UrlDataSource();
            urldatasource.setEnvironment(flashenvironment);
            _fld0113 = urldatasource.getData(s);
            if(_fld0113 == null || _fld0113.length < 2)
            {
                logError(flashenvironment, "DataSourceFormatError", s);
                _fld0109.release();
                return;
            }
            int l = findColumn(_fld0113, getStringParam(_fld0144, _fld0145, "clip", "clip"));
            int i1 = findColumn(_fld0113, getStringParam(_fld0144, _fld0145, "space", "space"));
            int j1 = findColumn(_fld0113, "instancename");
            if(l < 0)
            {
                logError(flashenvironment, "ClipColumnNotFound", s);
                _fld0109.release();
                return;
            }
            Rect rect = (Rect)_fld0109.add(script.getCommandRect(i));
            int k1 = rect.getXMin();
            int l1 = rect.getYMin();
            int i2 = rect.getXMax();
            int j2 = rect.getYMax();
            Script ascript[] = new Script[_fld0113.length];
            for(int k2 = 1; k2 < _fld0113.length; k2++)
            {
                Context context1 = (Context)_fld0109.add(new Context());
                context1.setParent(_fld0144);
                for(int l2 = 0; l2 < _fld0113[k2].length; l2++)
                    context1.setValue(_fld0113[0][l2], _fld0113[k2][l2]);

                ascript[k2] = (Script)_fld0109.add(script.findScript(_fld0113[k2][l]));
                if(ascript[k2] == null)
                    ascript[k2] = (Script)_fld0109.add(flashenvironment.getTemplate().findScript(_fld0113[k2][l]));
                if(ascript[k2] != null)
                {
                    ascript[k2] = (Script)_fld0109.add(ascript[k2].copyScript());
                    flashenvironment.processScript(ascript[k2], context1);
                } else
                {
                    logError(flashenvironment, "UnableToFindSymbol", _fld0113[k2][l]);
                }
                _fld0109.release(context1);
            }

            Script script2 = (Script)_fld0109.add(new Script());
            script2.setFileVersion(script.getFileVersion());
            int i3 = 0;
            for(int j3 = 1; j3 < _fld0113.length; j3++)
                if(ascript[j3] != null)
                {
                    int k3 = j;
                    if(i1 >= 0)
                        k3 += convertStringToInt(_fld0113[j3][i1], 0) * 20;
                    if(flag1)
                    {
                        Rect rect1 = ascript[j3].getBounds();
                        int i4 = flag ? rect1.getXMin() : rect1.getYMin();
                        int j4 = flag ? rect1.getXMax() : rect1.getYMax();
                        if(i4 > 0)
                            i4 = 0;
                        if(j4 < 0)
                            j4 = 0;
                        k3 += j4 - i4;
                    }
                    Matrix matrix = (Matrix)_fld0109.add(new Matrix());
                    if(s2.equalsIgnoreCase(getResourceString(flashenvironment, "left")))
                    {
                        if(flag)
                            matrix.setXOffset(k1 + i3);
                        else
                            matrix.setXOffset(k1);
                    } else
                    if(s2.equalsIgnoreCase(getResourceString(flashenvironment, "right")))
                    {
                        if(flag)
                            matrix.setXOffset(k1 + i3 + k3);
                        else
                            matrix.setXOffset(i2);
                    } else
                    if(flag)
                        matrix.setXOffset(k1 + i3 + k3 / 2);
                    else
                        matrix.setXOffset((k1 + i2) / 2);
                    if(s3.equalsIgnoreCase(getResourceString(flashenvironment, "top")))
                    {
                        if(flag)
                            matrix.setYOffset(l1);
                        else
                            matrix.setYOffset(l1 + i3);
                    } else
                    if(s3.equalsIgnoreCase(getResourceString(flashenvironment, "bottom")))
                    {
                        if(flag)
                            matrix.setYOffset(j2);
                        else
                            matrix.setYOffset(l1 + i3 + k3);
                    } else
                    if(flag)
                        matrix.setYOffset((l1 + j2) / 2);
                    else
                        matrix.setYOffset(l1 + i3 + k3 / 2);
                    String s5 = null;
                    if(j1 != -1)
                        s5 = _fld0113[j3][j1];
                    else
                        s5 = _fld0113[j3][l];
                    int k4 = ascript[j3].getLastFrame();
                    script2.insertObject(ascript[j3], 0, 0, matrix, k4, matrix, null, s5);
                    i3 += k3;
                }

            int l3 = i3 / k;
            if(l3 < 1)
                l3 = 1;
            if(l3 > 1000)
                l3 = 1000;
            if(l3 == 1)
            {
                Matrix matrix1 = (Matrix)_fld0109.add(new Matrix());
                String s6 = ResourceBundle.getBundle(getClass().getName().concat("Data"), Locale.getDefault()).getString("contents");
                if(script2 != null)
                    script1.insertObject(script2, 0, 0, matrix1, 1, matrix1, null, s6);
            } else
            {
                Matrix matrix2 = (Matrix)_fld0109.add(new Matrix());
                Matrix matrix3 = (Matrix)_fld0109.add(new Matrix());
                if(flag)
                    matrix3.setXOffset(-i3);
                else
                    matrix3.setYOffset(-i3);
                Matrix matrix4 = (Matrix)_fld0109.add(new Matrix());
                if(flag)
                    matrix4.setXOffset(i3);
                else
                    matrix4.setYOffset(i3);
                String s7 = ResourceBundle.getBundle(getClass().getName().concat("Data"), Locale.getDefault()).getString("contents");
                String s8 = ResourceBundle.getBundle(getClass().getName().concat("Data"), Locale.getDefault()).getString("contents_2");
                if(script2 != null)
                {
                    script1.insertObject(script2, 0, 0, matrix2, l3, matrix3, null, s7);
                    script1.insertObject(script2, 0, 0, matrix4, l3, matrix2, null, s8);
                }
            }
            if(flag2)
                script.setCommandMask(i, getMask(_fld0109, rect));
            if(s4 != null)
                script.setCommandLabel(i, s4);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "ErrorCreatingTicker", null);
        }
        _fld0109.release();
    }

    GenVector _fld0109;
    Context _fld0144;
    Properties _fld0145;
    String _fld0113[][];
}