final JMenuItem item = new JMenuItem(name);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
if (!f.exists()) {
JOptionPane.showMessageDialog(null,
L10N.getLocalString("msg.proj_not_found", "This project can no longer be found"));
GUISaveState.getInstance().fileNotFound(f);
return;
}
GUISaveState.getInstance().fileReused(f);// Move to front in
// GUISaveState, so
// it will be last
// thing to be
// removed from the
// list
recentMenuCache.addRecentFile(f);
if (!f.exists()) {
throw new IllegalStateException("User used a recent projects menu item that didn't exist.");
}
// Moved this outside of the thread, and above the line
// saveFile=f.getParentFile()
// Since if this save goes on in the thread below, there is
// no way to stop the save from
// overwriting the files we are about to load.
if (mainFrame.getCurProject() != null && mainFrame.isProjectChanged()) {
int response = JOptionPane.showConfirmDialog(mainFrame, L10N.getLocalString("dlg.save_current_changes",
"The current project has been changed, Save current changes?"), L10N.getLocalString(
"dlg.save_changes", "Save Changes?"), JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
if (mainFrame.getSaveFile() != null) {
mainFrame.getMainFrameLoadSaveHelper().save();
} else {
mainFrame.getMainFrameLoadSaveHelper().saveAs();
}
} else if (response == JOptionPane.CANCEL_OPTION)
{
return;
// IF no, do nothing.
}
}
SaveType st = SaveType.forFile(f);
boolean result = true;
switch (st) {
case XML_ANALYSIS:
result = mainFrame.openAnalysis(f, st);
break;
case FBP_FILE:
result = mainFrame.getMainFrameLoadSaveHelper().openFBPFile(f);
break;
case FBA_FILE:
result = mainFrame.getMainFrameLoadSaveHelper().openFBAFile(f);
break;
default:
mainFrame.error("Wrong file type in recent menu item.");
}
if (!result) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "There was an error in opening the file",
"Recent Menu Opening Error", JOptionPane.WARNING_MESSAGE);
}
} finally {
mainFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
mainFrame.setSaveType(localSaveType);
}
}
});
item.setFont(item.getFont().deriveFont(Driver.getFontSize()));