1 19 20 package org.netbeans.modules.tasklist.core.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 import javax.swing.JLabel ; 24 import javax.swing.SwingConstants ; 25 import org.openide.ErrorManager; 26 import org.openide.text.Line; 27 import org.openide.util.NbBundle; 28 29 32 public final class LineNumberPropertyEditor extends PropertyEditorSupport { 33 private static final JLabel LABEL = new JLabel (); 34 35 static { 36 LABEL.setHorizontalAlignment(SwingConstants.RIGHT); 37 } 38 39 public boolean isPaintable() { 40 return true; 41 } 42 43 public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) { 44 if (box.width <= 3) 45 return; 46 47 gfx.translate(box.x, box.y); 48 LABEL.setText(getAsText()); 49 LABEL.setSize(box.width - 3, box.height); 50 LABEL.setForeground(gfx.getColor()); 51 LABEL.paint(gfx); 52 gfx.translate(-box.x, -box.y); 53 } 54 55 public void setAsText(String text) throws java.lang.IllegalArgumentException { 56 try { 57 if (text.trim().length() == 0) 58 setValue(new Integer (0)); 59 else 60 setValue(new Integer (Integer.parseInt(text))); 61 } catch (NumberFormatException nfe) { 62 String msg = NbBundle.getMessage(LineNumberPropertyEditor.class, 63 "IllegalLineNumber", new Object [] {text}); RuntimeException iae = new IllegalArgumentException (msg); ErrorManager.getDefault().annotate(iae, ErrorManager.USER, msg, 66 msg, nfe, new java.util.Date ()); 67 throw iae; 68 } 69 } 70 71 public String getAsText() { 72 Object v = getValue(); 73 String s; 74 if (v instanceof Line) { 75 s = String.valueOf(((Line) v).getLineNumber() + 1); 76 } else if (v instanceof Integer ) { 77 int n = ((Integer ) v).intValue(); 78 if (n <= 0) 79 s = ""; 80 else 81 s = String.valueOf(n); 82 } else { 83 s = ""; 84 } 85 return s; 86 } 87 } 88 | Popular Tags |