1 19 package org.netbeans.modules.java.editor.codegen.ui; 20 21 import java.awt.*; 22 import java.beans.BeanInfo ; 23 import javax.swing.*; 24 import javax.swing.tree.*; 25 import org.openide.explorer.view.Visualizer; 26 import org.openide.nodes.Node; 27 28 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 54 55 56 public Component getTreeCellRendererComponent(JTree tree, Object 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 } 77 78 label.setText( n.getHtmlDisplayName() ); 79 label.setIcon( new ImageIcon( n.getIcon(BeanInfo.ICON_COLOR_16x16) ) ); 81 return this; 82 83 } 84 85 public Rectangle getCheckBounds() { 86 return (Rectangle)check.getBounds().clone(); 87 } 88 89 90 } 91 | Popular Tags |