MainApp.java 4.1 KB

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