Package commandLineMenus
Class Menu
- java.lang.Object
-
- commandLineMenus.Option
-
- commandLineMenus.Menu
-
- Direct Known Subclasses:
List
public class Menu extends Option
Menu printed on the terminal (if you don't override the layout) TheOption.titleis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMenu.CollisionExceptionThrown if two options have the same shortcut.classMenu.ConcurrentExecutionExceptionThrown if a menu is launched while an other is running.static classMenu.CycleDetectedExceptionThrown if a menu is an ancestor if himself.classMenu.EmptyMenuExceptionThrown if a menu has no option.classMenu.ShortcutMissingExceptionThrown if an option has no shortcut.-
Nested classes/interfaces inherited from class commandLineMenus.Option
Option.ConcurrentModificationException, Option.NoActionDefinedException
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Option option)Adds an option in the current menu.voidaddBack(java.lang.String shortcut)Adds an option to go back to the parent menu.voidaddBack(java.lang.String title, java.lang.String shortcut)Adds an option to go back to the parent menu.voidaddQuit(java.lang.String shortcut)Adds an option to close all menus.voidaddQuit(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 voidgoBack()Once soBack() is called, the current menu will close as soon as possible.static voidquit()Once quit() is called, all the menus will close as soon as possible.voidsetAutoBack(boolean autoBack)Setter for autoBack, that is true iff we go back to the parent menu once the action is complete.intsize()The number of options in the current menu.voidstart()Launches the menu.java.lang.StringtoString()-
Methods inherited from class commandLineMenus.Option
getRenderer, getShortcut, getTitle, setAction, setRenderer
-
-
-
-
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.
-
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.
-
-