Package edu.cnu.mdi.view
Class HeadlessPointerTool
java.lang.Object
edu.cnu.mdi.view.HeadlessPointerTool
- All Implemented Interfaces:
MouseListener,MouseMotionListener,EventListener
A minimal, "headless" pointer tool that enables item dragging (and other item
modifications supported by
AItem) on views that do not have a visible
AToolBar.
In the toolbar-driven workflow, a pointer tool (e.g. PointerButton) is typically
responsible for installing mouse listeners and driving AItem modification
state (start/modify/stop). This class provides the same essential behavior without
requiring a toolbar UI.
Behavior
- On mouse press, hit-tests for an
AItem. - If the item is draggable, the tool arms a potential drag.
- Once the mouse has moved beyond a configurable pixel threshold, the tool
creates an
ItemModification, callsAItem.startModification(), and then repeatedly callsAItem.modify()as the mouse moves. - On mouse release, if a modification was started, the tool calls
AItem.stopModification().
This tool intentionally does not attempt to manage selection state or
multi-item operations; it is meant for "mini-map"/virtual views such as
VirtualView, where the primary goal is simple item dragging.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault drag threshold (pixels) before promoting a press into a drag. -
Constructor Summary
ConstructorsConstructorDescriptionHeadlessPointerTool(BaseView view) Create and immediately install a headless pointer tool on the view's canvas. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Remove listeners from the component.intvoidvoidvoidvoidvoidvoidvoidvoidsetDragThresholdPx(int px) Set the drag threshold in pixels used to promote a press into a drag.
-
Field Details
-
DEFAULT_DRAG_THRESHOLD_PX
public static final int DEFAULT_DRAG_THRESHOLD_PXDefault drag threshold (pixels) before promoting a press into a drag.- See Also:
-
-
Constructor Details
-
HeadlessPointerTool
Create and immediately install a headless pointer tool on the view's canvas.- Parameters:
view- the view whose container/canvas should receive pointer behavior.- Throws:
NullPointerException- ifview, its container, or its component is null.
-
-
Method Details
-
dispose
public void dispose()Remove listeners from the component. Call this if the view/canvas is being disposed or replaced, to avoid leaks and duplicate listeners. -
setDragThresholdPx
public void setDragThresholdPx(int px) Set the drag threshold in pixels used to promote a press into a drag.- Parameters:
px- threshold in pixels; values less than 0 are treated as 0.
-
getDragThresholdPx
public int getDragThresholdPx()- Returns:
- current drag threshold in pixels.
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-