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

package com.macromedia.generator.commands;

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

public class PieChartCommand extends GenericCommand
{

    public PieChartCommand()
    {
        _fld010A = 50;
        _fld010B = 100;
        _fld0146 = 0;
        _fld0114 = null;
        _fld0115 = null;
        _fld0116 = null;
        _fld011A = 0;
        _fld011B = null;
        _fld011C = null;
        _fld0134 = 2;
        _fld0135 = 1;
        _fld0136 = 1.0F;
        _fld013A = 30;
        _fld013C = 0;
        _fld012E = true;
        _fld013F = 0.0F;
        _fld0140 = false;
    }

    boolean _mth0146(FlashEnvironment flashenvironment)
    {
        float f1 = 0.0F;
        Script script = (Script)_fld0109.add(new Script());
        try
        {
            script.setFileVersion(_fld011B.getFileVersion());
        }
        catch(GeneratorApiException _ex) { }
        int i = findColumn(_fld0113, "Value");
        if(i < 0)
        {
            i = findColumn(_fld0113, "val");
            if(i < 0)
            {
                logError(flashenvironment, "ValueColumnNotFound", _fld010E);
                return false;
            }
        }
        int j = findColumn(_fld0113, "Color");
        if(j < 0)
            logWarning(flashenvironment, "ColorColumnNotFound", _fld010E);
        int l = findColumn(_fld0113, "url");
        int i1 = findColumn(_fld0113, "window");
        int j1 = findColumn(_fld0113, "goto");
        int k1 = findColumn(_fld0113, "gotolabel");
        int k = findColumn(_fld0113, "offset");
        try
        {
            boolean flag = _fld0134 != 0 && _fld0116 != null;
            _fld0114.setDataCount(_fld0113.length - 1);
            for(int l1 = 1; l1 < _fld0113.length; l1++)
            {
                int i2;
                if(j != -1)
                    try
                    {
                        i2 = Color.getRGBValue(_fld0113[l1][j]);
                    }
                    catch(GeneratorApiException _ex)
                    {
                        i2 = Color.getRGBValue(_fld010F);
                    }
                else
                    i2 = Color.getRGBValue(_fld010F);
                float f;
                try
                {
                    f = Float.valueOf(_fld0113[l1][i]).floatValue();
                }
                catch(NumberFormatException _ex)
                {
                    f = 0.0F;
                }
                _fld0114.setDataValue(l1 - 1, f, i2);
                _mth0117(l1 - 1, l1, l, i1, j1, k1);
                if(flag)
                {
                    Context context = (Context)_fld0109.add(new Context());
                    context.setParent(_fld0119);
                    String s = (new Integer((int)f)).toString();
                    context.setValue("value", s);
                    _mth0112(context, l1);
                    Script script1 = (Script)_fld0109.add(_fld0116.copyScript());
                    _fld0115.processScript(script1, context);
                    _fld0114.addValueScript(l1 - 1, script1);
                    _fld0109.release(context);
                }
            }

        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "buildchartobject", _fld010E);
            return false;
        }
        _fld0114.computeChartSize();
        try
        {
            _fld0114.processPie();
        }
        catch(GeneratorApiException _ex) { }
        return true;
    }

    private void _mth0112(Context context, int i)
    {
        if(_fld0113 == null)
            return;
        int j = findColumn(_fld0113, "value");
        int k = findColumn(_fld0113, "color");
        if(j < 0)
            j = findColumn(_fld0113, "val");
        int l = _fld0113[i].length;
        for(int i1 = 0; i1 < l; i1++)
            if(i1 != j && i1 != k)
                context.setValue(_fld0113[0][i1], _fld0113[i][i1]);

    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        _fld0109 = new GenVector(16);
        _fld0110 = (Script)_fld0109.add(script.getCommandScript(i));
        if(_fld0110 == null)
            throw new FlashCommandException("movie clip missing");
        _fld0119 = context;
        _fld0115 = flashenvironment;
        _fld011B = script;
        _fld011C = _fld0110;
        _fld011A = script.getCommandFrameCount(i);
        _fld010E = properties.getProperty("datasource", "");
        _fld010F = properties.getProperty("color", "black");
        String s = properties.getProperty("instancename", null);
        try
        {
            if(s != null)
                script.setCommandLabel(i, s);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToSetInstanceName", s);
        }
        try
        {
            _fld010A = Float.valueOf(context.apply(properties.getProperty("gap", "0"))).intValue();
        }
        catch(NumberFormatException _ex)
        {
            _fld010A = 0;
        }
        try
        {
            _fld0146 = Float.valueOf(context.apply(properties.getProperty("explode", "0"))).intValue();
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvExplodeValue", null);
            _fld0146 = 0;
        }
        _fld0111 = properties.getProperty("type", getResourceString(flashenvironment, "strPie"));
        _fld0111 = context.apply(_fld0111);
        _fld010E = context.apply(_fld010E);
        try
        {
            UrlDataSource urldatasource = new UrlDataSource();
            urldatasource.setEnvironment(flashenvironment);
            try
            {
                _fld0113 = urldatasource.getData(_fld010E);
            }
            catch(Exception _ex)
            {
                logError(flashenvironment, "DataLoadError", _fld010E);
                return;
            }
            if(_fld0113 == null)
            {
                logError(flashenvironment, "DataSourceError", _fld010E);
                return;
            }
            if(_fld0113.length <= 1)
            {
                logError(flashenvironment, "invalidrows", _fld010E);
                return;
            }
            _mth0147(properties);
            Rect rect = (Rect)_fld0109.add(script.getCommandRect(i));
            _fld0114.setChartRect(rect);
            if(_fld0111.equalsIgnoreCase(getResourceString(flashenvironment, "strPie")))
            {
                if(!_mth0146(flashenvironment))
                    logError(flashenvironment, "createPieChart", null);
            } else
            if(_fld0111.equalsIgnoreCase(getResourceString(flashenvironment, "str3DPie")))
                try
                {
                    _fld010B = Float.valueOf(context.apply(properties.getProperty("depth", "100"))).intValue();
                }
                catch(NumberFormatException _ex)
                {
                    logError(flashenvironment, "InvDepthValue", null);
                    _fld010B = 100;
                }
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", _fld010E);
        }
        _fld0109.release();
    }

    private int _mth0113(int i, int j)
    {
        if(j == -1)
            return -1;
        int k = -1;
        try
        {
            k = Integer.valueOf(_fld0113[i][j]).intValue();
        }
        catch(NumberFormatException _ex) { }
        return k;
    }

    private String _mth0114(int i, int j)
    {
        if(j == -1)
            return null;
        else
            return _fld0113[i][j];
    }

    private boolean _mth0116(int i, int j)
    {
        if(j == -1)
            return false;
        return _fld0113[i][j] != null && _fld0113[i][j] != "";
    }

    private void _mth0117(int i, int j, int k, int l, int i1, int j1)
    {
        if(_mth0116(j, k))
        {
            try
            {
                String s = null;
                if(l != -1)
                    s = _fld0113[j][l];
                if(s == null || s.length() == 0)
                    s = "_self";
                _fld0114.setURL(i, _fld0113[j][k], s);
            }
            catch(GeneratorApiException _ex) { }
        } else
        {
            int k1 = _mth0113(j, i1);
            if(k1 == -1 && i1 != -1)
                logWarning(_fld0115, "invalidgoto", "");
            if(k1 != -1)
            {
                try
                {
                    _fld0114.setGoTo(i, k1, "../");
                }
                catch(GeneratorApiException _ex)
                {
                    logWarning(_fld0115, "invalidgoto", "");
                }
            } else
            {
                String s1 = _mth0114(j, j1);
                if(s1 != null && s1 != "")
                    try
                    {
                        _fld0114.setGoToLabel(i, "../", s1);
                    }
                    catch(GeneratorApiException _ex)
                    {
                        logWarning(_fld0115, "invalidgotolabel", "");
                    }
            }
        }
    }

    private boolean _mth0147(Properties properties)
    {
        PropertyParser propertyparser = new PropertyParser(getClass().getName(), _fld0115, _fld0119, properties);
        _fld0134 = 2;
        if(propertyparser.ParamEquals("valuedisplay", "never"))
            _fld0134 = 0;
        else
        if(propertyparser.ParamEquals("valuedisplay", "always"))
            _fld0134 = 1;
        else
        if(propertyparser.ParamEquals("valuedisplay", "rollover"))
            _fld0134 = 2;
        else
        if(propertyparser.HasParam("valuedisplay"))
            logError(_fld0115, "valueDisplayErr", properties.getProperty("valuedisplay"));
        _fld0135 = 3;
        _fld0136 = 1.0F;
        if(propertyparser.HasParam("valuescale"))
            if(propertyparser.ParamEquals("valuescale", "fixed"))
            {
                _fld0135 = 2;
                _fld0136 = 1.0F;
            } else
            if(propertyparser.ParamEquals("valuescale", "double"))
            {
                _fld0135 = 3;
                _fld0136 = 2.0F;
            } else
            if(propertyparser.ParamEquals("valuescale", "half"))
            {
                _fld0135 = 3;
                _fld0136 = 0.5F;
            } else
            {
                _fld0136 = propertyparser.GetFloatParam("valuescale", 1.0F);
                _fld0135 = 3;
                if(!propertyparser.Suceeded())
                {
                    logError(_fld0115, "valueScaleParamErr", propertyparser.GetStringParam("valuescale"));
                    _fld0135 = 1;
                }
            }
        _fld013A = 2;
        if(_fld013A < 1)
            _fld013A = 1;
        if(propertyparser.HasParam("lineSize"))
        {
            _fld013A = propertyparser.GetIntParam("lineSize", 20);
            if(!propertyparser.Suceeded())
                logError(_fld0115, "lineSizeErr", propertyparser.GetStringParam("lineSize"));
        }
        try
        {
            _fld013C = Color.getRGBValue(propertyparser.GetStringParam("color", "black"));
        }
        catch(GeneratorApiException _ex)
        {
            if(propertyparser.HasParam("color"))
                logWarning(_fld0115, "UseDefColor", propertyparser.GetStringParam("color"));
        }
        _fld013F = 0.0F;
        if(propertyparser.HasParam("depth"))
            if(propertyparser.ParamEquals("depth", "default"))
            {
                _fld013F = 0.0F;
            } else
            {
                _fld013F = propertyparser.GetFloatParam("depth", 0.0F);
                if(!propertyparser.Suceeded() || _fld013F < 0.0F)
                    logError(_fld0115, "InvDepthValue", propertyparser.GetStringParam("depth"));
            }
        _fld0140 = _fld013F > 1E-005F;
        _fld012E = true;
        if(propertyparser.HasParam("border"))
            if(propertyparser.ParamEquals("border", "true"))
                _fld012E = true;
            else
            if(propertyparser.ParamEquals("border", "false"))
            {
                _fld012E = false;
            } else
            {
                int i = propertyparser.GetIntParam("border", 1);
                if(!propertyparser.Suceeded())
                    logError(_fld0115, "borderErr", propertyparser.GetStringParam("border"));
                else
                    _fld012E = i != 0;
            }
        byte byte0 = 2;
        if(propertyparser.HasParam("valuepos"))
            if(propertyparser.ParamEquals("valuepos", "inside"))
                byte0 = 0;
            else
            if(propertyparser.ParamEquals("valuepos", "outside"))
                byte0 = 1;
            else
            if(propertyparser.ParamEquals("valuepos", "auto"))
            {
                byte0 = 2;
            } else
            {
                byte0 = 2;
                logError(_fld0115, "labelPosErr", propertyparser.GetStringParam("valuepos"));
            }
        if(propertyparser.HasParam("valueformat") && !propertyparser.ParamEquals("valueformat", "Arial") && !propertyparser.ParamEquals("valueformat", "Times") && !propertyparser.ParamEquals("valueformat", "Courier"))
            logError(_fld0115, "valueFormatErr", propertyparser.GetStringParam("valueformat"));
        try
        {
            _fld0114 = (Chart)_fld0109.add(new Chart(getClass().getName(), _fld0115, _fld0119, _fld011C));
            _fld0114.setBorder(_fld012E);
            _fld0114.setValueDisplay(_fld0134, _fld0135, _fld0136);
            _fld0114.setClip(_fld011C, _fld011A);
            _fld0114.setLineStyle(_fld013A, _fld013C, _fld013A, _fld013C);
            _fld0114.setEffect3D(_fld0140);
            _fld0114.setDepth3D(_fld013F);
            _fld0114.setPieLabelPosition(byte0);
            String s = null;
            if(propertyparser.HasParam("symbolfile"))
                s = propertyparser.GetStringParam("symbolfile");
            Script script = (Script)_fld0109.add(_fld0114.getSymbolScript(s));
            if(script != null)
                _fld0116 = (Script)_fld0109.add(_fld0114.getValueScript(script, propertyparser));
            if(_fld0134 != 0 && _fld0116 == null)
                logWarning(_fld0115, "valueSymbolMissing", "");
        }
        catch(GeneratorApiException _ex)
        {
            logError(_fld0115, "buildchartobject", "");
            return false;
        }
        return true;
    }

    int _fld010A;
    int _fld010B;
    int _fld0146;
    String _fld010E;
    String _fld010F;
    Script _fld0110;
    String _fld0111;
    String _fld0113[][];
    GenVector _fld0109;
    private Chart _fld0114;
    private FlashEnvironment _fld0115;
    private Script _fld0116;
    private Context _fld0119;
    private int _fld011A;
    private Script _fld011B;
    private Script _fld011C;
    private final String _fld0147 = "never";
    private final String _fld0148 = "always";
    private final String _fld0149 = "rollover";
    private int _fld0134;
    private int _fld0135;
    private float _fld0136;
    private int _fld013A;
    private int _fld013C;
    private boolean _fld012E;
    private float _fld013F;
    private boolean _fld0140;
}