Java Code Examples for javafx.scene.input.ScrollEvent#SCROLL_STARTED

The following examples show how to use javafx.scene.input.ScrollEvent#SCROLL_STARTED . 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 sendScrollEventToFX(EventType<ScrollEvent> eventType,
		double scrollX, double scrollY, int x, int y, int stateMask,
		boolean inertia) {
	// up to and including SWT 4.5, direction was inverted for pan
	// gestures on the Mac
	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=481331)
	final double multiplier = ("cocoa".equals(SWT.getPlatform())
			&& SWT.getVersion() < 4600) ? -5.0 : 5.0;

	if (eventType == ScrollEvent.SCROLL_STARTED) {
		totalScrollX = 0;
		totalScrollY = 0;
	} else if (inertia) {
		// inertia events do not belong to the gesture,
		// thus total scroll is not accumulated
		totalScrollX = scrollX;
		totalScrollY = scrollY;
	} else {
		// accumulate total scroll as long as the gesture occurs
		totalScrollX += scrollX;
		totalScrollY += scrollY;
	}

	final Point los = toDisplay(x, y);
	scheduleSceneRunnable(new ISceneRunnable() {
		@Override
		public void run(TKSceneListenerWrapper sceneListener) {
			sceneListener.scrollEvent(eventType, scrollX, scrollY,
					totalScrollX, totalScrollY, multiplier, multiplier,
					0, 0, 0, 0, 0, x, y, los.x, los.y,
					(stateMask & SWT.SHIFT) != 0,
					(stateMask & SWT.CONTROL) != 0,
					(stateMask & SWT.ALT) != 0,
					(stateMask & SWT.COMMAND) != 0, false, inertia);
		}
	});
}
 
Example 2
Source File: ChartZoomManager.java    From jfxutils with Apache License 2.0 4 votes vote down vote up
@Override
public void handle( ScrollEvent event ) {
	EventType<? extends Event> eventType = event.getEventType();
	if ( eventType == ScrollEvent.SCROLL_STARTED ) {
		//mouse wheel events never send SCROLL_STARTED
		ignoring = true;
	} else if ( eventType == ScrollEvent.SCROLL_FINISHED ) {
		//end non-mouse wheel event
		ignoring = false;

	} else if ( eventType == ScrollEvent.SCROLL &&
	            //If we are allowing mouse wheel zooming
	            mouseWheelZoomAllowed.get() &&
	            //If we aren't between SCROLL_STARTED and SCROLL_FINISHED
	            !ignoring &&
	            //inertia from non-wheel gestures might have touch count of 0
	            !event.isInertia() &&
	            //Only care about vertical wheel events
	            event.getDeltaY() != 0 &&
	            //mouse wheel always has touch count of 0
	            event.getTouchCount() == 0 ) {

		//Find out which axes to zoom based on the strategy
		double eventX = event.getX();
		double eventY = event.getY();
		DefaultChartInputContext context = new DefaultChartInputContext( chartInfo, eventX, eventY );
		AxisConstraint zoomMode = mouseWheelAxisConstraintStrategy.getConstraint( context );

		if ( zoomMode == AxisConstraint.None )
			return;

		//If we are are doing a zoom animation, stop it. Also of note is that we don't zoom the
		//mouse wheel zooming. Because the mouse wheel can "fly" and generate a lot of events,
		//animation doesn't work well. Plus, as the mouse wheel changes the view a small amount in
		//a predictable way, it "looks like" an animation when you roll it.
		//We might experiment with mouse wheel zoom animation in the future, though.
		zoomAnimation.stop();

		//At this point we are a mouse wheel event, based on everything I've read
		Point2D dataCoords = chartInfo.getDataCoordinates( eventX, eventY );

		//Determine the proportion of change to the lower and upper bounds based on how far the
		//cursor is along the axis.
		double xZoomBalance = getBalance( dataCoords.getX(),
		                                  getXAxisLowerBound(), getXAxisUpperBound() );
		double yZoomBalance = getBalance( dataCoords.getY(),
		                                  getYAxisLowerBound(), getYAxisUpperBound() );

		//Are we zooming in or out, based on the direction of the roll
		double direction = -Math.signum( event.getDeltaY() );

		//TODO: Do we need to handle "continuous" scroll wheels that don't work based on ticks?
		//If so, the 0.2 needs to be modified
		double zoomAmount = 0.2 * direction;

		if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Horizontal ) {
			double xZoomDelta = ( getXAxisUpperBound() - getXAxisLowerBound() ) * zoomAmount;
			xAxis.setAutoRanging( false );
			setXAxisLowerBound( getXAxisLowerBound() - xZoomDelta * xZoomBalance );
			setXAxisUpperBound( getXAxisUpperBound() + xZoomDelta * ( 1 - xZoomBalance ) );
		}

		if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Vertical ) {
			double yZoomDelta = ( getYAxisUpperBound() - getYAxisLowerBound() ) * zoomAmount;
			yAxis.setAutoRanging( false );
			setYAxisLowerBound( getYAxisLowerBound() - yZoomDelta * yZoomBalance );
			setYAxisUpperBound( getYAxisUpperBound() + yZoomDelta * ( 1 - yZoomBalance ) );
		}
	}
}