1 20 package edu.umd.cs.findbugs.gui; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 25 import javax.swing.ImageIcon ; 26 import javax.swing.JTree ; 27 import javax.swing.tree.DefaultMutableTreeNode ; 28 import javax.swing.tree.DefaultTreeCellRenderer ; 29 30 import edu.umd.cs.findbugs.BugInstance; 31 import edu.umd.cs.findbugs.ClassAnnotation; 32 import edu.umd.cs.findbugs.Detector; 33 import edu.umd.cs.findbugs.FieldAnnotation; 34 import edu.umd.cs.findbugs.MethodAnnotation; 35 import edu.umd.cs.findbugs.SourceLineAnnotation; 36 37 42 public class BugCellRenderer extends DefaultTreeCellRenderer { 43 44 private static final BugCellRenderer theInstance = new BugCellRenderer(); 45 46 51 public static BugCellRenderer instance() { 52 return theInstance; 53 } 54 55 private static final long serialVersionUID = 1L; 56 private ImageIcon bugGroupIcon; 57 private ImageIcon packageIcon; 58 private ImageIcon bugIcon; 59 private ImageIcon classIcon; 60 private ImageIcon methodIcon; 61 private ImageIcon fieldIcon; 62 private ImageIcon sourceFileIcon; 63 private Object value; 64 65 private BugCellRenderer() { 66 ClassLoader classLoader = this.getClass().getClassLoader(); 67 bugGroupIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/bug.png")); 68 packageIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/package.png")); 69 bugIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/bug2.png")); 70 classIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/class.png")); 71 methodIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/method.png")); 72 fieldIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/field.png")); 73 sourceFileIcon = new ImageIcon (classLoader.getResource("edu/umd/cs/findbugs/gui/sourcefile.png")); 74 } 75 76 @Override 77 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, 78 boolean expanded, boolean leaf, int row, boolean hasFocus) { 79 DefaultMutableTreeNode node = (DefaultMutableTreeNode ) value; 80 Object obj = node.getUserObject(); 81 82 this.value = obj; 83 84 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 85 86 if (obj instanceof BugInstance) { 88 setIcon(bugIcon); 89 } else if (obj instanceof ClassAnnotation) { 90 setIcon(classIcon); 91 } else if (obj instanceof MethodAnnotation) { 92 setIcon(methodIcon); 93 } else if (obj instanceof FieldAnnotation) { 94 setIcon(fieldIcon); 95 } else if (obj instanceof SourceLineAnnotation) { 96 setIcon(sourceFileIcon); 97 } else if (obj instanceof BugInstanceGroup) { 98 BugInstanceGroup groupNode = (BugInstanceGroup) obj; 100 String groupType = groupNode.getGroupType(); 101 if (groupType == FindBugsFrame.GROUP_BY_CLASS) { 102 setIcon(classIcon); 103 } else if (groupType == FindBugsFrame.GROUP_BY_PACKAGE) { 104 setIcon(packageIcon); 105 } else if (groupType == FindBugsFrame.GROUP_BY_BUG_TYPE) { 106 setIcon(bugGroupIcon); 107 } else if (groupType == FindBugsFrame.GROUP_BY_BUG_CATEGORY) { 108 setIcon(bugGroupIcon); 109 } 110 } else { 111 setIcon(null); 112 } 113 114 return this; 115 } 116 117 @Override 118 public Color getTextNonSelectionColor() { 119 return getCellTextColor(); 120 } 121 122 private Color getCellTextColor() { 123 Color color = Color.BLACK; 125 if (value instanceof BugInstance) { 126 BugInstance bugInstance = (BugInstance) value; 127 switch (bugInstance.getPriority()) { 128 case Detector.EXP_PRIORITY: 129 color = FindBugsFrame.EXP_PRIORITY_COLOR; 130 break; 131 case Detector.LOW_PRIORITY: 132 color = FindBugsFrame.LOW_PRIORITY_COLOR; 133 break; 134 case Detector.NORMAL_PRIORITY: 135 color = FindBugsFrame.NORMAL_PRIORITY_COLOR; 136 break; 137 case Detector.HIGH_PRIORITY: 138 color = FindBugsFrame.HIGH_PRIORITY_COLOR; 139 break; 140 } 141 } 142 return color; 143 } 144 } | Popular Tags |