Java Code Examples for javafx.scene.input.ScrollEvent#consume()

The following examples show how to use javafx.scene.input.ScrollEvent#consume() . 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: Fx3DStageController.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param event Zooms in and out when the mouse is scrolled.
 */
public void onScrollHandler(ScrollEvent event) {
  double delta = 1.2;
  double scale = (plot.getScaleX());

  if (event.getDeltaY() < 0) {
    scale /= delta;
  } else {
    scale *= delta;
  }

  scale = clamp(scale, MIN_SCALE, MAX_SCALE);

  plot.setScaleX(scale);
  plot.setScaleY(scale);

  event.consume();
}
 
Example 2
Source File: PlotCanvasBase.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** 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();
}
 
Example 3
Source File: Fx3DStageController.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param event
 *            Zooms in and out when the mouse is scrolled.
 */
public void onScrollHandler(ScrollEvent event) {
    double delta = 1.2;
    double scale = (plot.getScaleX());

    if (event.getDeltaY() < 0) {
        scale /= delta;
    } else {
        scale *= delta;
    }

    scale = clamp(scale, MIN_SCALE, MAX_SCALE);

    plot.setScaleX(scale);
    plot.setScaleY(scale);

    event.consume();
}
 
Example 4
Source File: WebViewEventDispatcher.java    From oim-fx with MIT License 5 votes vote down vote up
private void processScrollEvent(ScrollEvent ev) {
    if (page == null) {
        return;
    }
    double dx = - ev.getDeltaX() * webView.getFontScale() * webView.getScaleX();
    double dy = - ev.getDeltaY() * webView.getFontScale() * webView.getScaleY();
    WCMouseWheelEvent wheelEvent =
            new WCMouseWheelEvent((int)ev.getX(), (int)ev.getY(),
                (int)ev.getScreenX(), (int)ev.getScreenY(),
                System.currentTimeMillis(),
                ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(),
                ev.isMetaDown(), (float)dx, (float)dy);
    page.dispatchMouseWheelEvent(wheelEvent);
    ev.consume();
}
 
Example 5
Source File: ViewportGestures.java    From fxgraph with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public void handle(ScrollEvent event) {
	double scale = canvas.getScale(); // currently we only use Y, same value is used for X
	final double oldScale = scale;

	if(event.getDeltaY() < 0) {
		scale /= getZoomSpeed();
	} else if (event.getDeltaY() > 0) {
		scale *= getZoomSpeed();
	}

	scale = clamp(scale, minScaleProperty.get(), maxScaleProperty.get());
	final double f = (scale / oldScale) - 1;

	// maxX = right overhang, maxY = lower overhang
	final double maxX = canvas.getBoundsInParent().getMaxX() - canvas.localToParent(canvas.getPrefWidth(), canvas.getPrefHeight()).getX();
	final double maxY = canvas.getBoundsInParent().getMaxY() - canvas.localToParent(canvas.getPrefWidth(), canvas.getPrefHeight()).getY();

	// minX = left overhang, minY = upper overhang
	final double minX = canvas.localToParent(0, 0).getX() - canvas.getBoundsInParent().getMinX();
	final double minY = canvas.localToParent(0, 0).getY() - canvas.getBoundsInParent().getMinY();

	// adding the overhangs together, as we only consider the width of canvas itself
	final double subX = maxX + minX;
	final double subY = maxY + minY;

	// subtracting the overall overhang from the width and only the left and upper overhang from the upper left point
	final double dx = (event.getSceneX() - ((canvas.getBoundsInParent().getWidth() - subX) / 2 + (canvas.getBoundsInParent().getMinX() + minX)));
	final double dy = (event.getSceneY() - ((canvas.getBoundsInParent().getHeight() - subY) / 2 + (canvas.getBoundsInParent().getMinY() + minY)));

	canvas.setScale(scale);

	// note: pivot value must be untransformed, i. e. without scaling
	canvas.setPivot(f * dx, f * dy);

	event.consume();

}
 
Example 6
Source File: JFXZoomListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(ScrollEvent event) {
	if(!this.control.isIgnoreEvents()) {
		if( event.isControlDown() ) {
			this.onZoom(new UIZoomEvent(this.control, (event.getDeltaY() > 0 ? 1 : -1)));
			
			event.consume();
		}
	}
}
 
Example 7
Source File: JFXMouseWheelListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(ScrollEvent event) {
	if(!this.control.isIgnoreEvents()) {
		Integer button = JFXMouseButton.getMouseButton(MouseButton.MIDDLE);
		Integer value = (int) Math.round(event.getDeltaX() != 0 ? event.getDeltaX() : event.getDeltaY());
		this.onMouseWheel(new UIMouseWheelEvent(this.control, new UIPosition((float)event.getX(), (float)event.getY()), button, value));
		
		event.consume();
	}
}
 
Example 8
Source File: JFXScrollBarPanel.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void handle(ScrollEvent event) {
	this.control.onScroll((int) -Math.round(event.getDeltaX() != 0 ? event.getDeltaX() : event.getDeltaY()));
	
	event.consume();
}
 
Example 9
Source File: CellListManager.java    From Flowless with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Push scroll events received by cell nodes directly to
 * the 'owner' Node. (Generally likely to be a VirtualFlow
 * but not required.)
 *
 * Normal bubbling of scroll events gets interrupted during
 * a scroll gesture when the Cell's Node receiving the event
 * has moved out of the viewport and is thus removed from
 * the Navigator's children list. This breaks expected trackpad
 * scrolling behaviour, at least on macOS.
 * 
 * So here we take over event-bubbling duties for ScrollEvent
 * and push them ourselves directly to the given owner.
 */
private void pushScrollEvent(ScrollEvent se) {
    owner.fireEvent(se);
    se.consume();
}