MainApp.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package de.tu_darmstadt.informatik.tk.scopviz.main;
  2. import java.io.IOException;
  3. import java.net.URL;
  4. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  5. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyEdge;
  6. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyNode;
  7. import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLExporter;
  8. import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
  9. import de.tu_darmstadt.informatik.tk.scopviz.ui.css.CSSManager;
  10. import javafx.application.Application;
  11. import javafx.event.EventHandler;
  12. import javafx.fxml.FXMLLoader;
  13. import javafx.scene.Scene;
  14. import javafx.scene.layout.VBox;
  15. import javafx.stage.Stage;
  16. import javafx.stage.WindowEvent;
  17. /**
  18. * Main UI Class, loads GUI from FXML file and initializes all UI Elements.
  19. *
  20. * @author Jan Enders (jan.enders@stud.tu-darmstadt.de)
  21. * @version 1.2
  22. *
  23. */
  24. public class MainApp extends Application {
  25. private static final boolean exportOnClose = false;
  26. /**
  27. * Primary Stage for the UI Scene.
  28. */
  29. private Stage primaryStage;
  30. /**
  31. * Root Object of the Scene Graph.
  32. */
  33. private VBox rootLayout;
  34. /**
  35. * Main Method, launches the Application.
  36. *
  37. * @param args
  38. * Optional String arguments (command line flags), none
  39. * implemented
  40. */
  41. public static void main(final String[] args) {
  42. System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
  43. launch(args);
  44. }
  45. /**
  46. * Initializes the Main Class by invoking getInstance() for the first time.
  47. */
  48. @Override
  49. public void init() {
  50. Main.getInstance();
  51. }
  52. /**
  53. * Starts the Application by initializing the UI Layout.
  54. *
  55. * @param stage
  56. * the Stage of the Application Window
  57. */
  58. @Override
  59. public void start(final Stage stage) {
  60. this.primaryStage = stage;
  61. Main.getInstance().setPrimaryStage(this.primaryStage);
  62. initRootLayout();
  63. if (Debug.DEBUG_ENABLED) {
  64. GraphDisplayManager.setCurrentLayer(Layer.OPERATOR);
  65. GraphDisplayManager.addGraph(Debug.getDefaultOperatorGraph(), true);
  66. GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
  67. GraphDisplayManager.addGraph(Debug.getDefaultUnderlayGraph(), true);
  68. }
  69. CSSManager.addRule("node{text-alignment: at-right; size: 15px;}");
  70. }
  71. /**
  72. * Initializes the UI Layout by loading it from a FXML file. Implicitly
  73. * calls GUIController.initialize through the FXML loading process.
  74. */
  75. public void initRootLayout() {
  76. // Load root layout from fxml file.
  77. try {
  78. FXMLLoader loader = new FXMLLoader();
  79. URL test = MainApp.class.getResource("/de/tu_darmstadt/informatik/tk/scopviz/main/MainWindow.fxml");
  80. loader.setLocation(test);
  81. rootLayout = (VBox) loader.load();
  82. } catch (IOException e) {
  83. System.err.println("FXML File could not be loaded. Could the Path be incorrect?");
  84. e.printStackTrace();
  85. }
  86. // Make the full program exit on clicking the close button
  87. primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
  88. @Override
  89. public void handle(WindowEvent event) {
  90. if (exportOnClose) {
  91. GraphMLExporter exporter = new GraphMLExporter();
  92. exporter.writeGraph(Main.getInstance().getGraphManager().getGraph(), "shutdown.graphml", false);
  93. }
  94. System.exit(0);
  95. }
  96. });
  97. // Show the scene containing the root layout.
  98. Scene scene = new Scene(rootLayout);
  99. scene.getStylesheets().add(
  100. MainApp.class.getResource("/de/tu_darmstadt/informatik/tk/scopviz/main/GUITheme.css").toExternalForm());
  101. primaryStage.setMinHeight(400);
  102. primaryStage.setMinWidth(640);
  103. primaryStage.setScene(scene);
  104. primaryStage.show();
  105. }
  106. }