public void makeZoomable(Scene scene4EventFilter, Node control4Scaling) { scene4EventFilter.addEventFilter(ScrollEvent.ANY, (ScrollEvent event) -> { double delta = 1.2; double scale = control4Scaling.getScaleX(); if (ObjectUtils.smallerDoublePrecision(event.getDeltaY(), 0)) { scale /= delta; } else { scale *= delta; } if (scale < MIN_SCALE || scale > MAX_SCALE) { scale = scale < MIN_SCALE ? MIN_SCALE : MAX_SCALE; } control4Scaling.setScaleX(scale); control4Scaling.setScaleY(scale); event.consume(); }); }
public void changeHiddenPower(Event event) { if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; MouseButton mouseButton = mouseEvent.getButton(); if (mouseEvent.isShiftDown() || mouseButton.equals(MouseButton.SECONDARY)) { pokemon.setHiddenPower(hiddenPowerCalculator.updateToNext()); } else if (mouseButton.equals(MouseButton.PRIMARY)) { pokemon.setHiddenPower(hiddenPowerCalculator.updateToPrevious()); } else if (mouseButton.equals(MouseButton.MIDDLE)) { pokemon.setHiddenPower(hiddenPowerCalculator.setUnknown()); } } else if (event instanceof ScrollEvent) { double delta = ((ScrollEvent) event).getDeltaY(); if (delta > 0) { pokemon.setHiddenPower(hiddenPowerCalculator.updateToNext()); } else if (delta < 0) { pokemon.setHiddenPower(hiddenPowerCalculator.updateToPrevious()); } } }
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { // don't zoom unless the mouse pointer is in the plot's data area ChartRenderingInfo info = canvas.getRenderingInfo(); PlotRenderingInfo pinfo = info.getPlotInfo(); Point2D p = new Point2D.Double(e.getX(), e.getY()); if (pinfo.getDataArea().contains(p)) { Plot plot = (Plot) zoomable; // do not notify while zooming each axis boolean notifyState = plot.isNotify(); plot.setNotify(false); int clicks = (int) e.getDeltaY(); double zf = 1.0 + this.zoomFactor; if (clicks < 0) { zf = 1.0 / zf; } if (canvas.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (canvas.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
/** * Creates the canvas for scrolling and panning. * * @param primaryStage - Stage as given by the start method */ private void setupInterface(Stage primaryStage) { root = new Group(); primaryStage.setTitle("Drone simulator"); primaryStage.setResizable(false); primaryStage.setOnCloseRequest(onCloseEventHandler); Runtime.getRuntime().addShutdownHook(new Thread(() -> onCloseEventHandler.handle(null))); // create canvas canvas = new PannableCanvas(Settings.CANVAS_WIDTH, Settings.CANVAS_HEIGHT); canvas.setId("pane"); canvas.setTranslateX(0); canvas.setTranslateY(0); root.getChildren().add(canvas); double width = Settings.SCENE_WIDTH > Settings.CANVAS_WIDTH ? Settings.CANVAS_WIDTH : Settings.SCENE_WIDTH; double height = Settings.SCENE_HEIGHT > Settings.CANVAS_HEIGHT ? Settings.CANVAS_HEIGHT : Settings.SCENE_HEIGHT; // create scene which can be dragged and zoomed Scene scene = new Scene(root, width, height); SceneGestures sceneGestures = new SceneGestures(canvas); scene.addEventFilter(MouseEvent.MOUSE_PRESSED, sceneGestures.getOnMousePressedEventHandler()); scene.addEventFilter(MouseEvent.MOUSE_DRAGGED, sceneGestures.getOnMouseDraggedEventHandler()); scene.addEventFilter(ScrollEvent.ANY, sceneGestures.getOnScrollEventHandler()); scene.getStylesheets().addAll(this.getClass().getResource("/style.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); canvas.addGrid(); }
/** * Zooms the canvas to the mouse pointer * @param event */ @Override public void handle(ScrollEvent event) { double delta = 1.2; double scale = canvas.getScale(); // currently we only use Y, same value is used for X double oldScale = scale; if (event.getDeltaY() < 0) { scale /= delta; } else { scale *= delta; } scale = clamp(scale, MIN_SCALE, MAX_SCALE); double f = (scale / oldScale) - 1; double dx = (event.getSceneX() - (canvas.getBoundsInParent().getWidth() / 2 + canvas.getBoundsInParent().getMinX())); double dy = (event.getSceneY() - (canvas.getBoundsInParent().getHeight() / 2 + canvas.getBoundsInParent().getMinY())); canvas.setScale(scale); canvas.setPivot(f * dx, f * dy); canvas.setTranslateX(clamp(canvas.getTranslateX(), minX(), maxX())); canvas.setTranslateY(clamp(canvas.getTranslateX(), minY(), maxY())); event.consume(); }
private void registerListeners() { widthProperty().addListener(o -> resize()); heightProperty().addListener(o -> resize()); sceneProperty().addListener(o -> { if (!locations.isEmpty()) { addShapesToScene(locations.values()); } if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); } locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> { if (CHANGE.wasAdded()) { addShapesToScene(CHANGE.getValueAdded()); } else if(CHANGE.wasRemoved()) { Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved())); } }); }); }
/** * The process of scrolling value. */ private void processScroll(@NotNull final ScrollEvent event) { if (!event.isControlDown()) return; final TextField source = (TextField) event.getSource(); final String text = source.getText(); float value; try { value = parseFloat(text); } catch (final NumberFormatException e) { return; } long longValue = (long) (value * 1000); longValue += event.getDeltaY() * 1; final String result = String.valueOf(max(min(longValue / 1000F, 1F), 0F)); source.setText(result); source.positionCaret(result.length()); processChange((KeyEvent) null); }
/** * Enables handling of scroll and mouse wheel events for the node. * This type of events has a peculiarity on Windows. See the javadoc of notifyScrollEvents for more information. * @see #notifyScrollEvent * @param intersectionTestFunc a function that takes an event object and must return boolean * @return itself to let you use a chain of calls */ MouseEventNotificator setOnScrollListener(Function<NativeMouseWheelEvent, Boolean> intersectionTestFunc) { if (SystemUtils.IS_OS_WINDOWS) { if (!GlobalScreen.isNativeHookRegistered()) { try { GlobalScreen.registerNativeHook(); } catch (NativeHookException | UnsatisfiedLinkError e) { e.printStackTrace(); Main.log("Failed to initialize the native hooking. Rolling back to using JavaFX events..."); sender.addEventFilter(ScrollEvent.SCROLL, this::notifyScrollEvent); return this; } } mouseWheelListener = event -> notifyScrollEvent(event, intersectionTestFunc); GlobalScreen.addNativeMouseWheelListener(mouseWheelListener); } else { sender.addEventFilter(ScrollEvent.SCROLL, this::notifyScrollEvent); } return this; }
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { // don't zoom unless the mouse pointer is in the plot's data area ChartRenderingInfo info = canvas.getRenderingInfo(); PlotRenderingInfo pinfo = info.getPlotInfo(); Point2D p = new Point2D.Double(e.getX(), e.getY()); if (pinfo.getDataArea().contains(p)) { Plot plot = (Plot) zoomable; // do not notify while zooming each axis boolean notifyState = plot.isNotify(); plot.setNotify(false); int clicks = (int) e.getDeltaY(); double zf = 1.0 + this.zoomFactor; if (clicks < 0) { zf = 1.0 / zf; } if (true) { //this.chartPanel.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (true) { //this.chartPanel.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
protected void handleScroll(ScrollEvent ev) { if(ev.isShiftDown()) { // TODO horizontal scroll perhaps? D.print("horizontal scroll", ev.getDeltaX()); } else if(ev.isShortcutDown()) { // page up / page down if(ev.getDeltaY() >= 0) { editor.pageUp(); } else { editor.pageDown(); } } else { // vertical block scroll editor.blockScroll(ev.getDeltaY() >= 0); } }
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()); }
@Test(timeout = 60000) public void onScroll() { if (control.getProcessedEvents().contains(ScrollEvent.class)) { test(EventTypes.SCROLL, new Command() { public void invoke() { new GetAction<Object>() { @Override public void run(Object... os) throws Exception { primeDock.mouse().move(); primeDock.mouse().turnWheel(1); } }.dispatch(Root.ROOT.getEnvironment()); } }); } }
@Override public void handle(ScrollEvent event) { event.consume(); double deltaY = event.getDeltaY(); double deltaX = event.getDeltaX(); if (deltaY < 0) { scrollPane.setHvalue(Math.min(1, scrollPane.getHvalue() + 0.0007)); } else if (deltaY > 0) { scrollPane.setHvalue(Math.max(0, scrollPane.getHvalue() - 0.0007)); } if (deltaX < 0) { scrollPane.setVvalue(Math.min(1, scrollPane.getVvalue() + 0.05)); } else if (deltaX > 0) { scrollPane.setVvalue(Math.max(0, scrollPane.getVvalue() - 0.05)); } }
/** * Initialize fxml file. */ @Override public void initialize(URL arg0, ResourceBundle arg1) { scrollPane.addEventFilter(ScrollEvent.ANY, scrollEventHandler); loadData(); pane.boundsInParentProperty().addListener((observable, oldValue, newValue) -> { scrollPane.setPrefWidth(newValue.getWidth()); scrollPane.setPrefHeight(newValue.getHeight()); }); scrollPane.setHvalue(0); scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); innerGroup = getAnnotations(); // innerGroup.scaleYProperty().bind(scrollPane.heightProperty().divide(innerGroup.getBoundsInLocal().getHeight())); outerGroup = new Group(innerGroup); scrollPane.setContent(outerGroup); }
public void mouseWheelMoved(ScrollEvent e) { double scaledDeltaY = e.getDeltaY() > 0 ? -1 : 1; double formerZoom = zoom; zoom -= scaledDeltaY; zoom = zoom <= 1 ? 1 : zoom; double deltaX = deltaStart.getX() - delta.getX(); double deltaY = deltaStart.getY() - delta.getY(); double projX = (e.getX() + deltaX) / (formerZoom * zoomFactor); double projY = (e.getY() + deltaY) / (formerZoom * zoomFactor); double newPointX = (projX * zoom * zoomFactor) - deltaX; double newPointY = (projY * zoom * zoomFactor) - deltaY; setDeltaStart(new Point((int) newPointX, (int) newPointY)); delta = new Point((int) e.getX(), (int) e.getY()); }
@Override public void handle(ScrollEvent scrollEvent) { if (scrollEvent.isControlDown()) { Point2D mousePos = new Point2D(scrollEvent.getSceneX(), scrollEvent.getSceneY()); Point2D scenePositionToCentreZoomAround = m_root.sceneToLocal(new Point2D(scrollEvent.getSceneX(), scrollEvent.getSceneY())); final double scale = calculateScale(scrollEvent); m_root.setScaleX(scale); m_root.setScaleY(scale); scrollTo(mousePos, scenePositionToCentreZoomAround); scrollEvent.consume(); } }
@Override public void mount(){ EventHandler<? super ScrollEvent> oldHandler = pane.getOnScroll(); EventHandler<? super ScrollEvent> newHandler = (event)->{ if (event.isControlDown() == controlPressed) { double scale = pane.getScaleX() + event.getDeltaY() / zoomFactor; if (scale <= min) scale = min; if (scale >= max) scale = max; pane.setScaleX(scale); pane.setScaleY(scale); event.consume(); } }; Utils.chain(oldHandler, newHandler); pane.setOnScroll(newHandler); }
/** Zoom in/out triggered by mouse wheel * @param event Scroll event */ protected void wheelZoom(final ScrollEvent event) { // Invoked by mouse scroll wheel. // Only allow zoom (with control), not pan. if (! event.isControlDown()) return; if (event.getDeltaY() > 0) zoomInOut(event.getX(), event.getY(), 1.0/ZOOM_FACTOR); else if (event.getDeltaY() < 0) zoomInOut(event.getX(), event.getY(), ZOOM_FACTOR); else return; event.consume(); }
public void scrolling(ScrollEvent se) { double clickCount; if (se.getTouchCount() == 0) { finish(); clickCount = Math.signum(se.getDeltaY())*4; } else { if (!set) { start(se.getX(), se.getY()); } if (se.isInertia()) return; // inertia tends to cause crazy zooms clickCount = se.getTotalDeltaY() / se.getMultiplierY(); } zoom(Math.pow(scrollScaleFactor, clickCount), se.getX(), se.getY()); }
private void sendScrollEvent(EventType<ScrollEvent> fxEventType, final GestureEvent event, TKSceneListener sceneListener) { currentState.totalScrollX += event.xDirection; currentState.totalScrollY += event.yDirection; Point screenPosition = canvas.toDisplay(event.x, event.y); // System.out.println(fxEventType + " " + screenPosition); sceneListener.scrollEvent(fxEventType, event.xDirection, event.yDirection, // scrollX, scrollY 0, 0, // totalScrollX, totalScrollY 5.0, 5.0, // xMultiplier, yMultiplier 0, // touchCount 0, 0, // scrollTextX, scrollTextY 0, 0, // defaultTextX, defaultTextY event.x, event.y, // x, y screenPosition.x, screenPosition.y, // screenX, screenY isShift(event), isControl(event), isAlt(event), isMeta(event), false, // direct false); // inertia }
/** * When the user starts scrolling on the graph. * * @param scrollEvent {@link ScrollEvent} associated with the event */ @FXML void onScrollStarted(final ScrollEvent scrollEvent) { ((Node) scrollEvent.getSource()).getScene().setCursor(Cursor.CROSSHAIR); scrollEvent.consume(); }
/** * When the user scroll on the graph. * * @param scrollEvent {@link ScrollEvent} associated with the event */ @FXML void onScroll(final ScrollEvent scrollEvent) { graphMovementCalculator.onScroll(-scrollEvent.getDeltaY()); scrollEvent.consume(); }
/** * When the user finished scrolling. * * @param scrollEvent {@link ScrollEvent} associated with the event */ @FXML void onScrollFinished(final ScrollEvent scrollEvent) { ((Node) scrollEvent.getSource()).getScene().setCursor(Cursor.DEFAULT); scrollEvent.consume(); }
/** * Handles a scroll event by passing it on to the registered handlers. * * @param e the scroll event. */ protected void handleScroll(ScrollEvent e) { if (this.liveHandler != null && this.liveHandler.isEnabled()) { this.liveHandler.handleScroll(this, e); } for (MouseHandlerFX handler: this.auxiliaryMouseHandlers) { if (handler.isEnabled()) { handler.handleScroll(this, e); } } }
@Override public void handleScroll(ChartCanvas canvas, ScrollEvent e) { JFreeChart chart = canvas.getChart(); Plot plot = chart.getPlot(); if (plot instanceof Zoomable) { Zoomable zoomable = (Zoomable) plot; handleZoomable(canvas, zoomable, e); } else if (plot instanceof PiePlot) { PiePlot pp = (PiePlot) plot; pp.handleMouseWheelRotation((int) e.getDeltaY()); } }
public void bindHboxEvents(){ hbox.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if(hbox.getLayoutX() >= -850) hbox.setLayoutX(hbox.getLayoutX() - 100); else{ hbox.setLayoutX(50); } System.out.println(hbox.getLayoutX()); } }); }
public YearPageSkin(YearPage view) { super(view); view.addEventFilter(ScrollEvent.SCROLL, this::handleScroll); view.displayModeProperty().addListener(it -> updateVisibility()); updateVisibility(); }
private void handleScroll(ScrollEvent evt) { YearPage yearPage = getSkinnable(); double delta = evt.getDeltaX(); if (delta == 0) { return; } if (delta < 0) { yearPage.goForward(); } else if (delta > 0) { yearPage.goBack(); } }
@Override @FXThread public boolean isInside(final double sceneX, final double sceneY, @NotNull final Class<? extends Event> eventType) { final Pane editorPage = getPage(); final Pane editor3DPage = get3DArea() == null ? editorPage : get3DArea(); final boolean only3D = eventType.isAssignableFrom(MouseEvent.class) || eventType.isAssignableFrom(ScrollEvent.class); final Pane page = only3D ? editor3DPage : editorPage; final Point2D point2D = page.sceneToLocal(sceneX, sceneY); return page.contains(point2D); }
/** * The process of scrolling. */ @FXThread private void processScroll(@NotNull final Spinner<Double> spinner, @NotNull final ScrollEvent event) { if (!event.isControlDown()) return; final double deltaY = event.getDeltaY(); if (deltaY > 0) { spinner.increment(1); } else { spinner.decrement(1); } }