📄 findbugsframe.java
字号:
/* * FindBugs - Find bugs in Java programs * Copyright (C) 2003-2005, University of Maryland * Copyright (C) 2004 Dave Brosius <dbrosius@users.sourceforge.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* * FindBugsFrame.java * * Created on March 30, 2003, 12:05 PM */package edu.umd.cs.findbugs.gui;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.Color;import java.awt.Component;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Event;import java.awt.Font;import java.awt.Graphics;import java.awt.HeadlessException;import java.awt.Point;import java.awt.Rectangle;import java.awt.Shape;import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Serializable;import java.io.StringReader;import java.lang.reflect.Method;import java.net.URL;import java.text.MessageFormat;import java.util.Arrays;import java.util.Collection;import java.util.Comparator;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.TreeSet;import javax.swing.AbstractButton;import javax.swing.ButtonGroup;import javax.swing.DefaultListModel;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JList;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.JTextField;import javax.swing.JTree;import javax.swing.JViewport;import javax.swing.KeyStroke;import javax.swing.ListModel;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.filechooser.FileFilter;import javax.swing.text.BadLocationException;import javax.swing.text.DefaultHighlighter;import javax.swing.text.Highlighter;import javax.swing.text.JTextComponent;import javax.swing.text.Position;import javax.swing.text.View;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;import org.dom4j.DocumentException;import edu.umd.cs.findbugs.BugAnnotation;import edu.umd.cs.findbugs.BugInstance;import edu.umd.cs.findbugs.BugPattern;import edu.umd.cs.findbugs.Detector;import edu.umd.cs.findbugs.DetectorFactoryCollection;import edu.umd.cs.findbugs.FindBugs;import edu.umd.cs.findbugs.FindBugsCommandLine;import edu.umd.cs.findbugs.I18N;import edu.umd.cs.findbugs.L10N;import edu.umd.cs.findbugs.MethodAnnotation;import edu.umd.cs.findbugs.Project;import edu.umd.cs.findbugs.ShowHelp;import edu.umd.cs.findbugs.SourceLineAnnotation;import edu.umd.cs.findbugs.SystemProperties;import edu.umd.cs.findbugs.annotations.SuppressWarnings;import edu.umd.cs.findbugs.ba.SourceFile;import edu.umd.cs.findbugs.ba.SourceFinder;import edu.umd.cs.findbugs.config.AnalysisFeatureSetting;import edu.umd.cs.findbugs.config.ProjectFilterSettings;import edu.umd.cs.findbugs.config.UserPreferences;import edu.umd.cs.findbugs.config.CommandLine.HelpRequestedException;/** * The main GUI frame for FindBugs. * * @author David Hovemeyer */public final class FindBugsFrame extends javax.swing.JFrame implements LogSync { /** * */ private static final int fontSize = 12; /** * */ private static final Font SOURCE_FONT = new java.awt.Font("Monospaced", 0, fontSize); private static final Font JTREE_FONT = new java.awt.Font("SansSerif", 0, fontSize); /** * */ private static final Font LABEL_FONT = new java.awt.Font("Dialog", 1, 2*fontSize); /** * */ private static final Font BUTTON_FONT = new java.awt.Font("Dialog", 0, fontSize); private static final long serialVersionUID = 1L; /* ---------------------------------------------------------------------- * Helper classes * ---------------------------------------------------------------------- */ static final Color HIGH_PRIORITY_COLOR = new Color(0xff0000); static final Color NORMAL_PRIORITY_COLOR = new Color(0x9f0000); static final Color LOW_PRIORITY_COLOR = Color.BLACK; static final Color EXP_PRIORITY_COLOR = Color.BLACK; /** * Tree node type for BugInstances. * We use this instead of plain DefaultMutableTreeNodes in order to * get more control over the exact text that is shown in the tree. */ private class BugTreeNode extends DefaultMutableTreeNode { private static final long serialVersionUID = 1L; private int count; public BugTreeNode(BugInstance bugInstance) { super(bugInstance); count = -1; } public void setCount(int count) { this.count = count; } @Override public String toString() { try { BugInstance bugInstance = (BugInstance) getUserObject(); StringBuffer result = new StringBuffer(); if (count >= 0) { result.append(count); result.append(": "); } if (bugInstance.isExperimental()) result.append(L10N.getLocalString("msg.exp_txt", "EXP: ")); result.append(fullDescriptionsItem.isSelected() ? bugInstance.getMessage() : bugInstance.toString()); return result.toString(); } catch (Exception e) { return MessageFormat.format(L10N.getLocalString("msg.errorformatting_txt", "Error formatting message for bug: "), new Object[]{e.toString()}); } } } /** * Compare BugInstance class names. * This is useful for grouping bug instances by class. * Note that all instances with the same class name will compare * as equal. */ private static class BugInstanceClassComparator implements Comparator<BugInstance> { public int compare(BugInstance lhs, BugInstance rhs) { return lhs.getPrimaryClass().compareTo(rhs.getPrimaryClass()); } } /** * The instance of BugInstanceClassComparator. */ private static final Comparator<BugInstance> bugInstanceClassComparator = new BugInstanceClassComparator(); /** * Compare BugInstance package names. * This is useful for grouping bug instances by package. * Note that all instances with the same package name will compare * as equal. */ private static class BugInstancePackageComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L; public int compare(BugInstance lhs, BugInstance rhs) { return lhs.getPrimaryClass().getPackageName().compareTo(rhs.getPrimaryClass().getPackageName()); } } /** * The instance of BugInstancePackageComparator. */ private static final Comparator<BugInstance> bugInstancePackageComparator = new BugInstancePackageComparator(); /** * Compare BugInstance bug types. * This is useful for grouping bug instances by bug type. * Note that all instances with the same bug type will compare * as equal. */ private static class BugInstanceTypeComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L; public int compare(BugInstance lhs, BugInstance rhs) { String lhsString = lhs.toString(); String rhsString = rhs.toString(); return lhsString.substring(0, lhsString.indexOf(':')).compareTo(rhsString.substring(0, rhsString.indexOf(':'))); } } /** * The instance of BugInstanceTypeComparator. */ private static final Comparator<BugInstance> bugInstanceTypeComparator = new BugInstanceTypeComparator(); /** * Compare BugInstance bug categories. * This is useful for grouping bug instances by bug category. * Note that all instances with the same bug category will compare * as equal. */ private static class BugInstanceCategoryComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L; public int compare(BugInstance lhs, BugInstance rhs) { return getCategory(lhs).compareTo(getCategory(rhs)); } private String getCategory(BugInstance warning) { BugPattern bugPattern = warning.getBugPattern(); if (bugPattern == null) { if (FindBugs.DEBUG) System.out.println("Unknown bug pattern for bug type: " + warning.getType()); return ""; } else { return bugPattern.getCategory(); } } } /** * The instance of BugInstanceCategoryComparator. */ private static final Comparator<BugInstance> bugInstanceCategoryComparator = new BugInstanceCategoryComparator(); /** * Two-level comparison of bug instances by class name and * BugInstance natural ordering. */ private static class BugInstanceByClassComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L; public int compare(BugInstance a, BugInstance b) { int cmp = bugInstanceClassComparator.compare(a, b); if (cmp != 0) return cmp; return a.compareTo(b); } } /** * The instance of BugInstanceByClassComparator. */ private static final Comparator<BugInstance> bugInstanceByClassComparator = new FindBugsFrame.BugInstanceByClassComparator(); /** * Two-level comparison of bug instances by package and * BugInstance natural ordering. */ private static class BugInstanceByPackageComparator implements Comparator<BugInstance> { public int compare(BugInstance a, BugInstance b) { int cmp = bugInstancePackageComparator.compare(a, b); if (cmp != 0) return cmp; return a.compareTo(b); } } /** * The instance of BugInstanceByPackageComparator. */ private static final Comparator<BugInstance> bugInstanceByPackageComparator = new FindBugsFrame.BugInstanceByPackageComparator(); /** * Two-level comparison of bug instances by bug type and * BugInstance natural ordering. */ private static class BugInstanceByTypeComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L; public int compare(BugInstance a, BugInstance b) { int cmp = bugInstanceTypeComparator.compare(a, b); if (cmp != 0) return cmp; return a.compareTo(b); } } /** * The instance of BugTypeByTypeComparator. */ private static final Comparator<BugInstance> bugInstanceByTypeComparator = new FindBugsFrame.BugInstanceByTypeComparator(); /** * Two-level comparison of bug instances by bug category and * BugInstance natural ordering. */ private static class BugInstanceByCategoryComparator implements Comparator<BugInstance>, Serializable { private static final long serialVersionUID = 1L;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -