Пример #1
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();
  }