package galerie.control;

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

/**
 * Rôle unique : convertir un clic gauche/droite (moitié de composant)
 * en action "next" ou "previous".
 */
public class HalfClickNavigator extends MouseAdapter {
    private final JComponent surface;
    private final Runnable onNext;
    private final Runnable onPrevious;

    public HalfClickNavigator(JComponent surface, Runnable onNext, Runnable onPrevious) {
        this.surface = surface;
        this.onNext = onNext;
        this.onPrevious = onPrevious;
    }

    @Override public void mouseClicked(MouseEvent e) {
        int w = surface.getWidth();
        if (e.getX() >= w / 2) onNext.run();
        else onPrevious.run();
    }
}
