Class Deck

All Implemented Interfaces:
PlayerRoster.SideChangeListener, PropertySource, GamePiece, StateMergeable

public class Deck
extends Stack
implements PlayerRoster.SideChangeListener
A collection of pieces that behaves like a deck, i.e.: Doesn't move. Can't be expanded. Can be shuffled. Can be turned face-up and face-down.
  • Field Details

    • ID

      public static final String ID
      See Also:
      Constant Field Values
    • ALWAYS

      public static final String ALWAYS
      See Also:
      Constant Field Values
    • NEVER

      public static final String NEVER
      See Also:
      Constant Field Values
    • USE_MENU

      public static final String USE_MENU
      See Also:
      Constant Field Values
    • NO_USER

      public static final String NO_USER
      See Also:
      Constant Field Values
    • deckStackMetrics

      protected static StackMetrics deckStackMetrics
    • drawOutline

      protected boolean drawOutline
    • outlineColor

      protected Color outlineColor
    • size

      protected Dimension size
    • shuffle

      protected boolean shuffle
    • faceDownOption

      protected String faceDownOption
    • shuffleOption

      protected String shuffleOption
    • shuffleCommand

      protected String shuffleCommand
    • allowMultipleDraw

      protected boolean allowMultipleDraw
    • allowSelectDraw

      protected boolean allowSelectDraw
    • reversible

      protected boolean reversible
    • reshuffleCommand

      protected String reshuffleCommand
    • reshuffleTarget

      protected String reshuffleTarget
    • reshuffleMsgFormat

      protected String reshuffleMsgFormat
    • reshuffleListener

      protected NamedKeyStrokeListener reshuffleListener
    • reshuffleKey

      protected NamedKeyStroke reshuffleKey
    • reverseMsgFormat

      protected String reverseMsgFormat
    • reverseCommand

      protected String reverseCommand
    • reverseKey

      protected NamedKeyStroke reverseKey
    • reverseListener

      protected NamedKeyStrokeListener reverseListener
    • shuffleMsgFormat

      protected String shuffleMsgFormat
    • shuffleListener

      protected NamedKeyStrokeListener shuffleListener
    • shuffleKey

      protected NamedKeyStroke shuffleKey
    • faceDownMsgFormat

      protected String faceDownMsgFormat
    • drawFaceUp

      protected boolean drawFaceUp
    • persistable

      protected boolean persistable
    • selectDisplayProperty

      protected FormattedString selectDisplayProperty
    • selectSortProperty

      protected String selectSortProperty
    • countProperty

      protected MutableProperty.Impl countProperty
    • expressionProperties

      protected List<MutableProperty.Impl> expressionProperties
    • deckName

      protected String deckName
    • localizedDeckName

      protected String localizedDeckName
    • faceDown

      protected boolean faceDown
    • dragCount

      protected int dragCount
    • maxStack

      protected int maxStack
    • countExpressions

      protected Deck.CountExpression[] countExpressions
    • expressionCounting

      protected boolean expressionCounting
    • nextDraw

      protected List<GamePiece> nextDraw
    • commands

      protected KeyCommand[] commands
    • globalCommands

      protected List<DeckGlobalKeyCommand> globalCommands
    • hotkeyOnEmpty

      protected boolean hotkeyOnEmpty
    • emptyKey

      protected NamedKeyStroke emptyKey
    • restrictOption

      protected boolean restrictOption
    • restrictExpression

      protected PropertyExpression restrictExpression
    • propertySource

      protected PropertySource propertySource
    • commandEncoder

      protected CommandEncoder commandEncoder
  • Constructor Details

  • Method Details

    • setPropertySource

      public void setPropertySource​(PropertySource source)
    • sideChanged

      public void sideChanged​(String oldSide, String newSide)
      Specified by:
      sideChanged in interface PlayerRoster.SideChangeListener
    • addGlobalKeyCommand

      public void addGlobalKeyCommand​(DeckGlobalKeyCommand globalCommand)
    • removeGlobalKeyCommand

      public void removeGlobalKeyCommand​(DeckGlobalKeyCommand globalCommand)
    • getGlobalCommands

      protected String[] getGlobalCommands()
    • setGlobalCommands

      protected void setGlobalCommands​(String[] commands)
    • fireNumCardsProperty

      protected void fireNumCardsProperty()
      Set the _numPieces property in the containing Map
    • insertPieceAt

      protected void insertPieceAt​(GamePiece p, int index)
      Overrides:
      insertPieceAt in class Stack
    • removePieceAt

      protected void removePieceAt​(int index)
      Overrides:
      removePieceAt in class Stack
    • removeAll

      public void removeAll()
      Overrides:
      removeAll in class Stack
    • setMap

      public void setMap​(Map map)
      Description copied from interface: GamePiece
      Each GamePiece belongs to a single Map
      Specified by:
      setMap in interface GamePiece
      Overrides:
      setMap in class Stack
    • mySetType

      protected void mySetType​(String type)
    • getFaceDownOption

      public String getFaceDownOption()
    • isDrawFaceUp

      public boolean isDrawFaceUp()
      Returns:
      true if cards are turned face up when drawn from this deck
    • setDrawFaceUp

      public void setDrawFaceUp​(boolean drawFaceUp)
    • setFaceDownOption

      public void setFaceDownOption​(String faceDownOption)
    • getSize

      public Dimension getSize()
    • setSize

      public void setSize​(Dimension size)
    • getShuffleOption

      public String getShuffleOption()
    • setShuffleOption

      public void setShuffleOption​(String shuffleOption)
    • isShuffle

      public boolean isShuffle()
    • getMaxStack

      public int getMaxStack()
    • getMaximumVisiblePieceCount

      public int getMaximumVisiblePieceCount()
      Description copied from class: Stack
      Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular player
      Overrides:
      getMaximumVisiblePieceCount in class Stack
      Returns:
      Piece Count
    • getCountExpressions

      public String[] getCountExpressions()
    • doesExpressionCounting

      public boolean doesExpressionCounting()
    • getFaceDownMsgFormat

      public String getFaceDownMsgFormat()
    • setFaceDownMsgFormat

      public void setFaceDownMsgFormat​(String faceDownMsgFormat)
    • getReverseMsgFormat

      public String getReverseMsgFormat()
    • setReverseMsgFormat

      public void setReverseMsgFormat​(String reverseMsgFormat)
    • getReverseCommand

      public String getReverseCommand()
    • setReverseCommand

      public void setReverseCommand​(String s)
    • getReverseKey

      public NamedKeyStroke getReverseKey()
    • setReverseKey

      public void setReverseKey​(NamedKeyStroke reverseKey)
    • getShuffleMsgFormat

      public String getShuffleMsgFormat()
    • setShuffleMsgFormat

      public void setShuffleMsgFormat​(String shuffleMsgFormat)
    • getShuffleKey

      public NamedKeyStroke getShuffleKey()
    • setShuffleKey

      public void setShuffleKey​(NamedKeyStroke shuffleKey)
    • getShuffleCommand

      public String getShuffleCommand()
    • setShuffleCommand

      public void setShuffleCommand​(String s)
    • setShuffle

      public void setShuffle​(boolean shuffle)
    • isAllowMultipleDraw

      public boolean isAllowMultipleDraw()
    • setAllowMultipleDraw

      public void setAllowMultipleDraw​(boolean allowMultipleDraw)
    • isAllowSelectDraw

      public boolean isAllowSelectDraw()
    • setMaxStack

      public void setMaxStack​(int maxStack)
    • setCountExpressions

      public void setCountExpressions​(String[] countExpressionsString)
    • setExpressionCounting

      public void setExpressionCounting​(boolean expressionCounting)
    • setAllowSelectDraw

      public void setAllowSelectDraw​(boolean allowSelectDraw)
    • isReversible

      public boolean isReversible()
    • setReversible

      public void setReversible​(boolean reversible)
    • setDeckName

      public void setDeckName​(String n)
    • getDeckName

      public String getDeckName()
    • getLocalizedDeckName

      public String getLocalizedDeckName()
    • getReshuffleCommand

      public String getReshuffleCommand()
      Returns:
      The popup menu text for the command that sends the entire deck to another deck
    • setReshuffleCommand

      public void setReshuffleCommand​(String reshuffleCommand)
    • getReshuffleKey

      public NamedKeyStroke getReshuffleKey()
    • setReshuffleKey

      public void setReshuffleKey​(NamedKeyStroke reshuffleKey)
    • getReshuffleTarget

      public String getReshuffleTarget()
      The name of the DrawPile to which the contents of this deck will be sent when the reshuffle command is selected
    • setReshuffleTarget

      public void setReshuffleTarget​(String reshuffleTarget)
    • getReshuffleMsgFormat

      public String getReshuffleMsgFormat()
      Returns:
      The message to send to the chat window when the deck is reshuffled to another deck
    • setReshuffleMsgFormat

      public void setReshuffleMsgFormat​(String reshuffleMsgFormat)
    • isHotkeyOnEmpty

      public boolean isHotkeyOnEmpty()
    • setHotkeyOnEmpty

      public void setHotkeyOnEmpty​(boolean b)
    • getEmptyKey

      @Deprecated(since="2020-08-06", forRemoval=true) public KeyStroke getEmptyKey()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getNamedEmptyKey

      public NamedKeyStroke getNamedEmptyKey()
    • setEmptyKey

      @Deprecated(since="2020-08-06", forRemoval=true) public void setEmptyKey​(KeyStroke k)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setEmptyKey

      public void setEmptyKey​(NamedKeyStroke k)
    • setRestrictOption

      public void setRestrictOption​(boolean restrictOption)
    • isRestrictOption

      public boolean isRestrictOption()
    • setRestrictExpression

      public void setRestrictExpression​(PropertyExpression restrictExpression)
    • getRestrictExpression

      public PropertyExpression getRestrictExpression()
    • mayContain

      public boolean mayContain​(GamePiece piece)
      Does the specified GamePiece meet the rules to be contained in this Deck.
    • getType

      public String getType()
      Description copied from interface: GamePiece
      The type information is information that does not change during the course of a game. Image file names, popup menu command names, etc., all should be reflected in the type.
      Specified by:
      getType in interface GamePiece
      Overrides:
      getType in class Stack
      See Also:
      BasicCommandEncoder
    • shuffle

      public Command shuffle()
      Shuffle the contents of the Deck
    • drawCards

      public PieceIterator drawCards()
      Return an iterator of pieces to be drawn from the Deck. Normally, a random piece will be drawn, but if the Deck supports it, the user may have specified a particular set of pieces or a fixed number of pieces to select with the next draw.
    • setContents

      protected Command setContents​(Collection<GamePiece> c)
      Set the contents of this Deck to a Collection of GamePieces
    • setContents

      @Deprecated(since="2020-08-06", forRemoval=true) protected Command setContents​(Iterator<GamePiece> it)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the contents of this Deck to an Iterator of GamePieces
    • getState

      public String getState()
      Description copied from interface: GamePiece
      The state information is information that can change during the course of a game. State information is saved when the game is saved and is transferred between players on the server. For example, the relative order of pieces in a stack is state information, but whether the stack is expanded is not
      Specified by:
      getState in interface GamePiece
      Overrides:
      getState in class Stack
    • setState

      public void setState​(String state)
      Specified by:
      setState in interface GamePiece
      Overrides:
      setState in class Stack
    • setContentsFaceDown

      public Command setContentsFaceDown​(boolean value)
    • reverse

      public Command reverse()
      Reverse the order of the contents of the Deck
    • isDrawOutline

      public boolean isDrawOutline()
    • setOutlineColor

      public void setOutlineColor​(Color outlineColor)
    • setDrawOutline

      public void setDrawOutline​(boolean drawOutline)
    • getOutlineColor

      public Color getOutlineColor()
    • isFaceDown

      public boolean isFaceDown()
    • pieceAdded

      public Command pieceAdded​(GamePiece p)
      Description copied from class: Stack
      Perform some action on a GamePiece that has just been added to this Stack
      Overrides:
      pieceAdded in class Stack
      Parameters:
      p - Game Piece
      Returns:
      a Command that performs the equivalent action when executed
    • pieceRemoved

      public Command pieceRemoved​(GamePiece p)
      Description copied from class: Stack
      Perform some action on a GamePiece that has just been removed this Stack
      Overrides:
      pieceRemoved in class Stack
      Parameters:
      p - GamePiece
      Returns:
      a Command that performs the equivalent action when executed
    • setFaceDown

      public void setFaceDown​(boolean faceDown)
    • draw

      public void draw​(Graphics g, int x, int y, Component obs, double zoom)
      Description copied from class: Stack
      If the obs parameter is a Map, delegate drawing of this Stack to the StackMetrics of that Map. If obs is not a Map, use the default StackMetrics
      Specified by:
      draw in interface GamePiece
      Overrides:
      draw in class Stack
      x - x-location of the center of the piece
      y - y-location of the center of the piece
      obs - the Component on which this piece is being drawn
      zoom - the scaling factor.
      See Also:
      StackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double), Stack.getDefaultMetrics()
    • getBlankColor

      protected Color getBlankColor()
      The color used to draw boxes representing cards underneath the top one. If null, then draw each card normally for face-up decks, and duplicate the top card for face-down decks
    • getStackMetrics

      public StackMetrics getStackMetrics()
      Overrides:
      getStackMetrics in class Stack
    • boundingBox

      public Rectangle boundingBox()
      Description copied from interface: GamePiece
      The area which this GamePiece occupies when drawn at the point (0,0)
      Specified by:
      boundingBox in interface GamePiece
      Overrides:
      boundingBox in class Stack
    • getShape

      public Shape getShape()
      Description copied from interface: GamePiece
      The shape of the piece from the user's viewpoint. This defines the area in which the user must click to select or move the piece, for example. Like GamePiece.boundingBox(), it assumes the position is (0,0) and must be translated to the actual location where the piece is being drawn.
      Specified by:
      getShape in interface GamePiece
      Overrides:
      getShape in class Stack
    • getProperty

      public Object getProperty​(Object key)
      Specified by:
      getProperty in interface GamePiece
      Specified by:
      getProperty in interface PropertySource
      Overrides:
      getProperty in class Stack
    • getKeyCommands

      protected KeyCommand[] getKeyCommands()
    • reportCommand

      protected Command reportCommand​(String format, String commandName)
    • promptForDragCount

      public void promptForDragCount()
    • promptForNextDraw

      protected void promptForNextDraw()
    • sendToDeck

      public Command sendToDeck()
      Combine the contents of this Deck with the contents of the deck specified by reshuffleTarget
    • isExpanded

      public boolean isExpanded()
      Overrides:
      isExpanded in class Stack
    • isPersistable

      public boolean isPersistable()
      Return true if this deck can be saved to and loaded from a file on disk
    • setPersistable

      public void setPersistable​(boolean persistable)
    • saveDeck

      public void saveDeck​(File f) throws IOException
      Throws:
      IOException
    • loadDeck

      public Command loadDeck​(File f) throws IOException
      Throws:
      IOException
    • getDragCount

      public int getDragCount()
      Return the number of cards to be returned by next call to drawCards().
    • setDragCount

      public void setDragCount​(int dragCount)
      Set the number of cards to be returned by next call to drawCards().
      Parameters:
      dragCount - number of cards to be returned
    • setSelectDisplayProperty

      public void setSelectDisplayProperty​(String promptDisplayProperty)
    • setSelectSortProperty

      public void setSelectSortProperty​(String promptSortProperty)
    • getSelectDisplayProperty

      public String getSelectDisplayProperty()
    • getSelectSortProperty

      public String getSelectSortProperty()
    • repaintMap

      protected void repaintMap()