package csdl.jblanket.app;
import csdl.jblanket.app.tree.MethodNode;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
/**
* Provides the renderer used by the application. All non-method nodes are black and the colors of
* the method nodes are determined by their categories.
* (See <a href="MethodCategoryColor.html">MethodCategoryColor</a>)
*
* @author Joy M. Agustin
* @version $Id: AppRenderer.java,v 1.1 2004/11/07 00:32:41 timshadel Exp $
*/
public class AppRenderer extends DefaultTreeCellRenderer {
/**
* Constructs a new AppRenderer.
*/
public AppRenderer() {
super();
}
/**
* Configures the renderer based on the passed in components.
* <p>
* This method overrides the method in the parent class. Due to incomplete comments in the
* parent class, some parameters are unknown.
*
* @param tree the tree <code>value</code> belongs to.
* @param value the in the tree being processed.
* @param sel unknown.
* @param expanded unknown.
* @param leaf describes whether <code>value</code> is a leaf node.
* @param row the row number of <code>value</code>, starts at 0.
* @param hasFocus unknown.
* @return the <code>Component</code> that the renderer uses to draw the value.
*/
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
boolean expanded, boolean leaf, int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// Need to check font for rendering
Font font = getFont();
if (leaf) {
MethodNode node = (MethodNode) ((DefaultMutableTreeNode) value).getUserObject();
// set up for method category
setForeground(node.getNewColor());
// tried removing bold from Font outside if-else and set bold here, but didn't work?
if (node.isTested() && !font.isBold()) {
setFont(new Font(font.getFontName(), font.getStyle() + Font.BOLD, font.getSize()));
}
else if (!node.isTested() && font.isBold()) {
setFont(new Font(font.getFontName(), font.getStyle() - Font.BOLD, font.getSize()));
}
}
else {
setForeground(Color.BLACK);
if (font.isBold()) {
setFont(new Font(font.getFontName(), font.getStyle() - Font.BOLD, font.getSize()));
}
}
return this;
}
}
|