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.

81 lines
2.6 KiB

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