Package VASSAL.build.module.map
Class PieceMover
java.lang.Object
VASSAL.build.AbstractBuildable
VASSAL.build.module.map.PieceMover
- All Implemented Interfaces:
MouseListener
,Comparator<GamePiece>
,EventListener
,Buildable
,GameComponent
,PropertyNameSource
,ValidityChecker
public class PieceMover extends AbstractBuildable implements MouseListener, GameComponent, Comparator<GamePiece>
This is a MouseListener that moves pieces onto a Map window
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PieceMover.AbstractDragHandler
Common functionality for DragHandler for cases with and without drag image support.static class
PieceMover.DragHandler
Implementation of AbstractDragHandler when DragImage is supported by JREstatic class
PieceMover.DragHandlerMacOSX
static class
PieceMover.DragHandlerNoImage
Implements a psudo-cursor that follows the mouse cursor when user drags gamepieces. -
Field Summary
Fields Modifier and Type Field Description static String
AUTO_REPORT
The Preferences key for autoreporting moves.protected Point
dragBegin
protected GamePiece
dragging
protected PieceFinder
dragTargetSelector
protected PieceFinder
dropTargetSelector
static String
HOTKEY
static String
ICON_NAME
protected String
iconName
protected Map
map
protected LaunchButton
markUnmovedButton
protected String
markUnmovedIcon
protected String
markUnmovedText
static String
NAME
protected Comparator<GamePiece>
pieceSorter
protected PieceVisitorDispatcher
selectionProcessor
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validator
-
Constructor Summary
Constructors Constructor Description PieceMover()
-
Method Summary
Modifier and Type Method Description void
addTo(Buildable b)
Adds this component to its parent.protected Command
applyKeyAfterMove(List<GamePiece> pieces, KeyStroke key)
protected void
applyKeyAfterMove(List<GamePiece> pieces, Command comm, KeyStroke key)
Deprecated, for removal: This API element is subject to removal in a future version.protected boolean
canHandleEvent(MouseEvent e)
int
compare(GamePiece p1, GamePiece p2)
Implement Comparator to sort the contents of the drag buffer before completing the drag.protected PieceFinder
createDragTargetSelector()
Returns thePieceFinder
instance that will select aGamePiece
for processing when the user clicks on the map.protected PieceFinder
createDropTargetSelector()
When the user completes a drag-drop operation, the pieces being dragged will either be combined with an existing piece on the map or else placed on the map without stack.protected MovementReporter
createMovementReporter(Command c)
protected PieceVisitorDispatcher
createSelectionProcessor()
When the user clicks on the map, a piece from the map is selected by the dragTargetSelector.String[]
getAttributeNames()
Lists all the buildFile (XML) attribute names for this component.String
getAttributeValueString(String key)
Command
getRestoreCommand()
When saving a game, each GameComponent should return aCommand
that, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return nullprotected void
initButton()
boolean
isClick(Point pt)
Return true if this point is "close enough" to the point at which the user pressed the mouse to be considered a mouse click (such that no moves are done)protected boolean
isMultipleSelectionEvent(MouseEvent e)
Command
markMoved(GamePiece p, boolean hasMoved)
void
mouseClicked(MouseEvent e)
void
mouseEntered(MouseEvent e)
void
mouseExited(MouseEvent e)
void
mousePressed(MouseEvent e)
This listener is used for faking drag-and-drop on Java 1.1 systemsvoid
mouseReleased(MouseEvent e)
protected Command
movedPiece(GamePiece p, Point loc)
Invoked just before a piece is movedCommand
movePieces(Map map, Point p)
Moves pieces in DragBuffer to point p by generating a Command for each element in DragBufferprotected void
performDrop(Point p)
protected void
selectMovablePieces(MouseEvent e)
Place the clicked-on piece into theDragBuffer
protected void
selectMovablePieces(Point point)
Deprecated, for removal: This API element is subject to removal in a future version.void
setAttribute(String key, Object value)
Sets a buildFile (XML) attribute value for this component.protected void
setOldLocation(GamePiece p)
Deprecated, for removal: This API element is subject to removal in a future version.setOldLocations(GamePiece)
to return generated Commandsprotected Command
setOldLocations(GamePiece p)
void
setup(boolean gameStarting)
Notify the GameComponent that a game has started/endedprotected boolean
shouldMarkMoved()
Methods inherited from class VASSAL.build.AbstractBuildable
add, build, getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getPropertyNames, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
AUTO_REPORT
The Preferences key for autoreporting moves.- See Also:
- Constant Field Values
-
NAME
- See Also:
- Constant Field Values
-
HOTKEY
- See Also:
- Constant Field Values
-
map
-
dragBegin
-
dragging
-
markUnmovedButton
-
markUnmovedText
-
markUnmovedIcon
-
ICON_NAME
- See Also:
- Constant Field Values
-
iconName
-
dragTargetSelector
-
dropTargetSelector
-
selectionProcessor
-
pieceSorter
-
-
Constructor Details
-
PieceMover
public PieceMover()
-
-
Method Details
-
addTo
Description copied from interface:Buildable
Adds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class. -
createMovementReporter
-
createDropTargetSelector
When the user completes a drag-drop operation, the pieces being dragged will either be combined with an existing piece on the map or else placed on the map without stack.- Returns:
- a
PieceFinder
instance that determines whichGamePiece
(if any) to combine the being-dragged pieces with.
-
createSelectionProcessor
When the user clicks on the map, a piece from the map is selected by the dragTargetSelector. What happens to that piece is determined by thePieceVisitorDispatcher
instance returned by this method. The default implementation does the following: If a Deck, add the top piece to the drag buffer If a stack, add it to the drag buffer. Otherwise, add the piece and any other multi-selected pieces to the drag buffer.- Returns:
- Dispatcher
- See Also:
createDragTargetSelector()
-
createDragTargetSelector
Returns thePieceFinder
instance that will select aGamePiece
for processing when the user clicks on the map. The default implementation is to return the first piece whose shape contains the point clicked on.- Returns:
- Piece Finder
-
setup
public void setup(boolean gameStarting)Description copied from interface:GameComponent
Notify the GameComponent that a game has started/ended- Specified by:
setup
in interfaceGameComponent
- Parameters:
gameStarting
- if true, a game is starting. If false, then a game is ending
-
getRestoreCommand
Description copied from interface:GameComponent
When saving a game, each GameComponent should return aCommand
that, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return null- Specified by:
getRestoreCommand
in interfaceGameComponent
-
initButton
protected void initButton() -
getAttributeNames
Description copied from class:AbstractBuildable
Lists all the buildFile (XML) attribute names for this component. If this component is ALSO anAbstractConfigurable
, then this list of attributes determines the appropriate attribute order forAbstractConfigurable.getAttributeDescriptions()
andAbstractConfigurable.getAttributeTypes()
.- Specified by:
getAttributeNames
in classAbstractBuildable
- Returns:
- a list of all buildFile (XML) attribute names for this component
-
getAttributeValueString
- Specified by:
getAttributeValueString
in classAbstractBuildable
- Parameters:
key
- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()
- Returns:
- a String representation of the attribute with the given name. When initializing a module, this String value will be passed to
AbstractBuildable.setAttribute(java.lang.String, java.lang.Object)
.
-
setAttribute
Description copied from class:AbstractBuildable
Sets a buildFile (XML) attribute value for this component. Thekey
parameter will be one of those listed inAbstractBuildable.getAttributeNames()
. If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
will be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
- Specified by:
setAttribute
in classAbstractBuildable
- Parameters:
key
- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()
value
- If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
can also be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
-
isMultipleSelectionEvent
-
movedPiece
Invoked just before a piece is moved -
setOldLocation
Deprecated, for removal: This API element is subject to removal in a future version.setOldLocations(GamePiece)
to return generated Commands- Parameters:
p
- Piece
-
setOldLocations
-
markMoved
-
shouldMarkMoved
protected boolean shouldMarkMoved() -
movePieces
Moves pieces in DragBuffer to point p by generating a Command for each element in DragBuffer- Parameters:
map
- Mapp
- Point mouse released
-
applyKeyAfterMove
@Deprecated(since="2020-08-06", forRemoval=true) protected void applyKeyAfterMove(List<GamePiece> pieces, Command comm, KeyStroke key)Deprecated, for removal: This API element is subject to removal in a future version.UseapplyKeyAfterMove(List, KeyStroke)
to return Commands -
applyKeyAfterMove
-
mousePressed
This listener is used for faking drag-and-drop on Java 1.1 systems- Specified by:
mousePressed
in interfaceMouseListener
- Parameters:
e
- Event
-
selectMovablePieces
Place the clicked-on piece into theDragBuffer
-
selectMovablePieces
Deprecated, for removal: This API element is subject to removal in a future version. -
canHandleEvent
-
isClick
Return true if this point is "close enough" to the point at which the user pressed the mouse to be considered a mouse click (such that no moves are done) -
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
-
performDrop
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
compare
Implement Comparator to sort the contents of the drag buffer before completing the drag. This sorts the contents to be in the same order as the pieces were in their original parent stack.- Specified by:
compare
in interfaceComparator<GamePiece>
-
applyKeyAfterMove(List, KeyStroke)
to return Commands