📄 mainframe.java
字号:
AboutDialog.editorPaneHyperlinkUpdate(evt); } }); setStyleSheets(); //JPanel temp = new JPanel(new BorderLayout()); //temp.add(summaryTopPanel, BorderLayout.CENTER); JScrollPane summaryScrollPane = new JScrollPane(summaryTopOuter); summaryScrollPane.getVerticalScrollBar().setUnitIncrement( (int)Driver.getFontSize() ); JSplitPane splitP = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, summaryScrollPane, summaryHtmlScrollPane); splitP.setDividerLocation(GUISaveState.getInstance().getSplitSummary()); splitP.setOneTouchExpandable(true); return splitP; } /** * Creates bug summary component. If obj is a string will create a JLabel * with that string as it's text and return it. If obj is an annotation * will return a JLabel with the annotation's toString(). If that * annotation is a SourceLineAnnotation or has a SourceLineAnnotation * connected to it and the source file is available will attach * a listener to the label. * @param obj * @param bug TODO * @return */ private Component bugSummaryComponent(Object obj, BugInstance bug){ JLabel label = new JLabel(); label.setFont(label.getFont().deriveFont(Driver.getFontSize())); label.setFont(label.getFont().deriveFont(Font.PLAIN)); label.setForeground(Color.BLACK); if(obj instanceof String){ String str = (String) obj; label.setText(str); } else{ BugAnnotation value = (BugAnnotation) obj; if(value == null) return new JLabel(edu.umd.cs.findbugs.L10N.getLocalString("summary.null", "null")); if(value instanceof SourceLineAnnotation){ final SourceLineAnnotation note = (SourceLineAnnotation) value; if(sourceCodeExist(note)){ String srcStr = ""; int start = note.getStartLine(); int end = note.getEndLine(); if(start < 0 && end < 0) srcStr = edu.umd.cs.findbugs.L10N.getLocalString("summary.source_code", "source code."); else if(start == end) srcStr = " [" + edu.umd.cs.findbugs.L10N.getLocalString("summary.line", "Line") + " " + start + "]"; else if(start < end) srcStr = " [" + edu.umd.cs.findbugs.L10N.getLocalString("summary.lines", "Lines") + " " + start + " - " + end + "]"; label.setToolTipText(edu.umd.cs.findbugs.L10N.getLocalString("tooltip.click_to_go_to", "Click to go to") + " " + srcStr); label.addMouseListener(new BugSummaryMouseListener(bug, label, note)); } label.setText(note.toString()); } else if(value instanceof PackageMemberAnnotation){ PackageMemberAnnotation note = (PackageMemberAnnotation) value; final SourceLineAnnotation noteSrc = note.getSourceLines(); String srcStr = ""; if(sourceCodeExist(noteSrc) && noteSrc != null){ int start = noteSrc.getStartLine(); int end = noteSrc.getEndLine(); if(start < 0 && end < 0) srcStr = edu.umd.cs.findbugs.L10N.getLocalString("summary.source_code", "source code."); else if(start == end) srcStr = " [" + edu.umd.cs.findbugs.L10N.getLocalString("summary.line", "Line") + " " + start + "]"; else if(start < end) srcStr = " [" + edu.umd.cs.findbugs.L10N.getLocalString("summary.lines", "Lines") + " " + start + " - " + end + "]"; if(!srcStr.equals("")){ label.setToolTipText(edu.umd.cs.findbugs.L10N.getLocalString("tooltip.click_to_go_to", "Click to go to") + " " + srcStr); label.addMouseListener(new BugSummaryMouseListener(bug, label, noteSrc)); } } if(!srcStr.equals(edu.umd.cs.findbugs.L10N.getLocalString("summary.source_code", "source code."))) label.setText(note.toString() + srcStr); else label.setText(note.toString()); } else{ label.setText(((BugAnnotation) value).toString()); } } return label; } /** * @author pugh */ private final class InitializeGUI implements Runnable { public void run() { setTitle("FindBugs"); guiLayout.initialize(); bugPopupMenu = createBugPopupMenu(); branchPopupMenu = createBranchPopUpMenu(); comments.loadPrevCommentsList(GUISaveState.getInstance().getPreviousComments().toArray(new String[GUISaveState.getInstance().getPreviousComments().size()])); updateStatusBar(); setBounds(GUISaveState.getInstance().getFrameBounds()); Toolkit.getDefaultToolkit().setDynamicLayout(true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setJMenuBar(createMainMenuBar()); setVisible(true); //Initializes save and open filechooser. - Kristin saveOpenFileChooser = new FBFileChooser(); saveOpenFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); saveOpenFileChooser.setAcceptAllFileFilterUsed(false); saveOpenFileChooser.addChoosableFileFilter(FindBugsProjectFileFilter.INSTANCE); saveOpenFileChooser.addChoosableFileFilter(FindBugsAnalysisFileFilter.INSTANCE); saveOpenFileChooser.addChoosableFileFilter(FindBugsFBPFileFilter.INSTANCE); saveOpenFileChooser.addChoosableFileFilter(FindBugsFBAFileFilter.INSTANCE); saveOpenFileChooser.setFileFilter(FindBugsAnalysisFileFilter.INSTANCE); //Sets the size of the tooltip to match the rest of the GUI. - Kristin JToolTip tempToolTip = tableheader.createToolTip(); UIManager.put( "ToolTip.font", new FontUIResource(tempToolTip.getFont().deriveFont(Driver.getFontSize()))); if (MAC_OS_X) { try { osxAdapter = Class.forName("edu.umd.cs.findbugs.gui2.OSXAdapter"); Class[] defArgs = {MainFrame.class}; Method registerMethod = osxAdapter.getDeclaredMethod("registerMacOSXApplication", defArgs); if (registerMethod != null) { registerMethod.invoke(osxAdapter, MainFrame.this); } defArgs[0] = boolean.class; osxPrefsEnableMethod = osxAdapter.getDeclaredMethod("enablePrefs", defArgs); enablePreferences(true); } catch (NoClassDefFoundError e) { // This will be thrown first if the OSXAdapter is loaded on a system without the EAWT // because OSXAdapter extends ApplicationAdapter in its def System.err.println("This version of Mac OS X does not support the Apple EAWT. Application Menu handling has been disabled (" + e + ")"); } catch (ClassNotFoundException e) { // This shouldn't be reached; if there's a problem with the OSXAdapter we should get the // above NoClassDefFoundError first. System.err.println("This version of Mac OS X does not support the Apple EAWT. Application Menu handling has been disabled (" + e + ")"); } catch (Exception e) { System.err.println("Exception while loading the OSXAdapter: " + e); e.printStackTrace(); if (DEBUG) { e.printStackTrace(); } } } String loadFromURL = SystemProperties.getProperty("findbugs.loadBugsFromURL"); if (loadFromURL != null) { InputStream in; try { in = new URL(loadFromURL).openConnection().getInputStream(); if (loadFromURL.endsWith(".gz")) in = new GZIPInputStream(in); BugTreeModel.pleaseWait(edu.umd.cs.findbugs.L10N.getLocalString("msg.loading_bugs_over_network_txt", "Loading bugs over network...")); loadAnalysisFromInputStream(in); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); JOptionPane.showMessageDialog(MainFrame.this, "Error loading " +e1.getMessage()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); JOptionPane.showMessageDialog(MainFrame.this, "Error loading " +e1.getMessage()); } } addComponentListener(new ComponentAdapter(){ @Override public void componentResized(ComponentEvent e){ comments.resized(); } }); addWindowListener(new WindowAdapter(){ @Override public void windowClosing(WindowEvent e) { if(comments.hasFocus()) setProjectChanged(true); callOnClose(); } }); Driver.removeSplashScreen(); } } /** * Listens for when cursor is over the label and when it is clicked. * When the cursor is over the label will make the label text blue * and the cursor the hand cursor. When clicked will take the * user to the source code tab and to the lines of code connected * to the SourceLineAnnotation. * @author Kristin Stephens * */ private class BugSummaryMouseListener extends MouseAdapter{ private BugInstance bugInstance; private JLabel label; private SourceLineAnnotation note; BugSummaryMouseListener(@NonNull BugInstance bugInstance, @NonNull JLabel label, @NonNull SourceLineAnnotation note){ this.bugInstance = bugInstance; this.label = label; this.note = note; } @Override public void mouseClicked(MouseEvent e) { displayer.displaySource(bugInstance, note); } @Override public void mouseEntered(MouseEvent e){ label.setForeground(Color.blue); setCursor(new Cursor(Cursor.HAND_CURSOR)); } @Override public void mouseExited(MouseEvent e){ label.setForeground(Color.black); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } /** * Checks if source code file exists/is available * @param note * @return */ private boolean sourceCodeExist(SourceLineAnnotation note){ try{ sourceFinder.findSourceFile(note); }catch(FileNotFoundException e){ return false; }catch(IOException e){ return false; } return true; } private void setStyleSheets() { StyleSheet styleSheet = new StyleSheet(); styleSheet.addRule("body {font-size: " + Driver.getFontSize() +"pt}"); styleSheet.addRule("H1 {color: red; font-size: 120%; font-weight: bold;}"); styleSheet.addRule("code {font-family: courier; font-size: " + Driver.getFontSize() +"pt}"); htmlEditorKit.setStyleSheet(styleSheet); summaryHtmlArea.setEditorKit(htmlEditorKit); } JPanel createCommentsInputPanel() { return comments.createCommentsInputPanel(); } /** * Creates the source code panel, but does not put anything in it. * @param text * @return */ JPanel createSourceCodePanel() { Font sourceFont = new Font("Monospaced", Font.PLAIN, (int)Driver.getFontSize()); sourceCodeTextPane.setFont(sourceFont); sourceCodeTextPane.setEditable(false); sourceCodeTextPane.getCaret().setSelectionVisible(true); sourceCodeTextPane.setDocument(SourceCodeDisplay.SOURCE_NOT_RELEVANT); sourceCodeScrollPane = new JScrollPane(sourceCodeTextPane); sourceCodeScrollPane.getVerticalScrollBar().setUnitIncrement(20); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(sourceCodeScrollPane, BorderLayout.CENTER); panel.revalidate(); if (DEBUG) System.out.println("Created source code panel"); return panel; } JPanel createSourceSearchPanel() { GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); JPanel thePanel = new JPanel(); thePanel.setLayout(gridbag); c.gridx = 0; c.gridy = 0; c.weightx = 1.0; c.insets = new Insets(0, 5, 0, 5); c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(sourceSearchTextField, c); thePanel.add(sourceSearchTextField); //add the buttons findButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ searchSource(0); } }); c.gridx = 1; c.weightx = 0.0; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(findButton, c); thePanel.add(findButton); findNextButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ searchSource(1); } }); c.gridx = 2; c.weightx = 0.0; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(findNextButton, c); thePanel.add(findNextButton); findPreviousButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ searchSource(2); } }); c.gridx = 3; c.weightx = 0.0; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(findPreviousButton, c); thePanel.add(findPreviousButton); return thePanel; } void searchSource(int type) { int targetLineNum = -1; String targetString = sourceSearchTextField.getText(); switch(type) { case 0: targetLineNum = displayer.find(targetString); break; case 1: targetLineNum = displayer.findNext(targetString); break; case 2: targetLineNum = displayer.findPrevious(targetString); break; } if(targetLineNum != -1) displayer.foundItem(targetLineNum); } /** * Sets the title of the source tabs for either docking or non-docking * versions. * @param title */ void setSourceTabTitle(String title){ guiLayout.setSourceTitle(title); } /** * Returns the SorterTableColumnModel of the MainFrame. * @return */ SorterTableColumnModel getSorter() { return sorter; } /* * This is overridden for changing the font size */ @Override public void addNotify(){ super.addNotify(); float size = Driver.getFontSize(); getJMenuBar().setFont(getJMenuBar().getFont().deriveFont(size)); for(int i = 0; i < getJMenuBar().getMenuCount(); i++){ for(int j = 0; j < getJMenuBar().getMenu(i).getMenuComponentCount(); j++){ Component temp = getJMenuBar().getMenu(i).getMenuComponent(j); temp.setFont(temp.getFont().deriveFont(size)); } } bugPopupMenu.setFont(bug
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -