package ru.kirillius.cooler.controller.UI;

import ru.kirillius.cooler.controller.API.DataType;
import ru.kirillius.cooler.controller.API.MessageSystem;

import javax.swing.*;
import javax.swing.event.ChangeListener;

public class ReactiveSliderController extends ReactiveComponentController<JSlider> {
    private final ChangeListener listener;

    public ReactiveSliderController(DataType dataType, MessageSystem messageSystem, JSlider component, JLabel label, String units, float minValue, float maxValue, float multiplier) {
        super(dataType, messageSystem, component, label, units, minValue, maxValue, multiplier);
        listener = e -> updateSystem(component.getValue());
        component.addChangeListener(listener);
    }

    @Override
    protected void changeComponentValue(float value) {
        component.setValue((int) value);
    }

    @Override
    public void destroy() {
        component.removeChangeListener(listener);
    }
}
