1 /*
2 Copyright (C) 2000 - 2007 Grid Systems, S.A.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 /*
19 * Project: KernelConfigurator
20 * Created on 24-feb-2004
21 *
22 * Copyright (c)2003 Grid Systems
23 */
24 package com.gridsystems.config.app;
25
26 import java.awt.Color;
27 import java.awt.Component;
28
29 import javax.swing.Icon;
30 import javax.swing.JTree;
31 import javax.swing.tree.DefaultTreeCellRenderer;
32
33 import com.gridsystems.config.Configurator;
34 import com.gridsystems.config.ConfiguratorView;
35
36 /**
37 * Specialized version of TreeCellRenderer, able to render a ConfigNode.
38 *
39 * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
40 * @version 1.0
41 */
42 public class ConfigNodeCellRenderer extends DefaultTreeCellRenderer {
43
44 /**
45 * Renders the node, using the node icon if it is an instance of ConfigNode.
46 *
47 * {@inheritDoc}
48 */
49 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
50 boolean expanded, boolean leaf, int row,
51 boolean hasFocus) {
52
53 Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded,
54 leaf, row, hasFocus);
55
56 if (value instanceof ConfigNode) {
57 ConfigNode node = (ConfigNode)value;
58 Icon icon = node.getIcon();
59 if (icon != null) {
60 setIcon(icon);
61 }
62
63 Configurator cfg = node.getConfigurator();
64 ConfiguratorView view = (cfg == null) ? null : cfg.getView();
65 boolean error = view != null && view.hasErrors();
66 c.setForeground(error ? Color.RED : Color.BLACK);
67 }
68 return c;
69 }
70
71 }