1 24 package org.riotfamily.riot.list.ui.render; 25 26 import java.io.PrintWriter ; 27 import java.text.DateFormat ; 28 import java.text.SimpleDateFormat ; 29 import java.util.Date ; 30 31 public class DateRenderer implements CellRenderer { 32 33 private static final String SHORT = "short"; 34 35 private static final String MEDIUM = "medium"; 36 37 private static final String LONG = "long"; 38 39 40 private int style = DateFormat.MEDIUM; 41 42 public void setStyle(String style) { 43 if (SHORT.equals(style)) { 44 this.style = DateFormat.SHORT; 45 } 46 else if (MEDIUM.equals(style)) { 47 this.style = DateFormat.MEDIUM; 48 } 49 else if (LONG.equals(style)) { 50 this.style = DateFormat.LONG; 51 } 52 else { 53 throw new IllegalArgumentException ("Invalid date style: " + style); 54 } 55 } 56 57 public void render(String propertyName, Object value, RenderContext context, 58 PrintWriter writer) { 59 60 Date date = (Date ) value; 61 if (date != null) { 62 DateFormat format = SimpleDateFormat.getDateInstance( 63 style, context.getMessageResolver().getLocale()); 64 65 writer.print(format.format(date)); 66 } 67 } 68 } 69 | Popular Tags |