Class MouseTracker

  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener, javax.swing.event.MouseInputListener

    public class MouseTracker
    extends javax.swing.event.MouseInputAdapter
    A MouseTracker is used to delegate mouse events to the FSMouseListener instances associated with a BasicPanel. The tracker will start receiving events as soon as the first listener is added (via addListener(FSMouseListener) and will stop receiving events as soon as the last listener is removed via removeListener(FSMouseListener). This binding is handled automatically via the add and remove methods and the tracker will remain active as long as the tracker has at least one listener. The MouseTracker is also responsible for using MouseEvent coordinates to located the Box on which the mouse is acting.
    • Constructor Summary

      Constructors 
      Constructor Description
      MouseTracker​(BasicPanel panel)
      Instantiates a MouseTracker to listen to mouse events for the given panel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(FSMouseListener l)
      Adds a listener to receive callbacks on mouse events.
      java.util.List getListeners()
      Returns a (new) list of all listeners currently tracked for receiving events.
      void mouseDragged​(java.awt.event.MouseEvent e)
      void mouseEntered​(java.awt.event.MouseEvent e)
      void mouseExited​(java.awt.event.MouseEvent e)
      void mouseMoved​(java.awt.event.MouseEvent e)
      void mousePressed​(java.awt.event.MouseEvent e)
      void mouseReleased​(java.awt.event.MouseEvent e)
      void removeListener​(FSMouseListener l)
      Removes the given listener, after which it will no longer receive callbacks on mouse events.
      void reset()
      Utility method; calls FSMouseListener.reset() for all listeners currently being tracked.
      • Methods inherited from class java.awt.event.MouseAdapter

        mouseClicked, mouseWheelMoved
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.awt.event.MouseListener

        mouseClicked
    • Constructor Detail

      • MouseTracker

        public MouseTracker​(BasicPanel panel)
        Instantiates a MouseTracker to listen to mouse events for the given panel.
        Parameters:
        panel - the panel for which mouse events should be delegated.
    • Method Detail

      • addListener

        public void addListener​(FSMouseListener l)
        Adds a listener to receive callbacks on mouse events.
        Parameters:
        l - the listener
      • removeListener

        public void removeListener​(FSMouseListener l)
        Removes the given listener, after which it will no longer receive callbacks on mouse events.
        Parameters:
        l - the listener to remove
      • getListeners

        public java.util.List getListeners()
        Returns a (new) list of all listeners currently tracked for receiving events.
        Returns:
        a (new) list of all listeners currently tracked for receiving events.
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent e)
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
        Overrides:
        mouseEntered in class java.awt.event.MouseAdapter
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent e)
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
        Overrides:
        mouseExited in class java.awt.event.MouseAdapter
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent e)
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
        Overrides:
        mouseMoved in class java.awt.event.MouseAdapter
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Overrides:
        mouseReleased in class java.awt.event.MouseAdapter
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Overrides:
        mousePressed in class java.awt.event.MouseAdapter
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent e)
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
        Overrides:
        mouseDragged in class java.awt.event.MouseAdapter
      • reset

        public void reset()
        Utility method; calls FSMouseListener.reset() for all listeners currently being tracked.