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

/**
 * GalleryWListener
 */
public class ConfirmationListener implements WindowListener, MouseListener {

    @Override
    public void windowActivated(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void windowClosed(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void windowClosing(WindowEvent e) {
        JFrame window = (JFrame)e.getSource();
        JDialog d = new JDialog(window, true);
        DialogListener dl = new DialogListener(d);
        
        d.setTitle("aRE U SUR");
        d.setSize(300, 200);
        d.setLocation(500, 500);
        d.setLayout(new GridLayout(1, 2));
        JButton yesBT = new JButton("Oui");
        yesBT.setName("Oui");
        yesBT.addMouseListener(dl);
        JButton noBT = new JButton("Non");
        noBT.setName("Non");
        noBT.addMouseListener(dl);

        d.add(yesBT);
        d.add(noBT);
        d.setVisible(true);

        if (dl.getShouldClose()) {
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        } else {
            window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        }
    }

    @Override
    public void windowDeactivated(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void windowDeiconified(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void windowIconified(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void windowOpened(WindowEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void mousePressed(MouseEvent e) {
        JLabel source = (JLabel)e.getSource();
        int x = e.getX();

        if (x > source.getWidth() / 2) {
            Confirmation.next();
        } else {
            Confirmation.previous();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub
        
    }
    
}