KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.tasklist.core.PriorityListCellRenderer;
23 import java.awt.Component JavaDoc;
24 import java.awt.Image JavaDoc;
25 import javax.swing.*;
26 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
27 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
28 import org.openide.util.Utilities;
29
30 /**
31  * TableCellRenderer for priorities
32  *
33  * @author Petr Kuzel
34  */

35 public final class PriorityTableCellRenderer extends DefaultTableCellRenderer JavaDoc {
36     private static final Image JavaDoc LOW = Utilities.loadImage(
37         "org/netbeans/modules/tasklist/usertasks/renderers/low.gif"); // NOI18N
38
private static final Image JavaDoc MEDIUM_LOW = Utilities.loadImage(
39         "org/netbeans/modules/tasklist/usertasks/renderers/medium-low.gif"); // NOI18N
40
private static final Image JavaDoc HIGH = Utilities.loadImage(
41         "org/netbeans/modules/tasklist/usertasks/renderers/high.gif"); // NOI18N
42
private static final Image JavaDoc MEDIUM_HIGH = Utilities.loadImage(
43         "org/netbeans/modules/tasklist/usertasks/renderers/medium-high.gif"); // NOI18N
44
private static final Image JavaDoc MEDIUM = Utilities.loadImage(
45         "org/netbeans/modules/tasklist/usertasks/renderers/empty.gif"); // NOI18N
46

47     private static final long serialVersionUID = 1;
48
49     private ImageIcon icon = new ImageIcon();
50     
51     public Component JavaDoc getTableCellRendererComponent(JTable table, Object JavaDoc value,
52         boolean isSelected, boolean cellHasFocus, int row, int col) {
53         super.getTableCellRendererComponent(table, value, isSelected,
54             cellHasFocus, row, col);
55         if (value != null) {
56             int prio = ((Integer JavaDoc) value).intValue();
57             setText(UserTask.getPriorityNames()[prio - 1]);
58             if (!isSelected) {
59                 setForeground(PriorityListCellRenderer.COLORS[prio - 1]);
60             }
61             
62             Image JavaDoc im;
63             switch (prio) {
64                 case UserTask.HIGH:
65                     im = HIGH;
66                     break;
67                 case UserTask.LOW:
68                     im = LOW;
69                     break;
70                 case UserTask.MEDIUM_HIGH:
71                     im = MEDIUM_HIGH;
72                     break;
73                 case UserTask.MEDIUM_LOW:
74                     im = MEDIUM_LOW;
75                     break;
76                 default:
77                     im = MEDIUM;
78             }
79             icon.setImage(im);
80             setIcon(icon);
81         } else {
82             icon.setImage(MEDIUM);
83             setIcon(icon);
84         }
85         return this;
86     }
87
88     // overriden for performance reasons
89
@Override JavaDoc
90     protected void setValue(Object JavaDoc arg0) {
91     }
92 }
93
Popular Tags