Class ChessClock
java.lang.Object
VASSAL.search.AbstractImageFinder
VASSAL.build.AbstractBuildable
VASSAL.build.AbstractConfigurable
VASSAL.build.module.chessclockcontrol.ChessClock
- All Implemented Interfaces:
ActionListener
,EventListener
,AutoConfigurable
,Buildable
,Configurable
,GameComponent
,PropertyNameSource
,CommandEncoder
,ComponentDescription
,ValidityChecker
,Translatable
,Auditable
,ImageSearchTarget
,SearchTarget
public class ChessClock
extends AbstractConfigurable
implements CommandEncoder, GameComponent, ActionListener, ComponentDescription
CHESS CLOCK class for VASSAL.
The ChessClock class itself implements a single timer, which is added as a button to the Module toolbar.
Clicking the button starts and stops the clock, which we attempt to keep (roughly) in sync across multiple
players' computers. A pair (or more, or I suppose only one) of them are then added to
ChessClockControl
.- Author:
- Brian Reynolds and Michael Kiefte Class originally created by Michael Kiefte for Twilight Struggle, including handshaking for verification of time totals between online machines. Made more generically configurable, ChessClockControl added, and integrated into standard VASSAL, by Brian Reynolds.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Color auto-configurer.static class
Color auto-configurer.static class
Color auto-configurer.static class
Autoconfigurer for the icon for this timer.static class
PlayerSidesConfig makes a dropdown of all the player sidesNested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.Util
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected String
static final String
static final String
static final String
static final String
protected boolean
static final String
static final char
protected String
static final String
protected long
static final String
static final String
protected String
protected boolean
protected String
static final String
static final String
protected NamedKeyStrokeListener
protected long
static final String
protected NamedKeyStrokeListener
static final String
static final String
protected Color
protected Color
protected static Timer
protected LaunchButton
protected boolean
static final String
protected Color
static final String
protected long
Fields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, localizedName, myI18nData, name
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validator
Fields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This processes our timer updates every 100msvoid
Registers us with game module, command encoder, and the Chess Clock Control.void
Adds our clock button to the Module's toolbarDeserializes our command from a string version, if the command belongs to us.Serializes our command into a string, if it belongs to usClass[]
String[]
Return an array of Strings describing the attributes of this object.String[]
Lists all the buildFile (XML) attribute names for this component.Class<?>[]
Return the Class for the attributes of this object.Gets the value of one of this component's XML attributesstatic String
long
getName()
When saving a game, each GameComponent should return aCommand
that, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return nullgetSide()
long
void
Hides this clockprotected static boolean
boolean
void
removeFrom
(Buildable parent) Unregisters us when we are shutting downCreates a command to reset the clock and turn it offvoid
setAttribute
(String key, Object value) Sets the value of one of this component's XML attributesboolean
Updates clock text on the button, based on our configured stylevoid
setup
(boolean gameStarting) Detect when game is starting.void
Shows this clockCreates a command to make this clock the currently ticking clockprotected void
Make sure the static millisecond timer is actually running (unless it hasn't even been initialized yet)Creates a command to make this clock the currently ticking clockvoid
Updates the clock display for this clock (1) Checks new elapsed value from millisecond timerupdateState
(boolean ticking) Creates a command to update the clock and/or turn it on/off.protected void
Updates the color of this chess clock's button/display.Methods inherited from class VASSAL.build.AbstractConfigurable
add, addPropertyChangeListener, getAttributeVisibility, getConfigureComponents, getConfigureName, getConfigurer, getExpressionList, getFormattedStringList, getI18nData, getI18nPrefix, getLocalizedConfigureName, getMenuTextList, getNamedKeyStrokeList, getPropertyList, getTypeName, remove, removePropertyChangeListener, setAllAttributesUntranslatable, setAttributeTranslatable, setConfigureName
Methods inherited from class VASSAL.build.AbstractBuildable
addImageNamesRecursively, build, buildString, getAllDescendantComponentsOf, getAncestor, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getNonFolderAncestor, getPropertyNames, setAncestor, validate
Methods inherited from class VASSAL.search.AbstractImageFinder
addLocalImageNames, getAllImageNames, getLocalImageNames
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface VASSAL.script.expression.Auditable
getComponentName, getComponentTypeName
Methods inherited from interface VASSAL.build.Buildable
build, getBuildElement, isMandatory, isMovable, isUnique
-
Field Details
-
DELIMITER
public static final char DELIMITER- See Also:
-
COMMAND_PREFIX
- See Also:
-
ICON
- See Also:
-
SIDE
- See Also:
-
TOOLTIP
- See Also:
-
BUTTON_TEXT
- See Also:
-
DESCRIPTION
- See Also:
-
START_HOTKEY
- See Also:
-
STOP_HOTKEY
- See Also:
-
TICKING_BACKGROUND_COLOR
- See Also:
-
TICKING_FONT_COLOR
- See Also:
-
TOCKING_FONT_COLOR
- See Also:
-
GENERIC
- See Also:
-
CHESSMENU_START
-
CHESSMENU_NEXT
-
CHESSMENU_STOP
-
CHESSMENU_RESET
-
startListener
-
stopListener
-
tickingBackgroundColor
-
tickingFontColor
-
tockingFontColor
-
timer
-
startTime
protected long startTime -
timerButton
-
image
-
side
-
buttonText
-
elapsedTime
protected long elapsedTime -
verifiedTime
protected long verifiedTime -
clockTicking
protected boolean clockTicking -
tocking
protected boolean tocking -
instanceIsActive
protected boolean instanceIsActive -
description
-
-
Constructor Details
-
ChessClock
-
ChessClock
public ChessClock()
-
-
Method Details
-
getSide
- Returns:
- side this clock is assigned to
-
isTicking
public boolean isTicking()- Returns:
- true if this clock is running
-
getElapsed
public long getElapsed()- Returns:
- elapsed time from local perspective
-
getVerified
public long getVerified()- Returns:
- elapsed time verified by handshake (or fiat, depending on situation)
-
isReferee
- Parameters:
name
- side to check if a referee- Returns:
- True if passed side is a referee
-
getDescription
- Specified by:
getDescription
in interfaceComponentDescription
- Returns:
- Description to be displayed next to component type/name in the main Editor window. Or null or "" to not display anything.
-
startTimer
protected void startTimer()Make sure the static millisecond timer is actually running (unless it hasn't even been initialized yet) -
updateTimerColor
protected void updateTimerColor()Updates the color of this chess clock's button/display. Non-ticking clock uses "default" button look. Ticking clock uses special background and pulsing foreground. -
hideClock
public void hideClock()Hides this clock -
showClock
public void showClock()Shows this clock -
updateDisplay
public void updateDisplay()Updates the clock display for this clock (1) Checks new elapsed value from millisecond timer. (2) Calls setTimerButton to clock time (text) on the button (3) Updates timer button colors if appropriate -
setTimerButton
public boolean setTimerButton()Updates clock text on the button, based on our configured style- Returns:
- half second tick-tock pulse on/off
-
getName
-
addTo
-
addToToolbar
public void addToToolbar()Adds our clock button to the Module's toolbar -
removeFrom
Unregisters us when we are shutting down- Specified by:
removeFrom
in interfaceConfigurable
- Parameters:
parent
- Should be ChessClockControl
-
getAttributeNames
Description copied from class:AbstractBuildable
Lists all the buildFile (XML) attribute names for this component. If this component is ALSO anAbstractConfigurable
, then this list of attributes determines the appropriate attribute order forAbstractConfigurable.getAttributeDescriptions()
andAbstractConfigurable.getAttributeTypes()
.- Specified by:
getAttributeNames
in interfaceAutoConfigurable
- Specified by:
getAttributeNames
in classAbstractBuildable
- Returns:
- Key names for our attributes from the buildFile (XML) definition.
-
getAttributeDescriptions
Description copied from interface:AutoConfigurable
Return an array of Strings describing the attributes of this object. These strings are used as prompts in the Properties window for this object.- Specified by:
getAttributeDescriptions
in interfaceAutoConfigurable
- Specified by:
getAttributeDescriptions
in classAbstractConfigurable
- Returns:
- Descriptions for our buildFile (XML) attributes. These appear when our component is configured in the Editor window.
-
getAttributeTypes
Description copied from interface:AutoConfigurable
Return the Class for the attributes of this object. Valid classes are: String, Integer, Double, Boolean, Image, File, Color, and KeyStroke- Specified by:
getAttributeTypes
in interfaceAutoConfigurable
- Specified by:
getAttributeTypes
in classAbstractConfigurable
- Returns:
- Class types for configuring each of our buildFile (XML) attributes. Specifies which flavor of configurer to uses.
-
setAttribute
Sets the value of one of this component's XML attributes- Specified by:
setAttribute
in interfaceAutoConfigurable
- Specified by:
setAttribute
in interfaceTranslatable
- Specified by:
setAttribute
in classAbstractBuildable
- Parameters:
key
- the name of the attribute. Will be one of those listed ingetAttributeNames()
value
- New value for the attribute. Can be either String version or the actual Object.
-
getAttributeValueString
Gets the value of one of this component's XML attributes- Specified by:
getAttributeValueString
in interfaceAutoConfigurable
- Specified by:
getAttributeValueString
in interfaceTranslatable
- Specified by:
getAttributeValueString
in classAbstractBuildable
- Parameters:
key
- the name of the attribute. Will be one of those listed ingetAttributeNames()
- Returns:
- String value of the attribute.
-
getHelpFile
- Specified by:
getHelpFile
in interfaceConfigurable
- Returns:
- The help file for this component. Used when user clicks "Help" button while configuring the component in the Editor.
-
getConfigureTypeName
- Returns:
- Configure Tree name for component. Appears in [..] in module editor.
-
getAllowableConfigureComponents
- Specified by:
getAllowableConfigureComponents
in interfaceConfigurable
- Returns:
- Array of subcomponent types that can be added to this component
-
decode
Deserializes our command from a string version, if the command belongs to us.- Specified by:
decode
in interfaceCommandEncoder
- Parameters:
command
- Serialized string command- Returns:
- An
ChessClock.UpdateTimerCommand
-
encode
Serializes our command into a string, if it belongs to us- Specified by:
encode
in interfaceCommandEncoder
- Parameters:
c
- Command to serialize. Only serialized if it's an UpdateTimerCommand.- Returns:
- Serialized command, or null if command passed wasn't an UpdateTimerCommand.
-
setup
public void setup(boolean gameStarting) Detect when game is starting.- Specified by:
setup
in interfaceGameComponent
- Parameters:
gameStarting
- if true, a game is starting. If false, then a game is ending
-
getRestoreCommand
Description copied from interface:GameComponent
When saving a game, each GameComponent should return aCommand
that, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return null- Specified by:
getRestoreCommand
in interfaceGameComponent
- Returns:
- Our command for restoring from a saved game (or adding an online player)
-
actionPerformed
This processes our timer updates every 100ms- Specified by:
actionPerformed
in interfaceActionListener
- Parameters:
evt
- Timer event
-
startClock
Creates a command to make this clock the currently ticking clock- Returns:
- a command to set currently ticking clock to us
-
stopClock
Creates a command to make this clock the currently ticking clock- Returns:
- a command to set our clock to non-ticking
-
updateState
Creates a command to update the clock and/or turn it on/off.- Parameters:
ticking
- If true, the clock will be set to "running". If false the clock will be set to "stopped".- Returns:
- a command to communicate the status of this clock to others
-
resetState
Creates a command to reset the clock and turn it off- Returns:
- a command to communicate the status of this clock to others
-