|
|
@ -7,35 +7,47 @@ public class MenuManager { |
|
|
|
private ArrayList<Menu> menuList; |
|
|
|
private Menu currentMenu; |
|
|
|
|
|
|
|
public MenuManager(){ |
|
|
|
public MenuManager() { |
|
|
|
menuList = new ArrayList<>(); |
|
|
|
currentMenu = null; |
|
|
|
} |
|
|
|
|
|
|
|
public void addMenu(Menu menu){ |
|
|
|
public void addMenu(Menu menu) { |
|
|
|
menuList.add(menu); |
|
|
|
} |
|
|
|
|
|
|
|
public void select(int i){ |
|
|
|
if(currentMenu == null) |
|
|
|
public void select(int i) { |
|
|
|
if (currentMenu == null) |
|
|
|
this.currentMenu = menuList.get(i); |
|
|
|
else |
|
|
|
this.currentMenu = currentMenu.getMenu(i); |
|
|
|
} |
|
|
|
|
|
|
|
public void back() throws Exception { |
|
|
|
if(!this.inRootMenu()) |
|
|
|
if (!this.inRootMenu()) |
|
|
|
this.currentMenu = this.currentMenu.getPreviousMenu(); |
|
|
|
else |
|
|
|
throw new Exception("Menu is in the root menu, a previous menu doesn't exist"); |
|
|
|
} |
|
|
|
|
|
|
|
public Menu getCurrentMenu(){ |
|
|
|
public Menu getCurrentMenu() { |
|
|
|
return this.currentMenu; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean inRootMenu(){ |
|
|
|
public boolean inRootMenu() { |
|
|
|
return this.currentMenu == null; |
|
|
|
} |
|
|
|
|
|
|
|
public String getFormattedMenuList() { |
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
ArrayList<Menu> baseMenuList = this.menuList; |
|
|
|
if(!inRootMenu()) |
|
|
|
baseMenuList = currentMenu.getSubMenuList(); |
|
|
|
|
|
|
|
for(int i = 0; i < baseMenuList.size(); i++) |
|
|
|
result.append(i + 1).append(": ").append(baseMenuList.get(i).getName()).append("\n"); |
|
|
|
|
|
|
|
return result.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
} |