Class Decorator

java.lang.Object
VASSAL.counters.Decorator
All Implemented Interfaces:
PropertyNameSource, PropertySource, GamePiece, PropertyExporter, StateMergeable, PersistentPropertyContainer
Direct Known Subclasses:
ActionButton, AreaOfEffect, CalculatedProperty, Clone, CounterGlobalKeyCommand, Delete, DynamicProperty, Embellishment, Embellishment0, FreeRotator, GlobalHotKey, Hideable, Immobilized, Labeler, Marker, MenuSeparator, MovementMarkable, NonRectangular, Obscurable, Pivot, PlaceMarker, PlaySound, PropertySheet, ReportState, RestrictCommands, Restricted, ReturnToDeck, SendToLocation, SubMenu, TableInfo, Translate, TriggerAction, UsePrototype

public abstract class Decorator
extends Object
implements GamePiece, StateMergeable, PropertyNameSource, PersistentPropertyContainer, PropertyExporter
The abstract class describing a generic 'trait' of a GamePiece. Follows the Decorator design pattern of wrapping around another instance of GamePiece (the 'inner' piece) and delegating some of the GamePiece methods to it
  • Field Details

  • Constructor Details

    • Decorator

      public Decorator()
  • Method Details

    • setInner

      public void setInner​(GamePiece p)
      Set the inner GamePiece
    • setMap

      public void setMap​(Map m)
      Description copied from interface: GamePiece
      Each GamePiece belongs to a single Map
      Specified by:
      setMap in interface GamePiece
    • getInner

      public GamePiece getInner()
      Returns:
      the piece decorated by this Decorator
    • getMap

      public Map getMap()
      Specified by:
      getMap in interface GamePiece
    • setParent

      public void setParent​(Stack s)
      Specified by:
      setParent in interface GamePiece
    • getParent

      public Stack getParent()
      Specified by:
      getParent in interface GamePiece
      Returns:
      the Stack to which this piece belongs, or null if it doesn't belong to a stack.
    • getProperty

      public Object getProperty​(Object key)
      Specified by:
      getProperty in interface GamePiece
      Specified by:
      getProperty in interface PropertySource
    • getLocalizedProperty

      public Object getLocalizedProperty​(Object key)
      Specified by:
      getLocalizedProperty in interface PropertySource
    • setProperty

      public void setProperty​(Object key, Object val)
      Description copied from interface: GamePiece
      Other properties, possibly game-specific, can be associated with a piece. The properties may or may not need to be encoded in the piece's GamePiece.getState() method.
      Specified by:
      setProperty in interface GamePiece
    • setPersistentProperty

      public Command setPersistentProperty​(Object key, Object val)
      Specified by:
      setPersistentProperty in interface PersistentPropertyContainer
    • getPersistentProperty

      public Object getPersistentProperty​(Object key)
      Specified by:
      getPersistentProperty in interface PersistentPropertyContainer
    • getOuter

      public Decorator getOuter()
    • setPosition

      public void setPosition​(Point p)
      Specified by:
      setPosition in interface GamePiece
    • getPosition

      public Point getPosition()
      Specified by:
      getPosition in interface GamePiece
      Returns:
      the location of this piece on its owning Map
    • mySetState

      public abstract void mySetState​(String newState)
      Set just the state of this trait
      See Also:
      myGetState()
    • setState

      public void setState​(String newState)
      Extract the string describing this trait's state and forward the remaining string to the inner piece
      Specified by:
      setState in interface GamePiece
      Parameters:
      newState - the new state of this trait and all inner pieces
    • mergeState

      public void mergeState​(String newState, String oldState)
      Compute the difference between newState and oldState and appy that difference to the current state
      Specified by:
      mergeState in interface StateMergeable
      Parameters:
      newState - New State
      oldState - Old State
    • myGetState

      public abstract String myGetState()
      Returns:
      the state of this trait alone
      See Also:
      getState()
    • getState

      public String getState()
      The state of a Decorator is a composition of myGetState() and the inner piece's state
      Specified by:
      getState in interface GamePiece
    • myGetType

      public abstract String myGetType()
      Returns:
      the type of this trait alone
      See Also:
      getType()
    • getType

      public String getType()
      The type of a Decorator is a composition of myGetType() and the type of its inner piece
      Specified by:
      getType in interface GamePiece
      Returns:
      the combined type of this trait and its inner piece
      See Also:
      BasicCommandEncoder
    • myGetKeyCommands

      protected abstract KeyCommand[] myGetKeyCommands()
      Returns:
      the commands for this trait alone
      See Also:
      getKeyCommands()
    • getKeyCommands

      protected KeyCommand[] getKeyCommands()
      The set of key commands that will populate the piece's right-click menu. The key commands are accessible through the Properties.KEY_COMMANDS property. The commands for a Decorator are a composite of myGetKeyCommands() and the commands of its inner piece.
      Returns:
      the commands for this piece and its inner piece
    • myKeyEvent

      public abstract Command myKeyEvent​(KeyStroke stroke)
      The response of this trait alone to the given KeyStroke
      Parameters:
      stroke - Stroke to apply
      Returns:
      Generated Command or null if no effect
      See Also:
      keyEvent(javax.swing.KeyStroke)
    • keyEvent

      public Command keyEvent​(KeyStroke stroke)
      Append the command returned by myKeyEvent(javax.swing.KeyStroke) with the command returned by the inner piece's GamePiece.keyEvent(javax.swing.KeyStroke) method.
      Specified by:
      keyEvent in interface GamePiece
      Parameters:
      stroke - Stroke to apply
      Returns:
      Generated Command or null if no effect
      See Also:
      ForwardToKeyBuffer
    • getId

      public String getId()
      Description copied from interface: GamePiece
      Each GamePiece must have a unique String identifier
      Specified by:
      getId in interface GamePiece
      See Also:
      GameState.getNewPieceId()
    • setId

      public void setId​(String id)
      Specified by:
      setId in interface GamePiece
    • getOutermost

      public static GamePiece getOutermost​(GamePiece p)
      Parameters:
      p - Trait to find the outermost trait of.
      Returns:
      the outermost Decorator instance of this piece, i.e. the entire piece with all traits
    • getInnermost

      public static GamePiece getInnermost​(GamePiece p)
      Parameters:
      p - Trait to find the Innermost trait of
      Returns:
      the innermost GamePiece of this piece. In most cases, an instance of BasicPiece
    • getDecorator

      public static GamePiece getDecorator​(GamePiece p, Class<?> type)
      Returns:
      the first Decorator within the given GamePiece that is an instance of the given Class
    • getEditor

      public PieceEditor getEditor()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLocalizedName

      public String getLocalizedName()
      Return the translated name for this piece. Most pieces do not have translatable elements, so just return the standard name
      Specified by:
      getLocalizedName in interface GamePiece
    • getI18nData

      public PieceI18nData getI18nData()
      Return I18n data for this piece
      Returns:
      I18n data
    • getI18nData

      protected PieceI18nData getI18nData​(String command, String description)
    • getI18nData

      protected PieceI18nData getI18nData​(String[] commands, String[] descriptions)
    • getCommandDescription

      protected String getCommandDescription​(String description, String command)
    • getTranslation

      protected String getTranslation​(String key)
    • reportDataError

      protected static void reportDataError​(EditablePiece piece, String message, String data, Throwable e)
      Report a Data Error detected by a trait
    • reportDataError

      protected static void reportDataError​(EditablePiece piece, String message, String data)
    • reportDataError

      protected static void reportDataError​(EditablePiece piece, String message)
    • getPropertyNames

      public List<String> getPropertyNames()
      Default Property Name Source
      Specified by:
      getPropertyNames in interface PropertyNameSource
    • setOldProperties

      @Deprecated(since="20200906", forRemoval=true) public static void setOldProperties​(GamePiece p)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the Oldxxxx properties related to movement This call has been replaced by putOldProperties(GamePiece) Any changes to Oldxxxx properties MUST be recorded in Commands.
      Parameters:
      p - Piece to set properties on
    • putOldProperties

      public static Command putOldProperties​(GamePiece p)
      Set the Oldxxxx properties related to movement
      Parameters:
      p - Piece to set properties on
      Returns:
      Command encoding the property values
    • setOldProperties

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

      public static void repack​(Component c)
      Utility method to allow Decorator Editors to repack themselves. c must be one of the components that make up the Decorator's controls.
    • setSelected

      protected void setSelected​(boolean b)
      Support Selection status locally
    • isSelected

      protected boolean isSelected()
    • getProperties

      public Map<String,​Object> getProperties​(Map<String,​Object> result)
      Implement PropertyExporter.getProperties at the Decorator level. Add the properties from this Decorator to the supplied Map, then call the next innermost piece to do the same. Do not overwrite values if an outer trait has a property with the same name.
      Specified by:
      getProperties in interface PropertyExporter
      Parameters:
      result - Map of property values
      Returns:
      Updated Map of property values