KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > table > renderer > DateCellRenderer


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.components.table.renderer;
6
7 import com.opensymphony.webwork.components.table.WebTable;
8
9 import java.text.SimpleDateFormat JavaDoc;
10
11
12 /**
13  * @author $author$
14  * @version $Revision: 1.1 $
15  */

16 public class DateCellRenderer extends AbstractCellRenderer {
17     //~ Instance fields ////////////////////////////////////////////////////////
18

19     SimpleDateFormat JavaDoc _formater = new SimpleDateFormat JavaDoc();
20
21     /**
22      * this is the string that SimpleDateFormat needs to display the date
23      *
24      * @see SimpleDateFormat
25      */

26     String JavaDoc _formatString = null;
27
28     //~ Constructors ///////////////////////////////////////////////////////////
29

30     public DateCellRenderer() {
31         super();
32     }
33
34     //~ Methods ////////////////////////////////////////////////////////////////
35

36     public String JavaDoc getCellValue(WebTable table, Object JavaDoc data, int row, int col) {
37         java.util.Date JavaDoc cellValue = null;
38
39         if (data == null) {
40             return "";
41         }
42
43         if (data instanceof java.util.Date JavaDoc) {
44             return _formater.format((java.util.Date JavaDoc) data);
45         }
46
47         return data.toString();
48     }
49
50     public void setFormatString(String JavaDoc format) {
51         _formatString = format;
52         _formater.applyPattern(_formatString);
53     }
54 }
55
Popular Tags