VASSAL.counters
Class Stack

java.lang.Object
  |
  +--VASSAL.counters.Stack
All Implemented Interfaces:
GamePiece

public class Stack
extends java.lang.Object
implements GamePiece

A collection of GamePieces which can be moved as a single unit


Field Summary
protected  GamePiece[] contents
           
protected  Map map
           
protected  int pieceCount
           
protected  java.awt.Point pos
           
static java.lang.String TYPE
           
 
Constructor Summary
Stack()
           
Stack(GamePiece p)
           
 
Method Summary
 void add(GamePiece c)
           
 GamePiece bottomPiece()
           
 java.awt.Rectangle boundingBox()
          The area which this GamePiece occupies when drawn at the point given by getPosition().
 void draw(java.awt.Graphics g, int x, int y, java.awt.Component obs, double zoom)
          If the obs parameter is a Map, delegate drawing of this Stack to the StackMetrics of that Map.
 StackMetrics getDefaultMetrics()
           
 java.lang.String getId()
          Each GamePiece must have a unique String identifier
 Map getMap()
           
 java.lang.String getName()
          Return a comma-separated list of the names of the pieces in this Stack
 Stack getParent()
           
 GamePiece getPieceAt(int index)
           
 int getPieceCount()
           
 java.util.Enumeration getPieces()
           
 java.util.Enumeration getPiecesInReverseOrder()
           
 java.util.Enumeration getPiecesInVisibleOrder()
          Returns pieces in the order in which they are visible to the player -- topmost first In other words, selected pieces first, then unselected pieces from the top to the bottom
 java.awt.Point getPosition()
           
 java.lang.Object getProperty(java.lang.Object key)
           
 java.lang.String getState()
          The state information is information that can change during the course of a game.
 java.lang.String getType()
          The type information is information that does not change during the course of a game.
 int indexOf(GamePiece p)
           
 void insert(GamePiece p, int pos)
           
 boolean isExpanded()
           
 Command keyEvent(javax.swing.KeyStroke stroke)
          Keyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likes
 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  int nVisible()
           
 void remove(GamePiece p)
           
 void removeAll()
           
 java.awt.Rectangle selectionBounds()
          The area which is considered part of this GamePiece for purposes of selecting it with the mouse
 void selectNext(GamePiece c)
           
static void setDefaultMetrics(StackMetrics s)
           
 void setExpanded(boolean b)
           
 void setId(java.lang.String id)
           
 void setMap(Map map)
           
 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 s)
           
 GamePiece topPiece()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE

public static final java.lang.String TYPE
See Also:
Constant Field Values

contents

protected GamePiece[] contents

pieceCount

protected int pieceCount

pos

protected java.awt.Point pos

map

protected Map map
Constructor Detail

Stack

public Stack()

Stack

public Stack(GamePiece p)
Method Detail

getPieces

public java.util.Enumeration getPieces()
Returns:
an Enumeration of the pieces in the stack. This is a clone of the contents so add/remove operations during read won't affect it.

getPiecesInReverseOrder

public java.util.Enumeration getPiecesInReverseOrder()

getPiecesInVisibleOrder

public java.util.Enumeration getPiecesInVisibleOrder()
Returns pieces in the order in which they are visible to the player -- topmost first In other words, selected pieces first, then unselected pieces from the top to the bottom


remove

public void remove(GamePiece p)

removeAll

public void removeAll()

indexOf

public int indexOf(GamePiece p)

getPieceAt

public GamePiece getPieceAt(int index)

add

public void add(GamePiece c)

getPieceCount

public int getPieceCount()

insert

public void insert(GamePiece p,
                   int pos)

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y,
                 java.awt.Component obs,
                 double zoom)
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
See Also:
StackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double), getDefaultMetrics()

getName

public java.lang.String getName()
Return a comma-separated list of the names of the pieces in this Stack

Specified by:
getName in interface GamePiece

boundingBox

public java.awt.Rectangle boundingBox()
Description copied from interface: GamePiece
The area which this GamePiece occupies when drawn at the point given by getPosition().

Specified by:
boundingBox in interface GamePiece

selectionBounds

public java.awt.Rectangle selectionBounds()
Description copied from interface: GamePiece
The area which is considered part of this GamePiece for purposes of selecting it with the mouse

Specified by:
selectionBounds in interface GamePiece

selectNext

public void selectNext(GamePiece c)

topPiece

public GamePiece topPiece()
Returns:
the top visible piece in this stack

bottomPiece

public GamePiece bottomPiece()
Returns:
the bottom visible piece in this stack

nVisible

protected int nVisible()
Returns:
Number of GamePieces that are visible to me

keyEvent

public Command keyEvent(javax.swing.KeyStroke stroke)
Description copied from interface: GamePiece
Keyboard events are forward to this method when a piece is selected The GamePiece can respond in any way it likes

Specified by:
keyEvent in interface GamePiece
Returns:
a Command that, when executed, will invoke the same response. Usually a ChangePiece command.
See Also:
ForwardToKeyBuffer

isExpanded

public boolean isExpanded()

setExpanded

public void setExpanded(boolean b)

getState

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

setState

public void setState(java.lang.String s)
Specified by:
setState in interface GamePiece

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 -

getType

public java.lang.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
See Also:
BasicCommandEncoder

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

getProperty

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

setMap

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

getMap

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

getPosition

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

setPosition

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

getParent

public Stack getParent()
Specified by:
getParent in interface GamePiece

setParent

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

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
See Also:
GameState.getNewPieceId()

setId

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

setDefaultMetrics

public static void setDefaultMetrics(StackMetrics s)

getDefaultMetrics

public StackMetrics getDefaultMetrics()