KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Image JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import javax.swing.DefaultListCellRenderer JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
30 import org.openide.util.NbBundle;
31 import org.openide.util.Utilities;
32
33 /**
34  * ListCellRenderer for priorities
35  *
36  * @author tl
37  */

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

50
51     private static final long serialVersionUID = 1;
52
53     private static String JavaDoc[] TAGS;
54
55     /** Keys for the Bundle.properties */
56     private static final String JavaDoc[] PRIORITIES_KEYS = {
57         "PriorityHigh", // NOI18N
58
"PriorityMediumHigh", // NOI18N
59
"PriorityMedium", // NOI18N
60
"PriorityMediumLow", // NOI18N
61
"PriorityLow" // NOI18N
62
};
63
64     static {
65         TAGS = new String JavaDoc[PRIORITIES_KEYS.length];
66         ResourceBundle JavaDoc rb = NbBundle.getBundle(PriorityListCellRenderer.class);
67         for (int i = 0; i < PRIORITIES_KEYS.length; i++) {
68             TAGS[i] = rb.getString(PRIORITIES_KEYS[i]);
69         }
70     }
71
72     /**
73      * Default colors for diferent priorities
74      * [0] - high, [1] - medium-high, ...
75      */

76     public static final Color JavaDoc[] COLORS = {
77         new Color JavaDoc(221, 0, 0),
78         new Color JavaDoc(255, 128, 0),
79         Color.black,
80         new Color JavaDoc(0, 187, 0),
81         new Color JavaDoc(0, 128, 0)
82     };
83
84     private ImageIcon JavaDoc icon = new ImageIcon JavaDoc();
85     
86     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
87                                                   int index, boolean isSelected, boolean cellHasFocus) {
88         super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
89         if (value != null) {
90             int prio = ((Integer JavaDoc) value).intValue();
91             setText(UserTask.getPriorityNames()[prio - 1]);
92             if (!isSelected) {
93                 setForeground(PriorityListCellRenderer.COLORS[prio - 1]);
94             }
95             
96             Image JavaDoc im;
97             switch (prio) {
98                 case UserTask.HIGH:
99                     im = HIGH;
100                     break;
101                 case UserTask.LOW:
102                     im = LOW;
103                     break;
104                 case UserTask.MEDIUM_HIGH:
105                     im = MEDIUM_HIGH;
106                     break;
107                 case UserTask.MEDIUM_LOW:
108                     im = MEDIUM_LOW;
109                     break;
110                 default:
111                     im = MEDIUM;
112             }
113             icon.setImage(im);
114             setIcon(icon);
115         } else {
116             icon.setImage(MEDIUM);
117             setIcon(icon);
118         }
119         return this;
120     }
121 }
122
Popular Tags