Package VASSAL.build.module.map
Class KeyBufferer
java.lang.Object
java.awt.event.MouseAdapter
VASSAL.build.module.map.KeyBufferer
- All Implemented Interfaces:
MouseListener,MouseMotionListener,MouseWheelListener,EventListener,Buildable,Drawable
Selects and unselects pieces on the map, using the mouse.
The KeyBufferer listens for mouse clicks and drags on its parent
Its rather misleading name derives from the fact that the selected units are kept in a
If the user clicks on a
If you are looking for the drag-and-drop handler for dragging pieces on or between maps, instead see
The KeyBufferer listens for mouse clicks and drags on its parent
Map, determines whether the user is
performing a "lasso"/"band-select" or just clicking, draws the selection rectangle where appropriate, and
at the end of each relevant mouse action updates the KeyBuffer to maintain the list of which pieces are
currently "Selected" in the UI for the parent map.
Its rather misleading name derives from the fact that the selected units are kept in a
KeyBuffer,
with the idea being that if the player now presses a key, any resulting key command would be applied to all
the selected pieces, even though the actual tracking of keys getting pressed and key commands getting applied all
happens elsewhere, i.e. in the KeyBuffer class). A more appropriate name might have been e.g. "MouseSelection".
If the user clicks on a
GamePiece, that piece is added to the KeyBuffer. draw(Graphics, Map)
is responsible for drawing the mouse selection rectangle, and mouseDragged(MouseEvent) is responsible
for triggering repaint events as the selection rectangle is moved.
If you are looking for the drag-and-drop handler for dragging pieces on or between maps, instead see
PieceMover.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis "Visitor" dispatcher receives a method call for EVERY piece on the map (one by one), and must filter the pieces based on their presence in the appropriate selection bounds and take the correct action vis-a-vis that piece's selection status. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child component.voidAdds us to our parent map - we register as a mouse listener and a drawable componentvoidBuild the object from the XML representation of the Buildableprotected PieceVisitorDispatchercreateDragSelector(boolean selecting, boolean altDown, Rectangle mapsel) This PieceVisitorDispatcher determines what to do with pieces on the map when the player finished dragging a rectangle to select pieces.voidIf a drag operation begins, we clear any click-specific informationvoidDraws our current selection boxbooleanSelection box is always drawn "above counters'getBuildElement(Document doc) booleanisLasso()booleanIs this component a reqired component within its parent?booleanisUnique()Does this component need to be unique within it's parent?voidIf the mouse has dragged WHILE a band-select is in progress, sets the new location of the selection rectangle.voidvoidProcess mouse-pressed events.voidWhen the mouse button is released while doing a band-select, we handle updating the selection based on the final size of the selection box.protected voidInitiates a repaint on the selection rectangleMethods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseEntered, mouseExited, mouseWheelMoved
-
Field Details
-
map
-
selection
-
anchor
-
color
-
thickness
protected int thickness -
bandSelectPiece
-
isLasso
protected boolean isLasso
-
-
Constructor Details
-
KeyBufferer
public KeyBufferer()
-
-
Method Details
-
addTo
Adds us to our parent map - we register as a mouse listener and a drawable component -
dragStarted
public void dragStarted()If a drag operation begins, we clear any click-specific information -
add
Description copied from interface:BuildableAdds a child component. Both this method andBuildable.addTo(VASSAL.build.Buildable)are invoked when adding a child to a parent -
getBuildElement
- Specified by:
getBuildElementin interfaceBuildable- Parameters:
doc- XML file- Returns:
- an XML element from which this component can be built
-
build
Description copied from interface:BuildableBuild the object from the XML representation of the Buildable -
isLasso
public boolean isLasso()- Returns:
- true if we've got a valid "selection lasso" drag operation going on (must have breached dragThreshold)
-
mousePressed
Process mouse-pressed events. Depending on what's present where the button became pressed (i.e. movable piece? immovable piece? nothing?) we will determine whether this mouse event will be eligible to be a band-select action.- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classMouseAdapter- Parameters:
e- Mouse Event
-
mouseReleased
When the mouse button is released while doing a band-select, we handle updating the selection based on the final size of the selection box.- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMouseAdapter- Parameters:
e- Mouse event at point of release
-
createDragSelector
protected PieceVisitorDispatcher createDragSelector(boolean selecting, boolean altDown, Rectangle mapsel) This PieceVisitorDispatcher determines what to do with pieces on the map when the player finished dragging a rectangle to select pieces.- Returns:
- the "DeckVisitor" used to process each piece.
-
repaintSelectionRect
protected void repaintSelectionRect()Initiates a repaint on the selection rectangle -
mouseDragged
If the mouse has dragged WHILE a band-select is in progress, sets the new location of the selection rectangle.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMouseAdapter
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMouseAdapter
-
draw
Draws our current selection box -
drawAboveCounters
public boolean drawAboveCounters()Selection box is always drawn "above counters'- Specified by:
drawAboveCountersin interfaceDrawable- Returns:
- true
-
isMandatory
public boolean isMandatory()Description copied from interface:BuildableIs this component a reqired component within its parent?- Specified by:
isMandatoryin interfaceBuildable- Returns:
- true if component is mandatory
-
isUnique
public boolean isUnique()Description copied from interface:BuildableDoes this component need to be unique within it's parent?
-