1 package de.matthias_burbach.deputy.swing;
2
3 import javax.swing.JMenu;
4 import javax.swing.JMenuBar;
5 import javax.swing.JMenuItem;
6
7 /***
8 * Is the Deputy menu bar.
9 *
10 * @author Matthias Burbach
11 */
12 public class DeputyMenuBar extends JMenuBar {
13 /***
14 * The file menu definition. '-' represents a separator.
15 */
16 private String[] fileItems =
17 new String[] {
18
19 DeputyFrame.ACTION_OPEN,
20 "-",
21 DeputyFrame.ACTION_SAVE,
22 DeputyFrame.ACTION_SAVE_AS,
23 "-",
24 DeputyFrame.ACTION_SORT_SNAPSHOTS_TOPOLOGICALLY,
25 DeputyFrame.ACTION_EXPORT,
26 "-",
27 DeputyFrame.ACTION_EXIT,
28 };
29
30 /***
31 * The edit menu definition. '-' represents a separator.
32 */
33 private String[] editItems =
34 new String[] {
35 DeputyFrame.ACTION_APPLY_RULES,
36 "-",
37 DeputyFrame.ACTION_REMOVE_SELECTED_RULES,
38 DeputyFrame.ACTION_REMOVE_SNAPSHOT_ENFORCEMENTS,
39 DeputyFrame.ACTION_DERIVE_ENFORCEMENTS_FROM_PROJECT,
40 DeputyFrame.ACTION_REMOVE_DERIVED_RULES,
41 "-",
42 DeputyFrame.ACTION_EDIT_REPOSITORY_CONFIGS
43 };
44
45 /***
46 * The view menu definition. '-' represents a separator.
47 */
48 private String[] viewItems =
49 new String[] {
50 DeputyFrame.ACTION_REFRESH_REPOSITORY_BROWSER
51 };
52
53 /***
54 * The help menu definition. '-' represents a separator.
55 */
56 private String[] helpItems =
57 new String[] {
58 DeputyFrame.ACTION_HOMEPAGE,
59 DeputyFrame.ACTION_RELEASE_NOTES,
60 "-",
61 DeputyFrame.ACTION_SHOW_ABOUT
62 };
63
64 /***
65 * Constructs the depuyt menu bar.
66 *
67 * @param deputyFrame The deputy frame providing the menu item action
68 * listeners.
69 */
70 public DeputyMenuBar(final DeputyFrame deputyFrame) {
71 add(createMenu("File", fileItems, deputyFrame));
72 add(createMenu("Edit", editItems, deputyFrame));
73 add(createMenu("View", viewItems, deputyFrame));
74 add(createMenu("Help", helpItems, deputyFrame));
75 }
76
77 /***
78 * Creates a menu.
79 *
80 * @param menuName The name of the menu to appear in the menu bar.
81 * @param menuDefinition The definition of the items in the menu.
82 * @param deputyFrame The deputy frame providing the action listeners.
83 * @return The menu created.
84 */
85 private JMenu createMenu(
86 final String menuName,
87 final String[] menuDefinition,
88 final DeputyFrame deputyFrame) {
89 JMenu menu = new JMenu(menuName);
90 for (int i = 0; i < menuDefinition.length; i++) {
91 String itemName = menuDefinition[i];
92 if (itemName.equals("-")) {
93 menu.addSeparator();
94 } else {
95 JMenuItem item =
96 new JMenuItem(deputyFrame.getAction(itemName));
97 menu.add(item);
98 }
99 }
100 return menu;
101 }
102 }