package net.sf.anpr.rcp.widget;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

public class JCanvasPanel extends JLabel {
	private static final long serialVersionUID = 1L;
	private Rectangle focusArea=new Rectangle();
	private BufferedImage image;
	
	public JCanvasPanel() {
		super();
		this.setVerticalAlignment(SwingConstants.TOP);
		this.setHorizontalAlignment(SwingConstants.LEFT);
	}
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		if(focusArea==null) return ;
		if (focusArea.width >= 0 && focusArea.height >= 0) {
			Color c = g.getColor();
			g.setColor(Color.RED);
			g.drawRect(focusArea.x, focusArea.y, focusArea.width, focusArea.height);
			g.setColor(c);
		}
		g.dispose();
	}
	protected void setImage(BufferedImage image){
		this.image=image;
		this.setIcon(new ImageIcon(image));
	}
	
	public void setFocusArea(Rectangle focusArea) {
		this.focusArea = focusArea;
	}
	protected BufferedImage getImage() {
		return image;
	}
}
