package galerie.app;

import galerie.model.ImageList;
import galerie.view.GalleryCardLayoutFrame;
import galerie.view.ConfirmOnCloseDialog;

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

public class MainWithConfirmation {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            ImageList model = new ImageList("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
            JFrame frame = new GalleryCardLayoutFrame(model);

            frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
            frame.addWindowListener(new WindowAdapter() {
                @Override public void windowClosing(WindowEvent e) {
                    ConfirmOnCloseDialog dlg = new ConfirmOnCloseDialog(frame,
                            new ConfirmOnCloseDialog.ResultHandler() {
                                @Override public void onYes() { System.exit(0); }
                                @Override public void onNo()  { }
                            });
                    dlg.setVisible(true);
                }
            });

            frame.setVisible(true);
        });
    }
}
