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

The following examples show how to use java.awt.event.MouseWheelEvent#getPoint() . 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: NavigableImagePanel.java    From Ngram-Graphs with Apache License 2.0 6 votes vote down vote up
public void mouseWheelMoved(MouseWheelEvent e) {
	Point p = e.getPoint();
	boolean zoomIn = (e.getWheelRotation() < 0);
	if (isInNavigationImage(p)) {
		if (zoomIn) {
			navZoomFactor = 1.0 + zoomIncrement;
		} else {
			navZoomFactor = 1.0 - zoomIncrement;
		}
		zoomNavigationImage();
	} else if (isInImage(p)) {
		if (zoomIn) {
			zoomFactor = 1.0 + zoomIncrement;
		} else {
			zoomFactor = 1.0 - zoomIncrement;
		}
		zoomImage();
	}
}
 
Example 2
Source File: NavigableImagePanel.java    From Ngram-Graphs with Apache License 2.0 6 votes vote down vote up
public void mouseWheelMoved(MouseWheelEvent e) {
	Point p = e.getPoint();
	boolean zoomIn = (e.getWheelRotation() < 0);
	if (isInNavigationImage(p)) {
		if (zoomIn) {
			navZoomFactor = 1.0 + zoomIncrement;
		} else {
			navZoomFactor = 1.0 - zoomIncrement;
		}
		zoomNavigationImage();
	} else if (isInImage(p)) {
		if (zoomIn) {
			zoomFactor = 1.0 + zoomIncrement;
		} else {
			zoomFactor = 1.0 - zoomIncrement;
		}
		zoomImage();
	}
}
 
Example 3
Source File: NavigableImagePanel.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    if (image == null) {
        return;
    }
    Point p = e.getPoint();
    boolean zoomIn = (e.getWheelRotation() < 0);
    if (isInNavigationImage(p)) {
        if (zoomIn) {
            navZoomFactor = 1.0 + zoomIncrement;
        } else {
            navZoomFactor = 1.0 - zoomIncrement;
        }
        zoomNavigationImage();
    } else /*if (isInImage(p))*/ {
        zoomImage(zoomIn ? ZOOM_INC : 1 / ZOOM_INC);
    }
}
 
Example 4
Source File: MapViewer.java    From AMIDST with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	int notches = e.getWheelRotation();
	Point mouse = e.getPoint(); // Don't use getMousePosition() because when computer is swapping/grinding, mouse may have moved out of window before execution reaches here.
	for (Widget widget : widgets) {
		if ((widget.isVisible()) &&
			(mouse.x > widget.getX()) &&
			(mouse.y > widget.getY()) &&
			(mouse.x < widget.getX() + widget.getWidth()) &&
			(mouse.y < widget.getY() + widget.getHeight())) {
			if (widget.onMouseWheelMoved(mouse.x - widget.getX(), mouse.y - widget.getY(), notches))
				return;
		}
	}
	adjustZoom(getMousePosition(), notches);
}
 
Example 5
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 5 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
	// Translate along the Z-axis
	translationZ += e.getWheelRotation() * 0.25f;
	previousMousePosition = e.getPoint();
	updateModelviewMatrix();
}
 
Example 6
Source File: ViewerMouseListener.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	Point mousePosition = e.getPoint();
	int notches = e.getWheelRotation();
	if (!widgetManager.mouseWheelMoved(mousePosition, notches)) {
		doMouseWheelMoved(mousePosition, notches);
	}
}
 
Example 7
Source File: SimpleInteraction.java    From jcuda-samples with MIT License 5 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
    // Translate along the Z-axis
    translationZ += e.getWheelRotation() * 0.25f;
    previousMousePosition = e.getPoint();
    updateModelviewMatrix();
}
 
Example 8
Source File: PreviewPanel.java    From swingsane with Apache License 2.0 5 votes vote down vote up
@Override
public final void mouseWheelMoved(MouseWheelEvent e) {

  Point clickPoint = e.getPoint();

  JViewport viewport = ((JScrollPane) e.getSource()).getViewport();
  Point viewPosition = viewport.getViewPosition();

  // 1. Get viewport rectangle.
  Rectangle viewportRectangle = new Rectangle(viewPosition, viewport.getSize());

  // 2. Get the midpoint of the viewport.
  Point viewportMidpoint = getViewportMidpoint(viewport);

  // 3. calculate the distance from the click point to the midpoint
  int deltaX = (viewPosition.x + clickPoint.x) - viewportMidpoint.x;
  int deltaY = (viewPosition.y + clickPoint.y) - viewportMidpoint.y;

  // 4. translate the viewport rectangle
  viewportRectangle.translate(deltaX, deltaY);

  // 5. scroll the viewport to the new viewport rectangle position
  imagePreviewLabel.scrollRectToVisible(viewportRectangle);

  int notches = e.getWheelRotation();
  if (notches < 0) {
    zoomIn();
  } else {
    zoomOut();
  }

}
 
Example 9
Source File: ViewerMouseListener.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	Point mousePosition = e.getPoint();
	int notches = e.getWheelRotation();
	if (!widgetManager.mouseWheelMoved(mousePosition, notches)) {
		doMouseWheelMoved(mousePosition, notches);
	}
}