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
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 Summary
FieldsModifier and TypeFieldDescriptionprivate intThe current click delay, incremented on mouse drag and reset on mouse release.private intThe threshold for the click delay, used to differentiate between a click and a drag.private Pointprivate final MOwnerThe owner of the mouse input, used to determine if the current MouseOwner is the owner of the mouse input in the sceneManager.private final Mouseprotected ArrayList<EventListener> All registered EventListenersprivate Robot -
Constructor Summary
ConstructorsConstructorDescriptionMouseOwner(MOwner owner) Creates a new MouseOwner with the given owner.MouseOwner(MOwner owner, int clickDelayThreshold) Creates a new MouseOwner with the given owner and click delay threshold. -
Method Summary
Modifier and TypeMethodDescriptionvoidattachListener(EventListener event) Registers an event listener into the list of listeners.<K> voidbroadcast(EventType eventType, EventPayload<K> properties) Calls all events with the given event type and broadcast propertiesvoidclear()Resets the state of thephysicalMouseto its default (0,0) position.voidDeregisters all event listeners.voiddetachListener(EventListener event) Deregisters an event listener.protected ScreenPointCalculates the adjusted screen point from a givenMouseEvent.protected ScreenPointCalculates the adjusted screen point from the current physical mouse coordinates.protected MouseRetrieves the internalMouseobject representing the physical mouse state.protected ScreenPointCalculates the adjusted screen point for selection purposes from a givenMouseEvent.booleanChecks if the given event listener is attached to this event emitter.booleanChecks if this MouseOwner is not the owner of the mouse input in the sceneManager.voidHandles the mouse dragged eventvoidThis method is called when a mouse drag event occurs, but only after theclickDelayThresholdhas been exceeded.voidvoidHandles the mouse pressed event.voidRequests ownership of the mouse input in the sceneManager.voidMoves the physical mouse cursor to the center of the main application window.protected voidsetOldPoint(Point point) Sets the 'old' point, which is used to calculate mouse movement deltas for thewrap(MouseEvent)method.voidwrap(MouseEvent e) Implements mouse wrapping functionality, allowing the mouse cursor to seamlessly move from one edge of the screen to the opposite edge.Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseWheelMoved
-
Field Details
-
clickDelayThreshold
private int clickDelayThresholdThe threshold for the click delay, used to differentiate between a click and a drag. -
clickDelay
private int clickDelayThe current click delay, incremented on mouse drag and reset on mouse release. -
registered
All registered EventListeners -
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
-
physicalMouse
-
robot
-
-
Constructor Details
-
MouseOwner
Creates a new MouseOwner with the given owner.- Parameters:
owner- The owner of the mouse input.
-
MouseOwner
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
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMouseAdapter
-
getMouseLoc
Calculates the adjusted screen point from a givenMouseEvent. This method applies specific offsets (e.g., for menu bar) to the raw mouse coordinates.- Parameters:
e- TheMouseEventcontaining the raw mouse coordinates.- Returns:
- A
ScreenPointrepresenting the adjusted mouse location on the screen.
-
getMouseLocFromPhysical
Calculates the adjusted screen point from the current physical mouse coordinates. This method uses the internalphysicalMousestate and applies specific offsets.- Returns:
- A
ScreenPointrepresenting the adjusted physical mouse location on the screen.
-
getSelectionMouseLoc
Calculates the adjusted screen point for selection purposes from a givenMouseEvent. This method applies different offsets compared togetMouseLoc(MouseEvent).- Parameters:
e- TheMouseEventcontaining the raw mouse coordinates.- Returns:
- A
ScreenPointrepresenting the adjusted mouse location specifically for selection.
-
clear
public void clear()Resets the state of thephysicalMouseto its default (0,0) position. -
mouseDraggedUsingClickDelay
This method is called when a mouse drag event occurs, but only after theclickDelayThresholdhas been exceeded. This is used to differentiate between a click and a drag.- Parameters:
e- The mouse event.
-
mouseDragged
Handles the mouse dragged event- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMouseAdapter- Parameters:
e- the event to be processed
-
mouseReleased
Handles the mouse pressed event.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMouseAdapter- 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 aRobotto programmatically move the mouse and updates the internalphysicalMousestate to reflect the new position. -
wrap
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- TheMouseEventcontaining the current mouse coordinates.
-
getPhysicalMouse
Retrieves the internalMouseobject representing the physical mouse state.- Returns:
- The
Mouseobject.
-
setOldPoint
Sets the 'old' point, which is used to calculate mouse movement deltas for thewrap(MouseEvent)method.- Parameters:
point- The newPointto set as the 'old' point.- See Also:
-
attachListener
Description copied from interface:EventEmitterInterfaceRegisters an event listener into the list of listeners.- Specified by:
attachListenerin interfaceEventEmitterInterface- Parameters:
event- The listener to attach
-
detachListener
Description copied from interface:EventEmitterInterfaceDeregisters an event listener.- Specified by:
detachListenerin interfaceEventEmitterInterface- Parameters:
event- The listener to detach.
-
detachAll
public void detachAll()Description copied from interface:EventEmitterInterfaceDeregisters all event listeners.- Specified by:
detachAllin interfaceEventEmitterInterface
-
broadcast
Description copied from interface:EventEmitterInterfaceCalls all events with the given event type and broadcast properties- Specified by:
broadcastin interfaceEventEmitterInterface- Parameters:
eventType- The event type.properties- Properties to pass onto the listener.
-
isAttached
Description copied from interface:EventEmitterInterfaceChecks if the given event listener is attached to this event emitter.- Specified by:
isAttachedin interfaceEventEmitterInterface- Parameters:
e- The event listener to check.- Returns:
- True if the event listener is attached, false otherwise.
-