KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > plugin > DescriptionTreeRenderer


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.plugin;
17
18 import java.awt.Component JavaDoc;
19 import java.awt.Font JavaDoc;
20 import java.awt.FontMetrics JavaDoc;
21 import java.awt.Graphics JavaDoc;
22 import java.awt.Rectangle JavaDoc;
23
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.JTree JavaDoc;
26 import javax.swing.SwingConstants JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
29
30 import org.columba.api.plugin.PluginMetadata;
31 import org.columba.core.plugin.PluginManager;
32
33
34 /**
35  * @author frd
36  *
37  * To change the template for this generated type comment go to
38  * Window>Preferences>Java>Code Generation>Code and Comments
39  */

40
41 public class DescriptionTreeRenderer extends DefaultTreeCellRenderer JavaDoc {
42     /* (non-Javadoc)
43          * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
44          */

45     public Component JavaDoc getTreeCellRendererComponent(JTree JavaDoc tree, Object JavaDoc 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 JavaDoc id = node.getId();
54         
55         String JavaDoc 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 JavaDoc tooltip = node.getTooltip();
67         setToolTipText(tooltip);
68
69         return this;
70     }
71
72     public void paint(Graphics JavaDoc g) {
73         Rectangle JavaDoc bounds = g.getClipBounds();
74         Font JavaDoc font = getFont();
75         FontMetrics JavaDoc fontMetrics = g.getFontMetrics(font);
76
77      
78
79         int iconOffset = 0;
80
81         //int iconOffset = getHorizontalAlignment() + getIcon().getIconWidth() + 1;
82
if ((bounds.x == 0) && (bounds.y == 0)) {
83             bounds.width -= iconOffset;
84
85             String JavaDoc labelStr = layout(this, fontMetrics, getText(), bounds);
86             setText(labelStr);
87         }
88
89         super.paint(g);
90     }
91
92     private String JavaDoc layout(JLabel JavaDoc label, FontMetrics JavaDoc fontMetrics, String JavaDoc text,
93         Rectangle JavaDoc viewR) {
94         Rectangle JavaDoc iconR = new Rectangle JavaDoc();
95         Rectangle JavaDoc textR = new Rectangle JavaDoc();
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