Exemplo n.º 1
0
 void stop(Runnable callback) {
   if (player != null) {
     new Tween(player.getVolume())
         .tweenToZero(
             0.06,
             10L,
             (curVolume) -> {
               player.setVolume(curVolume);
             },
             (zeroVolume) -> {
               isPlaying = false;
               try {
                 if (currentAudioIn != null) {
                   currentAudioIn.close();
                 }
                 player.stop();
                 callback.run();
               } catch (IOException | IllegalStateException | NullPointerException ex) {
                 log.log(Level.ERROR, null, ex);
               }
             });
   } else {
     callback.run();
   }
 }
Exemplo n.º 2
0
 private MenuItem menuItem(String title, Runnable r) {
   MenuItem mi = new MenuItem(title);
   mi.setOnAction(
       event -> {
         r.run();
       });
   return mi;
 }
Exemplo n.º 3
0
 void pause(Runnable callback) {
   if (player != null) {
     new Tween(player.getVolume())
         .tweenToZero(
             0.06,
             10L,
             (curVolume) -> {
               player.setVolume(curVolume);
             },
             (zeroVolume) -> {
               player.pause();
               callback.run();
             });
     isPlaying = false;
   } else {
     callback.run();
   }
 }
Exemplo n.º 4
0
 void resume(Runnable callback) {
   if (player != null) {
     player.setVolume(0d);
     player.play();
     new Tween(player.getVolume())
         .tweenToValue(
             Settings.currentVolume,
             0.06,
             10L,
             (currentVolume) -> {
               player.setVolume(currentVolume);
             },
             (valueVolume) -> {
               player.setVolume(valueVolume);
               callback.run();
             });
     isPlaying = true;
   } else {
     callback.run();
   }
 }
Exemplo n.º 5
0
  public AddDeviceWidget(@NotNull DeviceController deviceController, @NotNull ActorRef tmServer) {
    super(I.addDevice());
    this.tmServer = tmServer;
    this.deviceController = deviceController;
    ObservableList<DeviceTypeInfo> deviceTypes =
        FXCollections.observableArrayList(new ModelDeviceTypeInfo(), new MavlinkDeviceTypeInfo());
    Label typeLabel = new Label(I.deviceType());
    ComboBox<DeviceTypeInfo> deviceTypeComboBox = new ComboBox<>(deviceTypes);

    Group deviceTypeConfigPane = new Group();

    Runnable deviceTypeSelectAction =
        () -> {
          deviceTypeConfigPane.getChildren().clear();
          deviceTypeComboBox
              .getSelectionModel()
              .getSelectedItem()
              .getTypedConfigFormNode()
              .ifPresent((n) -> deviceTypeConfigPane.getChildren().add(n));
        };

    deviceTypeComboBox.setOnAction(e -> deviceTypeSelectAction.run());
    deviceTypeComboBox.getSelectionModel().selectFirst();
    deviceTypeSelectAction.run();

    Button addButton = new Button(I.add());
    addButton.setOnAction(
        (e) ->
            deviceController
                .getDeviceRegistry()
                .getDevices()
                .addAll(deviceTypeComboBox.getSelectionModel().getSelectedItem().newDevice()));
    VBox box = new VBox(typeLabel, deviceTypeComboBox, deviceTypeConfigPane, addButton);
    box.setAlignment(Pos.CENTER_LEFT);
    box.setSpacing(5);
    setContent(box);
  }
Exemplo n.º 6
0
  public void addTab(Path path, Runnable... runnables) {

    ObservableList<String> recentFiles = controller.getRecentFilesList();
    if (Files.notExists(path)) {
      recentFiles.remove(path.toString());
      return;
    }

    ObservableList<Tab> tabs = controller.getTabPane().getTabs();
    for (Tab tab : tabs) {
      MyTab myTab = (MyTab) tab;
      Path currentPath = myTab.getPath();
      if (Objects.nonNull(currentPath))
        if (currentPath.equals(path)) {
          myTab.select(); // Select already added tab
          return;
        }
    }

    AnchorPane anchorPane = new AnchorPane();
    EditorPane editorPane = webviewService.createWebView();

    MyTab tab = createTab();
    tab.setEditorPane(editorPane);
    tab.setTabText(path.getFileName().toString());

    editorPane.confirmHandler(
        param -> {
          if ("command:ready".equals(param)) {
            JSObject window = editorPane.getWindow();
            window.setMember("afx", controller);
            window.call("updateOptions", new Object[] {});
            Map<String, String> shortCuts = controller.getShortCuts();
            Set<String> keySet = shortCuts.keySet();
            for (String key : keySet) {
              window.call("addNewCommand", new Object[] {key, shortCuts.get(key)});
            }
            if (Objects.isNull(path)) return true;
            threadService.runTaskLater(
                () -> {
                  String content = IOHelper.readFile(path);
                  threadService.runActionLater(
                      () -> {
                        window.call("changeEditorMode", path.toUri().toString());
                        window.call("setInitialized");
                        window.call("setEditorValue", new Object[] {content});
                        for (Runnable runnable : runnables) {
                          runnable.run();
                        }
                      });
                });
          }
          return false;
        });

    threadService.runActionLater(
        () -> {
          TabPane tabPane = controller.getTabPane();
          tabPane.getTabs().add(tab);
          tab.select();
        });

    Node editorVBox = editorService.createEditorVBox(editorPane, tab);
    controller.fitToParent(editorVBox);

    anchorPane.getChildren().add(editorVBox);
    tab.setContent(anchorPane);
    tab.setPath(path);

    Tooltip tip = new Tooltip(path.toString());
    Tooltip.install(tab.getGraphic(), tip);

    recentFiles.remove(path.toString());
    recentFiles.add(0, path.toString());

    editorPane.focus();
  }