package cz.kamma.llamarunner;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/**
 * DocumentListener that updates command preview on text changes.
 */
public class PreviewUpdateListener implements DocumentListener {

    private final Runnable updateCallback;

    public PreviewUpdateListener(Runnable updateCallback) {
        this.updateCallback = updateCallback;
    }

    @Override
    public void insertUpdate(DocumentEvent e) {
        updateCallback.run();
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        updateCallback.run();
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        updateCallback.run();
    }
}
