VASSAL.build
Class GameModule

java.lang.Object
  |
  +--VASSAL.build.AbstractBuildable
        |
        +--VASSAL.build.AbstractConfigurable
              |
              +--VASSAL.build.GameModule
All Implemented Interfaces:
AutoConfigurable, Buildable, CommandEncoder, Configurable

public abstract class GameModule
extends AbstractConfigurable
implements CommandEncoder

The GameModule class is the base class for a VASSAL module. It is the root of the Buildable containment hierarchy. Components which are added directly to the GameModule are contained in the VASSAL.build.module package It is a singleton, and contains access points for many other classes, such as DataArchive, ServerConnection, Logger, and Prefs


Nested Class Summary
 
Nested classes inherited from class VASSAL.build.AutoConfigurable
AutoConfigurable.Util
 
Field Summary
protected  DataArchive archive
           
protected  Chatter chat
           
protected  javax.swing.JPanel chatPanel
           
protected  CommandEncoder[] commandEncoders
           
protected static java.lang.String DEFAULT_NAME
           
protected  javax.swing.JFileChooser fileChooser
           
protected  java.awt.FileDialog fileDialog
           
protected  javax.swing.JFrame frame
           
protected  java.lang.String gameName
           
protected  Prefs globalPrefs
           
protected  java.util.Vector keyStrokeListeners
           
protected  java.util.Vector keyStrokeSources
           
protected  java.lang.String lastSavedConfiguration
           
protected  Logger logger
           
static java.lang.String MODULE_NAME
           
static java.lang.String MODULE_VERSION
           
protected  java.lang.String moduleVersion
           
static java.lang.String PERSONAL_INFO
          The Prefs key for the user's personal info
protected  Prefs preferences
           
static java.lang.String REAL_NAME
          The Prefs key for the user's real name
protected  java.util.Random RNG
           
static java.lang.String SECRET_NAME
          The Prefs key for the user's secret name
protected  javax.swing.JTextField status
           
protected  GameState theState
           
static java.lang.String VASSAL_VERSION_CREATED
           
static java.lang.String VASSAL_VERSION_RUNNING
          The System property of this name will return a version identifier for the version of VASSAL being run
protected  java.lang.String vassalVersionCreated
           
 
Fields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, name
 
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents
 
Fields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY
 
Constructor Summary
protected GameModule(DataArchive archive)
           
 
Method Summary
 void addCommandEncoder(CommandEncoder ce)
          This method adds a CommandEncoder to the list of objects that will attempt to decode/encode a command
 void addKeyStrokeListener(KeyStrokeListener l)
          The GameModule acts as the mediator for hotkey events.
 void addKeyStrokeSource(KeyStrokeSource src)
          The GameModule acts as the mediator for hotkey events.
 void addTo(Buildable b)
          Adds this component to its parent.
 void appendToTitle(java.lang.String s)
          Append the string to the title of the controls window and all Map windows
protected abstract  void build()
          Initialize the module
protected  java.lang.String buildString()
           
static int compareVersions(java.lang.String v1, java.lang.String v2)
          A valid verson format is "w.x.y[bz]", where 'w','x','y', and 'z' are integers.
 Command decode(java.lang.String command)
          Uses the registered CommandEncoders to decode a String into a Command.
 java.lang.String encode(Command c)
          Uses the registered CommandEncoders to encode a Command into a String object
 java.lang.Class[] getAllowableConfigureComponents()
          Return a list of valid sub-component Classes.
 ArchiveWriter getArchiveWriter()
          If the module is being edited, return the writeable archive for the module
 java.lang.String[] getAttributeDescriptions()
          Return an array of Strings describing the attributes of this object.
 java.lang.String[] getAttributeNames()
           
 java.lang.Class[] getAttributeTypes()
          Return the Class for the attributes of this object.
 java.lang.String getAttributeValueString(java.lang.String name)
          Called by the AbstractBuildable.getBuildElement(org.w3c.dom.Document) method to write the attributes into an XML element
 Chatter getChatter()
           
static java.lang.String getConfigureTypeName()
           
 DataArchive getDataArchive()
           
 javax.swing.JFileChooser getFileChooser()
           
 java.awt.FileDialog getFileDialog()
           
 javax.swing.JMenu getFileMenu()
           
 javax.swing.JFrame getFrame()
           
static GameModule getGameModule()
           
 java.lang.String getGameName()
           
 GameState getGameState()
          Return the object responsible for tracking the state of a game.
 java.lang.String getGameVersion()
           
 Prefs getGlobalPrefs()
          A set of preferences that applies to all modules
 HelpFile getHelpFile()
           
 Logger getLogger()
           
 Prefs getPrefs()
           
 java.util.Random getRNG()
           
abstract  ServerConnection getServer()
           
 javax.swing.JToolBar getToolBar()
           
static java.lang.String getUserId()
           
static void init(GameModule module)
          Set the singleton GameModule and invoke build() on it
 void quit()
          Exit the application, prompting user to save if necessary
 void removeCommandEncoder(CommandEncoder ce)
          This method removes a CommandEncoder from the list of objects that will attempt to decode/encode a command
 void removeFrom(Buildable parent)
          Remove this component from its parent
 void save()
          If the module is being edited, write the module data
protected  void save(boolean saveAs)
           
 void saveAs()
           
 void sendAndLog(Command c)
          Encode the Command, send it to the server and write it to a logfile (if any is open)
 void setAttribute(java.lang.String name, java.lang.Object value)
          Called by the build() method, where value is the String value read by the XML attribute.
 void setChatter(Chatter c)
          set the object that displays chat text
 void setPrefs(Prefs p)
           
static void setUserId(java.lang.String newId)
          Set the identifier for the user
 void warn(java.lang.String s)
          Display the given text in the control window's status line
 
Methods inherited from class VASSAL.build.AbstractConfigurable
addPropertyChangeListener, getAttributeVisibility, getConfigureComponents, getConfigureName, getConfigurer, remove, setConfigureName
 
Methods inherited from class VASSAL.build.AbstractBuildable
add, build, getBuildComponents, getBuildElement, getComponents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface VASSAL.build.Buildable
add, build, getBuildElement
 

Field Detail

DEFAULT_NAME

protected static final java.lang.String DEFAULT_NAME
See Also:
Constant Field Values

MODULE_NAME

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

MODULE_VERSION

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

VASSAL_VERSION_CREATED

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

VASSAL_VERSION_RUNNING

public static final java.lang.String VASSAL_VERSION_RUNNING
The System property of this name will return a version identifier for the version of VASSAL being run

See Also:
Constant Field Values

moduleVersion

protected java.lang.String moduleVersion

vassalVersionCreated

protected java.lang.String vassalVersionCreated

gameName

protected java.lang.String gameName

lastSavedConfiguration

protected java.lang.String lastSavedConfiguration

fileChooser

protected javax.swing.JFileChooser fileChooser

fileDialog

protected java.awt.FileDialog fileDialog

status

protected javax.swing.JTextField status

chatPanel

protected javax.swing.JPanel chatPanel

theState

protected GameState theState

archive

protected DataArchive archive

preferences

protected Prefs preferences

globalPrefs

protected Prefs globalPrefs

logger

protected Logger logger

chat

protected Chatter chat

RNG

protected java.util.Random RNG

frame

protected javax.swing.JFrame frame

keyStrokeSources

protected java.util.Vector keyStrokeSources

keyStrokeListeners

protected java.util.Vector keyStrokeListeners

commandEncoders

protected CommandEncoder[] commandEncoders

REAL_NAME

public static final java.lang.String REAL_NAME
The Prefs key for the user's real name

See Also:
Constant Field Values

SECRET_NAME

public static final java.lang.String SECRET_NAME
The Prefs key for the user's secret name

See Also:
Constant Field Values

PERSONAL_INFO

public static final java.lang.String PERSONAL_INFO
The Prefs key for the user's personal info

See Also:
Constant Field Values
Constructor Detail

GameModule

protected GameModule(DataArchive archive)
Method Detail

getFrame

public javax.swing.JFrame getFrame()
Returns:
the top-level frame of the controls window

build

protected abstract void build()
Initialize the module


setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from interface: AutoConfigurable
Called by the Buildable.build(org.w3c.dom.Element) method, where value is the String value read by the XML attribute. Can also be called with Object value to set the attribute.

Specified by:
setAttribute in interface AutoConfigurable
Specified by:
setAttribute in class AbstractBuildable
Parameters:
name - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()

getAttributeValueString

public java.lang.String getAttributeValueString(java.lang.String name)
Description copied from interface: AutoConfigurable
Called by the Buildable.getBuildElement(org.w3c.dom.Document) method to write the attributes into an XML element

Specified by:
getAttributeValueString in interface AutoConfigurable
Specified by:
getAttributeValueString in class AbstractBuildable
Parameters:
name - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()

compareVersions

public static int compareVersions(java.lang.String v1,
                                  java.lang.String v2)
A valid verson format is "w.x.y[bz]", where 'w','x','y', and 'z' are integers.

Returns:
a negative number if v2 is a later version the v1, a positive number if an earlier version, or zero if the versions are the same.

addTo

public void addTo(Buildable b)
Description copied from interface: Buildable
Adds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class.

Specified by:
addTo in interface Buildable

getConfigureTypeName

public static java.lang.String getConfigureTypeName()

removeFrom

public void removeFrom(Buildable parent)
Description copied from interface: Configurable
Remove this component from its parent

Specified by:
removeFrom in interface Configurable

getHelpFile

public HelpFile getHelpFile()
Specified by:
getHelpFile in interface Configurable
Returns:
a HelpFilte describing how to use and configure this component

getAttributeNames

public java.lang.String[] getAttributeNames()
Specified by:
getAttributeNames in interface AutoConfigurable
Specified by:
getAttributeNames in class AbstractBuildable
Returns:
an array of Strings giving all attributes of this Buildable component that will be written to/read from an XML element

getAttributeDescriptions

public java.lang.String[] getAttributeDescriptions()
Description copied from class: AbstractConfigurable
Return an array of Strings describing the attributes of this object. These strings are used as prompts in the Properties window for this object. The order of descriptions should be the same as the order of names in AbstractBuildable.getAttributeNames()

Specified by:
getAttributeDescriptions in interface AutoConfigurable
Specified by:
getAttributeDescriptions in class AbstractConfigurable

getAttributeTypes

public java.lang.Class[] getAttributeTypes()
Description copied from class: AbstractConfigurable
Return the Class for the attributes of this object. Valid classes are: String, Integer, Double, Boolean, Image, Color, and KeyStroke The order of classes should be the same as the order of names in AbstractBuildable.getAttributeNames()

Specified by:
getAttributeTypes in interface AutoConfigurable
Specified by:
getAttributeTypes in class AbstractConfigurable

getAllowableConfigureComponents

public java.lang.Class[] getAllowableConfigureComponents()
Description copied from interface: Configurable
Return a list of valid sub-component Classes. If a Class appears in this list, then instances of that class may be added to this component from the Configuration Window.

Specified by:
getAllowableConfigureComponents in interface Configurable

addKeyStrokeSource

public void addKeyStrokeSource(KeyStrokeSource src)
The GameModule acts as the mediator for hotkey events. Components that wish to fire hotkey events when they have the focus should register themselves using this method. These events will be forwarded to all listeners that have registered themselves with addKeyStrokeListener(VASSAL.tools.KeyStrokeListener)


addKeyStrokeListener

public void addKeyStrokeListener(KeyStrokeListener l)
The GameModule acts as the mediator for hotkey events. Objects that react to hotkey events should register themselves using this method. Any component that has been registered with addKeyStrokeSource(VASSAL.tools.KeyStrokeSource) will forward hotkey events to listeners registered with this method.


getGameName

public java.lang.String getGameName()
Returns:
the name of the game for this module

getGameVersion

public java.lang.String getGameVersion()

getPrefs

public Prefs getPrefs()
Returns:
the preferences for this module

getGlobalPrefs

public Prefs getGlobalPrefs()
A set of preferences that applies to all modules

Returns:

addCommandEncoder

public void addCommandEncoder(CommandEncoder ce)
This method adds a CommandEncoder to the list of objects that will attempt to decode/encode a command

See Also:
decode(java.lang.String), encode(VASSAL.command.Command)

removeCommandEncoder

public void removeCommandEncoder(CommandEncoder ce)
This method removes a CommandEncoder from the list of objects that will attempt to decode/encode a command

See Also:
decode(java.lang.String), encode(VASSAL.command.Command)

warn

public void warn(java.lang.String s)
Display the given text in the control window's status line


getRNG

public java.util.Random getRNG()
Returns:
a single Random number generator that all objects may share

getLogger

public Logger getLogger()
Returns:
the object responsible for logging commands to a logfile

setChatter

public void setChatter(Chatter c)
set the object that displays chat text


getChatter

public Chatter getChatter()
Returns:
the object that displays chat text

setPrefs

public void setPrefs(Prefs p)

decode

public Command decode(java.lang.String command)
Uses the registered CommandEncoders to decode a String into a Command.

Specified by:
decode in interface CommandEncoder

encode

public java.lang.String encode(Command c)
Uses the registered CommandEncoders to encode a Command into a String object

Specified by:
encode in interface CommandEncoder

getFileChooser

public javax.swing.JFileChooser getFileChooser()
Returns:
a common FileChooser so that recent file locations can be remembered

getFileDialog

public java.awt.FileDialog getFileDialog()

getToolBar

public javax.swing.JToolBar getToolBar()
Returns:
the JToolBar of the command window

getFileMenu

public javax.swing.JMenu getFileMenu()
Returns:
the File menu of the command window

appendToTitle

public void appendToTitle(java.lang.String s)
Append the string to the title of the controls window and all Map windows

Parameters:
s - If null, set the title to the defaul

quit

public void quit()
Exit the application, prompting user to save if necessary


sendAndLog

public void sendAndLog(Command c)
Encode the Command, send it to the server and write it to a logfile (if any is open)

See Also:
encode(VASSAL.command.Command)

getUserId

public static java.lang.String getUserId()
Returns:
a String that uniquely identifies the user

setUserId

public static void setUserId(java.lang.String newId)
Set the identifier for the user


getServer

public abstract ServerConnection getServer()
Returns:
the object reponsible for sending messages to the server

init

public static void init(GameModule module)
                 throws java.io.IOException
Set the singleton GameModule and invoke build() on it

java.io.IOException

getDataArchive

public DataArchive getDataArchive()
Returns:
the object which stores data for the module

getArchiveWriter

public ArchiveWriter getArchiveWriter()
If the module is being edited, return the writeable archive for the module


getGameModule

public static GameModule getGameModule()
Returns:
the singleton instance of GameModule

getGameState

public GameState getGameState()
Return the object responsible for tracking the state of a game. Only one game in progress is allowed;


saveAs

public void saveAs()

save

public void save()
If the module is being edited, write the module data


save

protected void save(boolean saveAs)

buildString

protected java.lang.String buildString()