KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > mrtg > client > TreeRenderer


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.mrtg.client;
26
27 import org.jrobin.mrtg.MrtgException;
28
29 import javax.swing.*;
30 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
31 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
32 import java.awt.*;
33
34 class TreeRenderer extends DefaultTreeCellRenderer JavaDoc {
35     private static ImageIcon MRTG_ICON;
36     private static ImageIcon ROUTER_ICON;
37     private static ImageIcon LINK_ICON;
38     private static ImageIcon INACTIVE_ROUTER_ICON;
39     private static ImageIcon INACTIVE_LINK_ICON;
40
41     static {
42         try {
43             MRTG_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "mrtg.png");
44             ROUTER_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "router.png");
45             LINK_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "link.png");
46             INACTIVE_ROUTER_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "router_inactive.png");
47             INACTIVE_LINK_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "link_inactive.png");
48         } catch (MrtgException e) {
49             e.printStackTrace();
50         }
51     }
52
53     TreeRenderer() {
54         setLeafIcon(null);
55         setClosedIcon(null);
56         setOpenIcon(null);
57     }
58
59     public Component getTreeCellRendererComponent(
60         JTree tree, Object JavaDoc value, boolean sel, boolean expanded,
61         boolean leaf, int row, boolean hasFocus) {
62         super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
63         DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)value;
64         Object JavaDoc nodeObj = node.getUserObject();
65         if(nodeObj instanceof ServerInfo) {
66             setFont(getFont().deriveFont(Font.BOLD));
67             setIcon(MRTG_ICON);
68         }
69         else if (nodeObj instanceof RouterInfo) {
70             setFont(getFont().deriveFont(Font.BOLD));
71             RouterInfo routerInfo = (RouterInfo) nodeObj;
72             //setForeground(routerInfo.isActive()? Color.BLACK: Color.RED);
73
setIcon(routerInfo.isActive()? ROUTER_ICON: INACTIVE_ROUTER_ICON);
74         }
75         else if (nodeObj instanceof LinkInfo) {
76             setFont(getFont().deriveFont(Font.PLAIN));
77             LinkInfo linkInfo = (LinkInfo) nodeObj;
78             //setForeground(linkInfo.isActive()? Color.BLACK: Color.RED);
79
setIcon(linkInfo.isActive()? LINK_ICON: INACTIVE_LINK_ICON);
80         }
81         else {
82             setFont(getFont().deriveFont(Font.PLAIN));
83             //setForeground(Color.BLACK);
84
}
85         return this;
86     }
87 }
88
Popular Tags