Package VASSAL.build.module.map
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.
NOTE: DragSource.isDragImageSupported() returns false for j2sdk1.4.2_02 on Windows 2000
- Author:
- Pieter Geerkens
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPicks the correct drag handler based on our OS, DragSource, and preferences. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected JLabelprotected doubleprotected doubleprotected Pointprotected static List<PieceMover> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThe the Drag Gesture Recognizer that we're officially beginning a drag.voidDRAG SOURCE LISTENER INTERFACEvoidvoidDROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system dragEnter - switches current drawWin when mouse enters a new DropTargetvoidvoidineffectual.voidDRAG GESTURE LISTENER INTERFACE EVENT uses SCALED, DRAG-SOURCE coordinate system.protected PointSets 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 windowvoidDRAG SOURCE MOTION LISTENER INTERFACE EVENT uses UNSCALED, SCREEN coordinate system Moves cursor after mouse.voidvoidineffectual.voidDROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system drop() - Last event of the drop operation.voidvoidineffectual.protected abstract doubleprotected DropTargetListenerprotected abstract intreturns the singleton DragHandler instanceprotected voidmakeDragCursor(double zoom) Installs the cursor image into our dragCursor JLabel.static DropTargetmakeDropTarget(Component theComponent, int dndContants, DropTargetListener dropTargetListener) Creates a new DropTarget and hooks us into the beginning of a DropTargetListener chain.protected voidmoveDragCursor(int dragX, int dragY) Moves the drag cursor on the current draw windowprotected voidRemoves the drag cursor from the current draw windowstatic voidremoveDropTarget(Component theComponent) Removes a dropTarget componentstatic voidReset our drag handler, e.g.static voidFinds all the piece slots in a module and resets their drop targets to use a new DragHandlervoidsetDrawWinToOwnerOf(Component newDropWin) creates or moves cursor object to given window.static voidsetTheDragHandler(PieceMover.AbstractDragHandler myHandler)
-
Field Details
-
dragCursor
-
dragPieceOffCenterZoom
protected double dragPieceOffCenterZoom -
currentPieceOffsetX
protected int currentPieceOffsetX -
currentPieceOffsetY
protected int currentPieceOffsetY -
dragCursorZoom
protected double dragCursorZoom -
pieceMovers
-
lastDragLocation
-
-
Constructor Details
-
AbstractDragHandler
public AbstractDragHandler()
-
-
Method Details
-
getTheDragHandler
returns the singleton DragHandler instance -
setTheDragHandler
-
getOffsetMult
protected abstract int getOffsetMult()- Returns:
- platform-dependent offset multiplier
-
getDeviceScale
- Parameters:
dge- DG event- Returns:
- platform-dependent device scale
-
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. -
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
-
getListener
- Parameters:
e- DropTargetEvent- Returns:
- associated DropTargetListener
-
moveDragCursor
protected void moveDragCursor(int dragX, int dragY) Moves the drag cursor on the current draw window- Parameters:
dragX- x positiondragY- y position
-
removeDragCursor
protected void removeDragCursor()Removes the drag cursor from the current draw window -
setDrawWinToOwnerOf
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.
-
makeDragCursor
protected void makeDragCursor(double zoom) Installs the cursor image into our dragCursor JLabel. Sets current zoom. Should be called at beginning of drag and whenever zoom changes. INPUT: DragBuffer.getBuffer OUTPUT: dragCursorZoom cursorOffCenterX cursorOffCenterY boundingBox- Parameters:
zoom- DragBuffer.getBuffer
-
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.DragHandlerif DragImage is supported by the JRE, orPieceMover.DragHandlerNoImageif not. Either one will have calleddragGestureRecognizedPrep(java.awt.dnd.DragGestureEvent), immediately below, before it calls this method.- Specified by:
dragGestureRecognizedin 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:
dragDropEndin interfaceDragSourceListener- Parameters:
e- DragSourceDropEvent
-
dragEnter
- Specified by:
dragEnterin interfaceDragSourceListener
-
dragExit
- Specified by:
dragExitin interfaceDragSourceListener
-
dragOver
- Specified by:
dragOverin interfaceDragSourceListener
-
dropActionChanged
- Specified by:
dropActionChangedin 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:
dragMouseMovedin interfaceDragSourceMotionListener
-
dragEnter
DROP TARGET INTERFACE EVENT uses UNSCALED, DROP-TARGET coordinate system dragEnter - switches current drawWin when mouse enters a new DropTarget- Specified by:
dragEnterin 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:
dropin interfaceDropTargetListener
-
dragExit
ineffectual. Passes event along listener chain- Specified by:
dragExitin interfaceDropTargetListener
-
dragOver
ineffectual. Passes event along listener chain- Specified by:
dragOverin interfaceDropTargetListener
-
dropActionChanged
ineffectual. Passes event along listener chain- Specified by:
dropActionChangedin interfaceDropTargetListener
-