1 19 20 package org.netbeans.modules.tasklist.usertasks.renderers; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Image ; 25 import java.util.ResourceBundle ; 26 import javax.swing.DefaultListCellRenderer ; 27 import javax.swing.ImageIcon ; 28 import javax.swing.JList ; 29 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 30 import org.openide.util.NbBundle; 31 import org.openide.util.Utilities; 32 33 38 public class PriorityListCellRenderer extends DefaultListCellRenderer { 39 private static final Image LOW = Utilities.loadImage( 40 "org/netbeans/modules/tasklist/usertasks/renderers/low.gif"); private static final Image MEDIUM_LOW = Utilities.loadImage( 42 "org/netbeans/modules/tasklist/usertasks/renderers/medium-low.gif"); private static final Image HIGH = Utilities.loadImage( 44 "org/netbeans/modules/tasklist/usertasks/renderers/high.gif"); private static final Image MEDIUM_HIGH = Utilities.loadImage( 46 "org/netbeans/modules/tasklist/usertasks/renderers/medium-high.gif"); private static final Image MEDIUM = Utilities.loadImage( 48 "org/netbeans/modules/tasklist/usertasks/renderers/empty.gif"); 50 51 private static final long serialVersionUID = 1; 52 53 private static String [] TAGS; 54 55 56 private static final String [] PRIORITIES_KEYS = { 57 "PriorityHigh", "PriorityMediumHigh", "PriorityMedium", "PriorityMediumLow", "PriorityLow" }; 63 64 static { 65 TAGS = new String [PRIORITIES_KEYS.length]; 66 ResourceBundle 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 76 public static final Color [] COLORS = { 77 new Color (221, 0, 0), 78 new Color (255, 128, 0), 79 Color.black, 80 new Color (0, 187, 0), 81 new Color (0, 128, 0) 82 }; 83 84 private ImageIcon icon = new ImageIcon (); 85 86 public Component getListCellRendererComponent(JList list, Object value, 87 int index, boolean isSelected, boolean cellHasFocus) { 88 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 89 if (value != null) { 90 int prio = ((Integer ) value).intValue(); 91 setText(UserTask.getPriorityNames()[prio - 1]); 92 if (!isSelected) { 93 setForeground(PriorityListCellRenderer.COLORS[prio - 1]); 94 } 95 96 Image 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 |