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

package com.macromedia.generator.commands;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import com.macromedia.generator.platform.Mac;
import java.util.Properties;

public class InsertGifFileCommand extends GenericCommand
{

    public InsertGifFileCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        Mac mac = Mac.getMac();
        int j = 0;
        int k = 80;
        _fld0109 = new GenVector(16);
        Script script1 = (Script)_fld0109.add(script.getCommandScript(i));
        String s = properties.getProperty("filename", "");
        String s1 = properties.getProperty("scale", "false");
        String s2 = properties.getProperty("frames", "");
        String s3 = properties.getProperty("export", "JPEG");
        String s4 = properties.getProperty("quality", "80");
        String s5 = properties.getProperty("cache", "false");
        String s6 = context.apply(properties.getProperty("scale", ""));
        boolean flag = s6.equalsIgnoreCase(getResourceString(flashenvironment, "true"));
        String s7 = properties.getProperty("instancename", "");
        s7 = context.apply(s7);
        try
        {
            if(s7 != null)
                script.setCommandLabel(i, s7);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToSetInstanceName", s7);
        }
        s = context.apply(s);
        s1 = context.apply(s1);
        s2 = context.apply(s2);
        s3 = context.apply(s3);
        s4 = context.apply(s4);
        try
        {
            k = Integer.valueOf(s4).intValue();
            if(k < 1 || k > 100)
            {
                logError(flashenvironment, "InvalidQualityRange", s4);
                k = 80;
            }
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvalidQualityValue", s4);
            k = 80;
        }
        if(s3.equalsIgnoreCase("JPEG"))
            j = 0;
        else
        if(s3.equalsIgnoreCase("Lossless"))
            j = 1;
        else
            logError(flashenvironment, "InvalidExportFormat", s3);
        int l;
        if(s2.equalsIgnoreCase("all"))
            l = -1;
        else
        if(s2.equalsIgnoreCase("single"))
            l = 1;
        else
            try
            {
                l = Integer.valueOf(s2).intValue();
                if(l <= 0)
                {
                    logWarning(flashenvironment, "InvalidFrameRange", s2);
                    l = 1;
                }
            }
            catch(NumberFormatException _ex)
            {
                logWarning(flashenvironment, "InvalidFrameValue", s2);
                l = 1;
            }
        Object obj = null;
        try
        {
            CacheManager cachemanager = flashenvironment.getCacheManager();
            if(cachemanager != null)
            {
                boolean flag1 = false;
                if(s5.equalsIgnoreCase("true"))
                    flag1 = true;
                obj = cachemanager.getMediaData(flashenvironment, s, flag1);
            }
            if(obj == null)
                throw new GeneratorApiException("unable to open file");
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        try
        {
            Matrix matrix = (Matrix)_fld0109.add(new Matrix());
            int i1 = script.getCommandFrameCount(i);
            Buffer buffer = new Buffer();
            if(buffer == null)
                throw new GeneratorApiException("buffer is null");
            buffer.write((byte[])obj);
            script1.insertAnimatedBitmapBuffer(buffer, 0, 0, matrix, i1, matrix, flag, l, j, k);
            buffer.release();
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToInsertFile", s);
        }
        _fld0109.release();
    }

    GenVector _fld0109;
}