Class Menu

java.lang.Object
pretty.layout.Menu

public class Menu extends Object
Used to render menus and get input from the user by terminal
  • Method Details

    • getInstance

      public static Menu getInstance()
      Get the singleton instance of Menu
      Returns:
      the instance of Menu
    • start

      public void start()
      Start the menu, called by the router by default
    • push

      public void push(String line)
      Push a line to the menu
      Parameters:
      line - - the line to be pushed
    • push

      public void push(String line, boolean newLine)
      Push a line to the menu
      Parameters:
      line - - the line to be pushed
      newLine - - if the line should be end with a new line
    • temporarilyPush

      public void temporarilyPush(String line)
      Temporarily push a line to the menu. The line will be removed after the next rollback.
      Parameters:
      line - - the line to be temporarily pushed
    • phantomPush

      public void phantomPush(String line)
      Push a line to the menu without rendering it
      Parameters:
      line - - the line to be pushed
    • rollback

      public void rollback()
      Rollback the last line and temporary lines
    • rollback

      public void rollback(int count)
      Rollback a number of lines, not including temporary lines
      Parameters:
      count - - the number of lines
    • rollbackKeepingTemporary

      public void rollbackKeepingTemporary()
      Rollback the last line, keeping temporary lines
    • cleanup

      public void cleanup()
      Rollback all lines and temporary lines
    • warning

      public void warning(String message)
      Rollback the last line and temporary lines and print an warning message
      Parameters:
      message - - the message to be printed
    • warning

      public void warning(String message, int rollbacks)
      Rollback a number of lines and temporary lines and print an warning message
      Parameters:
      message - - the message to be printed
      rollbacks - - the number of lines to rollback
    • header

      public void header(String title)
      Push a header to the menu
      Parameters:
      title - - the title
    • divider

      public void divider()
      Push a divider to the menu
    • getInt

      public int getInt(String prompt, Validator<Integer> validator)
      Get an integer from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the integer input
    • getInt

      public int getInt(String prompt, Validator<Integer> validator, Formatter<Integer,String> formatter)
      Get an integer from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the integer input
    • getLong

      public long getLong(String prompt, Validator<Long> validator)
      Get an long integer from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the long integer input
    • getLong

      public long getLong(String prompt, Validator<Long> validator, Formatter<Long,String> formatter)
      Get an long integer from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the long integer input
    • getDouble

      public double getDouble(String prompt, Validator<Double> validator)
      Get a double from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the double input
    • getDouble

      public double getDouble(String prompt, Validator<Double> validator, Formatter<Double,String> formatter)
      Get a double from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the double input
    • getFloat

      public float getFloat(String prompt, Validator<Float> validator)
      Get a float from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the float input
    • getFloat

      public float getFloat(String prompt, Validator<Float> validator, Formatter<Float,String> formatter)
      Get a float from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the float input
    • getChar

      public char getChar(String prompt, Validator<Character> validator)
      Get a char from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the char input
    • getChar

      public char getChar(String prompt, Validator<Character> validator, Formatter<Character,String> formatter)
      Get a char from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the char input
    • getString

      public String getString(String prompt, Validator<String> validator)
      Get a string from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      Returns:
      the string input
    • getString

      public String getString(String prompt, Validator<String> validator, Formatter<String,String> formatter)
      Get a string from the user
      Parameters:
      prompt - - the prompt to be shown
      validator - - the validator to be used
      formatter - - the formatter to be used
      Returns:
      the string input
    • getOption

      public int getOption(String prompt, String[] options)
      Show options to the user and get the selected option
      Parameters:
      prompt - - the prompt to be shown
      options - - the options to be shown
      Returns:
      the selected option
    • getOption

      public int getOption(String prompt, String[] options, int selected)
      Show options to the user and get the selected option
      Parameters:
      prompt - - the prompt to be shown
      options - - the options to be shown
      selected - - the default selected option
      Returns:
      the selected option, or -1 if no options is passed
    • pushPageBack

      public void pushPageBack()
      Push a footer to the menu with the only option to go back
    • getPageConfirmation

      public boolean getPageConfirmation()
      Get a confirmation from the user
      Returns:
      true, if the user confirms, false otherwise
    • getPageConfirmation

      public boolean getPageConfirmation(String reject)
      Get a confirmation from the user
      Parameters:
      reject - - reject option message
      Returns:
      true, if the user confirms, false otherwise
    • getPageOption

      public int getPageOption(String[] options)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, String exit)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      exit - - exit option message
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, Integer[] lockeds)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      lockeds - - the locked options
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, Integer[] lockeds, String exit)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      lockeds - - the locked options
      exit - - exit option message
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, Integer[] lockeds, int selected, String exit)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      lockeds - - the locked options
      selected - - the default selected option
      exit - - exit option message
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, int page, int optionsPerPage, int selected, String exit)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      page - - the current page
      optionsPerPage - - the max number of options per page
      selected - - the default selected option
      exit - - exit option message
      Returns:
      the selected option or -1 if no options are selected
    • getPageOption

      public int getPageOption(String[] options, Integer[] lockeds, int optionsPerPage, int selected, String exit)
      Get an option from the user
      Parameters:
      options - - the options to be shown
      lockeds - - the locked options
      optionsPerPage - - the max number of options per page
      selected - - the default selected option
      exit - - exit option message
      Returns:
      - the selected option or -1 if no options are selected