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()
    • 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
    • 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
    • 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 public Enumeration<GamePiece> getPieces()
      Deprecated.
      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