Package VASSAL.counters
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 Summary
Fields inherited from interface VASSAL.counters.PropertyExporter
LOCALIZED_NAME
-
Constructor Summary
Constructors Constructor Description Decorator()
-
Method Summary
Modifier and Type Method Description protected String
getCommandDescription(String description, String command)
static GamePiece
getDecorator(GamePiece p, Class<?> type)
PieceEditor
getEditor()
PieceI18nData
getI18nData()
Return I18n data for this pieceprotected PieceI18nData
getI18nData(String[] commands, String[] descriptions)
protected PieceI18nData
getI18nData(String command, String description)
String
getId()
Each GamePiece must have a unique String identifierGamePiece
getInner()
static GamePiece
getInnermost(GamePiece p)
protected KeyCommand[]
getKeyCommands()
The set of key commands that will populate the piece's right-click menu.String
getLocalizedName()
Return the translated name for this piece.Object
getLocalizedProperty(Object key)
Map
getMap()
Decorator
getOuter()
static GamePiece
getOutermost(GamePiece p)
Stack
getParent()
Object
getPersistentProperty(Object key)
Point
getPosition()
Map<String,Object>
getProperties(Map<String,Object> result)
Implement PropertyExporter.getProperties at the Decorator level.Object
getProperty(Object key)
List<String>
getPropertyNames()
Default Property Name SourceString
getState()
The state of a Decorator is a composition ofmyGetState()
and the inner piece's stateprotected String
getTranslation(String key)
String
getType()
The type of a Decorator is a composition ofmyGetType()
and the type of its inner pieceprotected boolean
isSelected()
Command
keyEvent(KeyStroke stroke)
Append the command returned bymyKeyEvent(javax.swing.KeyStroke)
with the command returned by the inner piece'sGamePiece.keyEvent(javax.swing.KeyStroke)
method.void
mergeState(String newState, String oldState)
Compute the difference betweennewState
andoldState
and appy that difference to the current stateprotected abstract KeyCommand[]
myGetKeyCommands()
abstract String
myGetState()
abstract String
myGetType()
abstract Command
myKeyEvent(KeyStroke stroke)
The response of this trait alone to the given KeyStrokeabstract void
mySetState(String newState)
Set just the state of this traitstatic Command
putOldProperties(GamePiece p)
Set the Oldxxxx properties related to movementstatic void
repack(Component c)
Utility method to allow Decorator Editors to repack themselves.protected static void
reportDataError(EditablePiece piece, String message)
protected static void
reportDataError(EditablePiece piece, String message, String data)
protected static void
reportDataError(EditablePiece piece, String message, String data, Throwable e)
Report a Data Error detected by a traitvoid
setId(String id)
void
setInner(GamePiece p)
Set the inner GamePiecevoid
setMap(Map m)
Each GamePiece belongs to a singleMap
void
setOldProperties()
Deprecated, for removal: This API element is subject to removal in a future version.static void
setOldProperties(GamePiece p)
Deprecated, for removal: This API element is subject to removal in a future version.void
setParent(Stack s)
Command
setPersistentProperty(Object key, Object val)
void
setPosition(Point p)
void
setProperty(Object key, Object val)
Other properties, possibly game-specific, can be associated with a piece.protected void
setSelected(boolean b)
Support Selection status locallyvoid
setState(String newState)
Extract the string describing this trait's state and forward the remaining string to the inner pieceString
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface VASSAL.counters.GamePiece
boundingBox, draw, getName, getShape
Methods inherited from interface VASSAL.counters.PropertyExporter
getProperties
-
Field Details
-
piece
-
-
Constructor Details
-
Decorator
public Decorator()
-
-
Method Details
-
setInner
Set the inner GamePiece -
setMap
Description copied from interface:GamePiece
Each GamePiece belongs to a singleMap
-
getInner
- Returns:
- the piece decorated by this Decorator
-
getMap
-
setParent
-
getParent
-
getProperty
- Specified by:
getProperty
in interfaceGamePiece
- Specified by:
getProperty
in interfacePropertySource
-
getLocalizedProperty
- Specified by:
getLocalizedProperty
in interfacePropertySource
-
setProperty
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'sGamePiece.getState()
method.- Specified by:
setProperty
in interfaceGamePiece
-
setPersistentProperty
- Specified by:
setPersistentProperty
in interfacePersistentPropertyContainer
-
getPersistentProperty
- Specified by:
getPersistentProperty
in interfacePersistentPropertyContainer
-
getOuter
-
setPosition
- Specified by:
setPosition
in interfaceGamePiece
-
getPosition
- Specified by:
getPosition
in interfaceGamePiece
- Returns:
- the location of this piece on its owning
Map
-
mySetState
Set just the state of this trait- See Also:
myGetState()
-
setState
Extract the string describing this trait's state and forward the remaining string to the inner piece -
mergeState
Compute the difference betweennewState
andoldState
and appy that difference to the current state- Specified by:
mergeState
in interfaceStateMergeable
- Parameters:
newState
- New StateoldState
- Old State
-
myGetState
- Returns:
- the state of this trait alone
- See Also:
getState()
-
getState
The state of a Decorator is a composition ofmyGetState()
and the inner piece's state -
myGetType
- Returns:
- the type of this trait alone
- See Also:
getType()
-
getType
The type of a Decorator is a composition ofmyGetType()
and the type of its inner piece- Specified by:
getType
in interfaceGamePiece
- Returns:
- the combined type of this trait and its inner piece
- See Also:
BasicCommandEncoder
-
myGetKeyCommands
- Returns:
- the commands for this trait alone
- See Also:
getKeyCommands()
-
getKeyCommands
The set of key commands that will populate the piece's right-click menu. The key commands are accessible through theProperties.KEY_COMMANDS
property. The commands for a Decorator are a composite ofmyGetKeyCommands()
and the commands of its inner piece.- Returns:
- the commands for this piece and its inner piece
-
myKeyEvent
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
Append the command returned bymyKeyEvent(javax.swing.KeyStroke)
with the command returned by the inner piece'sGamePiece.keyEvent(javax.swing.KeyStroke)
method.- Specified by:
keyEvent
in interfaceGamePiece
- Parameters:
stroke
- Stroke to apply- Returns:
- Generated Command or null if no effect
- See Also:
ForwardToKeyBuffer
-
getId
Description copied from interface:GamePiece
Each GamePiece must have a unique String identifier- Specified by:
getId
in interfaceGamePiece
- See Also:
GameState.getNewPieceId()
-
setId
-
getOutermost
- 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
- Parameters:
p
- Trait to find the Innermost trait of- Returns:
- the innermost GamePiece of this piece. In most cases, an instance of
BasicPiece
-
getDecorator
- Returns:
- the first Decorator within the given GamePiece that is an instance of the given Class
-
getEditor
-
toString
-
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 interfaceGamePiece
-
getI18nData
Return I18n data for this piece- Returns:
- I18n data
-
getI18nData
-
getI18nData
-
getCommandDescription
-
getTranslation
-
reportDataError
protected static void reportDataError(EditablePiece piece, String message, String data, Throwable e)Report a Data Error detected by a trait -
reportDataError
-
reportDataError
-
getPropertyNames
Default Property Name Source- Specified by:
getPropertyNames
in interfacePropertyNameSource
-
setOldProperties
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 byputOldProperties(GamePiece)
Any changes to Oldxxxx properties MUST be recorded in Commands.- Parameters:
p
- Piece to set properties on
-
putOldProperties
Set the Oldxxxx properties related to movement- Parameters:
p
- Piece to set properties on- Returns:
- Command encoding the property values
-
setOldProperties
Deprecated, for removal: This API element is subject to removal in a future version. -
repack
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
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 interfacePropertyExporter
- Parameters:
result
- Map of property values- Returns:
- Updated Map of property values
-
setOldProperties(GamePiece)