1 package org.columba.core.gui.plugin; 17 18 import java.awt.Component ; 19 import java.awt.Font ; 20 import java.awt.FontMetrics ; 21 import java.awt.Graphics ; 22 import java.awt.Rectangle ; 23 24 import javax.swing.JLabel ; 25 import javax.swing.JTree ; 26 import javax.swing.SwingConstants ; 27 import javax.swing.SwingUtilities ; 28 import javax.swing.tree.DefaultTreeCellRenderer ; 29 30 import org.columba.api.plugin.PluginMetadata; 31 import org.columba.core.plugin.PluginManager; 32 33 34 40 41 public class DescriptionTreeRenderer extends DefaultTreeCellRenderer { 42 45 public Component getTreeCellRendererComponent(JTree tree, Object value, 46 boolean selected, boolean expanded, boolean leaf, int row, 47 boolean hasFocus) { 48 super.getTreeCellRendererComponent(tree, value, selected, expanded, 49 leaf, row, hasFocus); 50 51 PluginNode node = (PluginNode) value; 52 53 String id = node.getId(); 54 55 String name = null; 56 57 PluginMetadata metadata = PluginManager.getInstance().getPluginMetadata(id); 58 59 if ( metadata != null) 60 name = metadata.getName(); 61 else 62 name = id; 63 64 setText(name); 65 66 String tooltip = node.getTooltip(); 67 setToolTipText(tooltip); 68 69 return this; 70 } 71 72 public void paint(Graphics g) { 73 Rectangle bounds = g.getClipBounds(); 74 Font font = getFont(); 75 FontMetrics fontMetrics = g.getFontMetrics(font); 76 77 78 79 int iconOffset = 0; 80 81 if ((bounds.x == 0) && (bounds.y == 0)) { 83 bounds.width -= iconOffset; 84 85 String labelStr = layout(this, fontMetrics, getText(), bounds); 86 setText(labelStr); 87 } 88 89 super.paint(g); 90 } 91 92 private String layout(JLabel label, FontMetrics fontMetrics, String text, 93 Rectangle viewR) { 94 Rectangle iconR = new Rectangle (); 95 Rectangle textR = new Rectangle (); 96 97 return SwingUtilities.layoutCompoundLabel(fontMetrics, text, null, 98 SwingConstants.RIGHT, SwingConstants.RIGHT, SwingConstants.RIGHT, 99 SwingConstants.RIGHT, viewR, iconR, textR, 0); 100 } 101 } 102 | Popular Tags |