package galerie.view;

import galerie.model.ImageList;
import galerie.control.HalfClickNavigator;

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

public class GalleryCardLayoutFrame extends JFrame {
    private final CardLayout cards = new CardLayout();
    private final JPanel deck = new JPanel(cards);

    public GalleryCardLayoutFrame(ImageList images) {
        super("Galerie — CardLayout");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(800, 600);
        setLocationRelativeTo(null);

        for (int i = 0; i < images.size(); i++) {
            JLabel lab = new JLabel(images.iconAt(i), SwingConstants.CENTER);
            lab.setVerticalAlignment(SwingConstants.CENTER);
            deck.add(lab, "card" + i);
        }
        deck.addMouseListener(new HalfClickNavigator(deck,
                () -> cards.next(deck),
                () -> cards.previous(deck)));

        setContentPane(deck);
    }
}
