KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.util.Date JavaDoc;
26 import javax.swing.JTable JavaDoc;
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 /**
35  * Renderer for the due date
36  *
37  * @author tl
38  */

39 public class DueDateTableCellRenderer extends DateTableCellRenderer {
40     private Font JavaDoc boldFont, normalFont;
41     
42     protected Duration getDuration(Object JavaDoc 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 JavaDoc getTableCellRendererComponent(
54         JTable JavaDoc table,
55         Object JavaDoc value, boolean isSelected, boolean hasFocus,
56         int row, int column) {
57         Object JavaDoc 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 JavaDoc 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