KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > renderers > DateTableCellRenderer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.renderers;
21
22 import java.text.SimpleDateFormat JavaDoc;
23 import java.util.Date JavaDoc;
24 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
25
26 /**
27  * A table cell renderer for the Date class.
28  *
29  * @author tl
30  */

31 public class DateTableCellRenderer extends DefaultTableCellRenderer JavaDoc {
32     private static SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc();
33
34     // TODO: not used
35
public void setAsText(String JavaDoc s) throws java.lang.IllegalArgumentException JavaDoc {
36         if (s.trim().length() == 0) {
37             setValue(null);
38             return;
39         }
40         /*try {
41             // TODO: setValue(format.parse(s));
42         } catch (ParseException e) {
43             String msg = NbBundle.getMessage(DateTableCellRenderer.class,
44                 "IllegalDateValue", new Object[] {s}); //NOI18N
45             RuntimeException iae = new IllegalArgumentException(msg);
46             ErrorManager.getDefault().annotate(iae, ErrorManager.USER, msg,
47                 msg, e, new java.util.Date());
48             throw iae;
49         }*/

50     }
51
52     @Override JavaDoc
53     protected void setValue(Object JavaDoc value) {
54         if (value instanceof Date JavaDoc) {
55             setText(format.format((Date JavaDoc) value));
56         } else if (value instanceof Long JavaDoc) {
57             long v = ((Long JavaDoc) value).longValue();
58             if (v == 0)
59                 setText(""); // NOI18N
60
else
61                 setText(format.format(new Date JavaDoc(v)));
62         } else {
63             setText(""); // NOI18N
64
}
65     }
66 }
67
Popular Tags