本文整理汇总了Java中org.reactfx.EventStream类的典型用法代码示例。如果您正苦于以下问题:Java EventStream类的具体用法?Java EventStream怎么用?Java EventStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventStream类属于org.reactfx包,在下文中一共展示了EventStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupListeners
import org.reactfx.EventStream; //导入依赖的package包/类
private void setupListeners() {
ObjectProperty<Point2D> mouseDown = new SimpleObjectProperty<>();
EventStreams.eventsOf(imageView, MouseEvent.MOUSE_PRESSED).subscribe(e -> {
Point2D mousePress = imageViewToImage(new Point2D(e.getX(), e.getY()));
mouseDown.set(mousePress);
});
EventStreams.eventsOf(imageView, MouseEvent.MOUSE_DRAGGED).subscribe(e -> {
Point2D dragPoint = imageViewToImage(new Point2D(e.getX(), e.getY()));
shift(dragPoint.subtract(mouseDown.get()));
mouseDown.set(imageViewToImage(new Point2D(e.getX(), e.getY())));
});
EventStream<ScrollEvent> scrollEvents = EventStreams.eventsOf(imageView, ScrollEvent.SCROLL);
EventStream<ScrollEvent> scrollEventsUp = scrollEvents.filter(scrollEvent -> scrollEvent.getDeltaY() < 0);
EventStream<ScrollEvent> scrollEventsDown = scrollEvents.filter(scrollEvent -> scrollEvent.getDeltaY() > 0);
scrollEventsUp.subscribe(scrollEvent -> scale = Math.min(scale + 0.25, 3));
scrollEventsDown.subscribe(scrollEvent -> scale = Math.max(scale - 0.25, 0.25));
EventStreams.merge(scrollEventsUp, scrollEventsDown).subscribe(scrollEvent -> scaleImageViewport(scale));
EventStreams.eventsOf(imageView, MouseEvent.MOUSE_CLICKED)
.filter(mouseEvent -> mouseEvent.getClickCount() == 2)
.subscribe(mouseEvent -> fitToView());
}
示例2: UndoManagerImpl
import org.reactfx.EventStream; //导入依赖的package包/类
public UndoManagerImpl(
ChangeQueue<C> queue,
Function<? super C, ? extends C> invert,
Consumer<C> apply,
BiFunction<C, C, Optional<C>> merge,
Predicate<C> isIdentity,
EventStream<C> changeSource,
Duration preventMergeDelay) {
this.queue = queue;
this.invert = invert;
this.apply = apply;
this.merge = merge;
this.isIdentity = isIdentity;
this.mark = queue.getCurrentPosition();
Subscription mainSub = changeSource.subscribe(this::changeObserved);
if (preventMergeDelay.isZero() || preventMergeDelay.isNegative()) {
subscription = mainSub;
} else {
Subscription sub2 = changeSource.successionEnds(preventMergeDelay).subscribe(ignore -> preventMerge());
subscription = mainSub.and(sub2);
}
}
示例3: start
import org.reactfx.EventStream; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
executor = Executors.newSingleThreadExecutor();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
EventStream<PlainTextChange> textChanges = codeArea.plainTextChanges();
textChanges.successionEnds(Duration.ofMillis(500))
.supplyTask(this::computeHighlightingAsync)
.awaitLatest(textChanges)
.subscribe(this::applyHighlighting);
codeArea.replaceText("port a Double(343)\n" +
"port b String(\"dfd\")\n" +
"node D begin\n" +
"port a Double(12)\n" +
"end");
Scene scene = new Scene(new StackPane(codeArea), 600, 400);
scene.getStylesheets().add(getClass().getResource("shiro-syntax.css").toExternalForm());
primaryStage.setTitle("Shiro Playground");
primaryStage.setScene(scene);
primaryStage.show();
}
示例4: create
import org.reactfx.EventStream; //导入依赖的package包/类
static <T> Val<T> create(
Supplier<? extends T> computeValue,
EventStream<?> invalidations) {
return new ValBase<T>() {
@Override
protected Subscription connect() {
return invalidations.subscribe(x -> invalidate());
}
@Override
protected T computeValue() {
return computeValue.get();
}
};
}
示例5: setEventStreamers
import org.reactfx.EventStream; //导入依赖的package包/类
private void setEventStreamers(GroupEntity rect) {
BooleanBinding animationRunning = rect.getRedoAnimation().statusProperty().isEqualTo(Animation.Status.RUNNING);
EventStream<UndoChange<CustomBoundingBox>> xChanges = makeEventStream(rect.getRect().xProperty(),
xRect -> new CustomBoundingBox(xRect.doubleValue(), rect.getRect().getY(), rect.getRect().getWidth(), rect.getRect().getHeight(), rect.getRotate()));
EventStream<UndoChange<CustomBoundingBox>> yChanges = makeEventStream(rect.getRect().yProperty(),
yRect -> new CustomBoundingBox(rect.getRect().getX(), yRect.doubleValue(), rect.getRect().getWidth(), rect.getRect().getHeight(), rect.getRotate()));
EventStream<UndoChange<CustomBoundingBox>> widthChanges = makeEventStream(rect.getRect().widthProperty(),
wRect -> new CustomBoundingBox(rect.getRect().getX(), rect.getRect().getY(), wRect.doubleValue(), rect.getRect().getHeight(), rect.getRotate()));
EventStream<UndoChange<CustomBoundingBox>> heightChanges = makeEventStream(rect.getRect().heightProperty(),
hRect -> new CustomBoundingBox(rect.getRect().getX(), rect.getRect().getY(), rect.getRect().getWidth(), hRect.doubleValue(), rect.getRotate()));
EventStream<UndoChange<CustomBoundingBox>> rotationChanges = makeEventStream(rect.rotateProperty(),
rRect -> new CustomBoundingBox(rect.getRect().getX(), rect.getRect().getY(), rect.getRect().getWidth(), rect.getRect().getHeight(), rRect.doubleValue()));
EventStream<UndoChange<CustomBoundingBox>> boundsChanges = EventStreams
.merge(xChanges, yChanges, widthChanges, heightChanges, rotationChanges).reducible(UndoChange::merge)
.suspendWhen(animationRunning);
rect.undoManager = UndoManagerFactory.unlimitedHistoryUndoManager(boundsChanges, UndoChange::invert, c -> {
rect.getRedoAnimation().getKeyFrames()
.setAll(new KeyFrame(GroupEntity.getRedoAnimationTime(),
new KeyValue(rect.getRect().xProperty(), c.getNewValue().getMinX()),
new KeyValue(rect.getRect().yProperty(), c.getNewValue().getMinY()),
new KeyValue(rect.getRect().widthProperty(), c.getNewValue().getWidth()),
new KeyValue(rect.getRect().heightProperty(), c.getNewValue().getHeight()),
new KeyValue(rect.rotateProperty(), c.getNewValue().getRotation())
));
rect.getRedoAnimation().play();
}, (c1, c2) -> Optional.of(c1.merge(c2)));
}
示例6: initialize
import org.reactfx.EventStream; //导入依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
executor = Executors.newSingleThreadExecutor();
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
OkButton.disableProperty().bind(Val.map(codeArea.lengthProperty(), n -> n == 0));
EventStream<?> richChanges = codeArea.richChanges();
richChanges
.successionEnds(Duration.ofMillis(500))
.supplyTask(this::computeHighlightingAsync)
.awaitLatest(richChanges)
.filterMap(t -> {
if (t.isSuccess()) {
return Optional.of(t.get());
} else {
t.getFailure().printStackTrace();
return Optional.empty();
}
})
.subscribe(this::applyHighlighting);
codeArea.replaceText(0, 0, getSampleCode());
borderPane.setCenter(codeArea);
borderPane.getStylesheets().add(getClass().getResource("/styles/JavaKeywords.css").toExternalForm());
JdkFolderLocation.setOnMouseClicked((event) -> {
if (event.getClickCount() == 2) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select JDK installation folder");
File file = new File("C:\\Program Files\\Java");
if (file.isDirectory()) { //check if it exists and a folder
directoryChooser.setInitialDirectory(file);
}
File directory = directoryChooser.showDialog(primaryStage);
if (directory != null) {
JdkFolderLocation.setText(directory.getAbsolutePath());
}
}
});
// borderPane.setCenter(new VirtualizedScrollPane<>(codeArea));
}
示例7: CounterStore
import org.reactfx.EventStream; //导入依赖的package包/类
public CounterStore(EventStream<Action> eventStream) {
eventStream.filter(a -> a instanceof IncreaseAction)
.cast(IncreaseAction.class)
.subscribe(this::increase);
eventStream.filter(a -> a instanceof DecreaseAction)
.cast(DecreaseAction.class)
.subscribe(this::decrease);
}
示例8: getActionStream
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* A filtered event-stream of actions of the given type.
*
* @param actionType the class type of the action.
* @param <T> the generic type of the action.
* @return an event-stream of all actions of the given type.
*/
@SuppressWarnings("unchecked")
<T extends Action> EventStream<T> getActionStream(Class<T> actionType) {
return Dispatcher.getInstance()
.getActionStream()
.filter(action -> action.getClass().equals(actionType))
.map(action -> (T) action);
}
示例9: unlimitedHistoryUndoManager
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Creates an {@link UndoManager} with unlimited history.
*
* For description of parameters, see {@link #create(EventStream, Function, Consumer)}.
*/
public static <C> UndoManager<C> unlimitedHistoryUndoManager(
EventStream<C> changeStream,
Function<? super C, ? extends C> invert,
Consumer<C> apply) {
return unlimitedHistoryUndoManager(changeStream, invert, apply, (c1, c2) -> Optional.empty());
}
示例10: unlimitedHistoryFactory
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Creates a factory for {@link UndoManager}s with unlimited history.
*/
public static UndoManagerFactory unlimitedHistoryFactory() {
return new UndoManagerFactory() {
@Override
public <C> UndoManager<C> create(
EventStream<C> changeStream,
Function<? super C, ? extends C> invert,
Consumer<C> apply,
BiFunction<C, C, Optional<C>> merge,
Predicate<C> isIdentity,
Duration preventMergeDelay) {
return unlimitedHistoryUndoManager(changeStream, invert, apply, merge, isIdentity, preventMergeDelay);
}
};
}
示例11: fixedSizeHistoryUndoManager
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Creates an {@link UndoManager} with bounded history.
* When at full capacity, a new change will cause the oldest change to be forgotten.
*
* <p>For description of the remaining parameters, see {@link #create(EventStream, Function, Consumer, BiFunction)}.</p>
*
* @param capacity maximum number of changes the returned UndoManager can store
*/
public static <C> UndoManager<C> fixedSizeHistoryUndoManager(
EventStream<C> changeStream,
Function<? super C, ? extends C> invert,
Consumer<C> apply,
BiFunction<C, C, Optional<C>> merge,
int capacity) {
return fixedSizeHistoryUndoManager(changeStream, invert, apply, merge, c -> false, Duration.ZERO, capacity);
}
示例12: fixedSizeHistoryFactory
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Creates a factory for {@link UndoManager}s with bounded history.
* When at full capacity, a new change will cause the oldest change to be forgotten.
*/
public static UndoManagerFactory fixedSizeHistoryFactory(int capacity) {
return new UndoManagerFactory() {
@Override
public <C> UndoManager<C> create(
EventStream<C> changeStream,
Function<? super C, ? extends C> invert,
Consumer<C> apply,
BiFunction<C, C, Optional<C>> merge,
Predicate<C> isIdentity,
Duration preventMergeDelay) {
return fixedSizeHistoryUndoManager(changeStream, invert, apply, merge, isIdentity, preventMergeDelay, capacity);
}
};
}
示例13: zeroHistoryFactory
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Creates a factory for {@link UndoManager}s with no history.
*
* @see #zeroHistoryUndoManager(EventStream)
*/
public static UndoManagerFactory zeroHistoryFactory() {
return new UndoManagerFactory() {
@Override
public <C> UndoManager<C> create(
EventStream<C> changeStream,
Function<? super C, ? extends C> invert,
Consumer<C> apply,
BiFunction<C, C, Optional<C>> merge,
Predicate<C> isIdentity,
Duration preventMergeDelay) {
return zeroHistoryUndoManager(changeStream);
}
};
}
示例14: plainChanges
import org.reactfx.EventStream; //导入依赖的package包/类
/**
* Returns an {@link EventStream} that emits a {@link PlainTextChange} every time a non-style change is made
* to this document. A style change would include setting a segment's style, but not changing that segment
* or setting a paragraph's style. A non-style change would include adding/removing/modifying a segment itself
*/
default EventStream<PlainTextChange> plainChanges() {
return richChanges()
.map(RichTextChange::toPlainTextChange)
// filter out rich changes where the style was changed but text wasn't added/removed
.filter(pc -> !pc.isIdentity());
}
示例15: booleanPulse
import org.reactfx.EventStream; //导入依赖的package包/类
private static EventStream<Boolean> booleanPulse(javafx.util.Duration javafxDuration, EventStream<?> restartImpulse) {
Duration duration = Duration.ofMillis(Math.round(javafxDuration.toMillis()));
EventStream<?> ticks = EventStreams.restartableTicks(duration, restartImpulse);
return StateMachine.init(false)
.on(restartImpulse.withDefaultEvent(null)).transition((state, impulse) -> true)
.on(ticks).transition((state, tick) -> !state)
.toStateStream();
}