package scriptbuilder.gui.drawers;

import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import scriptbuilder.structures.ScriptEvent;
import scriptbuilder.structures.ScriptEvent.ScriptEventType;
import images.*;

/**
 *
 * @author Greg Eddington <geddingt@calpoly.edu>
 */
public class EventIconDrawer
{
    private static Map<String, Image> images = null;

    private static Image radioEventImage = null;
    private static Image paramicsEventImage = null;
    private static Image cadEventImage = null;
    private static Image evaluationEventImage = null;

    private static Image getImage(String name)
    {
        if (images == null)
        {
            try
            {
                images = new HashMap<String, Image>();
                for (ScriptEventType t : ScriptEventType.values())
                {
                    images.put(t.IMAGE_NAME, ImageIO.read(Images.getImage(t.IMAGE_NAME + ".png")));
                }
            }
            catch (IOException ex)
            {
                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
            }
        }

        return images.get(name);
    }

    private static Image getRadioEventImage()
    {
        if (radioEventImage == null)
        {
            try
            {
                radioEventImage = ImageIO.read(Images.getImage("Radio.png"));
            }
            catch (IOException ex)
            {
                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return radioEventImage;
    }

    private static Image getParamicsEventImage()
    {
        if (paramicsEventImage == null)
        {
            try
            {
                paramicsEventImage = ImageIO.read(Images.getImage("Paramics.png"));
            }
            catch (IOException ex)
            {
                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return paramicsEventImage;
    }

        private static Image getCadEventImage()
    {
        if (cadEventImage == null)
        {
            try
            {
                cadEventImage = ImageIO.read(Images.getImage("CAD.png"));
            }
            catch (IOException ex)
            {
                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return cadEventImage;
    }

    private static Image getEvaluationEventImage()
    {
        if (evaluationEventImage == null)
        {
            try
            {
                evaluationEventImage = ImageIO.read(Images.getImage("Evaluation.png"));
            }
            catch (IOException ex)
            {
                Logger.getLogger(EventIconDrawer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return evaluationEventImage;
    }

    public static void DrawEventIcon(Graphics2D g2d, ScriptEvent event,
            int x, int y)
    {
        DrawEventIcon(g2d, event.getScriptEventType(), x, y);
    }

    public static void DrawEventIcon(Graphics2D g2d, ScriptEventType eventType,
            int x, int y)
    {
        g2d.drawImage(getImage(eventType.IMAGE_NAME), x, y, null);
        /**
        switch(eventType)
        {
            case CHP_RADIO_EVENT:
                break;
            case PARAMICS_EVENT:
                g2d.drawImage(getParamicsEventImage(), x, y, null);
                break;
            case CAD_EVENT:
                g2d.drawImage(getCadEventImage(), x, y, null);
                break;
            case CAD_EVAL_EVENT:
                g2d.drawImage(getEvaluationEventImage(), x, y, null);
                break;
        }
        */
    }
}
