39 lines
1.2 KiB
Java
39 lines
1.2 KiB
Java
package de.wwwu.awolf.view.services;
|
|
|
|
import de.wwwu.awolf.model.Line;
|
|
import de.wwwu.awolf.presenter.Presenter;
|
|
import de.wwwu.awolf.presenter.algorithms.Algorithm;
|
|
import javafx.beans.property.BooleanProperty;
|
|
import javafx.concurrent.Service;
|
|
import javafx.concurrent.Task;
|
|
|
|
public class ButtonClickService extends Service<Boolean> {
|
|
|
|
private final BooleanProperty startButtonDisabled;
|
|
private Algorithm.Type type;
|
|
|
|
public ButtonClickService(Algorithm.Type algorithmType, BooleanProperty startButtonDisabled) {
|
|
this.startButtonDisabled = startButtonDisabled;
|
|
this.type = algorithmType;
|
|
}
|
|
|
|
@Override
|
|
protected Task<Boolean> createTask() {
|
|
|
|
return new Task<Boolean>() {
|
|
@Override
|
|
protected Boolean call() throws Exception {
|
|
try {
|
|
Line line = Presenter.getInstance().executeAlgorithmByType(type, startButtonDisabled);
|
|
if (line != null) {
|
|
return true;
|
|
}
|
|
} catch (IllegalArgumentException e) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
}
|
|
}
|