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 StringgetCommandDescription(String description, String command)static GamePiecegetDecorator(GamePiece p, Class<?> type)PieceEditorgetEditor()PieceI18nDatagetI18nData()Return I18n data for this pieceprotected PieceI18nDatagetI18nData(String[] commands, String[] descriptions)protected PieceI18nDatagetI18nData(String command, String description)StringgetId()Each GamePiece must have a unique String identifierGamePiecegetInner()static GamePiecegetInnermost(GamePiece p)protected KeyCommand[]getKeyCommands()The set of key commands that will populate the piece's right-click menu.StringgetLocalizedName()Return the translated name for this piece.ObjectgetLocalizedProperty(Object key)MapgetMap()DecoratorgetOuter()static GamePiecegetOutermost(GamePiece p)StackgetParent()ObjectgetPersistentProperty(Object key)PointgetPosition()Map<String,Object>getProperties(Map<String,Object> result)Implement PropertyExporter.getProperties at the Decorator level.ObjectgetProperty(Object key)List<String>getPropertyNames()Default Property Name SourceStringgetState()The state of a Decorator is a composition ofmyGetState()and the inner piece's stateprotected StringgetTranslation(String key)StringgetType()The type of a Decorator is a composition ofmyGetType()and the type of its inner pieceprotected booleanisSelected()CommandkeyEvent(KeyStroke stroke)Append the command returned bymyKeyEvent(javax.swing.KeyStroke)with the command returned by the inner piece'sGamePiece.keyEvent(javax.swing.KeyStroke)method.voidmergeState(String newState, String oldState)Compute the difference betweennewStateandoldStateand appy that difference to the current stateprotected abstract KeyCommand[]myGetKeyCommands()abstract StringmyGetState()abstract StringmyGetType()abstract CommandmyKeyEvent(KeyStroke stroke)The response of this trait alone to the given KeyStrokeabstract voidmySetState(String newState)Set just the state of this traitstatic CommandputOldProperties(GamePiece p)Set the Oldxxxx properties related to movementstatic voidrepack(Component c)Utility method to allow Decorator Editors to repack themselves.protected static voidreportDataError(EditablePiece piece, String message)protected static voidreportDataError(EditablePiece piece, String message, String data)protected static voidreportDataError(EditablePiece piece, String message, String data, Throwable e)Report a Data Error detected by a traitvoidsetId(String id)voidsetInner(GamePiece p)Set the inner GamePiecevoidsetMap(Map m)Each GamePiece belongs to a singleMapvoidsetOldProperties()Deprecated, for removal: This API element is subject to removal in a future version.static voidsetOldProperties(GamePiece p)Deprecated, for removal: This API element is subject to removal in a future version.voidsetParent(Stack s)CommandsetPersistentProperty(Object key, Object val)voidsetPosition(Point p)voidsetProperty(Object key, Object val)Other properties, possibly game-specific, can be associated with a piece.protected voidsetSelected(boolean b)Support Selection status locallyvoidsetState(String newState)Extract the string describing this trait's state and forward the remaining string to the inner pieceStringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface VASSAL.counters.GamePiece
boundingBox, draw, getName, getShapeMethods 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:GamePieceEach GamePiece belongs to a singleMap -
getInner
- Returns:
- the piece decorated by this Decorator
-
getMap
-
setParent
-
getParent
-
getProperty
- Specified by:
getPropertyin interfaceGamePiece- Specified by:
getPropertyin interfacePropertySource
-
getLocalizedProperty
- Specified by:
getLocalizedPropertyin interfacePropertySource
-
setProperty
Description copied from interface:GamePieceOther 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:
setPropertyin interfaceGamePiece
-
setPersistentProperty
- Specified by:
setPersistentPropertyin interfacePersistentPropertyContainer
-
getPersistentProperty
- Specified by:
getPersistentPropertyin interfacePersistentPropertyContainer
-
getOuter
-
setPosition
- Specified by:
setPositionin interfaceGamePiece
-
getPosition
- Specified by:
getPositionin 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 betweennewStateandoldStateand appy that difference to the current state- Specified by:
mergeStatein 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:
getTypein 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_COMMANDSproperty. 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:
keyEventin interfaceGamePiece- Parameters:
stroke- Stroke to apply- Returns:
- Generated Command or null if no effect
- See Also:
ForwardToKeyBuffer
-
getId
Description copied from interface:GamePieceEach GamePiece must have a unique String identifier- Specified by:
getIdin 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:
getLocalizedNamein 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:
getPropertyNamesin 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:
getPropertiesin interfacePropertyExporter- Parameters:
result- Map of property values- Returns:
- Updated Map of property values
-
setOldProperties(GamePiece)