1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 import java.text.DateFormat ; 24 import java.text.ParseException ; 25 import java.util.Date ; 26 27 32 public class DateEditor extends PropertyEditorSupport { 33 34 private static DateFormat fmt = DateFormat.getDateTimeInstance(); 35 36 public String getAsText() { 37 Date d = (Date )getValue(); 38 if (d != null) { 39 return fmt.format(d); 40 } else { 41 return ""; } 43 } 44 45 public void setAsText(String text) throws IllegalArgumentException { 46 if ("".equals(text)) { setValue(null); 48 } else { 49 try { 50 setValue(fmt.parse(text)); 51 } catch (ParseException e) { 52 throw (IllegalArgumentException )new IllegalArgumentException (e.toString()).initCause(e); 53 } 54 } 55 } 56 57 public String getJavaInitializationString () { 59 return "new java.util.Date(" + ((Date ) getValue()).getTime() + "L)"; } 61 62 } 63 | Popular Tags |