use of org.reactfx.util.Either in project RichTextFX by FXMisc.
the class ParagraphBox method stationaryIndices.
public EventStream<Either<Tuple2<Point2D, Integer>, Object>> stationaryIndices(Duration delay) {
EventStream<Either<Point2D, Void>> stationaryEvents = new MouseStationaryHelper(this).events(delay);
EventStream<Tuple2<Point2D, Integer>> hits = stationaryEvents.filterMap(Either::asLeft).filterMap(p -> {
OptionalInt charIdx = hit(p).getCharacterIndex();
if (charIdx.isPresent()) {
return Optional.of(t(p, charIdx.getAsInt()));
} else {
return Optional.empty();
}
});
EventStream<?> stops = stationaryEvents.filter(Either::isRight).map(Either::getRight);
return hits.or(stops);
}
use of org.reactfx.util.Either in project RichTextFX by FXMisc.
the class MouseStationaryHelper method events.
/**
* Returns an {@link EventStream} that emits a {@link Point2D} whenever the mouse becomes stationary
* over the helper's node and emits a {@code null} value whenever the mouse moves after being stationary.
*/
public EventStream<Either<Point2D, Void>> events(Duration delay) {
EventStream<MouseEvent> mouseEvents = eventsOf(node, MouseEvent.ANY);
EventStream<Point2D> stationaryPositions = mouseEvents.successionEnds(delay).filter(e -> e.getEventType() == MOUSE_MOVED).map(e -> new Point2D(e.getX(), e.getY()));
EventStream<Void> stoppers = mouseEvents.supply((Void) null);
return stationaryPositions.or(stoppers).distinct();
}
Aggregations