VASSAL.counters
Class Decorator

java.lang.Object
  |
  +--VASSAL.counters.Decorator
All Implemented Interfaces:
GamePiece
Direct Known Subclasses:
Embellishment, FreeRotator, Hideable, Immobilized, Labeler, Marker, MovementMarkable, Obscurable, PlaceMarker, ReportState, Restricted, ReturnToDeck, SendToLocation, TableInfo

public abstract class Decorator
extends java.lang.Object
implements GamePiece

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


Constructor Summary
Decorator()
           
 
Method Summary
static GamePiece getDecorator(GamePiece p, java.lang.Class type)
           
 PieceEditor getEditor()
           
 java.lang.String getId()
          Each GamePiece must have a unique String identifier
 GamePiece getInner()
           
static GamePiece getInnermost(GamePiece p)
           
protected  KeyCommand[] getKeyCommands()
          The set of key commands that will populate the piece's right-click menu.
 Map getMap()
           
static GamePiece getOutermost(GamePiece p)
           
 Stack getParent()
           
 java.awt.Point getPosition()
           
 java.lang.Object getProperty(java.lang.Object key)
           
 java.lang.String getState()
          The state of a Decorator is a composition of myGetState() and the inner piece's state
 java.lang.String getType()
          The type of a Decorator is a composition of myGetType() and the type of its inner piece
 Command keyEvent(javax.swing.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.
 void mergeState(java.lang.String newState, java.lang.String oldState)
          Compute the difference between newState and oldState and appy that difference to the current state
protected abstract  KeyCommand[] myGetKeyCommands()
           
abstract  java.lang.String myGetState()
           
abstract  java.lang.String myGetType()
           
abstract  Command myKeyEvent(javax.swing.KeyStroke stroke)
          The response of this trait alone to the given KeyStroke
abstract  void mySetState(java.lang.String newState)
          Set just the state of this trait
 void setId(java.lang.String id)
           
 void setInner(GamePiece p)
          Set the inner GamePiece
 void setMap(Map m)
           
 void setParent(Stack s)
           
 void setPosition(java.awt.Point p)
           
 void setProperty(java.lang.Object key, java.lang.Object val)
          The GamePiece should store properties for retrieval (e.g in a Hashtable) It is not necessary that properties stored with this method be retained in the piece's getState() method.
 void setState(java.lang.String newState)
          Extract the string describing this trait's state and forward the remaining string to the inner piece
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface VASSAL.counters.GamePiece
boundingBox, draw, getName, selectionBounds
 

Constructor Detail

Decorator

public Decorator()
Method Detail

setInner

public void setInner(GamePiece p)
Set the inner GamePiece

getInner

public GamePiece getInner()
Returns:
the inner GamePiece

setMap

public void setMap(Map m)
Specified by:
setMap in interface GamePiece

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

getProperty

public java.lang.Object getProperty(java.lang.Object key)
Specified by:
getProperty in interface GamePiece

setProperty

public void setProperty(java.lang.Object key,
                        java.lang.Object val)
Description copied from interface: GamePiece
The GamePiece should store properties for retrieval (e.g in a Hashtable) It is not necessary that properties stored with this method be retained in the piece's GamePiece.getState() method.
Specified by:
setProperty in interface GamePiece

setPosition

public void setPosition(java.awt.Point p)
Specified by:
setPosition in interface GamePiece

getPosition

public java.awt.Point getPosition()
Specified by:
getPosition in interface GamePiece

mySetState

public abstract void mySetState(java.lang.String newState)
Set just the state of this trait
See Also:
myGetState()

setState

public void setState(java.lang.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(java.lang.String newState,
                       java.lang.String oldState)
Compute the difference between newState and oldState and appy that difference to the current state
Parameters:
newState -  
oldState -  

myGetState

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

getState

public java.lang.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 java.lang.String myGetType()
Returns:
the type of this trait alone
See Also:
getType()

getType

public java.lang.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

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(javax.swing.KeyStroke stroke)
The response of this trait alone to the given KeyStroke
Parameters:
stroke -  
Returns:
null if no effect
See Also:
keyEvent(javax.swing.KeyStroke)

keyEvent

public Command keyEvent(javax.swing.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 -  
Returns:
 

getId

public java.lang.String getId()
Description copied from interface: GamePiece
Each GamePiece must have a unique String identifier
Specified by:
getId in interface GamePiece
Following copied from interface: VASSAL.counters.GamePiece
See Also:
GameState.getNewPieceId()

setId

public void setId(java.lang.String id)
Specified by:
setId in interface GamePiece

getOutermost

public static GamePiece getOutermost(GamePiece p)
Parameters:
p -  
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 -  
Returns:
the innermost GamePiece of this piece. In most cases, an instance of BasicPiece

getDecorator

public static GamePiece getDecorator(GamePiece p,
                                     java.lang.Class type)
Returns:
the first Decorator within the given GamePiece that is an instance of the given Class

getEditor

public PieceEditor getEditor()