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
Modifier and TypeClassDescriptionclass
This "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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child component.void
Adds us to our parent map - we register as a mouse listener and a drawable componentvoid
Build the object from the XML representation of the Buildableprotected 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.void
If a drag operation begins, we clear any click-specific informationvoid
Draws our current selection boxboolean
Selection box is always drawn "above counters'getBuildElement
(Document doc) boolean
isLasso()
boolean
Is this component a reqired component within its parent?boolean
isUnique()
Does this component need to be unique within it's parent?void
If the mouse has dragged WHILE a band-select is in progress, sets the new location of the selection rectangle.void
void
Process mouse-pressed events.void
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.protected void
Initiates 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
-
dragStarted
public void dragStarted()If a drag operation begins, we clear any click-specific information -
add
Description copied from interface:Buildable
Adds a child component. Both this method andBuildable.addTo(VASSAL.build.Buildable)
are invoked when adding a child to a parent -
getBuildElement
- Specified by:
getBuildElement
in interfaceBuildable
- Parameters:
doc
- XML file- Returns:
- an XML element from which this component can be built
-
build
-
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:
mousePressed
in interfaceMouseListener
- Overrides:
mousePressed
in 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:
mouseReleased
in interfaceMouseListener
- Overrides:
mouseReleased
in 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:
mouseDragged
in interfaceMouseMotionListener
- Overrides:
mouseDragged
in classMouseAdapter
-
mouseMoved
- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Overrides:
mouseMoved
in classMouseAdapter
-
draw
-
drawAboveCounters
public boolean drawAboveCounters()Selection box is always drawn "above counters'- Specified by:
drawAboveCounters
in interfaceDrawable
- Returns:
- true
-
isMandatory
public boolean isMandatory()Description copied from interface:Buildable
Is this component a reqired component within its parent?- Specified by:
isMandatory
in interfaceBuildable
- Returns:
- true if component is mandatory
-
isUnique
-