Package edu.cnu.mdi.graphics.toolbar
Class GestureContext
java.lang.Object
edu.cnu.mdi.graphics.toolbar.GestureContext
Encapsulates the state of a single user interaction ("gesture") on a canvas.
A gesture typically begins on a mouse press (or the first meaningful move for hover-driven tools), proceeds through zero or more updates, and ends on release or exit. This class packages:
- The owning
AToolBar - The canvas
Component - The press-time target object (may be
null) - The press point (immutable)
- The previous and current points (updated as events arrive)
- Modifier key state (shift/ctrl/alt/meta) as of the most recent update
Immutability and copies
The press-time values are immutable, and this class returns defensive copies
for all Point accessors to avoid accidental external mutation.
-
Constructor Summary
ConstructorsConstructorDescriptionGestureContext(AToolBar toolBar, Component canvas, Object target, Point pressPoint, MouseEvent e) Create a context at gesture start using a mouse event. -
Method Summary
Modifier and TypeMethodDescriptionintdeltaX()intdeltaY()Optional extra angle for rubberband tools (e.g.booleanbooleanbooleanbooleanintintvoidupdate(MouseEvent e) Update the context using the event's point and modifier keys.voidupdate(Point current, MouseEvent e) Update the context using an explicit point and an event for modifier keys.
-
Constructor Details
-
GestureContext
public GestureContext(AToolBar toolBar, Component canvas, Object target, Point pressPoint, MouseEvent e) Create a context at gesture start using a mouse event.- Parameters:
toolBar- owning toolbar (non-null)canvas- canvas component (non-null)target- press-time target (may be null)pressPoint- press point (non-null)e- initiating mouse event (may be null)
-
-
Method Details
-
getRubberbandAngleDeg
Optional extra angle for rubberband tools (e.g. RADARC) in degrees.For RADARC this is the signed, unwrapped sweep (can exceed 180 in magnitude).
- Returns:
- the angle in degrees, or null if not provided
-
update
Update the context using the event's point and modifier keys.- Parameters:
e- mouse event (non-null)
-
update
Update the context using an explicit point and an event for modifier keys.- Parameters:
current- new current point (non-null)e- mouse event used to update modifiers (may be null)
-
getSourceEvent
- Returns:
- source mouse event (may be null)
-
getRecentEvent
- Returns:
- most recent mouse event (may be null)
-
getToolBar
- Returns:
- owning toolbar (never null)
-
getCanvas
- Returns:
- canvas component (never null)
-
getTarget
- Returns:
- press-time target object (may be null)
-
getPressPoint
- Returns:
- copy of the press point
-
getPreviousPoint
- Returns:
- copy of the previous point
-
getCurrentPoint
- Returns:
- copy of the current point
-
deltaX
public int deltaX()- Returns:
- incremental delta x (current - previous)
-
deltaY
public int deltaY()- Returns:
- incremental delta y (current - previous)
-
totalDeltaX
public int totalDeltaX()- Returns:
- total delta x (current - press)
-
totalDeltaY
public int totalDeltaY()- Returns:
- total delta y (current - press)
-
isShiftDown
public boolean isShiftDown()- Returns:
- true if shift is down at last update
-
isControlDown
public boolean isControlDown()- Returns:
- true if control is down at last update
-
isAltDown
public boolean isAltDown()- Returns:
- true if alt is down at last update
-
isMetaDown
public boolean isMetaDown()- Returns:
- true if meta/command is down at last update
-