📄 mainframe.java
字号:
case FBP_FILE: result = openFBPFile(f); break; case FBA_FILE: result = openFBAFile(f); break; default: 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 { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setSaveType(localSaveType); } } }); item.setFont(item.getFont().deriveFont(Driver.getFontSize())); return item; } BugCollection bugCollection; @SwingThread void setProjectAndBugCollection(Project project, @CheckForNull BugCollection bugCollection) { Filter suppressionMatcher = project.getSuppressionFilter(); if (suppressionMatcher != null) { suppressionMatcher.softAdd(LastVersionMatcher.DEAD_BUG_MATCHER); } // setRebuilding(false); if (bugCollection == null) { showTreeCard(); } else { curProject = project; this.bugCollection = bugCollection; displayer.clearCache(); BugTreeModel model = (BugTreeModel) getTree().getModel(); setSourceFinder(new SourceFinder()); getSourceFinder().setSourceBaseList(project.getSourceDirList()); BugSet bs = new BugSet(bugCollection); model.getOffListenerList(); model.changeSet(bs); if (bs.size() == 0 && bs.sizeUnfiltered() > 0) { warnUserOfFilters(); } updateStatusBar(); } PreferencesFrame.getInstance().updateFilterPanel(); setProjectChanged(false); reconfigMenuItem.setEnabled(true); newProject(); clearSourcePane(); clearSummaryTab(); /* This is here due to a threading issue. It can only be called after * curProject has been changed. Since this method is called by both open methods * it is put here.*/ changeTitle(); } void updateProjectAndBugCollection(Project project, BugCollection bugCollection, BugTreeModel previousModel) { setRebuilding(false); if (bugCollection != null) { displayer.clearCache(); BugSet bs = new BugSet(bugCollection); //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(); setProjectChanged(true); } setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } /** * Changes the title based on curProject and saveFile. * */ public void changeTitle(){ String name = curProject.getProjectName(); if(name == null && saveFile != null) name = saveFile.getAbsolutePath(); if(name == null) name = Project.UNNAMED_PROJECT; MainFrame.this.setTitle(TITLE_START_TXT + name); } /** * Creates popup menu for bugs on tree. * @return */ private JPopupMenu createBugPopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem filterMenuItem = newJMenuItem("menu.filterBugsLikeThis", "Filter bugs like this"); filterMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ saveComments(currentSelectedBugLeaf, currentSelectedBugAspects); new NewFilterFromBug(currentSelectedBugLeaf.getBug()); setProjectChanged(true); MainFrame.getInstance().getTree().setSelectionRow(0);//Selects the top of the Jtree so the CommentsArea syncs up. } }); popupMenu.add(filterMenuItem); JMenu changeDesignationMenu = newJMenu("menu.changeDesignation", "Change bug designation"); int i = 0; int keyEvents [] = {KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8, KeyEvent.VK_9}; for(String key : I18N.instance().getUserDesignationKeys(true)) { String name = I18N.instance().getUserDesignation(key); comments.addDesignationItem(changeDesignationMenu, name, keyEvents[i++]); } popupMenu.add(changeDesignationMenu); return popupMenu; } /** * Creates the branch pop up menu that ask if the user wants * to hide all the bugs in that branch. * @return */ private JPopupMenu createBranchPopUpMenu(){ JPopupMenu popupMenu = new JPopupMenu(); JMenuItem filterMenuItem = newJMenuItem("menu.filterTheseBugs", "Filter these bugs"); filterMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //TODO This code does a smarter version of filtering that is only possible for branches, and does so correctly //However, it is still somewhat of a hack, because if we ever add more tree listeners than simply the bugtreemodel, //They will not be called by this code. Using FilterActivity to notify all listeners will however destroy any //benefit of using the smarter deletion method. saveComments(currentSelectedBugLeaf, currentSelectedBugAspects); int startCount; TreePath path=MainFrame.getInstance().getTree().getSelectionPath(); TreePath deletePath=path; startCount=((BugAspects)(path.getLastPathComponent())).getCount(); int count=((BugAspects)(path.getParentPath().getLastPathComponent())).getCount(); while(count==startCount) { deletePath=deletePath.getParentPath(); if (deletePath.getParentPath()==null)//We are at the top of the tree, don't let this be removed, rebuild tree from root. { Matcher m = currentSelectedBugAspects.getMatcher(); Filter suppressionFilter = MainFrame.getInstance().getProject().getSuppressionFilter(); suppressionFilter.addChild(m); PreferencesFrame.getInstance().updateFilterPanel(); FilterActivity.notifyListeners(FilterListener.Action.FILTERING, null); return; } count=((BugAspects)(deletePath.getParentPath().getLastPathComponent())).getCount(); } /* deletePath should now be a path to the highest ancestor branch with the same number of elements as the branch to be deleted in other words, the branch that we actually have to remove in order to correctly remove the selected branch.*/ BugTreeModel model=MainFrame.getInstance().getBugTreeModel(); TreeModelEvent event=new TreeModelEvent(this,deletePath.getParentPath(), new int[]{model.getIndexOfChild(deletePath.getParentPath().getLastPathComponent(),deletePath.getLastPathComponent())}, new Object[]{deletePath.getLastPathComponent()}); Matcher m = currentSelectedBugAspects.getMatcher(); Filter suppressionFilter = MainFrame.getInstance().getProject().getSuppressionFilter(); suppressionFilter.addChild(m); PreferencesFrame.getInstance().updateFilterPanel(); model.sendEvent(event, TreeModification.REMOVE);// FilterActivity.notifyListeners(FilterListener.Action.FILTERING, null); setProjectChanged(true); MainFrame.getInstance().getTree().setSelectionRow(0);//Selects the top of the Jtree so the CommentsArea syncs up. } }); popupMenu.add(filterMenuItem); JMenu changeDesignationMenu = newJMenu("menu.changeDesignation", "Change bug designation"); int i = 0; int keyEvents [] = {KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8, KeyEvent.VK_9}; for(String key : I18N.instance().getUserDesignationKeys(true)) { String name = I18N.instance().getUserDesignation(key); addDesignationItem(changeDesignationMenu, name, keyEvents[i++]); } popupMenu.add(changeDesignationMenu); return popupMenu; } /** * Creates the MainFrame's menu bar. * @return the menu bar for the MainFrame */ protected JMenuBar createMainMenuBar() { JMenuBar menuBar = new JMenuBar(); //Create JMenus for menuBar. JMenu fileMenu = newJMenu("menu.file_menu", "File"); fileMenu.setMnemonic(KeyEvent.VK_F); JMenu editMenu = newJMenu("menu.edit_menu", "Edit"); editMenu.setMnemonic(KeyEvent.VK_E); //Edit fileMenu JMenu object. JMenuItem newProjectMenuItem = newJMenuItem("menu.new_item", "New Project", KeyEvent.VK_N); JMenuItem openMenuItem = newJMenuItem("menu.open_item", "Open...", KeyEvent.VK_O); recentMenu = newJMenu("menu.recent", "Recent"); recentMenuCache=new RecentMenu(recentMenu); JMenuItem saveAsMenuItem = newJMenuItem("menu.saveas_item", "Save As...", KeyEvent.VK_A);; redoAnalysis = newJMenuItem("menu.rerunAnalysis", "Redo Analysis", KeyEvent.VK_R); JMenuItem exitMenuItem = null; if (!MAC_OS_X) { exitMenuItem = newJMenuItem("menu.exit", "Exit", KeyEvent.VK_X); exitMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ callOnClose(); } }); } JMenu windowMenu = guiLayout.createWindowMenu(); attachAcceleratorKey(newProjectMenuItem, KeyEvent.VK_N); newProjectMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ newProjectMenu(); } }); reconfigMenuItem.setEnabled(false); attachAcceleratorKey(reconfigMenuItem, KeyEvent.VK_F); reconfigMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { saveComments(currentSelectedBugLeaf, currentSelectedBugAspects); new NewProjectWizard(curProject); } }); JMenuItem mergeMenuItem = newJMenuItem("menu.mergeAnalysis", "Merge Analysis..."); mergeMenuItem.setEnabled(true); mergeMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ mergeAnalysis(); } }); redoAnalysis.setEnabled(false); attachAcceleratorKey(redoAnalysis, KeyEvent.VK_R); redoAnalysis.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ redoAnalysis(); } }); openMenuItem.setEnabled(true); attachAcceleratorKey(openMenuItem, KeyEvent.VK_O); openMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ open(); } }); saveAsMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt) { saveAs(); } }); saveMenuItem.setEnabled(false); attachAcceleratorKey(saveMenuItem, KeyEvent.VK_S); saveMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt) { save(); } }); fileMenu.add(newProjectMenuItem); fileMenu.add(reconfigMenuItem); fileMenu.addSeparator(); fileMenu.add(openMenuItem); fileMenu.add(recentMenu); fileMenu.addSeparator(); fileMenu.add(saveAsMenuItem); fileMenu.add(saveMenuItem); fileMenu.addSeparator(); fileMenu.add(redoAnalysis); // fileMenu.add(mergeMenuItem); //TODO: This serves no purpose but to test something if(false){ JMenuItem temp = new JMenuItem("Temp"); temp.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { System.out.println("Current Project Name: " + curProject.getProjectName()); } }); fileMenu.add(temp); } if (exitMenuItem != null) { fileMenu.addSeparator(); fileMenu.add(exitMenuItem); } menuBar.add(fileMenu); //Edit editMenu Menu object. JMenuItem cutMenuItem = new JMenuItem(new CutAction()); JMenuItem copyMenuItem = new JMenuItem(new CopyAction()); JMenuItem pasteMenuItem = new JMenuItem(new PasteAction()); preferencesMenuItem = newJMenuItem("menu.preferences_menu", "Filters/Suppressions..."); JMenuItem sortMenuItem = newJMenuItem("menu.sortConfiguration", "Sort Configuration..."); JMenuItem goToLineMenuItem = newJMenuItem("menu.gotoLine", "Go to line..."); attachAcceleratorKey(cutMenuItem, KeyEvent.VK_X); attachAcceleratorKey(copyMenuItem, KeyEvent.VK_C); attachAcceleratorKey(pasteMenuItem, KeyEvent.VK_V); preferencesMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ preferences(); } }); sortMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ saveComments(currentSelectedBugLeaf, currentSelectedBugAspects); SorterDialog.getInstance().setLocationRelativeTo(MainFrame.this); SorterDialog.getInstance().setVisible(true); } }); attachAcceleratorKey(goToLineMenuItem, KeyEvent.VK_L); goToLineMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ guiLayout.makeSourceVisible(); try{ int num = Integer.parseInt(JOptionPane.showInputDialog(MainFrame.this, "", edu.umd.cs.findbugs.L10N.getLocalString("dlg.go_to_line_lbl", "Go To Line") + ":", JOptionPane.QUESTION_MESSAGE)); displayer.showLine(num); } catch(NumberFormatException e){} }}); editMenu.add(cutMenuItem); editMenu.add(copyMenuItem); editMenu.add(pasteMenuItem); editMenu.addSeparator(); editMenu.add(goToLineMenuItem); editMenu.addSeparator(); //editMenu.add(selectAllMenuItem);// editMenu.addSeparator(); if (!MAC_OS_X) { // Preferences goes in Findbugs menu and is handled by OSXAdapter editMenu.add(preferencesMenuItem); } editMenu.add(sortMenuItem); menuBar.add(editMenu); if (windowMenu != null) menuBar.add(windowMenu); final ActionMap map = tree.getActionMap(); JMenu navMenu = newJMenu("menu.navigation", "Navigation"); addNavItem(map, navMenu, "menu.expand", "Expand", "expand", KeyEvent.VK_RIGHT ); addNavItem(map, navMenu, "menu.collapse", "Collapse", "collapse", KeyEvent.VK_LEFT); addNavItem(map, navMenu, "menu.up", "Up", "selectPrevious", KeyEvent.VK_UP ); addNavItem(map, navMenu, "menu.down", "Down", "selectNext", KeyEvent.VK_DOWN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -