Class PieceMover.AbstractDragHandler
java.lang.Object
VASSAL.build.module.map.PieceMover.AbstractDragHandler
- All Implemented Interfaces:
DragGestureListener
,DragSourceListener
,DragSourceMotionListener
,DropTargetListener
,EventListener
- Direct Known Subclasses:
PieceMover.DragHandler
,PieceMover.DragHandlerNoImage
- Enclosing class:
PieceMover
public abstract static class PieceMover.AbstractDragHandler
extends Object
implements DragGestureListener, DragSourceListener, DragSourceMotionListener, DropTargetListener
Common functionality for DragHandler for cases with and without drag
image support.
- Author:
- Pieter Geerkens
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Picks the correct drag handler based on our OS, DragSource, and preferences. -
Field Summary
Modifier and TypeFieldDescriptionprotected Rectangle
protected Rectangle
protected int
protected int
protected static final int
protected JLabel
protected double
protected double
protected Map
<Component, DropTargetListener> protected static final int
protected Point
protected static List
<PieceMover> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Registers a PieceMoverprotected void
The the Drag Gesture Recognizer that we're officially beginning a drag.protected void
calculates the offset between cursor dragCursor positionsvoid
DRAG SOURCE LISTENER INTERFACEvoid
void
DROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system dragEnter - switches current drawWin when mouse enters a new DropTargetvoid
void
Passes event along listener chainvoid
DRAG GESTURE LISTENER INTERFACE EVENT uses SCALED, DRAG-SOURCE coordinate system.protected Point
Sets things up at the beginning of a drag-and-drop operation:
- Screen out any immovable pieces
- Account for any offsets on in the window
- Sets dragWin to our source windowvoid
DRAG SOURCE MOTION LISTENER INTERFACE EVENT uses UNSCALED, SCREEN coordinate system Moves cursor after mouse.void
void
Passes event along listener chainvoid
DROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system drop() - Last event of the drop operation.void
void
Passes event along listener chainprotected abstract double
protected abstract double
protected DropTargetListener
protected abstract int
returns the singleton DragHandler instanceprotected void
makeDragCursor
(double zoom) Deprecated, for removal: This API element is subject to removal in a future version.protected BufferedImage
makeDragImageCursorCommon
(double zoom, boolean doOffset, Component target, boolean setSize) Deprecated, for removal: This API element is subject to removal in a future version.protected BufferedImage
makeDragImageCursorCommon
(double mapzoom, double os_scale, boolean doOffset, Component target) static DropTarget
makeDropTarget
(Component theComponent, int dndContants, DropTargetListener dropTargetListener) Creates a new DropTarget and hooks us into the beginning of a DropTargetListener chain.protected void
moveDragCursor
(int dragX, int dragY) Deprecated, for removal: This API element is subject to removal in a future version.protected void
Deprecated, for removal: This API element is subject to removal in a future version.static void
removeDropTarget
(Component theComponent) Removes a dropTarget componentstatic void
Reset our drag handler, e.g. if our preferences change.static void
Finds all the piece slots in a module and resets their drop targets to use a new DragHandlervoid
setDrawWinToOwnerOf
(Component newDropWin) Deprecated, for removal: This API element is subject to removal in a future version.static void
setTheDragHandler
(PieceMover.AbstractDragHandler myHandler)
-
Field Details
-
pieceMovers
-
CURSOR_ALPHA
protected static final int CURSOR_ALPHA- See Also:
-
EXTRA_BORDER
protected static final int EXTRA_BORDER- See Also:
-
boundingBox
-
boundingBoxComp
-
dragPieceOffCenterZoom
protected double dragPieceOffCenterZoom -
currentPieceOffsetX
protected int currentPieceOffsetX -
currentPieceOffsetY
protected int currentPieceOffsetY -
dropTargetListeners
-
lastDragLocation
-
dragCursor
-
dragCursorZoom
protected double dragCursorZoom
-
-
Constructor Details
-
AbstractDragHandler
public AbstractDragHandler()
-
-
Method Details
-
getTheDragHandler
returns the singleton DragHandler instance -
setTheDragHandler
-
resetRecursivePieceSlots
Finds all the piece slots in a module and resets their drop targets to use a new DragHandler- Parameters:
target
- recursive search through components
-
resetDragHandler
public static void resetDragHandler()Reset our drag handler, e.g. if our preferences change. -
addPieceMover
Registers a PieceMover- Parameters:
pm
- PieceMover for this dragHandler
-
makeDropTarget
public static DropTarget makeDropTarget(Component theComponent, int dndContants, DropTargetListener dropTargetListener) Creates a new DropTarget and hooks us into the beginning of a DropTargetListener chain. DropTarget events are not multicast; there can be only one "true" listener. -
removeDropTarget
Removes a dropTarget component- Parameters:
theComponent
- component to remove
-
getOffsetMult
protected abstract int getOffsetMult()- Returns:
- platform-dependent offset multiplier
-
getDeviceScale
- Parameters:
dge
- DG event- Returns:
- platform-dependent device scale
-
getDeviceScale
-
getListener
- Parameters:
e
- DropTargetEvent- Returns:
- associated DropTargetListener
-
moveDragCursor
@Deprecated(since="2023-05-08", forRemoval=true) protected void moveDragCursor(int dragX, int dragY) Deprecated, for removal: This API element is subject to removal in a future version.Moves the drag cursor on the current draw window- Parameters:
dragX
- x positiondragY
- y position
-
removeDragCursor
Deprecated, for removal: This API element is subject to removal in a future version.Removes the drag cursor from the current draw window -
calcDrawOffset
protected void calcDrawOffset()calculates the offset between cursor dragCursor positions -
setDrawWinToOwnerOf
@Deprecated(since="2023-05-08", forRemoval=true) public void setDrawWinToOwnerOf(Component newDropWin) Deprecated, for removal: This API element is subject to removal in a future version.creates or moves cursor object to given window. Called when drag operation begins in a window or the cursor is dragged over a new drop-target window- Parameters:
newDropWin
- window component to be our new draw window.
-
makeDragImageCursorCommon
@Deprecated(since="2023-05-08", forRemoval=true) protected BufferedImage makeDragImageCursorCommon(double zoom, boolean doOffset, Component target, boolean setSize) Deprecated, for removal: This API element is subject to removal in a future version.Common functionality abstracted from makeDragImage and makeDragCursor- Parameters:
zoom
- Zoom LeveldoOffset
- Drag Offsettarget
- Target ComponentsetSize
- Set Size- Returns:
- Drag Image
-
makeDragImageCursorCommon
protected BufferedImage makeDragImageCursorCommon(double mapzoom, double os_scale, boolean doOffset, Component target) -
makeDragCursor
Deprecated, for removal: This API element is subject to removal in a future version. -
dragGestureRecognized
DRAG GESTURE LISTENER INTERFACE EVENT uses SCALED, DRAG-SOURCE coordinate system. ("component coordinates") PIECE uses SCALED, OWNER (arbitrary) coordinate system ("map coordinates") Fires after user begins moving the mouse several pixels over a map. This method will be overridden, but called as a super(), by the Drag Gesture extension that is used, which will either bePieceMover.DragHandler
if DragImage is supported by the JRE, orPieceMover.DragHandlerNoImage
if not. Either one will have calleddragGestureRecognizedPrep(java.awt.dnd.DragGestureEvent)
, immediately below, before it calls this method.- Specified by:
dragGestureRecognized
in interfaceDragGestureListener
-
dragGestureRecognizedPrep
Sets things up at the beginning of a drag-and-drop operation:
- Screen out any immovable pieces
- Account for any offsets on in the window
- Sets dragWin to our source window- Parameters:
dge
- dg event- Returns:
- mousePosition if we processed, or null if we bailed.
-
beginDragging
The the Drag Gesture Recognizer that we're officially beginning a drag.- Parameters:
dge
- DG event
-
dragDropEnd
DRAG SOURCE LISTENER INTERFACE- Specified by:
dragDropEnd
in interfaceDragSourceListener
- Parameters:
e
- DragSourceDropEvent
-
dragEnter
- Specified by:
dragEnter
in interfaceDragSourceListener
-
dragExit
- Specified by:
dragExit
in interfaceDragSourceListener
-
dragOver
- Specified by:
dragOver
in interfaceDragSourceListener
-
dropActionChanged
- Specified by:
dropActionChanged
in interfaceDragSourceListener
-
dragMouseMoved
DRAG SOURCE MOTION LISTENER INTERFACE EVENT uses UNSCALED, SCREEN coordinate system Moves cursor after mouse. Used to check for real mouse movement. Warning: dragMouseMoved fires 8 times for each point on development system (Win2k)- Specified by:
dragMouseMoved
in interfaceDragSourceMotionListener
-
dragEnter
DROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system dragEnter - switches current drawWin when mouse enters a new DropTarget- Specified by:
dragEnter
in interfaceDropTargetListener
-
drop
DROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system drop() - Last event of the drop operation. We adjust the drop point for off-center drag, remove the cursor, and pass the event along listener chain.- Specified by:
drop
in interfaceDropTargetListener
-
dragExit
Passes event along listener chain- Specified by:
dragExit
in interfaceDropTargetListener
-
dragOver
Passes event along listener chain- Specified by:
dragOver
in interfaceDropTargetListener
-
dropActionChanged
Passes event along listener chain- Specified by:
dropActionChanged
in interfaceDropTargetListener
-