01: package csdl.jblanket.app;
02:
03: import csdl.jblanket.app.tree.MethodNode;
04:
05: import java.awt.Color;
06: import java.awt.Component;
07: import java.awt.Font;
08:
09: import javax.swing.JTree;
10: import javax.swing.tree.DefaultMutableTreeNode;
11: import javax.swing.tree.DefaultTreeCellRenderer;
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 {
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 getTreeCellRendererComponent(JTree tree,
46: Object value, boolean sel, boolean expanded, boolean leaf,
47: int row, boolean hasFocus) {
48:
49: super .getTreeCellRendererComponent(tree, value, sel, expanded,
50: leaf, row, hasFocus);
51:
52: // Need to check font for rendering
53: Font font = getFont();
54:
55: if (leaf) {
56: MethodNode node = (MethodNode) ((DefaultMutableTreeNode) value)
57: .getUserObject();
58:
59: // set up for method category
60: setForeground(node.getNewColor());
61:
62: // tried removing bold from Font outside if-else and set bold here, but didn't work?
63: if (node.isTested() && !font.isBold()) {
64: setFont(new Font(font.getFontName(), font.getStyle()
65: + Font.BOLD, font.getSize()));
66: } else if (!node.isTested() && font.isBold()) {
67: setFont(new Font(font.getFontName(), font.getStyle()
68: - Font.BOLD, font.getSize()));
69: }
70: } else {
71: setForeground(Color.BLACK);
72: if (font.isBold()) {
73: setFont(new Font(font.getFontName(), font.getStyle()
74: - Font.BOLD, font.getSize()));
75: }
76: }
77: return this;
78: }
79: }
|