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 classPieceMover.AbstractDragHandlerCommon functionality for DragHandler for cases with and without drag image support.static classPieceMover.DragHandlerImplementation of AbstractDragHandler when DragImage is supported by JREstatic classPieceMover.DragHandlerMacOSXstatic classPieceMover.DragHandlerNoImageImplements a psudo-cursor that follows the mouse cursor when user drags gamepieces. -
Field Summary
Fields Modifier and Type Field Description static StringAUTO_REPORTThe Preferences key for autoreporting moves.protected PointdragBeginprotected GamePiecedraggingprotected PieceFinderdragTargetSelectorprotected PieceFinderdropTargetSelectorstatic StringHOTKEYstatic StringICON_NAMEprotected StringiconNameprotected Mapmapprotected LaunchButtonmarkUnmovedButtonprotected StringmarkUnmovedIconprotected StringmarkUnmovedTextstatic StringNAMEprotected Comparator<GamePiece>pieceSorterprotected PieceVisitorDispatcherselectionProcessorFields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validator -
Constructor Summary
Constructors Constructor Description PieceMover() -
Method Summary
Modifier and Type Method Description voidaddTo(Buildable b)Adds this component to its parent.protected CommandapplyKeyAfterMove(List<GamePiece> pieces, KeyStroke key)protected voidapplyKeyAfterMove(List<GamePiece> pieces, Command comm, KeyStroke key)Deprecated, for removal: This API element is subject to removal in a future version.protected booleancanHandleEvent(MouseEvent e)intcompare(GamePiece p1, GamePiece p2)Implement Comparator to sort the contents of the drag buffer before completing the drag.protected PieceFindercreateDragTargetSelector()Returns thePieceFinderinstance that will select aGamePiecefor processing when the user clicks on the map.protected PieceFindercreateDropTargetSelector()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 MovementReportercreateMovementReporter(Command c)protected PieceVisitorDispatchercreateSelectionProcessor()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.StringgetAttributeValueString(String key)CommandgetRestoreCommand()When saving a game, each GameComponent should return aCommandthat, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return nullprotected voidinitButton()booleanisClick(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 booleanisMultipleSelectionEvent(MouseEvent e)CommandmarkMoved(GamePiece p, boolean hasMoved)voidmouseClicked(MouseEvent e)voidmouseEntered(MouseEvent e)voidmouseExited(MouseEvent e)voidmousePressed(MouseEvent e)This listener is used for faking drag-and-drop on Java 1.1 systemsvoidmouseReleased(MouseEvent e)protected CommandmovedPiece(GamePiece p, Point loc)Invoked just before a piece is movedCommandmovePieces(Map map, Point p)Moves pieces in DragBuffer to point p by generating a Command for each element in DragBufferprotected voidperformDrop(Point p)protected voidselectMovablePieces(MouseEvent e)Place the clicked-on piece into theDragBufferprotected voidselectMovablePieces(Point point)Deprecated, for removal: This API element is subject to removal in a future version.voidsetAttribute(String key, Object value)Sets a buildFile (XML) attribute value for this component.protected voidsetOldLocation(GamePiece p)Deprecated, for removal: This API element is subject to removal in a future version.setOldLocations(GamePiece)to return generated Commandsprotected CommandsetOldLocations(GamePiece p)voidsetup(boolean gameStarting)Notify the GameComponent that a game has started/endedprotected booleanshouldMarkMoved()Methods inherited from class VASSAL.build.AbstractBuildable
add, build, getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getPropertyNames, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:BuildableAdds 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
PieceFinderinstance 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 thePieceVisitorDispatcherinstance 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 thePieceFinderinstance that will select aGamePiecefor 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:GameComponentNotify the GameComponent that a game has started/ended- Specified by:
setupin interfaceGameComponent- Parameters:
gameStarting- if true, a game is starting. If false, then a game is ending
-
getRestoreCommand
Description copied from interface:GameComponentWhen saving a game, each GameComponent should return aCommandthat, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return null- Specified by:
getRestoreCommandin interfaceGameComponent
-
initButton
protected void initButton() -
getAttributeNames
Description copied from class:AbstractBuildableLists 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:
getAttributeNamesin classAbstractBuildable- Returns:
- a list of all buildFile (XML) attribute names for this component
-
getAttributeValueString
- Specified by:
getAttributeValueStringin 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:AbstractBuildableSets a buildFile (XML) attribute value for this component. Thekeyparameter will be one of those listed inAbstractBuildable.getAttributeNames(). If thevalueparameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)for the samekey. If the implementing class extendsAbstractConfigurable, thenvaluewill be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()- Specified by:
setAttributein classAbstractBuildable- Parameters:
key- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()value- If thevalueparameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)for the samekey. If the implementing class extendsAbstractConfigurable, thenvaluecan 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:
mousePressedin 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:
mouseReleasedin interfaceMouseListener
-
performDrop
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClickedin 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:
comparein interfaceComparator<GamePiece>
-
applyKeyAfterMove(List, KeyStroke)to return Commands