KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > treetable > BooleanTableCellRenderer


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.treetable;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24
25 import javax.swing.JCheckBox JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JTable JavaDoc;
28 import javax.swing.UIManager JavaDoc;
29 import javax.swing.border.Border JavaDoc;
30 import javax.swing.border.EmptyBorder JavaDoc;
31 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
32 import javax.swing.table.TableCellRenderer JavaDoc;
33
34 /**
35  * Table cell renderer for boolean values
36  */

37 public class BooleanTableCellRenderer extends JCheckBox JavaDoc
38 implements TableCellRenderer JavaDoc {
39     private DefaultTableCellRenderer JavaDoc def = new DefaultTableCellRenderer JavaDoc();
40     protected static Border JavaDoc noFocusBorder = new EmptyBorder JavaDoc(1, 1, 1, 1);
41     
42     /**
43      * Creates a new instance of BooleanTableCellRenderer
44      */

45     public BooleanTableCellRenderer() {
46         setHorizontalAlignment(JLabel.CENTER);
47         setBorder(noFocusBorder);
48         setBorderPainted(true);
49         setBorderPaintedFlat(true);
50         setOpaque(true);
51     }
52
53     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
54         boolean isSelected, boolean hasFocus, int row, int column) {
55         if (value == null)
56             return def.getTableCellRendererComponent(table, value,
57                 isSelected, hasFocus, row, column);
58         if (isSelected) {
59             setForeground(table.getSelectionForeground());
60             super.setBackground(table.getSelectionBackground());
61         }
62         else {
63             setForeground(table.getForeground());
64             setBackground(table.getBackground());
65         }
66
67     if (hasFocus) {
68         setBorder(UIManager.getBorder("Table.focusCellHighlightBorder") ); // NOI18N
69
} else {
70         setBorder(noFocusBorder);
71     }
72         
73         setSelected((value != null && ((Boolean JavaDoc)value).booleanValue()));
74         return this;
75     }
76 }
77
Popular Tags