KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.netbeans.modules.tasklist.usertasks.renderers;
2
3 import java.awt.Color JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Font JavaDoc;
6 import org.netbeans.modules.tasklist.usertasks.options.Settings;
7 import org.netbeans.modules.tasklist.usertasks.model.Duration;
8 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
9
10 /**
11  * Renderer for the effort
12  */

13 public class EffortTableCellRenderer extends DurationTableCellRenderer {
14     private Font JavaDoc boldFont, normalFont;
15     
16     /**
17      * Constructor
18      */

19     public EffortTableCellRenderer() {
20     }
21
22     public Component JavaDoc getTableCellRendererComponent(javax.swing.JTable JavaDoc table,
23         Object JavaDoc value, boolean isSelected, boolean hasFocus,
24         int row, int column) {
25         if (normalFont == null || !normalFont.equals(table.getFont())) {
26             normalFont = table.getFont();
27             boldFont = normalFont.deriveFont(Font.BOLD);
28         }
29         setForeground(null);
30         super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
31             row, column);
32         UserTask ut = (UserTask) value;
33         if (ut != null) {
34             boolean b = ut.getEffort() >= ut.getSpentTime() +
35                     ut.getRemainingEffort();
36             setFont(b ? normalFont : boldFont);
37             if (!isSelected && !b)
38                 setForeground(Color.RED);
39         }
40         return this;
41     }
42
43     protected Duration getDuration(Object JavaDoc obj) {
44         UserTask ut = (UserTask) obj;
45         if (ut == null) {
46             return null;
47         } else {
48             return new Duration(ut.getEffort(),
49                 Settings.getDefault().getMinutesPerDay(),
50                 Settings.getDefault().getDaysPerWeek(), true);
51         }
52     }
53 }
54
Popular Tags