Module AM37

Class InputManager

java.lang.Object
it.polimi.ingsw.view.inputManagers.InputManager
Direct Known Subclasses:
AddWorkersInputManager, ChooseStartingPlayerInputManager, GodChoiceInputManager, LobbyInputManager, LoginManager, ReloadGameInputManager, SelectActionCellInputManager, SelectActionInputManager, SelectBlockInputManager, SelectWorkerInputManager

public abstract class InputManager
extends java.lang.Object
InputManager abstraction

An InputManager is an object responsible for the console input acquisition and redirection

  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected Client client
    The client to manage the input for
    protected static java.util.concurrent.ScheduledFuture<?> inputCountdown
    The scheduled task that manage the timeout on user input
    protected boolean isWaitingForInput
    Determines if an eventual input has to be discarded or not
    protected ViewInterface view
    The view to call methods on
  • Constructor Summary

    Constructors 
    Constructor Description
    InputManager​(Client client)
    Default constructor
  • Method Summary

    Modifier and Type Method Description
    protected java.lang.String cleanInput​(java.lang.String input)
    Sanitizes an input string
    abstract void manageInput​(java.lang.String input)
    Determines how to handle the received input based on the internal state
    void setWaitingForInput​(boolean waitingForInput)  
    void startTimer​(int availableTime)
    Starts the timer which will terminate the client if no input is received for a certain amount of time
    void stopTimer()
    This method cancels the task and reset the second passed

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • inputCountdown

      protected static java.util.concurrent.ScheduledFuture<?> inputCountdown
      The scheduled task that manage the timeout on user input
    • client

      protected final Client client
      The client to manage the input for
    • view

      protected final ViewInterface view
      The view to call methods on
    • isWaitingForInput

      protected boolean isWaitingForInput
      Determines if an eventual input has to be discarded or not
  • Constructor Details

    • InputManager

      public InputManager​(Client client)
      Default constructor
      Parameters:
      client - the client to manage the inputs for
  • Method Details

    • manageInput

      public abstract void manageInput​(java.lang.String input)
      Determines how to handle the received input based on the internal state

      This method expects an already trimmed input

      Parameters:
      input - the user input
    • cleanInput

      protected java.lang.String cleanInput​(java.lang.String input)
      Sanitizes an input string
      Parameters:
      input - the user input
      Returns:
      a sanitized version of the input string
    • setWaitingForInput

      public void setWaitingForInput​(boolean waitingForInput)
    • startTimer

      public void startTimer​(int availableTime)
      Starts the timer which will terminate the client if no input is received for a certain amount of time
      Parameters:
      availableTime - the maximum time the user has to input something
    • stopTimer

      public void stopTimer()
      This method cancels the task and reset the second passed