本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
});
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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
}
示例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());
}
示例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());
}
示例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"))));
}
示例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;
}
示例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());
}