001 package nl.cwi.sen1.error.viewer; 002 003 import java.awt.Color; 004 import java.awt.Component; 005 006 import javax.swing.Icon; 007 import javax.swing.JTree; 008 import javax.swing.tree.DefaultTreeCellRenderer; 009 010 import nl.cwi.sen1.error.model.ErrorNode; 011 012 public class ErrorTreeCellRenderer extends DefaultTreeCellRenderer { 013 014 public ErrorTreeCellRenderer() { 015 Icon personIcon = null; 016 setLeafIcon(personIcon); 017 setClosedIcon(personIcon); 018 setOpenIcon(personIcon); 019 } 020 021 public Component getTreeCellRendererComponent(JTree tree, Object value, 022 boolean sel, boolean expanded, boolean leaf, int row, 023 boolean hasFocus) { 024 Color textNonSelectionColor = getTextNonSelectionColor(); 025 Color backgroundNonSelectionColor = getBackgroundNonSelectionColor(); 026 027 if (value instanceof ErrorNode) { 028 ErrorNode node = (ErrorNode) value; 029 030 if (node.isWarning()) { 031 setTextNonSelectionColor(new Color(0, 0, 255)); 032 } else if (node.isError()) { 033 setTextNonSelectionColor(new Color(255, 0, 0)); 034 } else if (node.isFatal()) { 035 setBackgroundNonSelectionColor(new Color(255, 0, 0)); 036 } 037 } 038 039 Component comp = super.getTreeCellRendererComponent(tree, value, sel, 040 expanded, leaf, row, hasFocus); 041 042 setTextNonSelectionColor(textNonSelectionColor); 043 setBackgroundNonSelectionColor(backgroundNonSelectionColor); 044 045 return comp; 046 } 047 }