1 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 32 public class DateRenderer extends DefaultLabelRenderer { 33 static SimpleDateFormat dfWeek = new SimpleDateFormat ("EEE HH:mm", Locale 34 .getDefault()); 35 36 DateFormat dfCommon = DateFormat.getDateInstance(); 38 39 static final long OneDay = 24 * 60 * 60 * 1000; 40 41 static TimeZone localTimeZone = TimeZone.getDefault(); 42 43 private Font boldFont; 44 45 public DateRenderer() { 46 super(); 47 48 boldFont = UIManager.getFont("Tree.font"); 50 boldFont = boldFont.deriveFont(Font.BOLD); 51 52 } 53 54 public void updateUI() { 55 super.updateUI(); 56 57 boldFont = UIManager.getFont("Tree.font"); 58 boldFont = boldFont.deriveFont(Font.BOLD); 59 60 } 61 62 public static int getLocalDaysDiff(long t) { 63 return (int) (((System.currentTimeMillis() + localTimeZone 64 .getRawOffset()) - (((t + localTimeZone.getRawOffset()) / OneDay) * OneDay)) / OneDay); 65 } 66 67 public Component getTableCellRendererComponent(JTable table, Object value, 68 boolean isSelected, boolean hasFocus, int row, int column) { 69 70 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, 71 row, column); 72 73 if (value == null) { 74 setText(""); 75 76 return this; 77 } 78 79 Date date = (Date ) ((MessageNode) value).getHeader() 80 .get("columba.date"); 81 82 if (date == null) { 83 return this; 84 } 85 86 int diff = getLocalDaysDiff(date.getTime()); 87 88 if ((diff >= 0) && (diff < 7)) { 90 setText(dfWeek.format(date)); 91 } else { 92 setText(dfCommon.format(date)); 93 } 94 95 return this; 96 } 97 } 98 | Popular Tags |