MainApp.java 3.9 KB

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