Esempio n. 1
0
  private void initialiseEditConnectionsWindow() {
    // This is a dirty way to reload connection settings :) possibly could be removed if all
    // connections are closed before loading a new config file
    if (editConnectionsController != null) {
      eventManager.deregisterConnectionStatusObserver(editConnectionsController);
    }

    final FXMLLoader loader =
        FxmlUtils.createFxmlLoaderForProjectFile("EditConnectionsWindow.fxml");
    final AnchorPane connectionWindow = FxmlUtils.loadAnchorPane(loader);
    editConnectionsController = ((EditConnectionsController) loader.getController());
    editConnectionsController.setMainController(this);
    editConnectionsController.setEventManager(eventManager);
    editConnectionsController.setConnectionManager(connectionManager);
    editConnectionsController.setConfigurationManager(configurationManager);
    editConnectionsController.init();

    Scene scene = new Scene(connectionWindow);
    scene.getStylesheets().addAll(mainPane.getScene().getStylesheets());

    editConnectionsStage = new Stage();
    editConnectionsStage.setTitle("Connection list");
    editConnectionsStage.initModality(Modality.WINDOW_MODAL);
    editConnectionsStage.initOwner(getParentWindow());
    editConnectionsStage.setScene(scene);
  }
Esempio n. 2
0
  private void initialiseConverterWindow() {
    final FXMLLoader loader = FxmlUtils.createFxmlLoaderForProjectFile("ConverterWindow.fxml");
    final AnchorPane converterWindow = FxmlUtils.loadAnchorPane(loader);

    Scene scene = new Scene(converterWindow);
    scene.getStylesheets().addAll(mainPane.getScene().getStylesheets());

    converterStage = new Stage();
    converterStage.setTitle("Converter");
    converterStage.initOwner(getParentWindow());
    converterStage.setScene(scene);
  }
Esempio n. 3
0
  @Override
  /** Starts the application. */
  public void start(final Stage primaryStage) {
    final EventManager eventManager = new EventManager();
    final IdGenerator connectionIdGenerator = new IdGenerator();

    try {
      final ConfigurationManager configurationManager =
          new ConfigurationManager(eventManager, connectionIdGenerator);

      // Load the main window
      FxmlUtils.setParentClass(getClass());
      final FXMLLoader loader = FxmlUtils.createFxmlLoaderForProjectFile("MainWindow.fxml");

      // Get the associated pane
      AnchorPane pane = (AnchorPane) loader.load();

      final Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

      // Set scene width, height and style
      final double height =
          Math.min(
              UiProperties.getApplicationHeight(configurationManager),
              primaryScreenBounds.getHeight());
      final double width =
          Math.min(
              UiProperties.getApplicationWidth(configurationManager),
              primaryScreenBounds.getWidth());

      final Scene scene = new Scene(pane, width, height);
      scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

      // Get the associated controller
      final MainController mainController = (MainController) loader.getController();
      mainController.setEventManager(eventManager);
      mainController.setConfigurationManager(configurationManager);
      mainController.setSelectedPerspective(
          UiProperties.getApplicationPerspective(configurationManager));
      mainController
          .getResizeMessagePaneMenu()
          .setSelected(UiProperties.getResizeMessagePane(configurationManager));

      // Set the stage's properties
      primaryStage.setScene(scene);
      primaryStage.setMaximized(UiProperties.getApplicationMaximized(configurationManager));

      // Initialise resources in the main controller
      mainController.setApplication(this);
      mainController.setStage(primaryStage);
      mainController.setLastHeight(height);
      mainController.setLastWidth(width);
      mainController.init();
      final Image applicationIcon =
          new Image(getClass().getResourceAsStream("/images/mqtt-spy-logo.png"));
      primaryStage.getIcons().add(applicationIcon);

      // Show the main window
      primaryStage.show();

      // Load the config file if specified
      final String noConfig = this.getParameters().getNamed().get(NO_CONFIGURATION_PARAMETER_NAME);
      final String configurationFileLocation =
          this.getParameters().getNamed().get(CONFIGURATION_PARAMETER_NAME);

      if (noConfig != null) {
        // Do nothing - no config wanted
      } else if (configurationFileLocation != null) {
        mainController.loadConfigurationFileAndShowErrorWhenApplicable(
            new File(configurationFileLocation));
      } else {
        // If no configuration parameter is specified, use the user's home directory and the default
        // configuration file name
        mainController.loadDefaultConfigurationFile();
      }
    } catch (Exception e) {
      LoggerFactory.getLogger(Main.class).error("Error while loading the main window", e);
    }
  }