Class SnapMouseOwner
java.lang.Object
java.awt.event.MouseAdapter
com.j3d.engine.interact.input.mouse.MouseOwner
com.j3d.engine.interact.input.mouse.SnapMouseOwner
- All Implemented Interfaces:
EventEmitterInterface,MouseListener,MouseMotionListener,MouseWheelListener,EventListener
- Direct Known Subclasses:
TransformMouseOwner
A
MouseOwner which enables child classes which extend it, the capability to snap to
GObjects.
This class:
- Detects nearby
GObjects (points and midpoints of lines) within a small radius of the mouse cursor. - Highlights these potential snap targets visually in the scene.
- Broadcasts a
EventType.SNAP_TO_OBJevent when the user right-clicks on a highlighted snap target.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanA flag indicating whether the snapping functionality is currently enabled.private GObjectTheGObjectthat the mouse is currently hovering over within the snapping region.private ScreenPointThe current screen coordinates of the mouse cursor.static intThe radius (in pixels) around the mouse cursor within whichGObjects are considered potential snap targets.private booleanA flag indicating whether the overlap consumer has been scheduled with the scene manager.A list ofGObjects that are currently within the snapping region around the mouse cursor.private final UUIDA unique identifier for thisSnapMouseOwnerinstance, used for managing overlaps with theStaticRefs.getSceneManager().Fields inherited from class com.j3d.engine.interact.input.mouse.MouseOwner
registered -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all snapping-related state, including removing the overlap consumer from theSceneManager, clearing snapping candidates, and resetting thehoveringOverobject.private Consumer<Graphics2D> consumer()Returns aConsumer<Graphics2D>that handles the visual representation of snapping candidates.Returns the list ofGObjects that are currently considered potential snapping candidates.private booleanisWithinRegion(ScreenPoint target) voidHandles mouse click events.voidHandles mouse movement events.voidEnables the snapping functionality for thisSnapMouseOwner.Methods inherited from class com.j3d.engine.interact.input.mouse.MouseOwner
attachListener, broadcast, detachAll, detachListener, getMouseLoc, getMouseLocFromPhysical, getPhysicalMouse, getSelectionMouseLoc, isAttached, isNotOwner, mouseDragged, mouseDraggedUsingClickDelay, mouseReleased, requestOwnership, sendMouseToCentre, setOldPoint, wrapMethods inherited from class java.awt.event.MouseAdapter
mouseEntered, mouseExited, mousePressed, mouseWheelMoved
-
Field Details
-
offset
public static int offsetThe radius (in pixels) around the mouse cursor within whichGObjects are considered potential snap targets. -
snappingCandidates
A list ofGObjects that are currently within the snapping region around the mouse cursor. These are potential targets for snapping. -
hoveringOver
TheGObjectthat the mouse is currently hovering over within the snapping region. This object will be the target if a snap event is triggered. -
uuid
A unique identifier for thisSnapMouseOwnerinstance, used for managing overlaps with theStaticRefs.getSceneManager(). -
enabled
private boolean enabledA flag indicating whether the snapping functionality is currently enabled. -
overlapScheduled
private boolean overlapScheduledA flag indicating whether the overlap consumer has been scheduled with the scene manager. -
mouseLoc
The current screen coordinates of the mouse cursor.
-
-
Constructor Details
-
SnapMouseOwner
Constructs a newSnapMouseOwner.- Parameters:
owner- The owner of this mouse interaction.uuid- A unique identifier for this instance, used for managing overlaps with theSceneManager.
-
-
Method Details
-
consumer
Returns aConsumer<Graphics2D>that handles the visual representation of snapping candidates. This consumer is scheduled with theSceneManagerto draw overlays, identifying and highlighting potential snap targets (points and midpoints of lines) within the snapping region.- Returns:
- A
Consumerthat draws the snapping overlays.
-
mouseClicked
Handles mouse click events. If a right-click occurs on a highlighted snap target, it broadcasts aEventType.SNAP_TO_OBJevent with thehoveringOverobject.- Specified by:
mouseClickedin interfaceMouseListener- Overrides:
mouseClickedin classMouseAdapter- Parameters:
e- TheMouseEventgenerated by the click.
-
isWithinRegion
- Parameters:
target- TheScreenPointto check.- Returns:
trueif the target is within the region,falseotherwise.
-
snapEnabled
public void snapEnabled()Enables the snapping functionality for thisSnapMouseOwner. Subclasses must call this method to activate snapping. -
getMouseLocation
-
mouseMoved
Handles mouse movement events. When the mouse moves, it updates themouseLoc, clears previous snapping candidates, and queries theSelectionManagerfor new potential snap targets within the snapping region. It also schedules the overlap consumer if not already scheduled.- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMouseOwner- Parameters:
e- TheMouseEventgenerated by the mouse movement.
-
clear
public void clear()Clears all snapping-related state, including removing the overlap consumer from theSceneManager, clearing snapping candidates, and resetting thehoveringOverobject. This should be called when snapping is no longer needed.- Overrides:
clearin classMouseOwner
-
getSnappingCandidates
Returns the list ofGObjects that are currently considered potential snapping candidates.- Returns:
- An
ArrayListofGObjects.
-