KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > BugRenderer


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc;
23 import java.awt.Component JavaDoc;
24
25 import javax.swing.JTree JavaDoc;
26 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
27
28 import edu.umd.cs.findbugs.BugInstance;
29 import edu.umd.cs.findbugs.Detector;
30
31 @SuppressWarnings JavaDoc("serial")
32 /**
33  * Sets colors for JTree nodes
34  * @author Dan
35  */

36 public class BugRenderer extends DefaultTreeCellRenderer JavaDoc
37 {
38     public Component JavaDoc getTreeCellRendererComponent(JTree JavaDoc tree, Object JavaDoc node, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
39     {
40         Component JavaDoc toReturn=super.getTreeCellRendererComponent(tree,node,selected,expanded,leaf,row,hasFocus);
41         
42         if (!(node instanceof BugLeafNode))
43             return toReturn;
44         else
45         {
46             BugInstance bug=((BugLeafNode) node).getBug();
47             Color JavaDoc c;
48             switch (bug.getPriority())
49             {
50                 case Detector.LOW_PRIORITY:
51                     c=new Color JavaDoc(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 JavaDoc(.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 }
71
72
Popular Tags