javafx.scene.input.ZoomEvent Java Examples

The following examples show how to use javafx.scene.input.ZoomEvent. 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: FXCanvasEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void sendZoomEventToFX(EventType<ZoomEvent> eventType,
		GestureEvent gestureEvent) {
	Point los = toDisplay(gestureEvent.x, gestureEvent.y);

	double[] totalZoom = new double[] { gestureEvent.magnification };
	if (eventType == ZoomEvent.ZOOM_STARTED) {
		// ensure first event does not provide any zoom yet
		totalZoom[0] = lastTotalZoom = 1.0;
	} else if (eventType == ZoomEvent.ZOOM_FINISHED) {
		// SWT uses 0.0 for final event, while JavaFX still provides a
		// (total) zoom value
		totalZoom[0] = lastTotalZoom;
	}
	final double zoom = eventType == ZoomEvent.ZOOM_FINISHED ? 1.0
			: totalZoom[0] / lastTotalZoom;
	lastTotalZoom = totalZoom[0];

	final boolean inertia = !gestureActive;
	scheduleSceneRunnable(new ISceneRunnable() {
		@Override
		public void run(TKSceneListenerWrapper sceneListener) {
			sceneListener.zoomEvent(eventType, zoom, totalZoom[0],
					gestureEvent.x, gestureEvent.y, los.x, los.y,
					(gestureEvent.stateMask & SWT.SHIFT) != 0,
					(gestureEvent.stateMask & SWT.CONTROL) != 0,
					(gestureEvent.stateMask & SWT.ALT) != 0,
					(gestureEvent.stateMask & SWT.COMMAND) != 0, false,
					inertia);
		}
	});
}
 
Example #2
Source File: ZoomOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endZoom(ZoomEvent event) {
	if (invalidGesture) {
		return;
	}
	ITransactionalOperation commit = getViewportPolicy().commit();
	if (commit != null && !commit.isNoOp()) {
		try {
			getHost().getRoot().getViewer().getDomain().execute(commit,
					new NullProgressMonitor());
		} catch (ExecutionException e) {
			throw new RuntimeException(e);
		}
	}
}
 
Example #3
Source File: ZoomOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void startZoom(ZoomEvent event) {
	invalidGesture = !isZoom(event);
	if (invalidGesture) {
		return;
	}
	viewportPolicy = determineViewportPolicy();
	viewportPolicy.init();
}
 
Example #4
Source File: ZoomOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void zoom(ZoomEvent event) {
	if (invalidGesture) {
		return;
	}
	// compute zoom factor from the given event
	double zoomFactor = computeZoomFactor(event);
	if (isContentRestricted()) {
		// Ensure content is aligned with the viewport on the left and top
		// sides if there is free space on these sides and the content fits
		// into the viewport
		panningSupport.removeFreeSpace(viewportPolicy, Pos.TOP_LEFT, true);
		// calculate a pivot points to achieve a zooming similar to that of
		// a text editor (fix absolute content left in x-direction, fix
		// visible content top in y-direction)
		InfiniteCanvas infiniteCanvas = ((InfiniteCanvasViewer) getHost()
				.getRoot().getViewer()).getCanvas();
		// XXX: The pivot point computation needs to be done after free
		// space top/left is removed so that the content-bounds minX
		// coordinate is correct.
		Point2D pivotPointInScene = infiniteCanvas.localToScene(
				infiniteCanvas.getContentBounds().getMinX(), 0);
		// performing zooming
		viewportPolicy.zoom(true, true, zoomFactor,
				pivotPointInScene.getX(), pivotPointInScene.getY());
		// Ensure content is aligned with the viewport on the right and
		// bottom sides if there is free space on these sides and the
		// content does not fit into the viewport
		panningSupport.removeFreeSpace(viewportPolicy, Pos.BOTTOM_RIGHT,
				false);
	} else {
		// zoom into/out-of the event location
		viewportPolicy.zoom(true, true, zoomFactor, event.getSceneX(),
				event.getSceneY());
	}
}
 
Example #5
Source File: MnistImageView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addListeners() {
    this.addEventHandler(MouseEvent.MOUSE_PRESSED, pressedHandler);
    this.addEventHandler(MouseEvent.MOUSE_DRAGGED, draggedHandler);
    this.addEventHandler(MouseEvent.MOUSE_RELEASED, releasedHandler);
    
    if (Platform.isDesktop()) {
        this.addEventHandler(ScrollEvent.ANY, scrollHandler);
    } else {
        this.addEventHandler(ZoomEvent.ZOOM_STARTED, zoomStartedHandler);
        this.addEventHandler(ZoomEvent.ZOOM_FINISHED, zoomFinishedHandler);
        this.addEventHandler(ZoomEvent.ZOOM, zoomHandler);
    }
}
 
Example #6
Source File: MnistImageView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void removeListeners() {
    this.removeEventHandler(MouseEvent.MOUSE_PRESSED, pressedHandler);
    this.removeEventHandler(MouseEvent.MOUSE_DRAGGED, draggedHandler);
    this.removeEventHandler(MouseEvent.MOUSE_RELEASED, releasedHandler);
    if (Platform.isDesktop()) {
        this.removeEventHandler(ScrollEvent.ANY, scrollHandler);
    } else {
        this.removeEventHandler(ZoomEvent.ZOOM_STARTED, zoomStartedHandler);
        this.removeEventHandler(ZoomEvent.ZOOM_FINISHED, zoomFinishedHandler);
        this.removeEventHandler(ZoomEvent.ZOOM, zoomHandler);
    }
}
 
Example #7
Source File: PinchSpreadGesture.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void doHookScene(Scene scene) {
	EventHandler<ZoomEvent> zoomFilter = createZoomFilter(scene);
	scene.addEventFilter(ZoomEvent.ANY, zoomFilter);
	zoomFilters.put(scene, zoomFilter);
}
 
Example #8
Source File: PinchSpreadGesture.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void doUnhookScene(Scene scene) {
	scene.removeEventFilter(ZoomEvent.ANY, zoomFilters.remove(scene));
}
 
Example #9
Source File: IOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Reaction to the finish of pinch (close fingers) gestures.
 *
 * @param e
 *            The original {@link ZoomEvent}.
 */
void endZoom(ZoomEvent e);
 
Example #10
Source File: IOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Reaction to the detection of pinch (close fingers) gestures.
 *
 * @param e
 *            The original {@link ZoomEvent}.
 */
void startZoom(ZoomEvent e);
 
Example #11
Source File: IOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Continuous reaction to pinch (close fingers) gestures. Called
 * continuously on finger movement, after the gesture has been detected, and
 * before it has been finished.
 *
 * @param e
 *            The original {@link ZoomEvent}.
 */
void zoom(ZoomEvent e);
 
Example #12
Source File: ZoomOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Computes the zoom factor from the given {@link ZoomEvent}.
 *
 * @param event
 *            The {@link ZoomEvent} from which to compute the zoom factor.
 * @return The zoom factor according to the given {@link ZoomEvent}.
 */
protected double computeZoomFactor(ZoomEvent event) {
	return event.getZoomFactor();
}
 
Example #13
Source File: ZoomOnPinchSpreadHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns whether the given {@link ZoomEvent} should trigger zooming. Per
 * default, will always return <code>true</code>.
 *
 * @param event
 *            The {@link ZoomEvent} in question.
 * @return <code>true</code> if the given {@link ZoomEvent} should trigger
 *         zoom, otherwise <code>false</code>.
 */
protected boolean isZoom(ZoomEvent event) {
	return true;
}
 
Example #14
Source File: SizableImageView.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Handle a zoom event.
 *
 * @param event
 *            The zoom event.
 */
private void handleZoomEvent(final ZoomEvent event) {
	if (!Double.isNaN(event.getZoomFactor())) {
		zoomImage(event.getZoomFactor());
	}
}