KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > app > AppRenderer


1 package csdl.jblanket.app;
2
3 import csdl.jblanket.app.tree.MethodNode;
4
5 import java.awt.Color JavaDoc;
6 import java.awt.Component JavaDoc;
7 import java.awt.Font JavaDoc;
8
9 import javax.swing.JTree JavaDoc;
10 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
11 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
12
13 /**
14  * Provides the renderer used by the application. All non-method nodes are black and the colors of
15  * the method nodes are determined by their categories.
16  * (See <a HREF="MethodCategoryColor.html">MethodCategoryColor</a>)
17  *
18  * @author Joy M. Agustin
19  * @version $Id: AppRenderer.java,v 1.1 2004/11/07 00:32:41 timshadel Exp $
20  */

21 public class AppRenderer extends DefaultTreeCellRenderer JavaDoc {
22     
23   /**
24    * Constructs a new AppRenderer.
25    */

26   public AppRenderer() {
27     super();
28   }
29     
30   /**
31    * Configures the renderer based on the passed in components.
32    * <p>
33    * This method overrides the method in the parent class. Due to incomplete comments in the
34    * parent class, some parameters are unknown.
35    *
36    * @param tree the tree <code>value</code> belongs to.
37    * @param value the in the tree being processed.
38    * @param sel unknown.
39    * @param expanded unknown.
40    * @param leaf describes whether <code>value</code> is a leaf node.
41    * @param row the row number of <code>value</code>, starts at 0.
42    * @param hasFocus unknown.
43    * @return the <code>Component</code> that the renderer uses to draw the value.
44    */

45   public Component JavaDoc getTreeCellRendererComponent(JTree JavaDoc tree, Object JavaDoc value, boolean sel,
46                                                 boolean expanded, boolean leaf, int row,
47                                                 boolean hasFocus) {
48
49     super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
50     
51     // Need to check font for rendering
52
Font JavaDoc font = getFont();
53     
54     if (leaf) {
55       MethodNode node = (MethodNode) ((DefaultMutableTreeNode JavaDoc) value).getUserObject();
56
57       // set up for method category
58
setForeground(node.getNewColor());
59       
60       // tried removing bold from Font outside if-else and set bold here, but didn't work?
61
if (node.isTested() && !font.isBold()) {
62         setFont(new Font JavaDoc(font.getFontName(), font.getStyle() + Font.BOLD, font.getSize()));
63       }
64       else if (!node.isTested() && font.isBold()) {
65         setFont(new Font JavaDoc(font.getFontName(), font.getStyle() - Font.BOLD, font.getSize()));
66       }
67     }
68     else {
69       setForeground(Color.BLACK);
70       if (font.isBold()) {
71         setFont(new Font JavaDoc(font.getFontName(), font.getStyle() - Font.BOLD, font.getSize()));
72       }
73     }
74     return this;
75   }
76 }
Popular Tags