Skip to content
App.java 2.75 KiB
Newer Older
xtof's avatar
xtof committed
package org.josast.UVSQsatDecoder;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
xtof's avatar
xtof committed
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
xtof's avatar
xtof committed
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
xtof's avatar
xtof committed

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

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

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

    @Override
    public void start(Stage stage) throws IOException {
        
        System.setProperty("glass.accessible.force", "false");
        scene = new Scene(loadFXML("UVSQsat"), 800, 600);
        stage.setScene(scene);
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                Platform.exit();
                System.exit(0);
            }
        });
xtof's avatar
xtof committed
        Controler ctrl = fxmlLoader.getController();
        ctrl.setPrimaryStage(stage);
        scene.getStylesheets().add(this.getClass().getResource("boot.css").toExternalForm());
        stage.setTitle("UVSQsat Decoder - "+ctrl.getversion());
        stage.getIcons().add(new Image(App.class.getResourceAsStream("OIP.jpg")));
xtof's avatar
xtof committed
        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"));
        logger.info("class "+App.class.getResource(fxml + ".fxml").getFile().toString());
xtof's avatar
xtof committed
        return fxmlLoader.load();
    }
xtof's avatar
xtof committed

    public static void main(String[] args) {
        // initialisation du systéme de log en premier 
        try {
            String path = System.getProperty("user.dir") + "/log";
            File apath = new File(path);

            if (!apath.exists()) {
                if (apath.mkdir() == false) {
                	logger.severe("fail to create " + path);
xtof's avatar
xtof committed
                }
            }
            FileHandler fh = new FileHandler(path + "/" + "UVSQsat.log");
            logger.setUseParentHandlers(false);
            Handler[] handlers = logger.getHandlers();
            for (Handler handler : handlers) {
                logger.removeHandler(handler);
            }
            logger.addHandler(fh);

        } catch (SecurityException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }
        launch();
    }

}