package de.prob2.ui.internal;

import com.google.inject.Inject;
import com.google.inject.Injector;

import de.prob2.ui.menu.FileMenu;
import de.prob2.ui.prob2fx.CurrentTrace;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;

public final class NavigationButtons extends HBox {
	@FXML private Button backButton;
	@FXML private Button fastBackButton;
	@FXML private Button forwardButton;
	@FXML private Button fastForwardButton;
	@FXML private Button reloadButton;

	private final CurrentTrace currentTrace;
	private final Injector injector;

	@Inject
	private NavigationButtons(final StageManager stageManager, final CurrentTrace currentTrace, final Injector injector) {
		super();

		this.currentTrace = currentTrace;
		this.injector = injector;

		stageManager.loadFXML(this, "navigation_buttons.fxml");
	}

	@FXML
	private void initialize() {
		backButton.disableProperty().bind(currentTrace.canGoBackProperty().not());
		fastBackButton.disableProperty().bind(currentTrace.canGoBackProperty().not());
		forwardButton.disableProperty().bind(currentTrace.canGoForwardProperty().not());
		fastForwardButton.disableProperty().bind(currentTrace.canGoForwardProperty().not());
		reloadButton.disableProperty().bind(currentTrace.existsProperty().not());
	}

	@FXML
	private void handleBackButton() {
		if (currentTrace.exists()) {
			currentTrace.set(currentTrace.back());
		}
	}

	@FXML
	private void handleFastBackButton() {
		if (currentTrace.exists()) {
			while(currentTrace.canGoBack()) {
				currentTrace.set(currentTrace.back());
			}
		}
	}

	@FXML
	private void handleForwardButton() {
		if (currentTrace.exists()) {
			currentTrace.set(currentTrace.forward());
		}
	}

	@FXML
	private void handleFastForwardButton() {
		if (currentTrace.exists()) {
			while(currentTrace.canGoForward()) {
				currentTrace.set(currentTrace.forward());
			}
		}
	}

	@FXML
	private void handleReloadButton() {
		injector.getInstance(FileMenu.class).handleReloadMachine();
	}
}

@@ -1487,38 +1487,32 @@
 .exists()) %7B%0A%09%09%09
-while(
 currentTrace.can
@@ -1512,27 +1512,12 @@
 ace.
-canGoBack()) %7B%0A%09%09%09%09
+set(
 curr
@@ -1529,38 +1529,32 @@
 ace.
-set(currentTrace.back());%0A%09%09%09%7D
+get().gotoPosition(-1));
 %0A%09%09%7D
@@ -1774,14 +1774,8 @@
 %0A%09%09%09
-while(
 curr
@@ -1787,30 +1787,12 @@
 ace.
-canGoForward()) %7B%0A%09%09%09%09
+set(
 curr
@@ -1804,41 +1804,57 @@
 ace.
-set(currentTrace.forward());%0A%09%09%09%7D
+get().gotoPosition(currentTrace.get().size()-1));
 %0A%09%09%7D

Use gotoPosition instead of loop in fast back/forward implementation