当前位置: 首页>>代码示例>>Java>>正文


Java Var类代码示例

本文整理汇总了Java中org.reactfx.value.Var的典型用法代码示例。如果您正苦于以下问题:Java Var类的具体用法?Java Var怎么用?Java Var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Var类属于org.reactfx.value包,在下文中一共展示了Var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUndoInvertsTheChange

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testUndoInvertsTheChange() {
    EventSource<Integer> changes = new EventSource<>();
    Var<Integer> lastAction = Var.newSimpleVar(null);
    UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
            changes, i -> -i, i -> { lastAction.setValue(i); changes.push(i); });

    changes.push(3);
    changes.push(7);
    assertNull(lastAction.getValue());

    um.undo();
    assertEquals(-7, lastAction.getValue().intValue());

    um.undo();
    assertEquals(-3, lastAction.getValue().intValue());

    um.redo();
    assertEquals(3, lastAction.getValue().intValue());

    um.redo();
    assertEquals(7, lastAction.getValue().intValue());
}
 
开发者ID:FXMisc,项目名称:UndoFX,代码行数:24,代码来源:UndoManagerTest.java

示例2: ParagraphBox

import org.reactfx.value.Var; //导入依赖的package包/类
ParagraphBox(Paragraph<PS, SEG, S> par, BiConsumer<TextFlow, PS> applyParagraphStyle,
             Function<StyledSegment<SEG, S>, Node> nodeFactory) {
    this.getStyleClass().add("paragraph-box");
    this.text = new ParagraphText<>(par, nodeFactory);
    applyParagraphStyle.accept(this.text, par.getParagraphStyle());
    this.index = Var.newSimpleVar(0);
    getChildren().add(text);
    graphic = Val.combine(
            graphicFactory,
            this.index,
            (f, i) -> f != null ? f.apply(i) : null);
    graphic.addListener((obs, oldG, newG) -> {
        if(oldG != null) {
            getChildren().remove(oldG);
        }
        if(newG != null) {
            getChildren().add(newG);
        }
    });
    graphicOffset.addListener(obs -> requestLayout());
}
 
开发者ID:FXMisc,项目名称:RichTextFX,代码行数:22,代码来源:ParagraphBox.java

示例3: test

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void test() {
    SuspendableVar<String> a = Var.newSimpleVar("foo").suspendable();
    Counter counter = new Counter();
    a.addListener((obs, oldVal, newVal) -> counter.inc());

    EventSource<Void> src = new EventSource<>();
    EventStream<Void> suspender = src.suspenderOf(a);

    suspender.hook(x -> a.setValue("bar")).subscribe(x -> {
        assertEquals(0, counter.get());
    });

    src.push(null);
    assertEquals(1, counter.get());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:SuspenderStreamTest.java

示例4: test

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void test() {
    SuspendableVar<Boolean> property = Var.newSimpleVar(false).suspendable();
    Counter changes = new Counter();
    Counter invalidations = new Counter();
    property.addListener((obs, old, newVal) -> changes.inc());
    property.addListener(obs -> invalidations.inc());

    property.setValue(true);
    property.setValue(false);
    assertEquals(2, changes.getAndReset());
    assertEquals(2, invalidations.getAndReset());

    Guard g = property.suspend();
    property.setValue(true);
    property.setValue(false);
    g.close();
    assertEquals(0, changes.get());
    assertEquals(1, invalidations.get());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:21,代码来源:SuspendableVarTest.java

示例5: testDynamicMap

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testDynamicMap() {
    LiveList<String> strings = new LiveArrayList<>("1", "22", "333");
    Var<Function<String, Integer>> fn = Var.newSimpleVar(String::length);
    SuspendableList<Integer> ints = strings.mapDynamic(fn).suspendable();

    assertEquals(2, ints.get(1).intValue());

    ints.observeChanges(ch -> {
        for(ListModification<?> mod: ch) {
            assertEquals(Arrays.asList(1, 2, 3), mod.getRemoved());
            assertEquals(Arrays.asList(1, 16, 9), mod.getAddedSubList());
        }
    });

    ints.suspendWhile(() -> {
        strings.set(1, "4444");
        fn.setValue(s -> s.length() * s.length());
    });
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:21,代码来源:ListMapTest.java

示例6: testNullToValChange

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testNullToValChange() {
    Var<String> src = Var.newSimpleVar(null);
    LiveList<String> list = src.asList();
    assertEquals(0, list.size());

    List<ListModification<? extends String>> mods = new ArrayList<>();
    list.observeModifications(mods::add);

    src.setValue("foo");
    assertEquals(1, mods.size());
    ListModification<? extends String> mod = mods.get(0);
    assertEquals(0, mod.getRemovedSize());
    assertEquals(Collections.singletonList("foo"), mod.getAddedSubList());
    assertEquals(1, list.size());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:ValAsListTest.java

示例7: testValToNullChange

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testValToNullChange() {
    Var<String> src = Var.newSimpleVar("foo");
    LiveList<String> list = src.asList();
    assertEquals(1, list.size());

    List<ListModification<? extends String>> mods = new ArrayList<>();
    list.observeModifications(mods::add);

    src.setValue(null);
    assertEquals(1, mods.size());
    ListModification<? extends String> mod = mods.get(0);
    assertEquals(Collections.singletonList("foo"), mod.getRemoved());
    assertEquals(0, mod.getAddedSize());
    assertEquals(0, list.size());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:ValAsListTest.java

示例8: testValToValChange

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testValToValChange() {
    Var<String> src = Var.newSimpleVar("foo");
    LiveList<String> list = src.asList();
    assertEquals(1, list.size());

    List<ListModification<? extends String>> mods = new ArrayList<>();
    list.observeModifications(mods::add);

    src.setValue("bar");
    assertEquals(1, mods.size());
    ListModification<? extends String> mod = mods.get(0);
    assertEquals(Collections.singletonList("foo"), mod.getRemoved());
    assertEquals(Collections.singletonList("bar"), mod.getAddedSubList());
    assertEquals(1, list.size());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:ValAsListTest.java

示例9: test

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void test() {
    LiveList<Integer> list = new LiveArrayList<>(1, 2, 4);
    Var<IndexRange> range = Var.newSimpleVar(new IndexRange(0, 0));
    Val<Integer> rangeSum = list.reduceRange(range, (a, b) -> a + b);

    assertNull(rangeSum.getValue());

    List<Integer> observed = new ArrayList<>();
    rangeSum.values().subscribe(sum -> {
        observed.add(sum);
        if(sum == null) {
            range.setValue(new IndexRange(0, 2));
        } else if(sum == 3) {
            list.addAll(1, Arrays.asList(8, 16));
        } else if(sum == 9) {
            range.setValue(new IndexRange(2, 4));
        }
    });

    assertEquals(Arrays.asList(null, 3, 9, 18), observed);
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:23,代码来源:ListRangeReductionTest.java

示例10: testLateListNotifications

import org.reactfx.value.Var; //导入依赖的package包/类
/**
 * Tests the case when both list and range have been modified and range
 * change notification arrived first.
 */
@Test
public void testLateListNotifications() {
    SuspendableList<Integer> list = new LiveArrayList<Integer>(1, 2, 3).suspendable();
    SuspendableVar<IndexRange> range = Var.newSimpleVar(new IndexRange(0, 3)).suspendable();
    Val<Integer> rangeSum = list.reduceRange(range, (a, b) -> a + b);

    list.suspendWhile(() -> {
        range.suspendWhile(() -> {
            list.addAll(4, 5, 6);
            range.setValue(new IndexRange(3, 6));
        });
    });
    assertEquals(15, rangeSum.getValue().intValue());

    // most importantly, this test tests that no IndexOutOfBoundsException is thrown
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:21,代码来源:ListRangeReductionTest.java

示例11: testWhenBound

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testWhenBound() {
    ObservableList<Integer> list = FXCollections.observableArrayList(1, 1, 1, 1, 1);
    Val<Integer> sum = LiveList.reduce(list, (a, b) -> a + b);
    Var<Integer> lastObserved = Var.newSimpleVar(sum.getValue());

    assertEquals(5, lastObserved.getValue().intValue());

    sum.addListener((obs, oldVal, newVal) -> {
        assertEquals(lastObserved.getValue(), oldVal);
        lastObserved.setValue(newVal);
    });

    list.addAll(2, Arrays.asList(2, 2));
    assertEquals(9, lastObserved.getValue().intValue());

    list.subList(3, 6).clear();
    assertEquals(5, lastObserved.getValue().intValue());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:20,代码来源:ListReductionTest.java

示例12: testSuspendableVal

import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testSuspendableVal() {
    SuspendableVar<String> a = Var.<String>newSimpleVar(null).suspendable();
    Counter counter = new Counter();
    a.addListener(obs -> counter.inc());
    Guard g = a.suspend();
    a.setValue("x");
    assertEquals(0, counter.get());
    Guard h = a.suspend();
    g.close();
    assertEquals(0, counter.get());
    g.close();
    assertEquals(0, counter.get());
    h.close();
    assertEquals(1, counter.get());
}
 
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:17,代码来源:CountedBlockingTest.java

示例13: VirtualWebView

import org.reactfx.value.Var; //导入依赖的package包/类
VirtualWebView(WebView webView) {
    this.webView = webView;
    getChildren().add(webView);

    totalWidth = Val.create(() -> Double.parseDouble(String.valueOf(webView.getEngine().executeScript("document.body.scrollWidth"))));
    totalHeight = Val.create(() -> Double.parseDouble(String.valueOf(webView.getEngine().executeScript("document.body.scrollHeight"))));
    estimateScrollX = Var.newSimpleVar(Double.parseDouble(String.valueOf(webView.getEngine().executeScript("window.pageXOffset || document.documentElement.scrollLeft"))));
    estimateScrollY = Var.newSimpleVar(Double.parseDouble(String.valueOf(webView.getEngine().executeScript("window.pageYOffset || document.documentElement.scrollTop"))));
}
 
开发者ID:jdesive,项目名称:textmd,代码行数:10,代码来源:VirtualWebView.java

示例14: getParagraphBeginPints

import org.reactfx.value.Var; //导入依赖的package包/类
private List<Pair<Integer, Pair<Double, Double>>> getParagraphBeginPints(final VirtualFlow flow) {

        final List<Pair<Integer, Pair<Double, Double>>> paragraphBeginPoints;
        if (flow.visibleCells().isEmpty()) {
            paragraphBeginPoints = Collections.singletonList(
                    new Pair<>(Integer.valueOf(0), new Pair<>(Double.valueOf(0), Double.valueOf(0)))
            );
        } else {
            paragraphBeginPoints = new ArrayList<>(flow.visibleCells().size());
            for (Object o : flow.visibleCells()) {
                Node node = ((Cell) o).getNode();
                Field field = FieldUtils.getField(node.getClass(), "index", true);

                try {
                    Var<Integer> index = (Var<Integer>) field.get(node);
                    Pair<Integer, Pair<Double, Double>> rez = new Pair<>(
                            index.getValue(),
                            new Pair<>(node.getLayoutX(), node.getLayoutY())
                    );
                    paragraphBeginPoints.add(rez);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return paragraphBeginPoints;
    }
 
开发者ID:iazarny,项目名称:gitember,代码行数:28,代码来源:DiffViewController.java

示例15: ScaledVirtualized

import org.reactfx.value.Var; //导入依赖的package包/类
public ScaledVirtualized(V content) {
    super();
    this.content = content;
    getChildren().add(content);
    getTransforms().add(zoom);

    estHeight = Val.combine(
            content.totalHeightEstimateProperty(),
            zoom.yProperty(),
            (estHeight, scaleFactor) -> estHeight * scaleFactor.doubleValue()
    );
    estWidth = Val.combine(
            content.totalWidthEstimateProperty(),
            zoom.xProperty(),
            (estWidth, scaleFactor) -> estWidth * scaleFactor.doubleValue()
    );
    estScrollX = Var.mapBidirectional(
            content.estimatedScrollXProperty(),
            scrollX -> scrollX * zoom.getX(),
            scrollX -> scrollX / zoom.getX()
    );
    estScrollY = Var.mapBidirectional(
            content.estimatedScrollYProperty(),
            scrollY -> scrollY * zoom.getY(),
            scrollY -> scrollY / zoom.getY()
    );

    zoom.xProperty()     .addListener((obs, ov, nv) -> requestLayout());
    zoom.yProperty()     .addListener((obs, ov, nv) -> requestLayout());
    zoom.zProperty()     .addListener((obs, ov, nv) -> requestLayout());
    zoom.pivotXProperty().addListener((obs, ov, nv) -> requestLayout());
    zoom.pivotYProperty().addListener((obs, ov, nv) -> requestLayout());
    zoom.pivotZProperty().addListener((obs, ov, nv) -> requestLayout());
}
 
开发者ID:FXMisc,项目名称:Flowless,代码行数:35,代码来源:ScaledVirtualized.java


注:本文中的org.reactfx.value.Var类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。