final ActionMap map = tree.getActionMap(); System.out.println("tree action keys"); for(Object k : map.allKeys()) System.out.println("  " + k + " " + k.getClass().getName());  JMenu navMenu = new JMenu("Navigation");  addNavItem(map, navMenu, "Expand", "expand", KeyEvent.VK_RIGHT ); addNavItem(map, navMenu, "Collapse", "collapse", KeyEvent.VK_LEFT); addNavItem(map, navMenu, "Up", "selectPrevious", KeyEvent.VK_UP ); addNavItem(map, navMenu, "Down", "selectNext", KeyEvent.VK_DOWN);  menuBar.add(navMenu);  JMenu designationMenu = new JMenu("Designation"); int i = 0; int keyEvents [] = {KeyEvent.VK_0, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8}; for(String key :  I18N.instance().getUserDesignationKeys(true)) { String name = I18N.instance().getUserDesignation(key); addDesignationItem(designationMenu, name, keyEvents[i++]); } menuBar.add(designationMenu);
	protected JMenuBar createMainMenuBar() {		JMenuBar menuBar = new JMenuBar();				//Create JMenus for menuBar.		JMenu fileMenu = new JMenu("File");		fileMenu.setMnemonic(KeyEvent.VK_F);		JMenu editMenu = new JMenu("Edit");		editMenu.setMnemonic(KeyEvent.VK_E);				//Edit fileMenu JMenu object.		JMenuItem newProjectMenuItem = new JMenuItem("New Project", KeyEvent.VK_N);		JMenuItem openProjectMenuItem = new JMenuItem("Open Project...", KeyEvent.VK_O);		recentProjectsMenu = new JMenu("Recent Projects");		recentProjectsMenu.setMnemonic(KeyEvent.VK_E);		createRecentProjectsMenu();		JMenuItem saveAsProjectMenuItem = new JMenuItem("Save Project As...", KeyEvent.VK_A);		JMenuItem importBugsMenuItem = new JMenuItem("Load Analysis...", KeyEvent.VK_L);		JMenuItem exportBugsMenuItem = new JMenuItem("Save Analysis...", KeyEvent.VK_B);		JMenuItem redoAnalysis = new JMenuItem("Redo Analysis", KeyEvent.VK_R);		JMenuItem mergeMenuItem = new JMenuItem("Merge Analysis...");				JMenuItem exitMenuItem = null;		if (!System.getProperty("os.name").startsWith("Mac")) {			exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X);			exitMenuItem.addActionListener(new ActionListener(){						public void actionPerformed(ActionEvent evt){				callOnClose();			}			});		}		JMenu windowMenu = guiLayout.createWindowMenu();				newProjectMenuItem.setEnabled(true);		newProjectMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		newProjectMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);				new NewProjectWizard();								newProject = true;			}		});				editProjectMenuItem.setEnabled(false);		editProjectMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		editProjectMenuItem.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt)			{				saveCommentsToBug(currentSelectedBugLeaf);				new NewProjectWizard(curProject);			}		});				openProjectMenuItem.setEnabled(true);		openProjectMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		openProjectMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								FBFileChooser jfc=new FBFileChooser();				jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);				jfc.setFileFilter(FindBugsProjectFileFilter.INSTANCE);				File xmlFile=null;				if (projectChanged)				{					int response = JOptionPane.showConfirmDialog(MainFrame.this, 							"The current project has been changed, Save current changes?"							,"Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);					if (response == JOptionPane.YES_OPTION)					{						if (projectDirectory!=null)							save(projectDirectory);						else							projectSaveAs();					}					else if (response == JOptionPane.CANCEL_OPTION)						return;					//IF no, do nothing.				}								boolean loading = true;				while (loading)				{					int value=jfc.showOpenDialog(MainFrame.this);					if(value==JFileChooser.APPROVE_OPTION){						loading = false;						final File dir = jfc.getSelectedFile();																		if(!dir.exists() || !dir.isDirectory())						{							JOptionPane.showMessageDialog(null, "Warning! This project is not a directory.");							loading = true;							continue;						}						else						{							xmlFile= new File(dir.getAbsolutePath() + File.separator + dir.getName() + ".xml");									File fasFile=new File(dir.getAbsolutePath() + File.separator + dir.getName() + ".fas");							if (!xmlFile.exists())							{								JOptionPane.showMessageDialog(null, "This directory does not contain saved bug XML data, please choose a different directory.");								loading=true;								continue;							}														if (!fasFile.exists())							{								JOptionPane.showMessageDialog(MainFrame.this, "Filter settings not found, using default settings.");								try {									fasFile.createNewFile();									ProjectSettings.newInstance().save(new FileOutputStream(fasFile));								} catch (IOException e) {									if (MainFrame.DEBUG) System.err.println("Error saving new filter settings file, using default settings without saving these settings to the project.");									ProjectSettings.newInstance();								}							} 							else							{								try 								{									ProjectSettings.loadInstance(new FileInputStream(fasFile));								} catch (FileNotFoundException e) 								{									//Impossible.									if (MainFrame.DEBUG) System.err.println(".fas file not found, using default settings");									ProjectSettings.newInstance();								}							}														final File extraFinalReferenceToXmlFile=xmlFile;							new Thread(new Runnable(){								public void run()								{									BugTreeModel model=(BugTreeModel)tree.getModel();//									Debug.println("please wait called by open menu item");									BugTreeModel.pleaseWait();									MainFrame.this.setRebuilding(true);									BugSet bs=BugLoader.loadBugs(extraFinalReferenceToXmlFile);									MainFrame.this.setRebuilding(false);									if (bs!=null)									{										editProjectMenuItem.setEnabled(true);										model.getOffListenerList();										updateDesignation();										model.changeSet(bs);										curProject=BugLoader.getLoadedProject();										projectDirectory=dir;										curProject.setProjectFileName(projectDirectory.getName());										MainFrame.getInstance().updateStatusBar();									}								}							}).start();							MainFrame.this.setTitle("FindBugs: " + dir.getName());						}					}					else if (value==JFileChooser.CANCEL_OPTION)					{						return;					}					else						loading = false;				}//				List<String> projectPaths=new ArrayList<String>();				ArrayList<File> xmlFiles=GUISaveState.getInstance().getRecentProjects();				if (!xmlFiles.contains(xmlFile))				{					GUISaveState.getInstance().addRecentProject(xmlFile);					MainFrame.this.addRecentProjectToMenu(xmlFile);				}								//Clears the bottom tabs so they are blank. And makes comments				//tab not enabled.								clearBottomTabs();				designationChanged = false;				projectChanged = false;			}		});		mergeMenuItem.setEnabled(true);		mergeMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								setCursor(new Cursor(Cursor.WAIT_CURSOR));				BugSet bs=BugLoader.combineBugHistories();				if (bs!=null)				{					((BugTreeModel)tree.getModel()).getOffListenerList();					updateDesignation();					((BugTreeModel)tree.getModel()).changeSet(bs);					curProject=BugLoader.getLoadedProject();				}				setCursor(new Cursor(Cursor.DEFAULT_CURSOR));								setProjectChanged(true);			}		});				redoAnalysis.setEnabled(true);		redoAnalysis.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		redoAnalysis.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								setCursor(new Cursor(Cursor.WAIT_CURSOR));				new Thread()				{					public void run()					{						updateDesignation();						BugSet bs=BugLoader.redoAnalysisKeepComments(curProject);												if (bs!=null)						{							//Dont clear data, the data's correct, just get the tree off the listener lists.							((BugTreeModel) tree.getModel()).getOffListenerList();							((BugTreeModel)tree.getModel()).changeSet(bs);							curProject=BugLoader.getLoadedProject();						}						setCursor(new Cursor(Cursor.DEFAULT_CURSOR));						setProjectChanged(true);					}				}.start();			}		});/*		This seems pointless, all we could do on closing is have an empty window				closeProjectMenuItem.setEnabled(false);		closeProjectMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));		closeProjectMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				JOptionPane.showMessageDialog(null, "Close Project!!");			}		});*/				saveProjectMenuItem.setEnabled(false);		saveProjectMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		saveProjectMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								save(projectDirectory);			}		});				saveAsProjectMenuItem.setEnabled(true);		saveAsProjectMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								if(projectSaveAs())					saveProjectMenuItem.setEnabled(true);			}		});				importBugsMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								FBFileChooser jfc= new FBFileChooser();				jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);				jfc.setFileFilter(new FindBugsAnalysisFileFilter());								// jfc.setCurrentDirectory(GUISaveState.getInstance().getStarterDirectoryForLoadBugs()); this is done by FBFileChooser now.												boolean importing = true;				while(importing){					int returnValue=jfc.showOpenDialog(new JFrame());										if (returnValue==JFileChooser.APPROVE_OPTION)					{						File file=jfc.getSelectedFile();												if(!file.exists()){							JOptionPane.showMessageDialog(jfc, "That file does not exist");							importing = true;							continue;						}						else							importing = false;												setCursor(new Cursor(Cursor.WAIT_CURSOR));												final File extraFinalReferenceToXmlFile=file;						new Thread(new Runnable(){							public void run()							{								BugTreeModel model=(BugTreeModel)tree.getModel();//								BugTreeModel.pleaseWait();								MainFrame.this.setRebuilding(true);								BugSet bs=BugLoader.loadBugs(extraFinalReferenceToXmlFile);								MainFrame.this.setRebuilding(false);								if (bs!=null)								{									ProjectSettings.newInstance();									model.getOffListenerList();									updateDesignation();									model.changeSet(bs);									curProject=BugLoader.getLoadedProject();									MainFrame.this.updateStatusBar();								}							}						}).start();						setCursor(new Cursor(Cursor.DEFAULT_CURSOR));												setProjectChanged(false);					}					else						return;//					GUISaveState.getInstance().setStarterDirectoryForLoadBugs(jfc.getCurrentDirectory()); This is done by FBFileChooser				}			}		});				exportBugsMenuItem.setEnabled(true);		exportBugsMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);								if (curProject==null)				{					JOptionPane.showMessageDialog(MainFrame.this,"There is no project to save");					return;				}								FBFileChooser chooser=new FBFileChooser();				chooser.setFileFilter(new FindBugsAnalysisFileFilter());				boolean saving=true;				while (saving)				{							int value=chooser.showSaveDialog(MainFrame.this);					if (value==JFileChooser.APPROVE_OPTION)					{						saving=false;						File xmlFile = chooser.getSelectedFile();												if(!xmlFile.getName().endsWith(".xml"))							xmlFile = new File(xmlFile.getAbsolutePath()+".xml");												if (xmlFile.exists())						{							int response = JOptionPane.showConfirmDialog(chooser, 									"This analysis already exists.\nReplace it?",									"Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);														if(response == JOptionPane.OK_OPTION)								saving = false;							if(response == JOptionPane.CANCEL_OPTION){								saving = true;								continue;							}						}						BugSaver.saveBugs(xmlFile, BugSet.getMainBugSet(), MainFrame.this.curProject);					}				else return;				}			}		});								fileMenu.add(newProjectMenuItem);		fileMenu.add(editProjectMenuItem);		fileMenu.addSeparator();		fileMenu.add(openProjectMenuItem);		fileMenu.add(recentProjectsMenu);		fileMenu.addSeparator();		fileMenu.add(saveProjectMenuItem);		fileMenu.add(saveAsProjectMenuItem);		fileMenu.addSeparator();		fileMenu.add(importBugsMenuItem);		fileMenu.add(exportBugsMenuItem);		fileMenu.addSeparator();		fileMenu.add(redoAnalysis);		fileMenu.add(mergeMenuItem);		if (exitMenuItem != null) {			fileMenu.addSeparator();			fileMenu.add(exitMenuItem);		}				//TODO Delete later, this is just for testing purposes.//		JMenuItem temp = new JMenuItem("temp");//		temp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));//		temp.addActionListener(new ActionListener(){//			public void actionPerformed(ActionEvent evt){//				Debug.println("before v scrollbar max: " +sourceCodeScrollPane.getVerticalScrollBar().getMaximum());//				sourceCodeScrollPane.validate();//				Debug.println("after v scrollbar max: " +sourceCodeScrollPane.getVerticalScrollBar().getMaximum());//				Debug.println("scrollbar value: "+sourceCodeScrollPane.getVerticalScrollBar().getValue());//			}//		});//		fileMenu.add(temp);				menuBar.add(fileMenu);				//This kind of works, the key stroke works for the jtree, but the menuitems doesn't.		//Edit editMenu Menu object.		JMenuItem cutMenuItem = new JMenuItem(new CutAction());		JMenuItem copyMenuItem = new JMenuItem(new CopyAction());		JMenuItem pasteMenuItem = new JMenuItem(new PasteAction());		preferencesMenuItem = new JMenuItem("Preferences");		JMenuItem sortMenuItem = new JMenuItem("Sort Configuration...");		JMenuItem goToLineMenuItem = new JMenuItem("Go to line...");				cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));				preferencesMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);				PreferencesFrame.getInstance().setVisible(true);			}		});				sortMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){				saveCommentsToBug(currentSelectedBugLeaf);				SorterDialog.getInstance().setVisible(true);			}		});				goToLineMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));		goToLineMenuItem.addActionListener(new ActionListener(){			public void actionPerformed(ActionEvent evt){								int num = 0;				boolean cont = true;								try{					num = Integer.parseInt(JOptionPane.showInputDialog(MainFrame.this, "", "Go To Line:", JOptionPane.QUESTION_MESSAGE));				}				catch(NumberFormatException e){					cont = false;				}								if(cont)					displayer.showLine(num);									guiLayout.makeSourceVisible();			}		});				editMenu.add(cutMenuItem);		editMenu.add(copyMenuItem);		editMenu.add(pasteMenuItem);		editMenu.addSeparator();		editMenu.add(goToLineMenuItem);		editMenu.addSeparator();		//editMenu.add(selectAllMenuItem);//		editMenu.addSeparator();		editMenu.add(preferencesMenuItem);		editMenu.add(sortMenuItem);				menuBar.add(editMenu);				if (windowMenu != null)			menuBar.add(windowMenu);				JMenu helpMenu = new JMenu("Help");		JMenuItem aboutItem = new JMenuItem("About FindBugs");		helpMenu.add(aboutItem);         aboutItem.addActionListener(new java.awt.event.ActionListener() {             public void actionPerformed(java.awt.event.ActionEvent evt) {                 about();             }         });         menuBar.add(helpMenu);		return menuBar;	}