本文整理汇总了Java中org.reactfx.value.Val类的典型用法代码示例。如果您正苦于以下问题:Java Val类的具体用法?Java Val怎么用?Java Val使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Val类属于org.reactfx.value包,在下文中一共展示了Val类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.reactfx.value.Val; //导入依赖的package包/类
@Override
public Node apply(int lineNumber) {
Polygon triangle = new Polygon(0.0, 0.0, 40.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;
}
示例2: apply
import org.reactfx.value.Val; //导入依赖的package包/类
@Override
public Node apply(int idx) {
Val<String> formatted = nParagraphs.map(n -> format(idx + 1, n));
Label lineNo = new Label();
lineNo.setFont(DEFAULT_FONT);
lineNo.setBackground(DEFAULT_BACKGROUND);
highlightList
.stream()
.filter(range -> idx >= range.getFirst() && idx < range.getSecond())
.forEach(range -> {
lineNo.setBackground(DEFAULT_BACKGROUND_NEW);
});
lineNo.setTextFill(DEFAULT_TEXT_FILL);
lineNo.setPadding(DEFAULT_INSETS);
lineNo.getStyleClass().add("lineno");
// bind label's text to a Val that stops observing area's paragraphs
// when lineNo is removed from scene
lineNo.textProperty().bind(formatted.conditionOnShowing(lineNo));
return lineNo;
}
示例3: apply
import org.reactfx.value.Val; //导入依赖的package包/类
@Override
public Node apply(int idx) {
Val<String> formatted = nParagraphs.map(n -> format(idx+1, n));
Label lineNo = new Label();
lineNo.setFont(DEFAULT_FONT);
lineNo.setBackground(DEFAULT_BACKGROUND);
lineNo.setTextFill(DEFAULT_TEXT_FILL);
lineNo.setPadding(DEFAULT_INSETS);
lineNo.setAlignment(Pos.TOP_RIGHT);
lineNo.getStyleClass().add("lineno");
// bind label's text to a Val that stops observing area's paragraphs
// when lineNo is removed from scene
lineNo.textProperty().bind(formatted.conditionOnShowing(lineNo));
return lineNo;
}
示例4: ParagraphBox
import org.reactfx.value.Val; //导入依赖的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());
}
示例5: test
import org.reactfx.value.Val; //导入依赖的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);
}
示例6: testLateListNotifications
import org.reactfx.value.Val; //导入依赖的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
}
示例7: testMemoizedItemsChangeWithinForce
import org.reactfx.value.Val; //导入依赖的package包/类
@Test
public void testMemoizedItemsChangeWithinForce() {
LiveList<Integer> src = new LiveArrayList<>(1, 2, 4, 8, 16, 32);
MemoizationList<Integer> memo1 = src.memoize();
MemoizationList<Integer> memo2 = memo1.map(Function.identity()).memoize();
Val<Integer> memo1Sum = memo1.memoizedItems().reduce((a, b) -> a + b).orElseConst(0);
memo1Sum.addListener((obs, oldVal, newVal) -> memo2.forget(0, memo2.size()));
List<Integer> memo2Mirror = new ArrayList<>();
memo2.memoizedItems().observeModifications(mod -> {
memo2Mirror.subList(mod.getFrom(), mod.getFrom() + mod.getRemovedSize()).clear();
memo2Mirror.addAll(mod.getFrom(), mod.getAddedSubList());
// the main part of this test is that it does not throw IndexOutOfBoundsException
});
memo2.force(3, 6);
assertEquals(Arrays.asList(32), memo2Mirror);
}
示例8: test
import org.reactfx.value.Val; //导入依赖的package包/类
@Test
public void test() {
ObservableList<Integer> list = FXCollections.observableArrayList();
Val<Integer> size = LiveList.sizeOf(list);
List<Integer> sizes = new ArrayList<>();
Subscription sub = EventStreams.valuesOf(size).subscribe(sizes::add);
list.add(1);
list.addAll(2, 3, 4);
assertEquals(Arrays.asList(0, 1, 4), sizes);
sub.unsubscribe();
sizes.clear();
list.addAll(5, 6);
assertEquals(Arrays.asList(), sizes);
EventStreams.valuesOf(size).subscribe(sizes::add);
list.addAll(7, 8);
assertEquals(Arrays.asList(6, 8), sizes);
}
示例9: testWhenBound
import org.reactfx.value.Val; //导入依赖的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());
}
示例10: VirtualWebView
import org.reactfx.value.Val; //导入依赖的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"))));
}
示例11: apply
import org.reactfx.value.Val; //导入依赖的package包/类
@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;
}
示例12: apply
import org.reactfx.value.Val; //导入依赖的package包/类
@Override
public Node apply(int idx) {
Val<String> formatted = paragraphs.map(n -> format(idx + 1, n));
Label lineNo = new Label();
lineNo.setCursor(Cursor.HAND);
lineNo.setBackground(DEFAULT_BACKGROUND);
lineNo.setPadding(DEFAULT_INSETS);
lineNo.getStyleClass().add("lineno");
lineNo.textProperty().bind(formatted.conditionOnShowing(lineNo));
return lineNo;
}
示例13: avoidFalseInvalidations
import org.reactfx.value.Val; //导入依赖的package包/类
private static <T> Val<T> avoidFalseInvalidations(Val<T> src) {
return new ValBase<T>() {
@Override
protected T computeValue() {
return src.getValue();
}
@Override
protected Subscription connect() {
return src.observeChanges((obs, oldVal,
newVal) -> invalidate());
}
};
}
示例14: RevertChangesDialog
import org.reactfx.value.Val; //导入依赖的package包/类
public RevertChangesDialog(Val<Git> git, Status firstStatus) {
super(git);
setTitle("Revert modified files");
setResizable(true);
ButtonType revertButtonType = new ButtonType("Revert...", ButtonBar.ButtonData.YES);
setDialogPane(new RevertChangesDialogPane(git, new SelectableFileViewer(firstStatus), revertButtonType));
setResultConverter(buttonType -> {
if (buttonType.equals(revertButtonType)) {
return revertChanges();
} else {
return null;
}
});
}
示例15: RevertChangesDialogPaneBaseOld
import org.reactfx.value.Val; //导入依赖的package包/类
public RevertChangesDialogPaneBaseOld(Val<Git> git, F fileSelector, ButtonType revertButtonType) {
super();
this.git = git;
this.fileViewer = fileSelector;
this.revertButtonType = revertButtonType;
getButtonTypes().add(revertButtonType);
Button revertButton = (Button) lookupButton(revertButtonType);
revertButton.setOnAction(ae -> revertChanges());
revertButton.disableProperty().bind(Bindings.not(fileViewer.hasSelectedFilesProperty()));
}