package view.listener;

import presenter.Presenter;
import view.panels.tabs.LMSPanel;
import view.panels.tabs.RMPanel;
import view.panels.tabs.TSPanel;
import view.panels.tabs.TabPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
 *
 * @Author: Armin Wolf
 * @Email: a_wolf28@uni-muenster.de
 * @Date: 10.09.2017.
 */
public class StartAlgorithmListener implements ActionListener {

    private Presenter presenter;
    private TabPanel tabPanel;

    public StartAlgorithmListener(Presenter presenter, TabPanel tabPanel) {
        this.presenter = presenter;
        this.tabPanel = tabPanel;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (tabPanel instanceof LMSPanel){
            if ( ((LMSPanel) tabPanel).getInput() != null) {
                Thread t = new Thread(
                        () -> presenter.calculateLMS(((LMSPanel) tabPanel).getInput()));
                t.start();
            }
        } else if (tabPanel instanceof RMPanel){
            if ( ((RMPanel) tabPanel).getInput() != null) {
                Thread t = new Thread(
                        () -> presenter.calculateRM(((RMPanel) tabPanel).getInput()));
                t.start();
            }
        } else if(tabPanel instanceof TSPanel){
            Thread t = new Thread(
                    () -> presenter.calculateTS(""));
            t.start();
        } else {
            throw new IllegalArgumentException("Unknown Algortihm representation Panel!");
        }

    }
}
