KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Code 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.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Rectangle JavaDoc;
25
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JProgressBar 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.border.LineBorder JavaDoc;
32 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
33 import javax.swing.table.TableCellRenderer JavaDoc;
34
35 import org.openide.util.NbBundle;
36
37 /**
38  * PropertyEditor for done field.
39  */

40 public class PercentsTableCellRenderer extends JPanel JavaDoc implements TableCellRenderer JavaDoc {
41     protected static Border JavaDoc noFocusBorder = new EmptyBorder JavaDoc(2, 2, 2, 2);
42     
43     private JProgressBar JavaDoc progressBar;
44     private DefaultTableCellRenderer JavaDoc def = new DefaultTableCellRenderer JavaDoc();
45
46     /**
47      * Constructor
48      */

49     public PercentsTableCellRenderer() {
50         setOpaque(true);
51         progressBar = new JProgressBar JavaDoc();
52         progressBar.setStringPainted(true);
53         progressBar.setOpaque(true);
54         progressBar.setBorderPainted(false);
55
56         setLayout(new BorderLayout JavaDoc());
57         add(progressBar, BorderLayout.CENTER);
58     }
59     
60     public Component JavaDoc getTableCellRendererComponent(javax.swing.JTable JavaDoc table,
61         Object JavaDoc value, boolean isSelected, boolean hasFocus,
62         int row, int column) {
63         if (value == null)
64             return def.getTableCellRendererComponent(table, value, isSelected,
65                 hasFocus, row, column);
66         
67         if (isSelected) {
68             setBackground(table.getSelectionBackground());
69         }
70         else {
71             setBackground(table.getBackground());
72         }
73         int n = ((Integer JavaDoc) value).intValue();
74         progressBar.setValue(n);
75         progressBar.setString(n + "%"); // NOI18N
76
if (hasFocus) {
77         setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") ); // NOI18N
78
} else {
79         setBorder(null);
80     }
81         return this;
82     }
83 }
84
Popular Tags