1 19 20 package org.netbeans.modules.tasklist.core.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 import javax.swing.JLabel ; 24 import org.netbeans.modules.tasklist.client.SuggestionPriority; 25 import org.netbeans.modules.tasklist.core.PriorityListCellRenderer; 26 27 32 public final class PriorityPropertyEditor extends PropertyEditorSupport { 33 private static final String [] TAGS = SuggestionPriority.getPriorityNames(); 34 private static final JLabel LABEL = new JLabel (); 35 36 39 public PriorityPropertyEditor() { 40 } 41 42 public String getAsText() { 43 Object v = getValue(); 44 if (v instanceof SuggestionPriority) { 45 int value = ((SuggestionPriority) v).intValue(); 46 return TAGS[value - 1]; 47 } else { 48 return ""; 49 } 50 } 51 52 public void setAsText(String text) throws java.lang.IllegalArgumentException { 53 int index = -1; 54 for (int i = 0; i < TAGS.length; i++) { 55 if (text.equals(TAGS[i])) { 56 index = i; 57 break; 58 } 59 } 60 if (index == -1) throw new IllegalArgumentException ("Unknown priority"); 61 62 setValue(SuggestionPriority.getPriority(index + 1)); 63 } 64 65 public boolean isPaintable() { 66 return true; 67 } 68 69 public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) { 70 Object v = getValue(); 71 if (v instanceof SuggestionPriority) { 72 gfx.translate(box.x, box.y); 73 int value = ((SuggestionPriority) v).intValue(); 74 LABEL.setForeground(PriorityListCellRenderer.COLORS[value - 1]); LABEL.setText(getAsText()); 76 LABEL.setSize(box.width, box.height); 77 LABEL.paint(gfx); 78 gfx.translate(-box.x, -box.y); 79 } 80 } 81 82 public String [] getTags() { 83 return TAGS; 84 } 85 } 86 | Popular Tags |