001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.plugin;
017:
018: import java.awt.Component;
019: import java.awt.Font;
020: import java.awt.FontMetrics;
021: import java.awt.Graphics;
022: import java.awt.Rectangle;
023:
024: import javax.swing.JLabel;
025: import javax.swing.JTree;
026: import javax.swing.SwingConstants;
027: import javax.swing.SwingUtilities;
028: import javax.swing.tree.DefaultTreeCellRenderer;
029:
030: import org.columba.api.plugin.PluginMetadata;
031: import org.columba.core.plugin.PluginManager;
032:
033: /**
034: * @author frd
035: *
036: * To change the template for this generated type comment go to
037: * Window>Preferences>Java>Code Generation>Code and Comments
038: */
039:
040: public class DescriptionTreeRenderer extends DefaultTreeCellRenderer {
041: /* (non-Javadoc)
042: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
043: */
044: public Component getTreeCellRendererComponent(JTree tree,
045: Object value, boolean selected, boolean expanded,
046: boolean leaf, int row, boolean hasFocus) {
047: super .getTreeCellRendererComponent(tree, value, selected,
048: expanded, leaf, row, hasFocus);
049:
050: PluginNode node = (PluginNode) value;
051:
052: String id = node.getId();
053:
054: String name = null;
055:
056: PluginMetadata metadata = PluginManager.getInstance()
057: .getPluginMetadata(id);
058:
059: if (metadata != null)
060: name = metadata.getName();
061: else
062: name = id;
063:
064: setText(name);
065:
066: String tooltip = node.getTooltip();
067: setToolTipText(tooltip);
068:
069: return this ;
070: }
071:
072: public void paint(Graphics g) {
073: Rectangle bounds = g.getClipBounds();
074: Font font = getFont();
075: FontMetrics fontMetrics = g.getFontMetrics(font);
076:
077: int iconOffset = 0;
078:
079: //int iconOffset = getHorizontalAlignment() + getIcon().getIconWidth() + 1;
080: if ((bounds.x == 0) && (bounds.y == 0)) {
081: bounds.width -= iconOffset;
082:
083: String labelStr = layout(this , fontMetrics, getText(),
084: bounds);
085: setText(labelStr);
086: }
087:
088: super .paint(g);
089: }
090:
091: private String layout(JLabel label, FontMetrics fontMetrics,
092: String text, Rectangle viewR) {
093: Rectangle iconR = new Rectangle();
094: Rectangle textR = new Rectangle();
095:
096: return SwingUtilities.layoutCompoundLabel(fontMetrics, text,
097: null, SwingConstants.RIGHT, SwingConstants.RIGHT,
098: SwingConstants.RIGHT, SwingConstants.RIGHT, viewR,
099: iconR, textR, 0);
100: }
101: }
|