package fr.iutfbleau.projetAgile.Puissance4.Controller;

import javax.swing.JComponent;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import fr.iutfbleau.projetAgile.Puissance4.Utils.Constants;

/**
 * Classe inutile, peut être remplacée par l'appuie sur le bouton confirmé (A changer Jeudi)
 */
public class ColorChooserListener implements ChangeListener {

    private JComponent composant;
    private int player;

    public ColorChooserListener(JComponent c, int player) {
        this.composant = c;
        this.player = player;
    }

    @Override
    public void stateChanged(ChangeEvent e) {
        if(e.getSource() instanceof ColorSelectionModel) {
            ColorSelectionModel chooser = (ColorSelectionModel) e.getSource();
            if(this.player == Constants.PLAYER_ONE)
                Constants.PLAYER_ONE_COLOR = chooser.getSelectedColor();
            else if(this.player == Constants.PLAYER_TWO)
                Constants.PLAYER_TWO_COLOR = chooser.getSelectedColor();
            else
                Constants.PLAYER_THREE_COLOR = chooser.getSelectedColor();
            composant.repaint();
        }
    }
}
