Class MouseOwner

java.lang.Object
java.awt.event.MouseAdapter
com.j3d.engine.interact.input.mouse.MouseOwner
All Implemented Interfaces:
EventEmitterInterface, MouseListener, MouseMotionListener, MouseWheelListener, EventListener
Direct Known Subclasses:
AlwaysMouseOwner, NoMouseOwner, OrbitMouseOwner, QTranslateMouseOwner, SelectionMouseOwner, SnapMouseOwner

public class MouseOwner extends MouseAdapter implements EventEmitterInterface
MouseOwner is a class which represents an entity that can own the mouse input in the sceneManager. It extends MouseAdapter to allow it to handle mouse events and implements EventEmitterInterface to allow it to broadcast events to registered listeners.
Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • clickDelayThreshold

      private int clickDelayThreshold
      The threshold for the click delay, used to differentiate between a click and a drag.
    • clickDelay

      private int clickDelay
      The current click delay, incremented on mouse drag and reset on mouse release.
    • registered

      protected ArrayList<EventListener> registered
      All registered EventListeners
    • owner

      private final MOwner owner
      The owner of the mouse input, used to determine if the current MouseOwner is the owner of the mouse input in the sceneManager.
    • old

      private Point old
    • physicalMouse

      private final Mouse physicalMouse
    • robot

      private Robot robot
  • Constructor Details

    • MouseOwner

      public MouseOwner(MOwner owner)
      Creates a new MouseOwner with the given owner.
      Parameters:
      owner - The owner of the mouse input.
    • MouseOwner

      public MouseOwner(MOwner owner, int clickDelayThreshold)
      Creates a new MouseOwner with the given owner and click delay threshold.
      Parameters:
      owner - The owner of the mouse input.
      clickDelayThreshold - The threshold for the click delay.
  • Method Details

    • requestOwnership

      public void requestOwnership()
      Requests ownership of the mouse input in the sceneManager. This will set the mouse owner in the EngineFrame to this MouseOwner's owner.
    • isNotOwner

      public boolean isNotOwner()
      Checks if this MouseOwner is not the owner of the mouse input in the sceneManager.
      Returns:
      True if this MouseOwner is not the owner of the mouse input in the sceneManager, false otherwise.
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
      Overrides:
      mouseMoved in class MouseAdapter
    • getMouseLoc

      protected ScreenPoint getMouseLoc(MouseEvent e)
      Calculates the adjusted screen point from a given MouseEvent. This method applies specific offsets (e.g., for menu bar) to the raw mouse coordinates.
      Parameters:
      e - The MouseEvent containing the raw mouse coordinates.
      Returns:
      A ScreenPoint representing the adjusted mouse location on the screen.
    • getMouseLocFromPhysical

      protected ScreenPoint getMouseLocFromPhysical()
      Calculates the adjusted screen point from the current physical mouse coordinates. This method uses the internal physicalMouse state and applies specific offsets.
      Returns:
      A ScreenPoint representing the adjusted physical mouse location on the screen.
    • getSelectionMouseLoc

      protected ScreenPoint getSelectionMouseLoc(MouseEvent e)
      Calculates the adjusted screen point for selection purposes from a given MouseEvent. This method applies different offsets compared to getMouseLoc(MouseEvent).
      Parameters:
      e - The MouseEvent containing the raw mouse coordinates.
      Returns:
      A ScreenPoint representing the adjusted mouse location specifically for selection.
    • clear

      public void clear()
      Resets the state of the physicalMouse to its default (0,0) position.
    • mouseDraggedUsingClickDelay

      public void mouseDraggedUsingClickDelay(MouseEvent e)
      This method is called when a mouse drag event occurs, but only after the clickDelayThreshold has been exceeded. This is used to differentiate between a click and a drag.
      Parameters:
      e - The mouse event.
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Handles the mouse dragged event
      Specified by:
      mouseDragged in interface MouseMotionListener
      Overrides:
      mouseDragged in class MouseAdapter
      Parameters:
      e - the event to be processed
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Handles the mouse pressed event.
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class MouseAdapter
      Parameters:
      e - the event to be processed
    • sendMouseToCentre

      public void sendMouseToCentre()
      Moves the physical mouse cursor to the center of the main application window. This method uses a Robot to programmatically move the mouse and updates the internal physicalMouse state to reflect the new position.
    • wrap

      public void wrap(MouseEvent e)
      Implements mouse wrapping functionality, allowing the mouse cursor to seamlessly move from one edge of the screen to the opposite edge. When the mouse moves past a certain threshold near the left or right edge, it is repositioned to the corresponding opposite edge.
      Parameters:
      e - The MouseEvent containing the current mouse coordinates.
    • getPhysicalMouse

      protected Mouse getPhysicalMouse()
      Retrieves the internal Mouse object representing the physical mouse state.
      Returns:
      The Mouse object.
    • setOldPoint

      protected void setOldPoint(Point point)
      Sets the 'old' point, which is used to calculate mouse movement deltas for the wrap(MouseEvent) method.
      Parameters:
      point - The new Point to set as the 'old' point.
      See Also:
    • attachListener

      public void attachListener(EventListener event)
      Description copied from interface: EventEmitterInterface
      Registers an event listener into the list of listeners.
      Specified by:
      attachListener in interface EventEmitterInterface
      Parameters:
      event - The listener to attach
    • detachListener

      public void detachListener(EventListener event)
      Description copied from interface: EventEmitterInterface
      Deregisters an event listener.
      Specified by:
      detachListener in interface EventEmitterInterface
      Parameters:
      event - The listener to detach.
    • detachAll

      public void detachAll()
      Description copied from interface: EventEmitterInterface
      Deregisters all event listeners.
      Specified by:
      detachAll in interface EventEmitterInterface
    • broadcast

      public <K> void broadcast(EventType eventType, EventPayload<K> properties)
      Description copied from interface: EventEmitterInterface
      Calls all events with the given event type and broadcast properties
      Specified by:
      broadcast in interface EventEmitterInterface
      Parameters:
      eventType - The event type.
      properties - Properties to pass onto the listener.
    • isAttached

      public boolean isAttached(EventListener e)
      Description copied from interface: EventEmitterInterface
      Checks if the given event listener is attached to this event emitter.
      Specified by:
      isAttached in interface EventEmitterInterface
      Parameters:
      e - The event listener to check.
      Returns:
      True if the event listener is attached, false otherwise.