1 23 24 package org.objectweb.fractal.gui.tree.view; 25 26 import org.objectweb.fractal.gui.Constants; 27 import org.objectweb.fractal.gui.model.Component; 28 29 import java.awt.Color ; 30 import java.awt.Font ; 31 import java.net.URL ; 32 33 import javax.swing.JTree ; 34 import javax.swing.tree.DefaultTreeCellRenderer ; 35 import javax.swing.ImageIcon ; 36 37 44 45 public class BasicTreeCellRenderer extends DefaultTreeCellRenderer { 46 47 50 51 private Font normalFont; 52 53 public java.awt.Component getTreeCellRendererComponent ( 54 final JTree tree, 55 final Object value, 56 final boolean sel, 57 final boolean expanded, 58 final boolean leaf, 59 final int row, 60 final boolean hasFocus) 61 { 62 super.getTreeCellRendererComponent( 63 tree, value, sel, expanded, leaf, row, hasFocus); 64 if (!(value instanceof Component)) { 65 return this; 66 } 67 if (normalFont == null) { 68 normalFont = getFont(); 69 } 70 Component c = (Component)value; 71 long status = c.getStatus(); 72 setForeground (status == 0 ? Color.black : Constants.ERROR_COLOR); 73 if ((status & Component.NAME_MISSING) != 0) { 74 setText("<missing>"); 75 } else { 76 setText(c.getName()); 77 } 78 79 Color col = new Color (255, 255, 204); 80 tree.setBackground (col); 81 setBackgroundNonSelectionColor(col); 82 setBackgroundSelectionColor(new Color (255, 204, 102)); 83 84 URL url_item = getClass().getResource 85 ("/org/objectweb/fractal/gui/resources/tr_item.gif"); 86 this.setLeafIcon (new ImageIcon (url_item)); 87 URL url_open = getClass().getResource 88 ("/org/objectweb/fractal/gui/resources/tr_open.gif"); 89 this.setOpenIcon (new ImageIcon (url_open)); 90 URL url_closed = getClass().getResource 91 ("/org/objectweb/fractal/gui/resources/tr_closed.gif"); 92 this.setClosedIcon (new ImageIcon (url_closed)); 93 94 if (c.getMasterComponent() != null) { 95 setFont(normalFont.deriveFont(Font.ITALIC)); 96 } else { 97 setFont(normalFont); 98 } 99 return this; 100 } 101 } 102 | Popular Tags |