+ help = createMenu("Help", KeyEvent.VK_L);
+ add(help);
+
+ addItem(help, "User manual", "F1", KeyEvent.VK_M);
+ help.addSeparator();
+ addItem(help, "About", KeyEvent.VK_A, false);
+ }
+ /**
+ * Creats a menu in the menubar.
+ * @param name The name of the menu.
+ * @param mnemnic The shortcut-key to access the menu.
+ * @return menu The menu created.
+ */
+ private JMenu createMenu(String name, int mnemonic) {
+ JMenu menu = new JMenu(name);
+ menu.setMnemonic(mnemonic);
+ return menu;
+ }
+
+ /**
+ * Creats a menuitem in the menu.
+ * @param menu The menu where to add the menuitem.
+ * @param name The name of the menuitem.
+ * @param mnemonic The keyboard mnemonic used to access this menuitem
+ * @param accelerate whether to create a keyboard accelerator for this item
+ * @return item The menuitem created.
+ */
+ private JMenuItem addItem(JMenu menu, String name, int mnemonic, boolean accelerate) {
+ JMenuItem item = new JMenuItem(name);
+ item.addActionListener(this);
+ item.setMnemonic(mnemonic);
+ if (accelerate) item.setAccelerator(KeyStroke.getKeyStroke(mnemonic, ActionEvent.CTRL_MASK));
+ menu.add(item);
+ return item;
+ }
+
+ /**
+ * Creats a menuitem in the menu.
+ * @param menu The menu to where to add the menuitem.
+ * @param name The name of the menuitem.
+ * @param key The keystroke to access this menuitem.
+ * @param mnemonic The keyboard mnemonic used to access this menuitem
+ * @return item The menuitem created.
+ */
+ private JMenuItem addItem(JMenu menu, String name, String key, int mnemonic) {
+ JMenuItem item = new JMenuItem(name);
+ item.setMnemonic(mnemonic);
+ item.setAccelerator(KeyStroke.getKeyStroke(key));
+ item.addActionListener(this);
+ menu.add(item);
+ return item;
+ }
+
+ /**
+ * Adds an item for this file to the top of the reopen menu.
+ */
+ private void addReopenItem(String file) {
+ for (int i = 0; i < reopen.getMenuComponentCount(); i++) {
+ if (file.equals(((JMenuItem)reopen.getMenuComponent(i)).getText()))
+ reopen.remove(i);