/** * Get the menu items to add to the menu bar, to get recent file functionality * * @return a List of JMenuItem, representing recent files. JMenuItem may not be visible */ public static List<JComponent> getRecentFileMenuItems() { LinkedList<JComponent> menuItems = new LinkedList<>(); // Get the preference for the recent files for(int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { // Create the menu item JMenuItem recentFile = new JMenuItem(); // Use the index as the name, used when processing the action recentFile.setName(Integer.toString(i)); recentFile.addActionListener(ActionRouter.getInstance()); recentFile.setActionCommand(ActionNames.OPEN_RECENT); // Set the KeyStroke to use int shortKey = getShortcutKey(i); if(shortKey >= 0) { recentFile.setMnemonic(shortKey); } // Add the menu item menuItems.add(recentFile); } // Update menu items to reflect recent files updateMenuItems(menuItems); return menuItems; }