1 25 package org.jrobin.mrtg.client; 26 27 import org.jrobin.mrtg.MrtgException; 28 29 import javax.swing.*; 30 import javax.swing.tree.DefaultMutableTreeNode ; 31 import javax.swing.tree.DefaultTreeCellRenderer ; 32 import java.awt.*; 33 34 class TreeRenderer extends DefaultTreeCellRenderer { 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 value, boolean sel, boolean expanded, 61 boolean leaf, int row, boolean hasFocus) { 62 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 63 DefaultMutableTreeNode node = (DefaultMutableTreeNode )value; 64 Object 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 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 setIcon(linkInfo.isActive()? LINK_ICON: INACTIVE_LINK_ICON); 80 } 81 else { 82 setFont(getFont().deriveFont(Font.PLAIN)); 83 } 85 return this; 86 } 87 } 88 | Popular Tags |