String recentFilePath = getRecentFile(i); if(!loadedFileName.equals(recentFilePath)) { newRecentFiles.add(recentFilePath); String fileName = newRecentFiles.get(i); if(fileName != null) { setRecentFile(i, fileName); updateMenuItems(menuItems);
@Override public void doActionAfterCheck(ActionEvent e) { // We must ask the user if it is ok to close current project if (!Close.performAction(e)) { return; } // Load the file for this recent file command loadProjectFile(e, getRecentFile(e), false); }
public void setProjectFileLoaded(String file) { if (fileLoadRecentFiles != null && file != null) { LoadRecentProject.updateRecentFileMenuItems(fileLoadRecentFiles, file); recentFilesOpen.setEnabled(true); } }
/** * Set the content and visibility of menu items and menu separator, * based on the recent file stored user preferences. */ private static void updateMenuItems(List<JComponent> menuItems) { // Update the menu items for (int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { // Get the menu item JMenuItem recentFile = (JMenuItem) menuItems.get(i); // Find and set the file for this recent file command String recentFilePath = getRecentFile(i); if (recentFilePath != null) { File file = new File(recentFilePath); String sb = String.valueOf(i + 1) + " " + //$NON-NLS-1$ getMenuItemDisplayName(file); // Index before file name recentFile.setText(sb); recentFile.setToolTipText(recentFilePath); recentFile.setEnabled(true); recentFile.setVisible(true); } else { recentFile.setEnabled(false); recentFile.setVisible(false); } } }
/** * 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; }
fileLoadRecentFiles = LoadRecentProject.getRecentFileMenuItems(); fileLoadRecentFiles.forEach(jc -> recentFilesOpen.add(jc)); recentFilesOpen.setEnabled(LoadRecentProject.hasVisibleMenuItem(fileLoadRecentFiles));
private String processLAST(final String jmlogfile, final String suffix) { if (USE_LAST_JMX.equals(jmlogfile) || USE_LAST_JMX.concat(suffix).equals(jmlogfile)){ String last = LoadRecentProject.getRecentFile(0);// most recent if (last.toUpperCase(Locale.ENGLISH).endsWith(JMX_SUFFIX)){ return last.substring(0, last.length() - JMX_SUFFIX.length()).concat(suffix); } } return jmlogfile; }
/** * Get the recent file for the menu item */ private File getRecentFile(ActionEvent e) { JMenuItem menuItem = (JMenuItem)e.getSource(); // Get the preference for the recent files return new File(getRecentFile(Integer.parseInt(menuItem.getName()))); }
testFile = testFileOpt.getArgument(); if (USE_LAST_JMX.equals(testFile)) { testFile = LoadRecentProject.getRecentFile(0);// most recent