Class PlotMouseHandler

java.lang.Object
edu.cnu.mdi.splot.plot.PlotMouseHandler
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class PlotMouseHandler extends Object implements MouseListener, MouseMotionListener, MouseWheelListener
Handles all mouse interaction for a PlotCanvas.

This class was extracted from PlotCanvas to keep that class focused on coordinate geometry, painting, and data management. All MouseListener, MouseMotionListener, and MouseWheelListener logic lives here.

Responsibilities

Canvas coupling

The handler holds a reference back to its owning PlotCanvas for coordinate transforms, data access, and repaint requests. It does not hold any state that could not be reconstructed from the canvas.

Author:
heddle (original), refactored for extraction
See Also:
  • Constructor Details

    • PlotMouseHandler

      public PlotMouseHandler(PlotCanvas canvas)
      Creates a PlotMouseHandler bound to the given canvas.
      Parameters:
      canvas - the owning PlotCanvas (non-null)
  • Method Details

    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Handles drag events: moves the legend or the extra-text label if either is in the "dragging" state.
      Specified by:
      mouseDragged in interface MouseMotionListener
      Parameters:
      e - the mouse event
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Handles mouse-move events, updating the feedback pane with coordinate readouts and curve-specific information.

      Delegates to specialised private helpers depending on the current data type (2D histogram, bar plot, XY curves, 1D histogram).

      Specified by:
      mouseMoved in interface MouseMotionListener
      Parameters:
      e - the mouse event
    • mousePressed

      public void mousePressed(MouseEvent e)
      Primes the legend or extra-text label for dragging when the pointer tool is active and the mouse is pressed inside one of them.
      Specified by:
      mousePressed in interface MouseListener
      Parameters:
      e - the mouse event
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Ends any active drag on mouse release.
      Specified by:
      mouseReleased in interface MouseListener
      Parameters:
      e - the mouse event
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      No action.
      Specified by:
      mouseClicked in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      No action.
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      No action.
      Specified by:
      mouseExited in interface MouseListener
    • mouseWheelMoved

      public void mouseWheelMoved(MouseWheelEvent e)
      Zooms the canvas in or out using the scroll wheel.

      Base zoom factor is 1.12 per notch. Holding Ctrl/Meta gives finer control (1.04); holding Shift gives coarser control (1.20). The computed factor is clamped to [0.2, 5.0] as a safety net against runaway zooming.

      Specified by:
      mouseWheelMoved in interface MouseWheelListener
      Parameters:
      e - the mouse-wheel event