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

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 InsertJpegFileCommand extends GenericCommand
{

    public InsertJpegFileCommand()
    {
    }

    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("export", "JPEG");
        String s3 = properties.getProperty("quality", "80");
        String s4 = properties.getProperty("cache", "false");
        s = context.apply(s);
        s1 = context.apply(s1);
        s2 = context.apply(s2);
        s3 = context.apply(s3);
        String s5 = properties.getProperty("instancename", "");
        s5 = context.apply(s5);
        try
        {
            if(s5 != null)
                script.setCommandLabel(i, s5);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToSetInstanceName", s5);
        }
        try
        {
            k = Integer.valueOf(s3).intValue();
            if(k < 1 || k > 100)
            {
                logError(flashenvironment, "InvalidQualityRange", s3);
                k = 80;
            }
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvalidQualityValue", s3);
            k = 80;
        }
        if(s2.equalsIgnoreCase("JPEG"))
            j = 0;
        else
        if(s2.equalsIgnoreCase("Lossless"))
            j = 1;
        else
            logError(flashenvironment, "InvalidExportFormat", s2);
        Object obj = null;
        try
        {
            CacheManager cachemanager = flashenvironment.getCacheManager();
            if(cachemanager != null)
            {
                boolean flag = false;
                if(s4.equalsIgnoreCase("true"))
                    flag = true;
                obj = cachemanager.getMediaData(flashenvironment, s, flag);
            }
            if(obj == null)
                throw new GeneratorApiException("unable to open file");
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        Bitmap bitmap;
        try
        {
            bitmap = (Bitmap)_fld0109.add(new Bitmap());
            bitmap.setQuality(k);
            bitmap.setExport(j);
            Buffer buffer = new Buffer();
            if(buffer == null)
                throw new GeneratorApiException("buffer is null");
            buffer.write((byte[])obj);
            bitmap.setBuffer(buffer);
            buffer.release();
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        try
        {
            int l = bitmap.getWidth() * 20;
            int i1 = bitmap.getHeight() * 20;
            Matrix matrix = (Matrix)_fld0109.add(new Matrix());
            if(s1.equalsIgnoreCase("true"))
            {
                matrix.setXOffset(-l / 2);
                matrix.setYOffset(-i1 / 2);
                matrix.setXScale(2048F / (float)l);
                matrix.setYScale(2048F / (float)i1);
            } else
            {
                matrix.setXOffset(-l / 2);
                matrix.setYOffset(-i1 / 2);
            }
            script1.insertBitmap(bitmap, 0, 0, matrix, 1, matrix);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToInsertFile", s);
        }
        _fld0109.release();
    }

    GenVector _fld0109;
}