KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > renderers > SummaryTreeCellRenderer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.renderers;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Font JavaDoc;
24
25 import javax.swing.ImageIcon JavaDoc;
26 import javax.swing.JTree JavaDoc;
27 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
28 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
29 import org.netbeans.modules.tasklist.usertasks.UserTaskListTreeTableNode;
30 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode;
31
32 import org.openide.util.NbBundle;
33
34 /**
35  * Cell renderer for the summary attribute
36  */

37 public class SummaryTreeCellRenderer extends DefaultTreeCellRenderer JavaDoc {
38     private static final long serialVersionUID = 1;
39
40     private Font JavaDoc boldFont, normalFont;
41     private ImageIcon JavaDoc icon = new ImageIcon JavaDoc();
42     
43     public SummaryTreeCellRenderer() {
44         ImageIcon JavaDoc icon = new ImageIcon JavaDoc();
45         
46         // see TreeTable.TreeTableCellEditor.getTableCellEditorComponent
47
setLeafIcon(icon);
48         setOpenIcon(icon);
49         setClosedIcon(icon);
50     }
51     
52     public Component JavaDoc getTreeCellRendererComponent(JTree JavaDoc tree, Object JavaDoc value,
53                    boolean selected, boolean expanded,
54                    boolean leaf, int row, boolean hasFocus) {
55         super.getTreeCellRendererComponent(tree, value, selected, expanded,
56             leaf, row, hasFocus);
57         if (normalFont == null || !normalFont.equals(tree.getFont())) {
58             normalFont = tree.getFont();
59             boldFont = normalFont.deriveFont(Font.BOLD);
60         }
61         if (value instanceof UserTaskTreeTableNode) {
62             UserTaskTreeTableNode utl = (UserTaskTreeTableNode) value;
63             UserTask ut = utl.getUserTask();
64             setFont(ut.isStarted() ? boldFont : normalFont);
65             setText(ut.getSummary());
66             icon.setImage(UserTaskIconProvider.getUserTaskImage(ut, utl.isUnmatched()));
67         }
68         setIcon(icon);
69         return this;
70     }
71 }
72
Popular Tags