1 package net.sf.jhylafax; 2 3 import java.text.DateFormat; 4 import java.util.Calendar; 5 import java.util.Date; 6 import javax.swing.SwingConstants; 7 import javax.swing.table.DefaultTableCellRenderer; 8 9 class TimeCellRenderer extends DefaultTableCellRenderer 10 { 11 12 private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); 13 private DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); 14 private DateFormat tooltipFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); 15 16 public TimeCellRenderer() { 17 setHorizontalAlignment(SwingConstants.RIGHT); 18 } 19 20 protected void setValue(Object value) 21 { 22 if (value == null) { 23 super.setValue(null); 24 } 25 else { 26 Date date = (Date)value; 27 28 Calendar cal = Calendar.getInstance(); 29 cal.set(Calendar.HOUR_OF_DAY, 0); 30 cal.set(Calendar.MINUTE, 0); 31 cal.set(Calendar.SECOND, 0); 32 Date today = cal.getTime(); 33 34 cal.setTimeInMillis(cal.getTimeInMillis() + 24 * 3600 * 1000); 35 Date tomorrow = cal.getTime(); 36 37 if (date.after(today) && date.before(tomorrow)) { 38 super.setValue(timeFormat.format(date)); 39 } 40 else { 41 super.setValue(dateFormat.format(date)); 42 } 43 setToolTipText(tooltipFormat.format(date)); 44 } 45 } 46 47 }