Java Code Examples for org.reactfx.value.Val#map()

The following examples show how to use org.reactfx.value.Val#map() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArrowFactory.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Node apply(int lineNumber) {
    Polygon triangle = new Polygon(0.0, 0.0, 10.0, 5.0, 0.0, 10.0);
    triangle.setFill(Color.GREEN);

    ObservableValue<Boolean> visible = Val.map(shownLine, sl -> sl == lineNumber);

    triangle.visibleProperty().bind(
        Val.flatMap(triangle.sceneProperty(), scene -> {
            return scene != null ? visible : Val.constant(false);
    }));

    return triangle;
}
 
Example 2
Source File: CaretSelectionBindImpl.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
CaretSelectionBindImpl(Function<SuspendableNo, ? extends CaretNode> createCaret,
                       Function<SuspendableNo, Selection<PS, SEG, S>> createSelection) {
    SuspendableNo delegateUpdater = new SuspendableNo();
    delegateCaret = createCaret.apply(delegateUpdater);
    delegateSelection = createSelection.apply(delegateUpdater);
    if (delegateCaret.getArea() != delegateSelection.getArea()) {
        throw new IllegalArgumentException(String.format(
                "Caret and Selection must be asociated with the same area. Caret area = %s | Selection area = %s",
                delegateCaret.getArea(), delegateSelection.getArea()
        ));
    }

    Val<Tuple3<Integer, Integer, Integer>> anchorPositions = startedByAnchor.flatMap(b ->
            b.get()
                ? Val.constant(Tuples.t(getStartPosition(), getStartParagraphIndex(), getStartColumnPosition()))
                : Val.constant(Tuples.t(getEndPosition(), getEndParagraphIndex(), getEndColumnPosition()))
    );

    anchorPosition = anchorPositions.map(Tuple3::get1);
    anchorParIndex = anchorPositions.map(Tuple3::get2);
    anchorColPosition = anchorPositions.map(Tuple3::get3);

    Suspendable omniSuspendable = Suspendable.combine(
            // first, so it's released last
            beingUpdated,

            startedByAnchor,

            // last, so it's released before startedByAnchor, so that anchor's values are correct
            delegateUpdater
    );

    subscription = omniSuspendable.suspendWhen(getArea().beingUpdatedProperty());
}
 
Example 3
Source File: MutableTabPane.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Currently focused tab.
 */
public Val<T> currentFocusedController() {
    return Val.map(getSelectionModel().selectedItemProperty(), this::controllerFromTab);
}
 
Example 4
Source File: NodeEditionCodeArea.java    From pmd-designer with BSD 2-Clause "Simplified" License 3 votes vote down vote up
public IntFunction<javafx.scene.Node> testCaseLineNumberFactory(LiveTestCase liveTestCase) {
    IntFunction<javafx.scene.Node> base = defaultLineNumberFactory();


    Val<Map<Integer, LiveList<LiveViolationRecord>>> mapVal = ReactfxUtil.groupBy(liveTestCase.getExpectedViolations(), (LiveViolationRecord v) -> v.getRange().startPos.line);

    Subscription pin = mapVal.pin();

    liveTestCase.addCommitHandler(t -> pin.unsubscribe());

    Val<IntFunction<Val<Integer>>> map1 = mapVal.map(it -> (int j) -> Optional.ofNullable(it.get(j)).orElse(new LiveArrayList<>()).sizeProperty());

    IntFunction<Val<Integer>> numViolationsPerLine = i -> map1.flatMap(it -> it.apply(i));

    return idx -> {
        javafx.scene.Node label = base.apply(idx);

        HBox hBox = new HBox();

        hBox.setSpacing(3);


        Label foo = buildExpectedLabel(numViolationsPerLine, idx);

        hBox.getChildren().addAll(foo, label);

        return hBox;
    };
}