1 17 18 package org.objectweb.jac.aspects.gui; 19 20 import java.text.DecimalFormat ; 21 import java.text.ParsePosition ; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.core.rtti.FieldItem; 24 import org.objectweb.jac.core.rtti.MetaItem; 25 import org.objectweb.jac.core.rtti.RttiAC; 26 import org.objectweb.jac.util.Strings; 27 28 public class IntFormat implements Format { 29 static Logger logger = Logger.getLogger("gui"); 30 31 protected DecimalFormat format; 32 protected FieldItem field; 33 34 public IntFormat(FieldItem field) { 35 this.field = field; 36 37 MetaItem type = RttiAC.getFieldType(field); 38 String formatString = null; 39 if (type!=null) 40 formatString = GuiAC.getIntFormat(type); 41 else 42 formatString = GuiAC.getIntFormat(field); 43 44 if (formatString!=null) 45 format = new DecimalFormat (formatString); 46 else 47 logger.error("No format for "+field); 48 } 49 50 public String format(Object value) { 51 return format((Number )value); 52 } 53 54 public String format(Number value) { 55 if (value!=null) 56 return format(value.longValue()); 57 else 58 return ""; 59 } 60 61 public String format(long value) { 62 if (format!=null) 63 return format.format(value); 64 else 65 return ""+value; 66 } 67 68 public Object parse(String str, ParsePosition pos) { 69 return parseNumber(str,pos); 70 } 71 72 public Number parseNumber(String str, ParsePosition pos) { 73 String string = str.trim(); 74 75 if (Strings.isEmpty(string)) 76 return null; 77 78 return format.parse(str,pos); 79 } 80 } 81 82 | Popular Tags |