本文整理汇总了Java中org.reactfx.value.Var类的典型用法代码示例。如果您正苦于以下问题:Java Var类的具体用法?Java Var怎么用?Java Var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Var类属于org.reactfx.value包,在下文中一共展示了Var类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testMultipleModificationsWhenBound
import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testMultipleModificationsWhenBound() {
SuspendableList<Integer> list = new LiveArrayList<>(1, 1, 1, 1, 1).suspendable();
Val<Integer> sum = list.reduce((a, b) -> a + b);
Var<Integer> lastObserved = Var.newSimpleVar(null);
sum.observeChanges((obs, oldVal, newVal) -> lastObserved.setValue(newVal));
list.suspendWhile(() -> {
list.addAll(0, Arrays.asList(3, 2));
list.remove(4, 6);
list.addAll(4, Arrays.asList(8, 15));
});
assertEquals(31, lastObserved.getValue().intValue());
}
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:14,代码来源:ListReductionTest.java
示例17: testRecursion
import org.reactfx.value.Var; //导入依赖的package包/类
@Test
public void testRecursion() {
SuspendableList<Integer> list = new LiveArrayList<>(1, 1, 1, 1, 1).suspendable();
Val<Integer> sum = list.reduce((a, b) -> a + b);
Var<Integer> lastObserved = Var.newSimpleVar(null);
Random random = new Random(0xcafebabe);
sum.addListener(obs -> {
Integer newVal = sum.getValue();
if(newVal < 1000) {
list.suspendWhile(() -> {
// remove 4 items
int i = random.nextInt(list.size() - 3);
list.subList(i, i + 3).clear();
list.remove(random.nextInt(list.size()));
// insert 5 items
list.addAll(random.nextInt(list.size()), Arrays.asList(
random.nextInt(12), random.nextInt(12), random.nextInt(12)));
list.add(random.nextInt(list.size()), random.nextInt(12));
list.add(random.nextInt(list.size()), random.nextInt(12));
});
}
});
sum.observeChanges((obs, oldVal, newVal) -> lastObserved.setValue(newVal));
list.set(2, 0);
assertThat(lastObserved.getValue().intValue(), greaterThanOrEqualTo(1000));
}
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:28,代码来源:ListReductionTest.java
示例18: start
import org.reactfx.value.Var; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) {
Circle circle = new Circle(30.0);
Pane canvas = new Pane(circle);
// animate circle position
Var<Point2D> center = Var.newSimpleVar(new Point2D(W/2, H/2));
Val<Point2D> animCenter = center.animate(
(p1, p2) -> Duration.ofMillis((long) p1.distance(p2)),
(p1, p2, frac) -> p1.multiply(1.0-frac).add(p2.multiply(frac)));
circle.centerXProperty().bind(animCenter.map(Point2D::getX));
circle.centerYProperty().bind(animCenter.map(Point2D::getY));
// animate circle color
Var<Color> color = Var.newSimpleVar(Color.BLUE);
Val<Color> animColor = Val.animate(color, Duration.ofMillis(500));
circle.fillProperty().bind(animColor);
// on click, move to random position and transition to random color
Random random = new Random();
circle.setOnMouseClicked(click -> {
center.setValue(new Point2D(
random.nextInt(W),
random.nextInt(H)));
color.setValue(Color.rgb(
random.nextInt(240),
random.nextInt(240),
random.nextInt(240)));
});
primaryStage.setScene(new Scene(canvas, W, H));
primaryStage.show();
}
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:35,代码来源:AnimatedValDemo.java
示例19: main
import org.reactfx.value.Var; //导入依赖的package包/类
public static void main(String[] args) {
int n = 40;
FibTest eagerTest = new FibTest(n);
LongProperty eagerResult = new SimpleLongProperty();
eagerTest.setupFor(eagerResult);
FibTest lazyTest = new FibTest(n);
SuspendableVar<Number> lazyResult = Var.suspendable(Var.newSimpleVar(0L));
lazyTest.setupFor(lazyResult);
long t1 = System.currentTimeMillis();
eagerTest.run();
long t2 = System.currentTimeMillis();
double eagerTime = (t2-t1)/1000.0;
t1 = System.currentTimeMillis();
Guard g = lazyResult.suspend();
lazyTest.run();
g.close();
t2 = System.currentTimeMillis();
double lazyTime = (t2-t1)/1000.0;
System.out.println("EAGER TEST:");
System.out.println(" fib_" + n + " = " + eagerResult.get());
System.out.println(" result invalidations: " + eagerTest.invalidationCount);
System.out.println(" duration: " + eagerTime + " seconds");
System.out.println();
System.out.println("LAZY TEST:");
System.out.println(" fib_" + n + " = " + lazyResult.getValue());
System.out.println(" result invalidations: " + lazyTest.invalidationCount);
System.out.println(" duration: " + lazyTime + " seconds");
}
开发者ID:TomasMikula,项目名称:ReactFX,代码行数:34,代码来源:FibTest.java
示例20: estimatedScrollXProperty
import org.reactfx.value.Var; //导入依赖的package包/类
@Override
public Var<Double> estimatedScrollXProperty() {
return estimateScrollX;
}
开发者ID:jdesive,项目名称:textmd,代码行数:5,代码来源:VirtualWebView.java
注:本文中的org.reactfx.value.Var类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论