import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class GestionSouris implements MouseListener {

	private Fenetre fenetre;
	private JPanel rect;
	private int debutX;
	private int debutY;
	private int finX;
	private int finY;
	private boolean rectActif;

	public GestionSouris(Fenetre fenetre) {
		this.fenetre = fenetre;
		this.rectActif = false;
	}


	public void mouseClicked(MouseEvent evenement) {
	}        
	
	public void mouseEntered(MouseEvent evenement){
	}         

	public void mouseExited(MouseEvent evenement){
	} 

	public void mousePressed(MouseEvent evenement){
		if (this.rectActif) {
			this.fenetre.remove(this.rect);
		}
		System.out.println("Appui simple");
		this.rect = new JPanel();
		this.rect.setOpaque(true);
		this.rect.setBackground(Color.BLUE);
		this.debutX = evenement.getX()-4; // Le -4 est du à un décalage de la méthode getX jsp pourquoi sah
		this.debutY = evenement.getY()-26;	// Pareil pour le -26
		this.fenetre.add(this.rect);
		this.fenetre.repaint();
	}
 
	public void mouseReleased(MouseEvent evenement){
		this.rectActif = true;
	} 

	public void setRect(int finX, int finY) {
		System.out.println(this.debutX + "  " + this.debutY + "  " + (finX-this.debutX+5) + "  " + (finY-this.debutY-10) + "");
		this.rect.setBounds(this.debutX, this.debutY, finX-this.debutX-4, finY-this.debutY-26); // Décalage encore
		//System.out.println("debut : [" + this.debutX + ", " + this.debutY + "]");
		//System.out.println("fin : [" + finX + ", " + finY + "]");
		this.fenetre.repaint();
	}
}