01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18: */
19:
20: package edu.umd.cs.findbugs.gui2;
21:
22: import java.awt.Color;
23: import java.awt.Component;
24:
25: import javax.swing.JTree;
26: import javax.swing.tree.DefaultTreeCellRenderer;
27:
28: import edu.umd.cs.findbugs.BugInstance;
29: import edu.umd.cs.findbugs.Detector;
30:
31: @SuppressWarnings("serial")
32: /**
33: * Sets colors for JTree nodes
34: * @author Dan
35: */
36: public class BugRenderer extends DefaultTreeCellRenderer {
37: @Override
38: public Component getTreeCellRendererComponent(JTree tree,
39: Object node, boolean selected, boolean expanded,
40: boolean leaf, int row, boolean hasFocus) {
41: Component toReturn = super .getTreeCellRendererComponent(tree,
42: node, selected, expanded, leaf, row, hasFocus);
43:
44: if (!(node instanceof BugLeafNode))
45: return toReturn;
46: else {
47: BugInstance bug = ((BugLeafNode) node).getBug();
48: Color c;
49: switch (bug.getPriority()) {
50: case Detector.LOW_PRIORITY:
51: c = new Color(0.4f, 0.4f, 0.6f);
52: break;
53: case Detector.NORMAL_PRIORITY:
54: c = Color.black;
55: break;
56: case Detector.HIGH_PRIORITY:
57: c = new Color(.85f, 0, 0);
58: break;
59: case Detector.EXP_PRIORITY:
60: case Detector.IGNORE_PRIORITY:
61: default:
62: c = Color.black;
63: break;
64: }
65: if (leaf)
66: toReturn.setForeground(c);
67: return toReturn;
68: }
69: }
70: }
|