Class ChessClockControl

All Implemented Interfaces:
AutoConfigurable, Buildable, Configurable, GameComponent, PropertyNameSource, CommandEncoder, ComponentDescription, ValidityChecker, Translatable, Auditable, ImageSearchTarget, SearchTarget, UniqueIdManager.Identifyable

CHESS CLOCK CONTROLLER for VASSAL. This Module-level component manages a set of one or more ChessClock clocks. It creates a master "Chess Clocks" button on the Module's toolbar. Clicking the button shows/hides the clocks themselves, when no clocks are running, or stops all clocks if one is running. The Chess Clock Control component also contains the configurable elements that specify how the clocks are to be displayed.
  • Field Details

  • Constructor Details

    • ChessClockControl

      public ChessClockControl()
  • Method Details

    • isInstanceIsActive

      public boolean isInstanceIsActive()
    • getChessClocks

      public List<ChessClock> getChessClocks()
      Returns:
      Our list of chessclocks
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface ComponentDescription
      Returns:
      Description to be displayed next to component type/name in the main Editor window. Or null or "" to not display anything.
    • build

      public void build(Element e)
      Builds the clock control's component hierarchy from a given XML element, or a null one is given initializes a brand new default "new clock control" hierarchy.
      Specified by:
      build in interface Buildable
      Overrides:
      build in class AbstractBuildable
      Parameters:
      e - XML element to build from, or null to build the default hierarchy
    • addTo

      public void addTo(Buildable parent)
      Registers us with the game module, tool bar, command encoder, etc.
      Specified by:
      addTo in interface Buildable
      Parameters:
      parent - - Should be the main GameModule, but in any event that's what we add it to
    • removeFrom

      public void removeFrom(Buildable parent)
      Unregisters us from everything when shutting down.
      Specified by:
      removeFrom in interface Configurable
      Parameters:
      parent - - Presumably the main GameModule, but in any event that's what we remove ourselves from.
    • setId

      public void setId(String id)
      Manages our unique ID
      Specified by:
      setId in interface UniqueIdManager.Identifyable
      Parameters:
      id - - sets our unique id
    • getId

      public String getId()
      Specified by:
      getId in interface UniqueIdManager.Identifyable
      Returns:
      our unique id
    • isAllowReset

      public boolean isAllowReset()
      Returns:
      Whether clocks can be reset manually
    • getChessClocksVisible

      public boolean getChessClocksVisible()
      Returns:
      true if the group of chess clocks we manage is currently visible
    • getConfigureTypeName

      public static String getConfigureTypeName()
      Returns:
      Component type name, which appears in [..] in Editor window
    • getAllowableConfigureComponents

      public Class<?>[] getAllowableConfigureComponents()
      Specified by:
      getAllowableConfigureComponents in interface Configurable
      Returns:
      List of valid subcomponent class types for this component (in our case, individual Chess Clocks!) which can be added in the Editor.
    • getAttributeNames

      public String[] getAttributeNames()
      Description copied from class: AbstractBuildable
      Lists all the buildFile (XML) attribute names for this component. If this component is ALSO an AbstractConfigurable, then this list of attributes determines the appropriate attribute order for AbstractConfigurable.getAttributeDescriptions() and AbstractConfigurable.getAttributeTypes().
      Specified by:
      getAttributeNames in interface AutoConfigurable
      Specified by:
      getAttributeNames in class AbstractBuildable
      Returns:
      Key names for our attributes from the buildFile (XML) definition.
    • getAttributeDescriptions

      public String[] 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 interface AutoConfigurable
      Specified by:
      getAttributeDescriptions in class AbstractConfigurable
      Returns:
      Descriptions for our buildFile (XML) attributes. These appear when our component is configured in the Editor window.
    • getAttributeTypes

      public Class<?>[] 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 interface AutoConfigurable
      Specified by:
      getAttributeTypes in class AbstractConfigurable
      Returns:
      Class types for configuring each of our buildFile (XML) attributes. Specifies which flavor of configurer to uses.
    • setAttribute

      public void setAttribute(String key, Object value)
      Sets the value of one of this component's XML attributes
      Specified by:
      setAttribute in interface AutoConfigurable
      Specified by:
      setAttribute in interface Translatable
      Specified by:
      setAttribute in class AbstractBuildable
      Parameters:
      key - the name of the attribute. Will be one of those listed in getAttributeNames()
      value - New value for the attribute. Can be either String version or the actual Object.
    • getAttributeValueString

      public String getAttributeValueString(String key)
      Gets the value of one of this component's XML attributes
      Specified by:
      getAttributeValueString in interface AutoConfigurable
      Specified by:
      getAttributeValueString in interface Translatable
      Specified by:
      getAttributeValueString in class AbstractBuildable
      Parameters:
      key - the name of the attribute. Will be one of those listed in getAttributeNames()
      Returns:
      String value of the attribute.
    • getHelpFile

      public HelpFile getHelpFile()
      Specified by:
      getHelpFile in interface Configurable
      Returns:
      The help file for this component. Used when user clicks "Help" button while configuring the component in the Editor.
    • getInstance

      public static ChessClockControl getInstance()
      When we need to find a ChessClockControl in a static context
      Returns:
      First ChessClockControl in our module
    • getShowTenths

      public String getShowTenths()
      Returns:
      Setting for showing tenths of seconds. (Always, Auto, Never)
    • getShowSeconds

      public String getShowSeconds()
      Returns:
      Setting for showing seconds. (Always, Auto, Never)
    • getShowHours

      public String getShowHours()
      Returns:
      Setting for showing hours. (Always, Auto, Never)
    • getShowDays

      public String getShowDays()
      Returns:
      Setting for showing days. (Always, Auto, Never)
    • getClocksTicking

      public int getClocksTicking()
      Returns:
      the number of chess clocks currently ticking/active
    • stopAllClocks

      public Command stopAllClocks()
      Returns:
      A command to stop all the clocks
    • startNextClock

      public Command startNextClock()
      Returns:
      a command to start the next clock after stopping the one currently running (if any)
    • startOpponentClock

      public Command startOpponentClock()
      Returns:
      a command to start the opponents clock after stopping the one currently running (if any)
    • startClock

      public Command startClock(ChessClock targetClock)
      Returns:
      a command to start the requested clock after stopping the one currently running (if any)
    • stopClock

      public Command stopClock(ChessClock targetClock)
      Returns:
      a command to start the requested clock after stopping the one currently running (if any)
    • hideClocks

      public void hideClocks()
      Hide all the clocks on the toolbar
    • showClocks

      public void showClocks()
      Show all the clocks on the toolbar
    • updateAllClocks

      public void updateAllClocks()
      Update all clocks (when our time-display format changes)
    • pressControlButton

      public void pressControlButton()
      Figures out "the right thing to do" when player clicks the main Chess Clock Control button. Does one of the following, in order of priority: (1) If the clocks are hidden, show them (2) If any clock is running, stop them all (3) Hide all the clocks
    • setOnline

      public void setOnline(boolean online)
      Tells Chess Clock Control that this is a real online game, meaning we move to stricter verification standards for clocks (completely non-online clocks are really just "sandbox toys")
      Parameters:
      online - True if this is an online game
    • isOnline

      public boolean isOnline()
      Returns:
      True if this has been marked as an online game
    • setup

      public void setup(boolean gameStarting)
      Handles starting and ending a game from the point of view of Chess Clocks.
      Specified by:
      setup in interface GameComponent
      Parameters:
      gameStarting - If true, a game is starting. If false, then a game is ending.
    • addChessClock

      public void addChessClock(ChessClock clock)
      Allows individual chess clocks to add themselves to our control scheme
      Parameters:
      clock - clock to be added
    • removeChessClock

      public void removeChessClock(ChessClock clock)
      Removes a chess clock
      Parameters:
      clock - clock to be removed
    • decode

      public Command decode(String command)
      Deserializes our command from a string version, if the command belongs to us.
      Specified by:
      decode in interface CommandEncoder
      Parameters:
      command - Serialized string command
      Returns:
      An ChessClockControl.UpdateClockControlCommand
    • encode

      public String encode(Command c)
      Serializes our command into a string, if it belongs to us
      Specified by:
      encode in interface CommandEncoder
      Parameters:
      c - Command to serialize. Only serialized if it's an UpdateClockControlCommand.
      Returns:
      Serialized command, or null if command passed wasn't an UpdateClockControlCommand.
    • getRestoreCommand

      public Command getRestoreCommand()
      Description copied from interface: GameComponent
      When saving a game, each GameComponent should return a Command 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 interface GameComponent
      Returns:
      Our command for restoring from a saved game (or adding an online player)
    • isUnique

      public boolean isUnique()
      There can be only one!
      Specified by:
      isUnique in interface Buildable
      Returns: