Skip to content

Commit

Permalink
chore: Mouse wheel events on the scroll pane are no properly tracked
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed May 7, 2024
1 parent bbff974 commit e8df750
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.Area;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -1553,7 +1554,8 @@ public void zoom(@NotNull ZoomTarget<@NotNull T> zoomTarget) {
* @param <T>
* @see FlamegraphView.HoverListener
*/
private static class FlamegraphHoveringScrollPaneMouseListener<T> implements MouseInputListener, FocusListener {
private static class FlamegraphHoveringScrollPaneMouseListener<T>
implements MouseInputListener, MouseWheelListener, FocusListener {
private Point pressedPoint;
private final FlamegraphCanvas<T> canvas;
private Rectangle hoveredFrameRectangle;
Expand Down Expand Up @@ -1671,6 +1673,15 @@ public void mouseExited(@NotNull MouseEvent e) {

@Override
public void mouseMoved(@NotNull MouseEvent e) {
handleMouseLocationChange(e);
}

@Override
public void mouseWheelMoved(@NotNull MouseWheelEvent e) {
handleMouseLocationChange(e);
}

private void handleMouseLocationChange(@NotNull MouseEvent e) {
var latestMouseLocation = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(latestMouseLocation, canvas);

Expand Down Expand Up @@ -1760,6 +1771,9 @@ public void install(@NotNull JScrollPane sp) {
sp.addMouseListener(this);
sp.addMouseMotionListener(this);
sp.addFocusListener(this);
// impl note, mouse wheel listener should be added on the scroll pane
// otherwise the scroll pane don't receive wheel events
sp.addMouseWheelListener(this);
}
}

Expand Down

0 comments on commit e8df750

Please sign in to comment.