Ejemplo n.º 1
0
  public StageLoader(String xmlPath, boolean isMainStageOwner) {
    try {
      FXMLLoader loader =
          new FXMLLoader(new File(Utils.getFullPath("./ui/" + xmlPath)).toURI().toURL());
      Parent root = loader.load();
      controller = loader.getController();

      Scene scene = new Scene(root);
      setScene(scene);

      if (isMainStageOwner) {
        initModality(Modality.NONE);
        initOwner(SingleObject.mainStage.getScene().getWindow());
      }

      getScene()
          .addEventHandler(
              KeyEvent.KEY_PRESSED,
              t -> {
                if (t.getCode() == KeyCode.ESCAPE) {
                  LogFiles.log.log(Level.INFO, "Exit " + getTitle());
                  ((Stage) ((Scene) t.getSource()).getWindow()).hide();
                } else if (t.getCode() == KeyCode.ENTER) {
                  runOnEnter(method);
                }
              });
    } catch (IOException e) {
      LogFiles.log.log(Level.SEVERE, e.getMessage(), e);
    }
  }
Ejemplo n.º 2
0
  @FXML
  public void btnOK() {
    LogFiles.log.log(Level.INFO, "Building stage");
    ((Stage) btnOK.getScene().getWindow()).close();
    SingleObject.ipAddress = txtAddress.getText();

    new SingleFromDB(new ClientPowerSys());
    if (!checkUser()) {
      LogFiles.log.log(Level.WARNING, "Autification error");
      System.exit(0);
    }
    LogFiles.log.log(Level.INFO, "Autification -> " + tUser.getText());

    MainStage stage = new MainStage("./ui/Main.xml");
    try {
      stage
          .getIcons()
          .add(
              new Image(
                  new File(Utils.getFullPath("./Icon/PowerSyS_ARM.png"))
                      .toURI()
                      .toURL()
                      .toString()));
    } catch (MalformedURLException e) {
      LogFiles.log.log(Level.SEVERE, "Application Icon set ...", e);
    }
    SingleObject.mainStage = stage;

    new Thread(new ReceiveTopic(SingleObject.ipAddress + ":7676"), "ReceiveTopic").start();
    new Thread(() -> new UpdateTimeOut(SingleFromDB.validTimeOutTI, 1), "UpdateTimeOut_TI").start();
    new Thread(() -> new UpdateTimeOut(SingleFromDB.validTimeOutTS, 2), "UpdateTimeOut_TS").start();

    stage.setOnCloseRequest(e -> Controller.exitProgram());

    while (SingleObject.mainScheme == null) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        LogFiles.log.log(Level.SEVERE, e.getMessage(), e);
      }
    }

    setStageParams(stage);

    SingleObject.hotkeys
        .values()
        .stream()
        .filter(f -> f.getCode().length() > 0)
        .forEach(
            h -> {
              MenuItem mi = SingleObject.getMenuItemById(null, h.getIdCode());
              KeyCodeCombination kk =
                  new KeyCodeCombination(
                      KeyCode.getKeyCode(h.getCode().toUpperCase()),
                      h.isShift()
                          ? KeyCombination.ModifierValue.DOWN
                          : KeyCombination.ModifierValue.UP,
                      h.isCtrl()
                          ? KeyCombination.ModifierValue.DOWN
                          : KeyCombination.ModifierValue.UP,
                      h.isAlt()
                          ? KeyCombination.ModifierValue.DOWN
                          : KeyCombination.ModifierValue.UP,
                      KeyCombination.ModifierValue.UP,
                      KeyCombination.ModifierValue.UP);
              if (mi != null) {
                mi.setAccelerator(kk);
                SingleObject.mainStage
                    .getScene()
                    .getAccelerators()
                    .put(kk, () -> mi.getOnAction().handle(null));

              } else {
                Button btn =
                    (Button)
                        MainStage.controller
                            .getToolBarController()
                            .getTbMain()
                            .getItems()
                            .filtered(f -> h.getIdCode().equals(f.getId()))
                            .get(0);
                SingleObject.mainStage
                    .getScene()
                    .getAccelerators()
                    .put(kk, () -> btn.getOnAction().handle(null));
              }
            });

    SingleObject.chat =
        new StageLoader(
            "Chat.xml", SingleObject.getResourceBundle().getString("keyChatTitle"), true);

    LogFiles.log.log(Level.INFO, "Show");
    stage.show();
  }