Class MenuInputReader

java.lang.Object
java.lang.Thread
it.polimi.ingsw.am13.client.view.tui.MenuInputReader
All Implemented Interfaces:
Runnable

public class MenuInputReader extends Thread
Class implementing the thread listening for command line inputs from the user, used for TUI view Note that, being an object mediating between the server and the client, it has references to both the NetworkHandler and the ViewTUI.
Once started, it catches anything typed via command line after pressing enter. It parses the first word of the typed line, interprets it as the command and uses the current menu exposed be the view to try and execute the command, otherwise it throws an exception. If the typed command is present in the menu, that MenuItem is executed, passing the rest of the parameters typed after the command key to it.
  • Field Details

    • scanner

      private final Scanner scanner
      Scanner used to listen to the input from stdin
    • view

      private final ViewTUI view
      Reference to the view of the client. It should be used only to handle the input-parsing exceptions.
    • networkHandler

      private final NetworkHandler networkHandler
      Reference to the handler of the network, to send commands to the server
  • Constructor Details

    • MenuInputReader

      public MenuInputReader(ViewTUI view, NetworkHandler networkHandler)
      Builds a new listeners for the command line input from the user
      Parameters:
      view - Reference of the view of the client
      networkHandler - Reference of the handler of the network
  • Method Details

    • getNetworkHandler

      public NetworkHandler getNetworkHandler()
    • run

      public void run()
      Listen for command line inputs coming from the user, and execute them
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread