Java Code Examples for java.awt.event.MouseWheelEvent#getWheelRotation()

The following examples show how to use java.awt.event.MouseWheelEvent#getWheelRotation() . 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: ScrollPaneWheelScroller.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static int getIncrementFromAdjustable(Adjustable adj,
                                             MouseWheelEvent e) {
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        if (adj == null) {
            log.fine("Assertion (adj != null) failed");
        }
    }

    int increment = 0;

    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        increment = e.getUnitsToScroll() * adj.getUnitIncrement();
    }
    else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
        increment = adj.getBlockIncrement() * e.getWheelRotation();
    }
    return increment;
}
 
Example 2
Source File: ScrollPaneWheelScroller.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int getIncrementFromAdjustable(Adjustable adj,
                                             MouseWheelEvent e) {
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        if (adj == null) {
            log.fine("Assertion (adj != null) failed");
        }
    }

    int increment = 0;

    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        increment = e.getUnitsToScroll() * adj.getUnitIncrement();
    }
    else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
        increment = adj.getBlockIncrement() * e.getWheelRotation();
    }
    return increment;
}
 
Example 3
Source File: Input.java    From lizzie with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (Lizzie.frame.processCommentMouseWheelMoved(e)) {
    return;
  }
  if (e.getWhen() - wheelWhen > 0) {
    wheelWhen = e.getWhen();
    if (Lizzie.board.inAnalysisMode()) Lizzie.board.toggleAnalysis();
    if (e.getWheelRotation() > 0) {
      if (Lizzie.frame.isMouseOver) {
        Lizzie.frame.doBranch(1);
      } else {
        redo();
      }
    } else if (e.getWheelRotation() < 0) {
      if (Lizzie.frame.isMouseOver) {
        Lizzie.frame.doBranch(-1);
      } else {
        undo();
      }
    }
    Lizzie.frame.refresh();
  }
}
 
Example 4
Source File: WorldMapPane.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    if (!isEnabled()) {
        return;
    }
    double oldFactor = layerCanvas.getViewport().getZoomFactor();
    final int wheelRotation = e.getWheelRotation();
    final double newZoomFactor = layerCanvas.getViewport().getZoomFactor() * Math.pow(1.1, wheelRotation);
    final Rectangle viewBounds = layerCanvas.getViewport().getViewBounds();
    final Rectangle2D modelBounds = worldMapLayer.getModelBounds();
    final double minZoomFactor = Math.min(viewBounds.getWidth() / modelBounds.getWidth(),
                                          viewBounds.getHeight() / modelBounds.getHeight());
    layerCanvas.getViewport().setZoomFactor(Math.max(newZoomFactor, minZoomFactor));

    if (layerCanvas.getViewport().getZoomFactor() > oldFactor
            || viewportIsInWorldMapBounds(0, 0, layerCanvas)) {
        fireScrolled();
        return;
    }
    layerCanvas.getViewport().setZoomFactor(oldFactor);
}
 
Example 5
Source File: InstanceMapInputListener.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event)
{
	if (!overlay.isMapShown() || isNotWithinOverlay(event.getPoint()))
	{
		return event;
	}

	int direction = event.getWheelRotation();

	if (direction > 0)
	{
		plugin.ascendMap();
	}
	else
	{
		plugin.descendMap();
	}

	event.consume();
	return event;
}
 
Example 6
Source File: ScrollPaneWheelScroller.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int getIncrementFromAdjustable(Adjustable adj,
                                             MouseWheelEvent e) {
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        if (adj == null) {
            log.fine("Assertion (adj != null) failed");
        }
    }

    int increment = 0;

    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        increment = e.getUnitsToScroll() * adj.getUnitIncrement();
    }
    else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
        increment = adj.getBlockIncrement() * e.getWheelRotation();
    }
    return increment;
}
 
Example 7
Source File: JSliderMW.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	boolean up = e.getWheelRotation() > 0;
	int delta = (minorTickSpacing == 0) ? majorTickSpacing : minorTickSpacing;
	int value = this.getValue();
	value = up ?
		Math.max(
			this.getMinimum(),
			value - delta
		)
	:
		Math.min(
			value + delta,
			this.getMaximum()
		)
	;
	this.setValue(value);
}
 
Example 8
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override protected void processMouseWheelEvent(MouseWheelEvent e, JLayer<? extends JScrollPane> l) {
  Component c = e.getComponent();
  int dir = e.getWheelRotation();
  JScrollPane main = l.getView();
  if (c instanceof JScrollPane && !c.equals(main)) {
    JScrollPane child = (JScrollPane) c;
    BoundedRangeModel m = child.getVerticalScrollBar().getModel();
    int extent = m.getExtent();
    int minimum = m.getMinimum();
    int maximum = m.getMaximum();
    int value = m.getValue();
    boolean b1 = dir > 0 && value + extent >= maximum;
    boolean b2 = dir < 0 && value <= minimum;
    if (b1 || b2) {
      main.dispatchEvent(SwingUtilities.convertMouseEvent(c, e, main));
    }
  }
}
 
Example 9
Source File: ListHelper.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean doWheelScroll(XVerticalScrollbar vsb,
                                 XHorizontalScrollbar hsb,
                                 MouseWheelEvent e) {
    XScrollbar scroll = null;
    int wheelRotation;

    // Determine which, if any, sb to scroll
    if (vsb != null) {
        scroll = vsb;
    }
    else if (hsb != null) {
        scroll = hsb;
    }
    else { // Neither scrollbar is showing
        return false;
    }

    wheelRotation = e.getWheelRotation();

    // Check if scroll is necessary
    if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
        (wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
        wheelRotation != 0) {

        int type = e.getScrollType();
        int incr;
        if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
            incr = wheelRotation * scroll.getBlockIncrement();
        }
        else { // type is WHEEL_UNIT_SCROLL
            incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
        }
        scroll.setValue(scroll.getValue() + incr);
        return true;
    }
    return false;
}
 
Example 10
Source File: PDControlScrollPane.java    From Decoder-Improved with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    JScrollPane parent = getParentScrollPane();
    if (parent != null) {
        /*
         * Only dispatch if we have reached top/bottom on previous scroll
         */
        if (e.getWheelRotation() < 0) {
            // If vertical scroll bar exists
            if (getMax(verticalBar) > 0) {
                if (verticalBar.getValue() == 0 && verticalPreviousValue == 0) {
                    parent.dispatchEvent(cloneEvent(e));
                }
            } else if (horizontalBar.getValue() == 0 && horizontalPreviousValue == 0) {
                parent.dispatchEvent(cloneEvent(e));
            }

        } else {
            // If vertical scroll bar exists
            if (getMax(verticalBar) > 0) {
                if (verticalBar.getValue() == getMax(verticalBar) && verticalPreviousValue == getMax(verticalBar)) {
                    parent.dispatchEvent(cloneEvent(e));
                }
            } else if (horizontalBar.getValue() == getMax(horizontalBar) && horizontalPreviousValue == getMax(horizontalBar)) {
                parent.dispatchEvent(cloneEvent(e));
            }
        }
        horizontalPreviousValue = horizontalBar.getValue();
        verticalPreviousValue = verticalBar.getValue();
    }
    /*
     * If parent scrollpane doesn't exist, remove this as a listener.
     * We have to defer this till now (vs doing it in constructor)
     * because in the constructor this item has no parent yet.
     */
    else {
        PDControlScrollPane.this.removeMouseWheelListener(this);
    }
}
 
Example 11
Source File: Java3DEditor.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
private void mouseWheel(MouseWheelEvent e) {
    if (!e.isControlDown()) {
        if (e.getWheelRotation() < 0 && currentLayer < maxLayer - 1) {
            currentLayer++;
        }
        if (e.getWheelRotation() > 0 && currentLayer > 0) {
            currentLayer--;
        }

        setCurrentLayer(currentLayer);
    } else {
        scaleByAmount(e.getUnitsToScroll() * -0.1);
    }
}
 
Example 12
Source File: MouseWheelHandler.java    From openstock with GNU General Public License v3.0 5 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(Zoomable zoomable, MouseWheelEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
    if (!pinfo.getDataArea().contains(p)) {
        return;
    }

    Plot plot = (Plot) zoomable;
    // do not notify while zooming each axis
    boolean notifyState = plot.isNotify();
    plot.setNotify(false);
    int clicks = e.getWheelRotation();
    double zf = 1.0 + this.zoomFactor;
    if (clicks < 0) {
        zf = 1.0 / zf;
    }
    if (chartPanel.isDomainZoomable()) {
        zoomable.zoomDomainAxes(zf, pinfo, p, true);
    }
    if (chartPanel.isRangeZoomable()) {
        zoomable.zoomRangeAxes(zf, pinfo, p, true);
    }
    plot.setNotify(notifyState);  // this generates the change event too
}
 
Example 13
Source File: ListHelper.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean doWheelScroll(XVerticalScrollbar vsb,
                                 XHorizontalScrollbar hsb,
                                 MouseWheelEvent e) {
    XScrollbar scroll = null;
    int wheelRotation;

    // Determine which, if any, sb to scroll
    if (vsb != null) {
        scroll = vsb;
    }
    else if (hsb != null) {
        scroll = hsb;
    }
    else { // Neither scrollbar is showing
        return false;
    }

    wheelRotation = e.getWheelRotation();

    // Check if scroll is necessary
    if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
        (wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
        wheelRotation != 0) {

        int type = e.getScrollType();
        int incr;
        if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
            incr = wheelRotation * scroll.getBlockIncrement();
        }
        else { // type is WHEEL_UNIT_SCROLL
            incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
        }
        scroll.setValue(scroll.getValue() + incr);
        return true;
    }
    return false;
}
 
Example 14
Source File: ListHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static boolean doWheelScroll(XVerticalScrollbar vsb,
                                 XHorizontalScrollbar hsb,
                                 MouseWheelEvent e) {
    XScrollbar scroll = null;
    int wheelRotation;

    // Determine which, if any, sb to scroll
    if (vsb != null) {
        scroll = vsb;
    }
    else if (hsb != null) {
        scroll = hsb;
    }
    else { // Neither scrollbar is showing
        return false;
    }

    wheelRotation = e.getWheelRotation();

    // Check if scroll is necessary
    if ((wheelRotation < 0 && scroll.getValue() > scroll.getMinimum()) ||
        (wheelRotation > 0 && scroll.getValue() < scroll.getMaximum()) ||
        wheelRotation != 0) {

        int type = e.getScrollType();
        int incr;
        if (type == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
            incr = wheelRotation * scroll.getBlockIncrement();
        }
        else { // type is WHEEL_UNIT_SCROLL
            incr = e.getUnitsToScroll() * scroll.getUnitIncrement();
        }
        scroll.setValue(scroll.getValue() + incr);
        return true;
    }
    return false;
}
 
Example 15
Source File: GanttPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
	if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) {
		return;
	}
	if (e.getWheelRotation() < 0) {
		zoomChartAxis(e.getPoint(), true);
	} else {
		zoomChartAxis(e.getPoint(), false);
	}
}
 
Example 16
Source File: MouseWheelHandler.java    From ECG-Viewer with GNU General Public License v2.0 5 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(Zoomable zoomable, MouseWheelEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
    if (!pinfo.getDataArea().contains(p)) {
        return;
    }

    Plot plot = (Plot) zoomable;
    // do not notify while zooming each axis
    boolean notifyState = plot.isNotify();
    plot.setNotify(false);
    int clicks = e.getWheelRotation();
    double zf = 1.0 + this.zoomFactor;
    if (clicks < 0) {
        zf = 1.0 / zf;
    }
    if (chartPanel.isDomainZoomable()) {
        zoomable.zoomDomainAxes(zf, pinfo, p, true);
    }
    if (chartPanel.isRangeZoomable()) {
        zoomable.zoomRangeAxes(zf, pinfo, p, true);
    }
    plot.setNotify(notifyState);  // this generates the change event too
}
 
Example 17
Source File: DesktopEditorMarkupModelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void mouseWheelMoved(MouseWheelEvent e) {
  if (myEditorPreviewHint == null) return;
  myWheelAccumulator += (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ? e.getUnitsToScroll() * e.getScrollAmount() : e.getWheelRotation() < 0 ? -e.getScrollAmount() : e.getScrollAmount());
  myRowAdjuster = myWheelAccumulator / myEditor.getLineHeight();
  showToolTipByMouseMove(e);
}
 
Example 18
Source File: GamePanel.java    From epic-inventor with GNU General Public License v2.0 4 votes vote down vote up
private void processMouseWheelMove(MouseWheelEvent e) {
    int steps = e.getWheelRotation();

    gameController.handleMouseScroll(steps);
}
 
Example 19
Source File: ChartPanel.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
void onMouseWheelMoved(MouseWheelEvent e) {
    Plot plt = selPlot(e.getX(), e.getY());
    if (!(plt instanceof AbstractPlot2D)) {
        return;
    }

    double minX, maxX, minY, maxY, lonRan, latRan, zoomF;
    double mouseLon, mouseLat;
    Extent drawExtent = ((AbstractPlot2D) plt).getDrawExtent();
    lonRan = drawExtent.maxX - drawExtent.minX;
    latRan = drawExtent.maxY - drawExtent.minY;
    mouseLon = drawExtent.minX + lonRan / 2;
    mouseLat = drawExtent.minY + latRan / 2;

    zoomF = 1 + e.getWheelRotation() / 10.0f;

    minX = mouseLon - (lonRan / 2 * zoomF);
    maxX = mouseLon + (lonRan / 2 * zoomF);
    minY = mouseLat - (latRan / 2 * zoomF);
    maxY = mouseLat + (latRan / 2 * zoomF);
    switch (this.mouseMode) {
        case PAN:
            if (plt instanceof MapPlot) {
                MapPlot mplt = (MapPlot) plt;
                Graphics2D g = (Graphics2D) this.getGraphics();
                Rectangle2D mapRect = mplt.getGraphArea();
                
                this.lastMouseWheelTime = LocalDateTime.now();
                if (!this.mouseWheelDetctionTimer.isRunning()) {
                    this.mouseWheelDetctionTimer.start();
                    tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
                        (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D tg = tempImage.createGraphics();
                    tg.setColor(Color.white);
                    tg.fill(mapRect);
                    tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
                    tg.dispose();
                }
                
                g.setClip(mapRect);
                g.setColor(Color.white);
                //g.clearRect((int)mapRect.getX(), (int)mapRect.getY(), (int)mapRect.getWidth(), (int)mapRect.getHeight());
                paintScale = paintScale / zoomF;
                float nWidth = (float)mapRect.getWidth() * (float) paintScale;
                float nHeight = (float)mapRect.getHeight() * (float) paintScale;
                float nx = ((float)mapRect.getWidth() - nWidth) / 2;
                float ny = ((float)mapRect.getHeight() - nHeight) / 2;
                if (nx > 0) {
                    g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
                    g.fillRect((int) (mapRect.getMaxX() - nx), (int) mapRect.getY(), (int)nx, (int) mapRect.getHeight());
                }
                if (ny > 0) {
                    g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), (int)ny);
                    g.fillRect((int) mapRect.getX(), (int) (mapRect.getMaxY() - ny), (int) mapRect.getWidth(), (int)ny);
                } 
                g.drawImage(tempImage, (int)(mapRect.getX() + nx), (int)(mapRect.getY() + ny), 
                        (int)nWidth, (int)nHeight, null);       
                g.setColor(this.getForeground());
                g.draw(mapRect);
                mplt.setDrawExtent(new Extent(minX, maxX, minY, maxY));
            } else {
                ((AbstractPlot2D) plt).setDrawExtent(new Extent(minX, maxX, minY, maxY));
                //this.paintGraphics();
                this.repaintNew();
            }
            break;
    }
}
 
Example 20
Source File: ProcessPanelScroller.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
	if (e.isControlDown() && e.getWheelRotation() != 0) {
		double oldZoomFactor = rendererView.getModel().getZoomFactor();
		if (e.getWheelRotation() < 0) {
			rendererView.getModel().zoomIn();
		} else {
			rendererView.getModel().zoomOut();
		}
		rendererView.getModel().fireProcessZoomChanged();

		// calculate how the scrollbar needs to be adjusted for centered zoom
		double relativeZoomFactor = rendererView.getModel().getZoomFactor() / oldZoomFactor;
		double differenceHorizontal = e.getPoint().getX() * (relativeZoomFactor - 1);
		double differenceVertical = e.getPoint().getY() * (relativeZoomFactor - 1);

		int newX = Math.max(0, (int) (scrollPane.getHorizontalScrollBar().getValue() + differenceHorizontal));
		int newY = Math.max(0, (int) (scrollPane.getVerticalScrollBar().getValue() + differenceVertical));

		scrollPane.getHorizontalScrollBar().setValue(newX);
		scrollPane.getVerticalScrollBar().setValue(newY);

		// prevent flickering when another adjustment of the scrollbars is needed
		RepaintManager.currentManager(scrollPane).markCompletelyClean(scrollPane);

		/**
		 * Setting the value as above does not always work since the scrollbars are not yet
		 * updated to the size changes caused by the zooming. Set flag an values to try
		 * again after the resizing happened.
		 */
		zoomed = true;
		desiredVerticalScrollValue = newY;
		desiredHorizontalScrollValue = newX;
		return;
	}

	Container p = rendererView.getParent();
	if (p != null) {
		p.dispatchEvent(SwingUtilities.convertMouseEvent(rendererView, e, p));
	}
}