01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.mail.gui.table.plugins;
17:
18: import java.awt.Component;
19: import java.awt.Font;
20: import java.text.DateFormat;
21: import java.text.SimpleDateFormat;
22: import java.util.Date;
23: import java.util.Locale;
24: import java.util.TimeZone;
25:
26: import javax.swing.JTable;
27: import javax.swing.UIManager;
28:
29: import org.columba.mail.gui.table.model.MessageNode;
30:
31: public class DateRenderer extends DefaultLabelRenderer {
32: static SimpleDateFormat dfWeek = new SimpleDateFormat("EEE HH:mm",
33: Locale.getDefault());
34:
35: // use local date settings
36: DateFormat dfCommon = DateFormat.getDateInstance();
37:
38: static final long OneDay = 24 * 60 * 60 * 1000;
39:
40: static TimeZone localTimeZone = TimeZone.getDefault();
41:
42: private Font boldFont;
43:
44: public DateRenderer() {
45: super ();
46:
47: // setOpaque(true); //MUST do this for background to show up.
48: boldFont = UIManager.getFont("Tree.font");
49: boldFont = boldFont.deriveFont(Font.BOLD);
50:
51: }
52:
53: public void updateUI() {
54: super .updateUI();
55:
56: boldFont = UIManager.getFont("Tree.font");
57: boldFont = boldFont.deriveFont(Font.BOLD);
58:
59: }
60:
61: public static int getLocalDaysDiff(long t) {
62: return (int) (((System.currentTimeMillis() + localTimeZone
63: .getRawOffset()) - (((t + localTimeZone.getRawOffset()) / OneDay) * OneDay)) / OneDay);
64: }
65:
66: public Component getTableCellRendererComponent(JTable table,
67: Object value, boolean isSelected, boolean hasFocus,
68: int row, int column) {
69:
70: super .getTableCellRendererComponent(table, value, isSelected,
71: hasFocus, row, column);
72:
73: if (value == null) {
74: setText("");
75:
76: return this ;
77: }
78:
79: Date date = (Date) ((MessageNode) value).getHeader().get(
80: "columba.date");
81:
82: if (date == null) {
83: return this ;
84: }
85:
86: int diff = getLocalDaysDiff(date.getTime());
87:
88: // if ( today
89: if ((diff >= 0) && (diff < 7)) {
90: setText(dfWeek.format(date));
91: } else {
92: setText(dfCommon.format(date));
93: }
94:
95: return this;
96: }
97: }
|