147 lines
3.4 KiB
Java
147 lines
3.4 KiB
Java
package de.wwwu.awolf.presenter;
|
|
|
|
import de.wwwu.awolf.model.LineModel;
|
|
import de.wwwu.awolf.model.communication.Data;
|
|
import de.wwwu.awolf.presenter.data.DataProvider;
|
|
import de.wwwu.awolf.presenter.evaluation.EvaluateAlgorithms;
|
|
import de.wwwu.awolf.presenter.util.IntersectionComputer;
|
|
import de.wwwu.awolf.presenter.util.Logging;
|
|
import de.wwwu.awolf.view.MainFrame;
|
|
|
|
import javax.swing.*;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Flow;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 10.09.2017.
|
|
*/
|
|
public abstract class AbstractPresenter implements Flow.Subscriber<Data> {
|
|
|
|
private final ExecutorService executor;
|
|
private LineModel model;
|
|
private MainFrame view;
|
|
private EvaluateAlgorithms eval;
|
|
private DataProvider dataProvider;
|
|
|
|
/**
|
|
* Konstruktor
|
|
*
|
|
* @param model Modell
|
|
* @param view View
|
|
*/
|
|
public AbstractPresenter(LineModel model, MainFrame view) {
|
|
this.model = model;
|
|
this.view = view;
|
|
executor = Executors.newCachedThreadPool();
|
|
dataProvider = new DataProvider(this);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSubscribe(Flow.Subscription subscription) {
|
|
Logging.logInfo("New Subscription: " + subscription.toString());
|
|
subscription.request(15);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onNext(Data data) {
|
|
switch (data.getType()) {
|
|
case EVALUATION_TABLE_DATA:
|
|
evaluatedDatas(data);
|
|
break;
|
|
case LMS:
|
|
visualizeLmsAlgorithm(data);
|
|
break;
|
|
case RM:
|
|
visualizeRmAlgorithm(data);
|
|
break;
|
|
case TS:
|
|
visualizeTsAlgorithm(data);
|
|
break;
|
|
case GENERATOR:
|
|
Logging.logInfo("Generierung war Erfolgreich");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
protected abstract void visualizeTsAlgorithm(Data data);
|
|
|
|
protected abstract void visualizeRmAlgorithm(Data data);
|
|
|
|
protected abstract void visualizeLmsAlgorithm(Data data);
|
|
|
|
protected abstract void evaluatedDatas(Data data);
|
|
|
|
@Override
|
|
public void onError(Throwable throwable) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
|
|
}
|
|
|
|
/**
|
|
* @return das zu grunde legende Modell
|
|
*/
|
|
public LineModel getModel() {
|
|
return model;
|
|
}
|
|
|
|
/**
|
|
* @param model das zu grunde legende Modell
|
|
*/
|
|
public void setModel(LineModel model) {
|
|
this.model = model;
|
|
}
|
|
|
|
/**
|
|
* @return die zu grunde legende View
|
|
*/
|
|
public MainFrame getView() {
|
|
return view;
|
|
}
|
|
|
|
/**
|
|
* @param view die zu grunde legende View
|
|
*/
|
|
public void setView(MainFrame view) {
|
|
this.view = view;
|
|
}
|
|
|
|
/**
|
|
* @return Evaluation
|
|
*/
|
|
public EvaluateAlgorithms getEval() {
|
|
return eval;
|
|
}
|
|
|
|
/**
|
|
* @param eval Evaluation
|
|
*/
|
|
public void setEval(EvaluateAlgorithms eval) {
|
|
this.eval = eval;
|
|
}
|
|
|
|
public DataProvider getDataProvider() {
|
|
return dataProvider;
|
|
}
|
|
|
|
|
|
public ExecutorService getExecutor() {
|
|
if (executor == null)
|
|
return Executors.newCachedThreadPool();
|
|
else
|
|
return executor;
|
|
}
|
|
}
|