package ac.ooechs.oil;

import ac.essex.ooechs.imaging.commons.util.panels.ImagePanel;
import ac.essex.ooechs.imaging.commons.util.LineEquation;
import ac.essex.ooechs.imaging.commons.ImageWindow;
import ac.essex.ooechs.imaging.commons.edge.hough.HoughLine;

import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;
import java.awt.*;
import java.util.Vector;

/**
 * <p/>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 * @author Olly Oechsle, University of Essex, Date: 23-Jun-2008
 * @version 1.0
 */
public class ImagePanelWindow extends ImagePanel {

    protected Vector<HoughLine> lines;
    protected ImageWindow window;
    protected boolean showRectangle;

    public ImagePanelWindow(boolean showRectangle) {

        this.showRectangle = showRectangle;

        addMouseMotionListener(new MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                window = new ImageWindow(e.getX(), e.getY(), 50, 50);
                onNewWindow(e.getX(), e.getY());
                repaint();
            }

        });

    }

    public void onNewWindow(int mouseX, int mouseY) {
        // do nothing
    }

    public void paintComponent(Graphics graphics) {
        super.paintComponent(graphics);
        if (showRectangle) {
            if (window != null)  {
                graphics.setColor(Color.WHITE);
                graphics.drawRect(window.left, window.top, window.width, window.height);
            }
        }
        if (lines != null) {
            graphics.setColor(Color.RED);
            for (int i = 0; i < lines.size(); i++) {
                HoughLine houghLine = lines.elementAt(i);
                houghLine.draw(getImage(), graphics);
            }
        }
    }

}
