PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/ch/hslu/mobsys/manet/Main.java

https://gitlab.com/simon-erni/mobsys-manet
Java | 99 lines | 54 code | 21 blank | 24 comment | 0 complexity | 24919677363fc986c1c1a7510ae83a7e MD5 | raw file
  1. package ch.hslu.mobsys.manet;
  2. import ch.hslu.mobsys.manet.protocol.ClientConfiguration;
  3. import ch.hslu.mobsys.manet.protocol.SendService;
  4. import com.google.common.util.concurrent.ServiceManager;
  5. import com.google.inject.Injector;
  6. import javafx.application.Application;
  7. import javafx.fxml.FXMLLoader;
  8. import javafx.scene.Scene;
  9. import javafx.scene.layout.VBox;
  10. import javafx.stage.Stage;
  11. import javafx.util.Callback;
  12. import java.io.IOException;
  13. import static com.google.inject.Guice.createInjector;
  14. public class Main extends Application {
  15. private Stage primaryStage;
  16. private VBox rootLayout;
  17. private static Injector injector;
  18. public static void main(String[] args) throws Exception {
  19. Injector injector = createInjector(new ManetModule());
  20. Main.injector = injector;
  21. ServiceManager manager = injector.getInstance(ServiceManager.class);
  22. manager.startAsync().awaitHealthy();
  23. SendService sendService = injector.getInstance(SendService.class);
  24. ClientConfiguration clientConfiguration = injector.getInstance(ClientConfiguration.class);
  25. clientConfiguration.setIdentifier((int) (Math.random() * 100) + "");
  26. launch(args);
  27. }
  28. /**
  29. * Initializes the root layout.
  30. */
  31. public void initRootLayout() {
  32. try {
  33. // Load root layout from fxml file.
  34. FXMLLoader loader = new FXMLLoader();
  35. loader.setControllerFactory(new Callback<Class<?>, Object>() {
  36. public Object call(Class<?> type) {
  37. return injector.getInstance(type);
  38. }
  39. });
  40. loader.setLocation(Main.class.getClassLoader().getResource("controller.fxml"));
  41. rootLayout = loader.load();
  42. // Show the scene containing the root layout.
  43. Scene scene = new Scene(rootLayout);
  44. primaryStage.setScene(scene);
  45. primaryStage.show();
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. /**
  51. * Returns the main stage.
  52. * @return
  53. */
  54. public Stage getPrimaryStage() {
  55. return primaryStage;
  56. }
  57. /**
  58. * The main entry point for all JavaFX applications.
  59. * The start method is called after the init method has returned,
  60. * and after the system is ready for the application to begin running.
  61. * <p/>
  62. * <p>
  63. * NOTE: This method is called on the JavaFX Application Thread.
  64. * </p>
  65. *
  66. * @param primaryStage the primary stage for this application, onto which
  67. * the application scene can be set. The primary stage will be embedded in
  68. * the browser if the application was launched as an applet.
  69. * Applications may create other stages, if needed, but they will not be
  70. * primary stages and will not be embedded in the browser.
  71. */
  72. @Override
  73. public void start(Stage primaryStage) throws Exception {
  74. this.primaryStage = primaryStage;
  75. this.primaryStage.setTitle("MANET Controller");
  76. initRootLayout();
  77. }
  78. }