package de.wwwu.awolf;

import de.wwwu.awolf.presenter.Presenter;
import de.wwwu.awolf.presenter.util.Logging;
import de.wwwu.awolf.view.ViewController;
import de.wwwu.awolf.view.services.GuiRegisterService;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
 *
 * @Author: Armin Wolf
 * @Email: a_wolf28@uni-muenster.de
 * @Date: 28.05.2017.
 */
public class App extends Application {

    private final String TITLE = "Algorithmen zur Berechnung von Ausgleichsgeraden";

    /**
     * Maim Methode
     *
     * @param argv
     */
    public static void main(String[] argv) {
        //create instances
        final Presenter presenter = Presenter.getInstance();

        Logging.logDebug("Presenter initialized!");
        //start gui
        Platform.setImplicitExit(false);
        Logging.logDebug("Start ....");

        Application.launch(App.class, argv);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Platform.runLater(() -> {

            try {
                FXMLLoader fxmlLoader = new FXMLLoader(ViewController.class.getResource("/views/MainFrame.fxml"));
                Parent pane = fxmlLoader.load();
                //register at presenter
                new GuiRegisterService(fxmlLoader.getController()).start();
                primaryStage.setTitle(TITLE);
                Scene scene = new Scene(pane, 1000, 800);
                scene.getStylesheets().add(ViewController.class.getResource("/style/console.css").toExternalForm());
                primaryStage.setScene(scene);
                primaryStage.show();
            } catch (IOException e) {
                Logging.logError("Error reading FXML file. ", e);
            }
        });
    }
}
