package org.cemte.jacek.mpo;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.awt.image.MemoryImageSource;

import javax.swing.JPanel;

public class ImagePanel extends Panel{
	
	public boolean drawState = false;
	public boolean drawState2 = false;
	public ImageOps iOps;
	
	public ImagePanel(){
		iOps=new ImageOps();
		setLayout(new BorderLayout());
		//setSize(1024,768);
		this.setBackground(Color.black);
		//setOpaque(false);
	}//ImagePanel()
	

	public void createAndDrawImage(){
		iOps.setImage(new ImageFactory().getImage(400,400));
		iOps.img2bi();
		repaint();
	}//createAndDrawImage()
	
			
	public void paint (Graphics g) { 
	       Insets insets = getInsets(); 
	       g.translate (insets.left, insets.top);
	       Graphics2D g2d = (Graphics2D) g;
	       g2d.clearRect(0,0,1200,800);
	       setBackground(Color.black);
	       Point center=getCenterScale();
	       g2d.drawImage(iOps.getBImage(),null,center.x,center.y);
	       
	 }//paint() 
	
	public Point getCenterScale(){
		Dimension frameSize = getSize();
                int lokX=(frameSize.width - iOps.width) / 2;
                int lokY=(frameSize.height - iOps.height) / 2;
                return new Point(lokX,lokY); 
	}//getCenterScale
	
}//class ImagePanel

