protected void processMouseWheelEvent(MouseWheelEvent e) { MouseWheelEvent transformedEvent = (MouseWheelEvent) transformMouseEvent(e); MouseWheelListener[] mouseWheelListeners = transformedEvent.getComponent().getMouseWheelListeners(); for (MouseWheelListener listener : mouseWheelListeners) { listener.mouseWheelMoved(transformedEvent); } super.processMouseWheelEvent(e); }
private MouseEvent transformMouseEvent(MouseEvent event) { if (event == null) { throw new IllegalArgumentException("MouseEvent is null"); } MouseEvent newEvent; if (event instanceof MouseWheelEvent) { MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event; newEvent = new MouseWheelEvent( mouseWheelEvent.getComponent(), mouseWheelEvent.getID(), mouseWheelEvent.getWhen(), mouseWheelEvent.getModifiers(), mouseWheelEvent.getX(), mouseWheelEvent.getY(), mouseWheelEvent.getClickCount(), mouseWheelEvent.isPopupTrigger(), mouseWheelEvent.getScrollType(), mouseWheelEvent.getScrollAmount(), mouseWheelEvent.getWheelRotation()); } else { newEvent = new MouseEvent( event.getComponent(), event.getID(), event.getWhen(), event.getModifiers(), event.getX(), event.getY(), event.getClickCount(), event.isPopupTrigger(), event.getButton()); } if (view != null && at.getDeterminant() != 0) { Rectangle viewBounds = getTransformedSize(); Insets insets = JXTransformer.this.getInsets(); int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2; int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2; double x = newEvent.getX() + viewBounds.getX() - insets.left; double y = newEvent.getY() + viewBounds.getY() - insets.top; Point2D p = new Point2D.Double(x - xgap, y - ygap); Point2D tp; try { tp = at.inverseTransform(p, null); } catch (NoninvertibleTransformException ex) { // can't happen, we check it before throw new AssertionError("NoninvertibleTransformException"); } // Use transformed coordinates to get the current component mouseCurrentComponent = SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY()); if (mouseCurrentComponent == null) { mouseCurrentComponent = JXTransformer.this; } Component tempComponent = mouseCurrentComponent; if (mouseDraggedComponent != null) { tempComponent = mouseDraggedComponent; } Point point = SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent); newEvent.setSource(tempComponent); newEvent.translatePoint(point.x - event.getX(), point.y - event.getY()); } return newEvent; }