コード例 #1
0
  private void initializeAssignmentListViewAndFilters() {
    final ListBinding<PersonnelAssignment> filteredAssignementBinding =
        new ListBinding<PersonnelAssignment>() {
          final ObjectBinding<ObservableList<PersonnelAssignment>> internalBinding =
              Bindings.select(
                  assignmentsFilterComboBox.getSelectionModel().selectedItemProperty(),
                  "assignments");

          {
            bind(internalBinding);
          }

          @Override
          protected ObservableList<PersonnelAssignment> computeValue() {
            return internalBinding.get();
          }

          @Override
          public Spliterator<PersonnelAssignment> spliterator() {
            return super.spliterator();
          }
        };

    assigmentsListView.itemsProperty().bind(filteredAssignementBinding);
    assigmentsListView.setCellFactory(
        new PropertyListCellFactory<PersonnelAssignment>("name", null));

    assignmentsFilterComboBox.getItems().clear();
    assignmentsFilterComboBox.getItems().addAll(assignementFilters);
    assignmentsFilterComboBox.setCellFactory(
        new PropertyListCellFactory<AssignementFilter>("name", null));
    assignmentsFilterComboBox.setButtonCell(
        new ListCell<AssignementFilter>() {
          @Override
          protected void updateItem(AssignementFilter item, boolean empty) {
            super.updateItem(item, empty);
            if (textProperty().isBound()) {
              textProperty().unbind();
            }
            if (item != null || !empty) {
              textProperty().bind(item.nameProperty());
            }
          }
        });
  }
コード例 #2
0
  public void connectMyo() {
    try {

      LOGGER.info("Connecting to Myo");
      updateMyoStatus("Attempting to find a Myo...");
      Myo myo = hub.waitForMyo(10000);

      if (myo == null) {
        LOGGER.error("Unable to connect to Myo");
        throw new RuntimeException("Unable to find a Myo!");
      }

      myo.setStreamEmg(StreamEmgType.STREAM_EMG_ENABLED);
      LOGGER.info("EMG Stream enabled");
      updateMyoStatus("Connected to a Myo armband!");

      jsonDataCollector = new JsonDataCollector();
      jsonDataCollector.addListsner(new FileMyoDataCollector("c:\\tmp\\myo"));
      jsonDataCollector.addListsner(new SocketServerCollector());

      hub.addListener(jsonDataCollector);
      LOGGER.info("Listener added");

      indicatorMyo.setIndicatorStyle(SimpleIndicator.IndicatorStyle.GREEN);
      startButton.setDisable(false);
      startButton.setDefaultButton(true);

      Task<ObservableList<String>> task =
          new Task<ObservableList<String>>() {
            @Override
            protected ObservableList<String> call() throws Exception {

              while (true) {
                List<RecordListener> collect =
                    jsonDataCollector
                        .getListeners()
                        .stream()
                        .filter(s -> s instanceof SocketServerCollector)
                        .collect(Collectors.toList());
                List<String> connections =
                    collect
                        .stream()
                        .map(s -> ((SocketServerCollector) s).channels)
                        .flatMap(c -> c.stream().map(f -> mapRemoteAddress(f)))
                        .collect(Collectors.toList());
                updateValue(FXCollections.observableList(connections));
                Thread.sleep(10);
              }
            }
          };

      Task<Boolean> booleanTask =
          new Task<Boolean>() {
            @Override
            protected Boolean call() throws Exception {
              while (true) {
                List<RecordListener> collect =
                    jsonDataCollector
                        .getListeners()
                        .stream()
                        .filter(s -> s instanceof SocketServerCollector)
                        .collect(Collectors.toList());
                long count =
                    collect
                        .stream()
                        .map(s -> ((SocketServerCollector) s).channels)
                        .flatMap(Collection::stream)
                        .filter(AsynchronousSocketChannel::isOpen)
                        .count();
                updateValue(count > 0 ? Boolean.TRUE : Boolean.FALSE);
                Thread.sleep(10);
              }
            }
          };

      Task<SimpleIndicator.IndicatorStyle> stringTask =
          new Task<SimpleIndicator.IndicatorStyle>() {

            @Override
            protected SimpleIndicator.IndicatorStyle call() throws Exception {
              while (true) {
                List<RecordListener> collect =
                    jsonDataCollector
                        .getListeners()
                        .stream()
                        .filter(s -> s instanceof SocketServerCollector)
                        .collect(Collectors.toList());
                long count =
                    collect
                        .stream()
                        .map(s -> ((SocketServerCollector) s).channels)
                        .flatMap(Collection::stream)
                        .filter(AsynchronousSocketChannel::isOpen)
                        .count();

                updateValue(
                    count > 0
                        ? SimpleIndicator.IndicatorStyle.RED
                        : SimpleIndicator.IndicatorStyle.GREEN);
                Thread.sleep(10);
              }
            }
          };

      inboundConnections.itemsProperty().bind(task.valueProperty());
      indicatorServer.onProperty().bind(booleanTask.valueProperty());
      //            try {
      //                indicatorServer.indicatorStyleProperty().bind(stringTask.valueProperty());
      //            } catch (Throwable e) {
      //                //??Throws a null ppointer but it works??
      //            }

      Thread thread = new Thread(task);
      thread.setDaemon(true);
      thread.start();

      Thread thread2 = new Thread(booleanTask);
      thread2.setDaemon(true);
      thread2.start();

      Thread thread3 = new Thread(stringTask);
      thread3.setDaemon(true);
      thread3.start();

    } catch (Exception e) {
      e.printStackTrace();
      updateMyoStatus("Error: " + e.getMessage());
    }
  }