1 7 package org.ejtools.adwt.editor; 8 9 import java.text.DateFormat ; 10 import java.text.ParseException ; 11 import java.text.SimpleDateFormat ; 12 import java.util.Date ; 13 14 21 public class DateTimeEditor extends GenericEditor 22 { 23 24 protected DateFormat fmts[]; 25 26 27 28 public DateTimeEditor() 29 { 30 fmts = new DateFormat [5]; 31 fmts[0] = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss z"); 32 fmts[1] = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 33 fmts[2] = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); 34 fmts[3] = new SimpleDateFormat ("yyMMdd HH:mm:ss"); 35 fmts[4] = new SimpleDateFormat ("yyMMdd HH:mm"); 36 } 37 38 39 44 public String getAsText() 45 { 46 if (this.value != null) 47 { 48 return this.fmts[0].format((Date ) this.value); 49 } 50 else 51 { 52 return ""; 53 } 54 } 55 56 57 62 public void setAsText(String s) 63 { 64 if (s.equals("")) 65 { 66 this.value = null; 67 return; 68 } 69 for (int i = 0; i < fmts.length; i++) 70 { 71 try 72 { 73 this.value = fmts[i].parse(s); 74 this.firePropertyChange(); 75 return; 76 } 77 catch (ParseException pe) 78 { 79 } 81 } 82 } 83 } 84 85 | Popular Tags |