You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB

  1. package com.sothr.imagetools.ui;
  2. import com.sothr.imagetools.engine.AppConfig;
  3. import com.sothr.imagetools.engine.errors.ImageToolsException;
  4. import com.sothr.imagetools.engine.util.ResourceLoader;
  5. import javafx.application.Application;
  6. import javafx.fxml.FXMLLoader;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.stage.Stage;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import java.io.IOException;
  13. import java.util.List;
  14. /**
  15. * Image Tools
  16. */
  17. public class App extends Application
  18. {
  19. private static Logger logger;
  20. private static final String MAINGUI_FXML = "fxml/mainapp/MainApp.fxml";
  21. public static void main( String[] args )
  22. {
  23. AppConfig.configureApp();
  24. try {
  25. //try to run the UI
  26. launch(args);
  27. } catch (Exception ex) {
  28. logger.error("A fatal error has occurred: ", ex);
  29. //show popup about the error to the user then exit
  30. }
  31. }
  32. @Override
  33. public void init() throws Exception{
  34. AppConfig.configureApp();
  35. logger = LoggerFactory.getLogger(this.getClass());
  36. logger.info("Initializing Image Tools");
  37. List<String> parameters = this.getParameters().getRaw();
  38. logger.info(String.format("Application was called with '%s' parameters", parameters.toString()));
  39. super.init();
  40. }
  41. @Override
  42. public void start(Stage primaryStage) throws Exception {
  43. logger.info("Image-Tools is starting");
  44. logger.info(String.format("Launching GUI with FXML file %s", MAINGUI_FXML));
  45. //store the primary stage globally for reference in popups and the like
  46. AppConfig.setPrimaryStage(primaryStage);
  47. try {
  48. Parent root = FXMLLoader.load(ResourceLoader.get().getResource(MAINGUI_FXML));
  49. primaryStage.setScene(new Scene(root));
  50. //config main scene
  51. primaryStage.setTitle("Image Tools");
  52. primaryStage.setMinHeight(600.0);
  53. primaryStage.setMinWidth(800.0);
  54. primaryStage.setResizable(true);
  55. //show main scene
  56. primaryStage.show();
  57. } catch (IOException ioe) {
  58. String message = String.format("Unable to load FXML file: %s", MAINGUI_FXML);
  59. ImageToolsException ite = new ImageToolsException(message, ioe);
  60. logger.error(message, ioe);
  61. throw ite;
  62. } catch (Exception ex) {
  63. String message = "An unhandled exception was thrown by the GUI";
  64. ImageToolsException ite = new ImageToolsException(message, ex);
  65. logger.error(message, ex);
  66. throw ite;
  67. }
  68. }
  69. @Override
  70. public void stop() throws Exception {
  71. logger.info("Image-Tools is shutting down");
  72. AppConfig.shutdown();
  73. super.stop();
  74. //force the JVM to close
  75. System.exit(0);
  76. }
  77. }