io.reactivex.rxjavafx.observables.JavaFxObservable Java Examples
The following examples show how to use
io.reactivex.rxjavafx.observables.JavaFxObservable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Hand.java From latexdraw with GNU General Public License v3.0 | 6 votes |
@Override protected void configureBindings() { disposables.add(JavaFxObservable.changesOf(canvas.getViews().getChildren()) .observeOn(JavaFxScheduler.platform()) .subscribe(next -> setUpCursorOnShapeView(next), ex -> BadaboomCollector.INSTANCE.add(ex))); bindDnD2Select(); bindPressureToSelectShape(); bindDnDTranslate(); dbleClickToInitTextSetter(); shortcutBinder() .toProduce(() -> new SelectShapes(canvas.getDrawing())) .on(canvas) .with(KeyCode.A, OperatingSystem.getControlKey()) .first(c -> c.getShapes().addAll(canvas.getDrawing().getShapes())) .bind(); shortcutBinder() .toProduce(() -> new UpdateToGrid(canvas.getMagneticGrid(), canvas.getDrawing().getSelection().duplicateDeep(false))) .on(canvas) .with(KeyCode.U, OperatingSystem.getControlKey()) .when(i -> prefs.isMagneticGrid()) .bind(); }
Example #2
Source File: MeshProgressBar.java From paintera with GNU General Public License v2.0 | 5 votes |
public void bindTo(final ObservableMeshProgress meshProgress) { unbind(); this.meshProgress = meshProgress; if (this.meshProgress != null) { this.disposable = JavaFxObservable .invalidationsOf(this.meshProgress) .throttleLast(updateIntervalMsec, TimeUnit.MILLISECONDS) .observeOn(JavaFxScheduler.platform()) .subscribe(val -> { final int numTasks = meshProgress.getNumTasks(); final int numCompletedTasks = meshProgress.getNumCompletedTasks(); if (numTasks == 0) setProgress(0.0); // hide progress bar when there is nothing to do else if (numCompletedTasks <= 0) setProgress(1e-7); // displays an empty progress bar else if (numCompletedTasks >= numTasks) { setStyle(ProgressStyle.FINISHED); setProgress(1.0); } else { setStyle(ProgressStyle.IN_PROGRESS); setProgress((double) numCompletedTasks / numTasks); } statusToolTip.setText(numCompletedTasks + "/" + numTasks); }); } }
Example #3
Source File: BasicView.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
BasicView() { setCenter(shapeCanvas); // clear selection on canvas click JavaFxObservable.eventsOf(shapeCanvas, MouseEvent.MOUSE_CLICKED) .subscribe( e-> clearSelection()); }
Example #4
Source File: BasicView.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
BaseShape( BasicView view, Supplier<Shape> buildRootShape) { this.view = view; rootShape = buildRootShape.get(); view.select(rootShape); // select shape on click Disposable disposable = JavaFxObservable.eventsOf(rootShape, MouseEvent.MOUSE_CLICKED) .subscribe( e -> { view.select(rootShape); e.consume(); }); // dispose "listeners" when shape is removed from the scene JavaFxObservable.changesOf(rootShape.sceneProperty()) .filter( scene -> scene == null ) .subscribe( s -> disposable.dispose()); // calculate delta between shape location and initial mouse position on mouse pressed JavaFxObservable .eventsOf( rootShape, MouseEvent.MOUSE_PRESSED ) .map( e -> new Point2D( e.getSceneX(), e.getSceneY())) .subscribe( p -> { view.select(rootShape); Bounds bounds = rootShape.localToScene(rootShape.getLayoutBounds()); delta = p.subtract( new Point2D(bounds.getMinX(), bounds.getMinY()) ); }); // User current mouse position and delta to recalculate and set new shape location on mouse dragged JavaFxObservable .eventsOf( rootShape, MouseDragEvent.MOUSE_DRAGGED ) .map( e -> rootShape.sceneToLocal(e.getSceneX() - delta.getX(), e.getSceneY() - delta.getY())) .map( p -> rootShape.localToParent(p)) .subscribe( p -> rootShape.relocate( p.getX(), p.getY())); }
Example #5
Source File: ChatClient.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Build the UI and wire up event handlers */ @Override public void start(Stage primaryStage) { primaryStage.setTitle("Reactive Chat - " + author); Scene scene = buildScene(); /* ****************************** * Subscribe to incoming messages * ******************************/ disposables.add(Single // Trigger .just(Empty.getDefaultInstance()) .subscribeOn(Schedulers.io()) // Invoke .as(stub::getMessages) .map(this::fromMessage) // Execute .observeOn(JavaFxScheduler.platform()) .subscribe(messages::appendText)); /* ************************* * Publish outgoing messages * *************************/ disposables.add(JavaFxObservable // Trigger .actionEventsOf(send) .subscribeOn(Schedulers.io()) // Invoke .map(x -> message.getText()) .map(this::toMessage) .flatMapSingle(stub::postMessage) // Execute .observeOn(JavaFxScheduler.platform()) .subscribe(ignore -> message.clear())); /* ********************************* * Publish arrival/departure message * *********************************/ disposables.add(WindowEventSource // Trigger .fromWindowEvents(primaryStage, WindowEvent.ANY) .subscribeOn(Schedulers.io()) .filter(event -> event.getEventType().equals(WindowEvent.WINDOW_SHOWING) | event.getEventType().equals(WindowEvent.WINDOW_HIDING)) // Invoke .map(event -> event.getEventType().equals(WindowEvent.WINDOW_SHOWING) ? "joined" : "left") .map(this::toMessage) .flatMapSingle(stub::postMessage) // Execute .subscribe()); primaryStage.setScene(scene); primaryStage.show(); }
Example #6
Source File: Canvas.java From latexdraw with GNU General Public License v3.0 | 4 votes |
/** * Creates the canvas. */ @Inject public Canvas(final PreferencesService prefs, final ViewFactory viewFactory) { super(); this.viewFactory = Objects.requireNonNull(viewFactory); modified = false; drawing = ShapeFactory.INST.createDrawing(); zoom = new SimpleDoubleProperty(1d); tempView = Optional.empty(); page = new PageView(prefs, getOrigin()); magneticGrid = new MagneticGrid(this, prefs); disposables = new ArrayList<>(); widgetsPane = new Group(); shapesPane = new Group(); shapesToViewMap = new HashMap<>(); selectionBorder = new Rectangle(); ongoingSelectionBorder = new Rectangle(); widgetsPane.setFocusTraversable(false); ongoingSelectionBorder.setFocusTraversable(false); ongoingSelectionBorder.setMouseTransparent(true); ongoingSelectionBorder.setFill(null); ongoingSelectionBorder.setStroke(Color.GRAY); ongoingSelectionBorder.setStrokeLineCap(StrokeLineCap.BUTT); ongoingSelectionBorder.getStrokeDashArray().addAll(7d, 7d); getChildren().add(page); getChildren().add(magneticGrid); getChildren().add(shapesPane); getChildren().add(widgetsPane); widgetsPane.getChildren().add(selectionBorder); widgetsPane.getChildren().add(ongoingSelectionBorder); widgetsPane.relocate(ORIGIN.getX(), ORIGIN.getY()); shapesPane.relocate(ORIGIN.getX(), ORIGIN.getY()); defineShapeListToViewBinding(); selectionBorder.setFocusTraversable(false); selectionBorder.setVisible(false); selectionBorder.setFill(null); selectionBorder.setStroke(Color.GRAY); selectionBorder.setStrokeLineCap(StrokeLineCap.BUTT); selectionBorder.getStrokeDashArray().addAll(7d, 7d); // Bloody key shortcuts. To work the canvas must grab the focus // Must be a MOUSE_CLICKED, not a MOUSE_PRESSED, do not know why... io.github.interacto.jfx.binding.Bindings .anonCmdBinder(() -> requestFocus()) .usingInteraction(Click::new) .on(this) .bind(); // Instead of triggering the update on each change, wait for 20 ms disposables.add(JavaFxObservable.<ObservableList<Shape>>changesOf(drawing.getSelection().getShapes()) .throttleLast(20, TimeUnit.MILLISECONDS) .observeOn(JavaFxScheduler.platform()) .subscribe(next -> updateSelectionBorders(), ex -> BadaboomCollector.INSTANCE.add(ex))); disposables.add(CommandsRegistry.getInstance().commands() .filter(c -> c instanceof Modifying || c instanceof Undo || c instanceof Redo) .subscribe(c -> update())); shapesPane.setFocusTraversable(false); prefWidthProperty().bind(Bindings.createDoubleBinding(() -> margins * 2d + prefs.getPage().getWidth() * Shape.PPC, prefs.pageProperty())); prefHeightProperty().bind(Bindings.createDoubleBinding(() -> margins * 2d + prefs.getPage().getHeight() * Shape.PPC, prefs.pageProperty())); }