Class Menu

  • Direct Known Subclasses:
    List

    public class Menu
    extends Option
    Menu printed on the terminal (if you don't override the layout) The Option.title is displayed on the top of the menu, followed by an options list. The user can select one option that is automatically triggered, or add a sub-menu as an option.
    • Constructor Summary

      Constructors 
      Constructor Description
      Menu​(java.lang.String title)
      Creates a menu.
      Menu​(java.lang.String title, java.lang.String shortcut)
      Creates a menu.
      Menu​(java.lang.String longTitle, java.lang.String shortTitle, java.lang.String shortcut)
      Creates a menu.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Option option)
      Adds an option in the current menu.
      void addBack​(java.lang.String shortcut)
      Adds an option to go back to the parent menu.
      void addBack​(java.lang.String title, java.lang.String shortcut)
      Adds an option to go back to the parent menu.
      void addQuit​(java.lang.String shortcut)
      Adds an option to close all menus.
      void addQuit​(java.lang.String title, java.lang.String shortcut)
      Adds an option to close all menus.
      java.util.Collection<Option> getOptions()
      Returns the options of this menu.
      static void goBack()
      Once soBack() is called, the current menu will close as soon as possible.
      static void quit()
      Once quit() is called, all the menus will close as soon as possible.
      void setAutoBack​(boolean autoBack)
      Setter for autoBack, that is true iff we go back to the parent menu once the action is complete.
      int size()
      The number of options in the current menu.
      void start()
      Launches the menu.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Menu

        public Menu​(java.lang.String title)
        Creates a menu.
        Parameters:
        title - The title displayed on the top of the menu.
      • Menu

        public Menu​(java.lang.String title,
                    java.lang.String shortcut)
        Creates a menu.
        Parameters:
        title - The title displayed on the top of the menu.
        shortcut - If this is a sub-menu, the shortcut that will appear in the parent menu.
      • Menu

        public Menu​(java.lang.String longTitle,
                    java.lang.String shortTitle,
                    java.lang.String shortcut)
        Creates a menu.
        Parameters:
        longTitle - The title displayed on the top of the menu.
        shortcut - If this is a sub-menu, the shortcut that will appear in the parent menu.
        shortTitle - If this is a sub-menu, the title that will appear in the parent menu.
    • Method Detail

      • add

        public void add​(Option option)
        Adds an option in the current menu.
        Parameters:
        option - The option to add.
      • getOptions

        public java.util.Collection<Option> getOptions()
        Returns the options of this menu.
        Returns:
        The options of this menu.
      • size

        public int size()
        The number of options in the current menu.
        Returns:
        The number of options.
      • addQuit

        public void addQuit​(java.lang.String shortcut)
        Adds an option to close all menus.
        Parameters:
        shortcut - The shortcut that will appear in the menu.
      • addQuit

        public void addQuit​(java.lang.String title,
                            java.lang.String shortcut)
        Adds an option to close all menus.
        Parameters:
        title - The title that will appear in the menu.
        shortcut - The shortcut that will appear in the menu.
      • addBack

        public void addBack​(java.lang.String shortcut)
        Adds an option to go back to the parent menu.
        Parameters:
        shortcut - The shortcut that will appear in the menu.
      • addBack

        public void addBack​(java.lang.String title,
                            java.lang.String shortcut)
        Adds an option to go back to the parent menu.
        Parameters:
        title - The title that will appear in the menu.
        shortcut - The shortcut that will appear in the menu.
      • setAutoBack

        public void setAutoBack​(boolean autoBack)
        Setter for autoBack, that is true iff we go back to the parent menu once the action is complete.
        Parameters:
        autoBack - iff go back to the parent menu once the action is complete.
      • start

        public void start()
        Launches the menu. Be careful, the menu is run in he main thread and it is not possible to start a menu while an other is running.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Option
      • quit

        public static void quit()
        Once quit() is called, all the menus will close as soon as possible.
      • goBack

        public static void goBack()
        Once soBack() is called, the current menu will close as soon as possible.