Class KeyBuffer

java.lang.Object
VASSAL.counters.KeyBuffer

public class KeyBuffer extends Object
The KeyBuffer is the list of "currently selected pieces" in the VASSAL UI (map windows). Its somewhat confusing name derives from the idea that if the player then presses a key, a key command will be sent to all of the pieces in the buffer. KeyBuffer is a "singleton", so there is one for the whole app, across all map windows.
  • Method Details

    • init

      public static void init(KeyBuffer kb)
    • getBuffer

      public static KeyBuffer getBuffer()
    • setSuppressActionButtons

      public void setSuppressActionButtons(boolean suppress)
    • isSuppressActionButtons

      public boolean isSuppressActionButtons()
    • getSlotForPiece

      public PieceSlot getSlotForPiece(GamePiece piece)
    • setClickPoint

      public void setClickPoint(Point p)
    • getClickPoint

      public Point getClickPoint()
    • add

      public void add(GamePiece p)
      Adding a piece to the KeyBuffer "selects the piece" (and lets it know about in its SELECTED property)
      Parameters:
      p - Piece to select
    • addFromPalette

      public void addFromPalette(GamePiece p, PieceSlot slot)
      Parameters:
      p - piece to select
      slot - PieceSlot it comes from (so we can repaint it when selection later cleared)
    • cleansePalette

      public void cleansePalette()
      If we had items selected from a palette, repaint them now that they aren't selected, and switch out of palette mode
    • clear

      public void clear()
      Deselects all pieces (removes them all from the KeyBuffer)
    • remove

      public void remove(GamePiece p)
      Deselect the specified piece -- removes it from the KeyBuffer
      Parameters:
      p - piece to deselect
    • removeFromPalette

      public void removeFromPalette(GamePiece p, PieceSlot slot)
      Deselects a palette piece, repainting its palette slot
      Parameters:
      p - piece
      slot - pieceSlot
    • contains

      public boolean contains(GamePiece p)
      Tells if a particular piece is selected (i.e. present in the KeyBuffer)
      Parameters:
      p - piece to check
      Returns:
      True if the piece is in the KeyBuffer, i.e. is selected
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if the KeyBuffer is empty - i.e. no pieces are selected
    • keyCommand

      public Command keyCommand(KeyStroke stroke)
      Applies a key command to every selected piece (i.e. to piece in the KeyBuffer)
      Parameters:
      stroke - Keystroke to apply
      Returns:
      Command that encapsulates any changes to the game state made while processing the key command, for replay on other clients or in logfile.
    • asList

      public List<GamePiece> asList()
      Returns a list of all selected pieces.
      Returns:
      an unmodifiable List of GamePieces contained in this KeyBuffer
    • getPiecesIterator

      public Iterator<GamePiece> getPiecesIterator()
      Returns an iterator for all selected pieces.
      Returns:
      an iterator for the GamePieces contained in the KeyBuffer
    • getPieces

      @Deprecated(since="2021-12-01", forRemoval=true) public Enumeration<GamePiece> getPieces()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getPiecesIterator() instead.
    • sort

      public void sort(Comparator<GamePiece> comp)
      Sorts the selected pieces based on a particular Comparator
      Parameters:
      comp - Comparator to use
    • containsChild

      public boolean containsChild(Stack stack)
      Check if any member of the specified Stack is currently selected
      Parameters:
      stack - Stack to check
      Returns:
      true if a child of the specified Stack is selected