1 19 20 package org.netbeans.modules.tasklist.usertasks.renderers; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Font ; 25 import java.util.Date ; 26 import javax.swing.JTable ; 27 import org.netbeans.modules.tasklist.usertasks.options.Settings; 28 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode; 29 import org.netbeans.modules.tasklist.usertasks.model.Duration; 30 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 31 32 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTable; 33 34 39 public class DueDateTableCellRenderer extends DateTableCellRenderer { 40 private Font boldFont, normalFont; 41 42 protected Duration getDuration(Object obj) { 43 UserTask ut = (UserTask) obj; 44 if (ut == null) { 45 return null; 46 } else { 47 return new Duration(ut.getEffort(), 48 Settings.getDefault().getMinutesPerDay(), 49 Settings.getDefault().getDaysPerWeek(), true); 50 } 51 } 52 53 public Component getTableCellRendererComponent( 54 JTable table, 55 Object value, boolean isSelected, boolean hasFocus, 56 int row, int column) { 57 Object node = ((TreeTable) table).getNodeForRow(row); 58 if (normalFont == null || !normalFont.equals(table.getFont())) { 59 normalFont = table.getFont(); 60 boldFont = normalFont.deriveFont(Font.BOLD); 61 } 62 setForeground(null); 63 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, 64 row, column); 65 UserTaskTreeTableNode n = (UserTaskTreeTableNode) node; 66 UserTask ut = (UserTask) n.getUserTask(); 67 Date due = ut.getDueDate(); 68 boolean overdue = false; 69 if (!ut.isDone()) { 70 if (due != null && 71 due.getTime() < System.currentTimeMillis()) 72 overdue = true; 73 } else { 74 if (due != null && 75 due.getTime() < ut.getCompletedDate()) 76 overdue = true; 77 } 78 setFont(overdue ? boldFont : normalFont); 79 if (!isSelected && overdue) 80 setForeground(Color.RED); 81 82 return this; 83 } 84 } 85 | Popular Tags |