package org.josast.ApplicationAmicalsat;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;



/**
 * JavaFX App
 */
public class App extends Application {

    private static Scene scene;
    private static FXMLLoader fxmlLoader;
    Logger logger = Logger.getLogger("EntrySatLogger");

    @Override
    public void start(Stage stage) throws IOException {
        try {
            String path = System.getProperty("user.dir")+"/log";
            File apath = new File(path);
            
            if (!apath.exists())
            {
                if (apath.mkdir() == false)
                {
                    System.err.println("fail to create "+ path);
                }
            }
            FileHandler fh=new FileHandler(path+"/"+"EntrySatLog.txt");

            logger.addHandler(fh);

            } catch (SecurityException e) {

            e.printStackTrace();

            } catch (IOException e) {

            e.printStackTrace();

            }
        System.setProperty("glass.accessible.force", "false");
        scene = new Scene(loadFXML("Amicalsat"), 640, 480);
        stage.setScene(scene);
        
        Controler ctrl = fxmlLoader.getController();
        ctrl.setPrimaryStage(stage);
        scene.getStylesheets().add("/BasicApplication.css");
    //    stage.setScene(scene);
        stage.setTitle("Amicalsat Decoder");
        ctrl.initMMI();
        stage.show();
    }

    static void setRoot(String fxml) throws IOException {
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
         fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        
        
        
        return fxmlLoader.load();
    }

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

}