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

The following examples show how to use javafx.scene.input.ScrollEvent#getX() . 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: ScrollHandlerFX.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 2
Source File: Zoomer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
private static void zoomOnAxis(final Axis axis, final ScrollEvent event) {
    if (hasBoundedRange(axis)) {
        return;
    }
    final boolean isZoomIn = event.getDeltaY() > 0;
    final boolean isHorizontal = axis.getSide().isHorizontal();

    final double mousePos = isHorizontal ? event.getX() : event.getY();
    final double posOnAxis = axis.getValueForDisplay(mousePos);
    final double max = axis.getMax();
    final double min = axis.getMin();
    final double scaling = isZoomIn ? 0.9 : 1 / 0.9;
    final double diffHalf1 = scaling * Math.abs(posOnAxis - min);
    final double diffHalf2 = scaling * Math.abs(max - posOnAxis);

    axis.set(posOnAxis - diffHalf1, posOnAxis + diffHalf2);

    axis.forceRedraw();
}
 
Example 3
Source File: TaScrollHandlerFX.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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(TaChartCanvas canvas, Zoomable zoomable,
                            ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's org.sjwimmer.tacharting.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
    }
}
 
Example 4
Source File: ScrollHandlerFX.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 5
Source File: ScrollHandlerFX.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 6
Source File: ScrollHandlerFX.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 7
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 8
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
    } 
}
 
Example 9
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 10
Source File: ScrollHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param canvas  the chart canvas.
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, 
        ScrollEvent e) {
	if (canvas.getChart() == null) {
	    return;
	}
    // 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
    } 
}
 
Example 11
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 ) );
		}
	}
}