KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > codegen > ui > CheckRenderer


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.editor.codegen.ui;
20
21 import java.awt.*;
22 import java.beans.BeanInfo JavaDoc;
23 import javax.swing.*;
24 import javax.swing.tree.*;
25 import org.openide.explorer.view.Visualizer;
26 import org.openide.nodes.Node;
27
28 /**
29  * @author Petr Hrebejk
30  */

31 class CheckRenderer extends JPanel implements TreeCellRenderer {
32
33     private JCheckBox check;
34     private JLabel label;
35             
36     private static final JList LIST_FOR_COLORS = new JList();
37     
38     public CheckRenderer() {
39         
40         setLayout(new BorderLayout() );
41         setOpaque(true);
42         
43         this.check = new JCheckBox();
44         this.label = new JLabel();
45         
46         add(check, BorderLayout.WEST );
47         add(label, BorderLayout.CENTER );
48         
49         check.setOpaque(false);
50         label.setOpaque(false);
51     }
52         
53     /** The component returned by HtmlRenderer.Renderer.getTreeCellRendererComponent() */
54     
55     
56     public Component getTreeCellRendererComponent(JTree tree, Object JavaDoc value,
57     boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
58         
59         Node n = Visualizer.findNode(value);
60         ElementNode.Description description = n.getLookup().lookup(ElementNode.Description.class);
61         
62         if ( description != null ) {
63             check.setVisible(description.isSelectable());
64             check.setSelected(description.isSelected());
65         }
66             
67         if ( isSelected ) {
68             label.setForeground(LIST_FOR_COLORS.getSelectionForeground());
69             setOpaque(true);
70             setBackground(LIST_FOR_COLORS.getSelectionBackground());
71         }
72         else {
73             label.setForeground(tree.getForeground());
74             setOpaque(false);
75             //setBackground(tree.getBackground());
76
}
77         
78         label.setText( n.getHtmlDisplayName() );
79         label.setIcon( new ImageIcon( n.getIcon(BeanInfo.ICON_COLOR_16x16) ) ); // XXX Ask description directly
80

81         return this;
82         
83     }
84     
85     public Rectangle getCheckBounds() {
86         return (Rectangle)check.getBounds().clone();
87     }
88         
89
90 }
91
Popular Tags