1 | package de.uka.ipd.sdq.prototype.framework.utils; |
2 | |
3 | import java.util.Collection; |
4 | import java.util.LinkedList; |
5 | import java.util.List; |
6 | import java.util.Scanner; |
7 | |
8 | import de.uka.ipd.sdq.prototype.framework.AbstractAllocationStorage; |
9 | |
10 | public class UserMenu |
11 | { |
12 | protected static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger(); |
13 | |
14 | /** |
15 | * Shows the user menu and receives user selections |
16 | * @return List of selections the user made |
17 | */ |
18 | public static List<Integer> showUserMenu(String[][] systems) { |
19 | System.out.println("Select starting option:"); |
20 | showMenuItems(systems); |
21 | System.out.print("Option: "); |
22 | Scanner sc = new Scanner(System.in); |
23 | String st = null; |
24 | if (sc.hasNextLine()) { |
25 | st = sc.nextLine(); |
26 | } |
27 | sc.close(); |
28 | |
29 | List<Integer> ids = new LinkedList<Integer>(); |
30 | if (st != null) { |
31 | sc = new Scanner(st); |
32 | |
33 | while (sc.hasNextInt()) { |
34 | ids.add(sc.nextInt()); |
35 | } |
36 | } |
37 | sc.close(); |
38 | |
39 | return ids; |
40 | } |
41 | |
42 | /** |
43 | * Shows the list of menu items |
44 | */ |
45 | private static void showMenuItems(String[][] systems) |
46 | { |
47 | System.out.println("1: Start everything in local mode (hardware container #1 is used, only for testing purpose!)"); |
48 | System.out.println("2: RmiRegistry"); |
49 | System.out.println("3: Usage Scenarios"); |
50 | |
51 | int i = 4; |
52 | |
53 | // systems |
54 | for(String[] system : systems) |
55 | { |
56 | System.out.println(i+": System "+system[1]); |
57 | i++; |
58 | } |
59 | |
60 | // container |
61 | Collection<String> containers = AbstractAllocationStorage.getContainerNames(); |
62 | for(String container : containers) |
63 | { |
64 | System.out.println(i+": Container "+container); |
65 | i++; |
66 | } |
67 | } |
68 | } |