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
Nested ClassesModifier and TypeClassDescriptionstatic classColor auto-configurer.static classColor auto-configurer.static classColor auto-configurer.static classAutoconfigurer for the icon for this timer.static classPlayerSidesConfig makes a dropdown of all the player sidesNested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.Util -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanstatic final Stringstatic final charprotected Stringstatic final Stringprotected longstatic final Stringstatic final Stringprotected Stringprotected booleanprotected Stringstatic final Stringstatic final Stringprotected NamedKeyStrokeListenerprotected longstatic final Stringprotected NamedKeyStrokeListenerstatic final Stringstatic final Stringprotected Colorprotected Colorprotected static Timerprotected LaunchButtonprotected booleanstatic final Stringprotected Colorstatic final Stringprotected longFields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, localizedName, myI18nData, nameFields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validatorFields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis processes our timer updates every 100msvoidRegisters us with game module, command encoder, and the Chess Clock Control.voidAdds 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 StringlonggetName()When saving a game, each GameComponent should return aCommandthat, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return nullgetSide()longvoidHides this clockprotected static booleanbooleanvoidremoveFrom(Buildable parent) Unregisters us when we are shutting downCreates a command to reset the clock and turn it offvoidsetAttribute(String key, Object value) Sets the value of one of this component's XML attributesbooleanUpdates clock text on the button, based on our configured stylevoidsetup(boolean gameStarting) Detect when game is starting.voidShows this clockCreates a command to make this clock the currently ticking clockprotected voidMake 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 clockvoidUpdates 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 voidUpdates 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, setConfigureNameMethods inherited from class VASSAL.build.AbstractBuildable
addImageNamesRecursively, build, buildString, getAllDescendantComponentsOf, getAncestor, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getNonFolderAncestor, getPropertyNames, setAncestor, validateMethods inherited from class VASSAL.search.AbstractImageFinder
addLocalImageNames, getAllImageNames, getLocalImageNamesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface VASSAL.script.expression.Auditable
getComponentName, getComponentTypeNameMethods 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:
getDescriptionin 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:
removeFromin interfaceConfigurable- Parameters:
parent- Should be ChessClockControl
-
getAttributeNames
Description copied from class:AbstractBuildableLists 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:
getAttributeNamesin interfaceAutoConfigurable- Specified by:
getAttributeNamesin classAbstractBuildable- Returns:
- Key names for our attributes from the buildFile (XML) definition.
-
getAttributeDescriptions
Description copied from interface:AutoConfigurableReturn 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:
getAttributeDescriptionsin interfaceAutoConfigurable- Specified by:
getAttributeDescriptionsin classAbstractConfigurable- Returns:
- Descriptions for our buildFile (XML) attributes. These appear when our component is configured in the Editor window.
-
getAttributeTypes
Description copied from interface:AutoConfigurableReturn the Class for the attributes of this object. Valid classes are: String, Integer, Double, Boolean, Image, File, Color, and KeyStroke- Specified by:
getAttributeTypesin interfaceAutoConfigurable- Specified by:
getAttributeTypesin 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:
setAttributein interfaceAutoConfigurable- Specified by:
setAttributein interfaceTranslatable- Specified by:
setAttributein 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:
getAttributeValueStringin interfaceAutoConfigurable- Specified by:
getAttributeValueStringin interfaceTranslatable- Specified by:
getAttributeValueStringin classAbstractBuildable- Parameters:
key- the name of the attribute. Will be one of those listed ingetAttributeNames()- Returns:
- String value of the attribute.
-
getHelpFile
- Specified by:
getHelpFilein 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:
getAllowableConfigureComponentsin 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:
decodein interfaceCommandEncoder- Parameters:
command- Serialized string command- Returns:
- An
ChessClock.UpdateTimerCommand
-
encode
Serializes our command into a string, if it belongs to us- Specified by:
encodein 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:
setupin interfaceGameComponent- Parameters:
gameStarting- if true, a game is starting. If false, then a game is ending
-
getRestoreCommand
Description copied from interface:GameComponentWhen saving a game, each GameComponent should return aCommandthat, when executed, restores the GameComponent to its state when the game was saved If this component has no persistent state, return null- Specified by:
getRestoreCommandin 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:
actionPerformedin 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
-