Class ConsoleCheckerboardViewerImpl<P extends Player<P,S>,S>

  • Type Parameters:
    P - the generic type of the Player
    S - The type which's instances represent a Player state.
    All Implemented Interfaces:
    CheckerboardObserver<P,S>, CheckerboardViewer<P,S,ConsoleCheckerboardViewer<P,S>>, ConsoleCheckerboardViewer<P,S>, org.refcodes.component.Component, org.refcodes.component.Destroyable, org.refcodes.component.Initializable, org.refcodes.component.Initializable.InitializeBuilder<P>, org.refcodes.component.InitializableComponent, org.refcodes.graphical.GridDimension, org.refcodes.graphical.GridHeightAccessor, org.refcodes.graphical.GridModeAccessor, org.refcodes.graphical.GridWidthAccessor, org.refcodes.graphical.MinViewportDimension, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionBuilder<P>, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionMutator, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionProperty, org.refcodes.graphical.ViewportDimension, org.refcodes.graphical.ViewportDimension.ViewportDimensionBuilder<P>, org.refcodes.graphical.ViewportDimension.ViewportDimensionMutator, org.refcodes.graphical.ViewportDimension.ViewportDimensionProperty, org.refcodes.graphical.ViewportHeightAccessor, org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightBuilder<P>, org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightMutator, org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightProperty, org.refcodes.graphical.ViewportOffset, org.refcodes.graphical.ViewportOffset.ViewportOffsetBuilder<P>, org.refcodes.graphical.ViewportOffset.ViewportOffsetMutator, org.refcodes.graphical.ViewportOffset.ViewportOffsetProperty, org.refcodes.graphical.ViewportOffsetXAccessor, org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXBuilder<P>, org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXMutator, org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXProperty, org.refcodes.graphical.ViewportOffsetYAccessor, org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYBuilder<P>, org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYMutator, org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYProperty, org.refcodes.graphical.ViewportWidthAccessor, org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthBuilder<P>, org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthMutator, org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthProperty, org.refcodes.mixin.ColumnWidthAccessor, org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthBuilder<P>, org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthMutator, org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthProperty, org.refcodes.observer.ObservableObserver<P>


    public class ConsoleCheckerboardViewerImpl<P extends Player<P,S>,S>
    extends AbstractCheckerboardViewer<P,S,java.lang.String,ConsoleSpriteFactory<S>,ConsoleCheckerboardViewer<P,S>>
    implements ConsoleCheckerboardViewer<P,S>
    Most basic implementation of the CheckerboardViewer interface printing the current checkerboard as good as it gets. Call initialize() when everything is setup correctly. When a redraw time <= 0 is set upon construction, then the Checkerboard is printed out upon any according events from the underlying Checkerboard or, in case the refresh time is > 0 the Checkerboard is redrawn as of the refresh loop time. Attention: The Checkerboard is only redrawn in case the Checkerboard changed compared to the last redraw process.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.refcodes.mixin.ColumnWidthAccessor

        org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthBuilder<B extends org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthBuilder<B>>, org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthMutator, org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthProperty
      • Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

        org.refcodes.component.Destroyable.DestroyAutomaton
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.GridDimension

        org.refcodes.graphical.GridDimension.GridDimensionBuilder<B extends org.refcodes.graphical.GridDimension.GridDimensionBuilder<B>>, org.refcodes.graphical.GridDimension.GridDimensionMutator, org.refcodes.graphical.GridDimension.GridDimensionProperty, org.refcodes.graphical.GridDimension.GridDimensionPropertyBuilder
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.GridHeightAccessor

        org.refcodes.graphical.GridHeightAccessor.GridHeightBuilder<B extends org.refcodes.graphical.GridHeightAccessor.GridHeightBuilder<B>>, org.refcodes.graphical.GridHeightAccessor.GridHeightMutator, org.refcodes.graphical.GridHeightAccessor.GridHeightProperty
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.GridModeAccessor

        org.refcodes.graphical.GridModeAccessor.GridModeBuilder<B extends org.refcodes.graphical.GridModeAccessor.GridModeBuilder<B>>, org.refcodes.graphical.GridModeAccessor.GridModeMutator, org.refcodes.graphical.GridModeAccessor.GridModeProperty
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.GridWidthAccessor

        org.refcodes.graphical.GridWidthAccessor.GridWidthBuilder<B extends org.refcodes.graphical.GridWidthAccessor.GridWidthBuilder<B>>, org.refcodes.graphical.GridWidthAccessor.GridWidthMutator, org.refcodes.graphical.GridWidthAccessor.GridWidthProperty
      • Nested classes/interfaces inherited from interface org.refcodes.component.Initializable

        org.refcodes.component.Initializable.InitializeAutomaton, org.refcodes.component.Initializable.InitializeBuilder<B extends org.refcodes.component.Initializable.InitializeBuilder<B>>, org.refcodes.component.Initializable.UncheckedInitializable
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.MinViewportDimension

        org.refcodes.graphical.MinViewportDimension.MinViewportDimensionBuilder<B extends org.refcodes.graphical.MinViewportDimension.MinViewportDimensionBuilder<B>>, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionMutator, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionProperty, org.refcodes.graphical.MinViewportDimension.MinViewportDimensionPropertyBuilderBuilder
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportDimension

        org.refcodes.graphical.ViewportDimension.ViewportDimensionBuilder<B extends org.refcodes.graphical.ViewportDimension.ViewportDimensionBuilder<B>>, org.refcodes.graphical.ViewportDimension.ViewportDimensionMutator, org.refcodes.graphical.ViewportDimension.ViewportDimensionProperty, org.refcodes.graphical.ViewportDimension.ViewportDimensionPropertyBuilderBuilder
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportHeightAccessor

        org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightBuilder<B extends org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightBuilder<B>>, org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightMutator, org.refcodes.graphical.ViewportHeightAccessor.ViewportHeightProperty
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportOffset

        org.refcodes.graphical.ViewportOffset.ViewportOffsetBuilder<B extends org.refcodes.graphical.ViewportOffset.ViewportOffsetBuilder<B>>, org.refcodes.graphical.ViewportOffset.ViewportOffsetMutator, org.refcodes.graphical.ViewportOffset.ViewportOffsetProperty, org.refcodes.graphical.ViewportOffset.ViewportOffsetPropertyBuilder
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportOffsetXAccessor

        org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXBuilder<B extends org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXBuilder<B>>, org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXMutator, org.refcodes.graphical.ViewportOffsetXAccessor.ViewportOffsetXProperty
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportOffsetYAccessor

        org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYBuilder<B extends org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYBuilder<B>>, org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYMutator, org.refcodes.graphical.ViewportOffsetYAccessor.ViewportOffsetYProperty
      • Nested classes/interfaces inherited from interface org.refcodes.graphical.ViewportWidthAccessor

        org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthBuilder<B extends org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthBuilder<B>>, org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthMutator, org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthProperty
    • Constructor Detail

      • ConsoleCheckerboardViewerImpl

        public ConsoleCheckerboardViewerImpl​(Checkerboard<P,S> aCheckerboard,
                                             ConsoleSpriteFactory<S> aSpriteFactory,
                                             int aRedrawLoopTimeInMillis)
        Constructs the ConsoleCheckerboardViewer with the provided SpriteFactory creating "Sprites" (in this case String instances) for visualizing the playground's state. The ConsoleCheckerboardViewer is initialized with the according redraw loop time. When a redraw time <= 0 is set upon construction, then the Checkerboard is printed out upon any according events from the underlying Checkerboard or, in case the refresh time is > 0 the Checkerboard is redrawn as of the refresh loop time. Attention: The Checkerboard is only redrawn in case the Checkerboard changed compared to the last redraw process. A default column width of 3 is configured.
        Parameters:
        aRedrawLoopTimeInMillis - The redraw loop time to work with.
        aCheckerboard - The Checkerboard for which to construct the viewer.
        aSpriteFactory - The SpriteFactory to be used.
      • ConsoleCheckerboardViewerImpl

        public ConsoleCheckerboardViewerImpl​(Checkerboard<P,S> aCheckerboard,
                                             ConsoleSpriteFactory<S> aSpriteFactory,
                                             int aColumnWidth,
                                             int aRedrawLoopTimeInMillis)
        Constructs the ConsoleCheckerboardViewer with the provided SpriteFactory creating "Sprites" (in this case String instances) for visualizing the playground's state. The ConsoleCheckerboardViewer is initialized with the according redraw loop time. When a redraw time <= 0 is set upon construction, then the Checkerboard is printed out upon any according events from the underlying Checkerboard or, in case the refresh time is > 0 the Checkerboard is redrawn as of the refresh loop time. Attention: The Checkerboard is only redrawn in case the Checkerboard changed compared to the last redraw process.
        Parameters:
        aRedrawLoopTimeInMillis - The redraw loop time to work with.
        aCheckerboard - The Checkerboard for which to construct the viewer.
        aColumnWidth - The column width to be used when drawing the Checkerboard table.
        aSpriteFactory - The SpriteFactory to be used.
    • Method Detail

      • initialize

        public void initialize​()
                        throws org.refcodes.component.InitializeException
        Specified by:
        initialize in interface org.refcodes.component.Initializable
        Throws:
        org.refcodes.component.InitializeException
      • onCheckerboardEvent

        public void onCheckerboardEvent​(CheckerboardEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onCheckerboardEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onPlayerAddedEvent

        public void onPlayerAddedEvent​(PlayerAddedEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onPlayerAddedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onPlayerRemovedEvent

        public void onPlayerRemovedEvent​(PlayerRemovedEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onPlayerRemovedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onGridModeChangedEvent

        public void onGridModeChangedEvent​(GridModeChangedEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onGridModeChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onGridDimensionChangedEvent

        public void onGridDimensionChangedEvent​(GridDimensionChangedEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onGridDimensionChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onViewportOffsetChangedEvent

        public void onViewportOffsetChangedEvent​(ViewportOffsetChangedEvent<P,S> aCheckerboardEvent)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onViewportOffsetChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aCheckerboardEvent - the checkerboard event
      • onPlayerEvent

        public void onPlayerEvent​(PlayerEvent<P> aPlayerEvent,
                                  Checkerboard<P,S> aSource)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onPlayerEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aPlayerEvent - the player event
        aSource - The according source (origin).
      • onChangePositionEvent

        public void onChangePositionEvent​(ChangePositionEvent<P> aPlayerEvent,
                                          Checkerboard<P,S> aSource)
                                   throws org.refcodes.exception.VetoException
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onChangePositionEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aPlayerEvent - the player event
        aSource - The according source (origin).
        Throws:
        org.refcodes.exception.VetoException - the veto exception
      • onPositionChangedEvent

        public void onPositionChangedEvent​(PositionChangedEvent<P> aPlayerEvent,
                                           Checkerboard<P,S> aSource)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onPositionChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aPlayerEvent - the player event
        aSource - The according source (origin).
      • onStateChangedEvent

        public void onStateChangedEvent​(StateChangedEvent<P,S> aPlayerEvent,
                                        Checkerboard<P,S> aSource)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onStateChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aPlayerEvent - the player event
        aSource - The according source (origin).
      • onVisibilityChangedEvent

        public void onVisibilityChangedEvent​(VisibilityChangedEvent<P> aPlayerEvent,
                                             Checkerboard<P,S> aSource)
        This method is called when information about an Checkerboard which was previously requested using an asynchronous interface becomes available.
        Specified by:
        onVisibilityChangedEvent in interface CheckerboardObserver<P extends Player<P,S>,S>
        Parameters:
        aPlayerEvent - the player event
        aSource - The according source (origin).
      • getRedrawLoopTimeInMillis

        public int getRedrawLoopTimeInMillis​()
        Retrieves the refresh loop time between two redraw cycles of the Checkerboard. This is the delay time between succeeding print outs of the Checkerboard states to the console. If the refresh loop time is > 0, then the Checkerboard is redrawn at most with intervals of the given refresh loop time. Attention: The Checkerboard is only redrawn in case the Checkerboard changed compared to the last redraw process.
        Specified by:
        getRedrawLoopTimeInMillis in interface ConsoleCheckerboardViewer<P extends Player<P,S>,S>
        Returns:
        The according time in milliseconds.
      • printPlaygroundDaemon

        protected void printPlaygroundDaemon​()
        Loops the playground printing via printPlayground().
      • onEventPrintPlayground

        protected void onEventPrintPlayground​()
        Prints the playground upon an according Checkerboard event in case the
      • getColumnWidth

        public int getColumnWidth​()
        Specified by:
        getColumnWidth in interface org.refcodes.mixin.ColumnWidthAccessor
      • setColumnWidth

        public void setColumnWidth​(int aColumnWidth)
        Specified by:
        setColumnWidth in interface org.refcodes.mixin.ColumnWidthAccessor.ColumnWidthMutator