1 19 20 26 27 package org.netbeans.modules.xml.schema.ui.basic.editors; 28 29 import java.awt.FontMetrics ; 30 import java.awt.Graphics ; 31 import java.awt.Rectangle ; 32 import java.beans.PropertyEditorSupport ; 33 import org.openide.util.NbBundle; 34 35 39 public class StringEditor extends PropertyEditorSupport { 40 41 public final static String EMPTY = ""; 42 43 44 public StringEditor() { 45 } 46 47 public String getAsText() { 48 Object value = super.getValue(); 49 return value==null?EMPTY:super.getAsText(); 50 } 51 52 53 public void setAsText(String s) { 54 if ( EMPTY.equals(s) && getValue() == null ) return; 56 setValue(s); 57 } 58 59 public boolean isPaintable() { 60 return true; 61 } 62 63 public void paintValue(Graphics g, Rectangle rectangle) { 64 String paintableString=getPaintableString(); 65 66 FontMetrics metrics=g.getFontMetrics(); 67 g.drawString(paintableString,rectangle.x, 68 rectangle.y+(rectangle.height-metrics.getHeight())/2+ 69 metrics.getAscent()); 70 } 71 72 protected String getPaintableString() { 73 String value=(String )getValue(); 74 return value==null?NbBundle.getMessage(StringEditor.class,"LBL_Null"):value; 75 } 76 } 77 | Popular Tags |