KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > tree > VTreeCellRenderer


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
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 for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid.tree;
15
16 import javax.swing.tree.*;
17 import java.awt.*;
18 import javax.swing.*;
19
20 import org.compiere.model.*;
21
22 /**
23  * Tree Cell Renderer to context sensitive display Icon
24  * @author Jorg Janke
25  * @version $Id: VTreeCellRenderer.java,v 1.4 2003/02/14 06:44:14 jjanke Exp $
26  */

27 public final class VTreeCellRenderer extends DefaultTreeCellRenderer
28 {
29     /**
30      * Constructor
31      */

32     public VTreeCellRenderer()
33     {
34         super();
35     } // VTreeCellRenderer
36

37
38     /**
39      * Get Tree Cell Renderer Component.
40      * Sets Icon, Name, Description for leaves
41      * @param tree tree
42      * @param value value
43      * @param selected selected
44      * @param expanded expanded
45      * @param leaf leaf
46      * @param row row
47      * @param hasFocus focus
48      * @return renderer
49      */

50     public Component getTreeCellRendererComponent(JTree tree, Object JavaDoc value,
51         boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
52     {
53         VTreeCellRenderer c = (VTreeCellRenderer)super.getTreeCellRendererComponent
54             (tree, value, selected, expanded, leaf, row, hasFocus);
55         if (!leaf)
56             return c;
57
58         // We have a leaf
59
MTreeNode nd = (MTreeNode)value;
60         Icon icon = nd.getIcon();
61         if (icon != null)
62             c.setIcon(icon);
63         c.setText(nd.getName());
64         c.setToolTipText(nd.getDescription());
65         return c;
66     } // getTreeCellRendererComponent
67

68 } // VTreeCellRenderer
69
Popular Tags