package project;

import java.io.IOException;

import org.opencv.core.Core;

import Objects.DetectionAPP;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class Main extends Application {
	static {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
			}

	Detect detect = new Detect();
	Controller jedna = null;
	DetectionAPP app = new DetectionAPP();

	@Override
	public void start(Stage primaryStage) {

		Parent root = null;
		// Controller jedna = null;

		try {
			// root = FXMLLoader.load(getClass().getResource("GUI.fxml"));
			FXMLLoader loader = new FXMLLoader(getClass().getResource("GUI.fxml"));
			root = (Parent) loader.load();
			jedna = loader.getController();

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// Canvas canvas = new Canvas();
		// GraphicsContext gc = canvas.getGraphicsContext2D();

		Scene scene = new Scene(root);
		primaryStage.setScene(scene);
		primaryStage.show();
		app.controller = jedna;
		/*
		 * detect.controller= jedna; detect.detection();
		 */

		MyTask task = new MyTask();
		task.controller = jedna;
		new Thread(task).start();
		
		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent t) {
                Platform.exit();
                System.exit(0);
            }
				});
		

	}

	public static void main(String[] args) {
		launch(args);

	}

}
