View Javadoc

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