package org.sunflow.system;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.event.MouseInputAdapter;

import org.sunflow.core.Display;
import org.sunflow.image.Color;

@SuppressWarnings("serial")
public class ImagePanel extends JPanel implements Display {
    private static final int[] BORDERS = { Color.RED.toRGB(),
            Color.GREEN.toRGB(), Color.BLUE.toRGB(), Color.YELLOW.toRGB(),
            Color.CYAN.toRGB(), Color.MAGENTA.toRGB() };
    private BufferedImage image;
    private float xo, yo;
    private float w, h;
    private long repaintCounter;

    private class ScrollZoomListener extends MouseInputAdapter {
        int mx;
        int my;
        boolean dragging;
        boolean zooming;

        @Override
        public void mousePressed(MouseEvent e) {
            mx = e.getX();
            my = e.getY();
            switch (e.getButton()) {
                case MouseEvent.BUTTON1:
                    dragging = true;
                    zooming = false;
                    break;
                case MouseEvent.BUTTON2: {
                    dragging = zooming = false;
                    // if CTRL is pressed
                    if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK)
                        fit();
                    else
                        reset();
                    break;
                }
                case MouseEvent.BUTTON3:
                    zooming = true;
                    dragging = false;
                    break;
                default:
                    return;
            }
            repaint();
        }

}
