KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > FilterFolderCellRenderer


1 package net.suberic.pooka.gui;
2 import net.suberic.pooka.*;
3 import net.suberic.pooka.cache.*;
4 import net.suberic.pooka.gui.filter.DisplayFilter;
5 import javax.swing.table.*;
6 import java.awt.*;
7 import javax.swing.*;
8 import java.util.Date JavaDoc;
9 import java.util.Calendar JavaDoc;
10
11 /**
12  * This class overrides the default TableCellRenderer in order to
13  * show things like unread messages, etc.
14  */

15
16 public class FilterFolderCellRenderer extends DefaultTableCellRenderer {
17
18     public Component getTableCellRendererComponent(JTable table, Object JavaDoc value, boolean isSelected, boolean hasFocus, int row, int column) {
19     
20     Component returnValue = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
21     if (isSelected) {
22         setForeground(table.getSelectionForeground());
23         setBackground(table.getSelectionBackground());
24     }
25     else {
26         setForeground(table.getForeground());
27         setBackground(table.getBackground());
28     }
29     
30     if (value instanceof TableCellIcon) {
31         TableCellIcon tcIcon = (TableCellIcon)value;
32         Component icon = tcIcon.getIcon();
33         if (icon != null) {
34         icon.setBackground(returnValue.getBackground());
35         }
36         return icon;
37     } else if (value instanceof RowCounter) {
38         if (returnValue instanceof JLabel)
39         ((JLabel)returnValue).setText(Integer.toString(row + 1));
40         else {
41         JLabel label = new JLabel(Integer.toString(row + 1));
42         label.setBackground(returnValue.getBackground());
43         label.setForeground(returnValue.getForeground());
44         label.setFont(returnValue.getFont());
45         returnValue = label;
46         }
47     } else if (value instanceof Date JavaDoc) {
48         Date JavaDoc displayDate = (Date JavaDoc)value;
49         String JavaDoc dateText = null;
50         Calendar JavaDoc current = Calendar.getInstance();
51         current.set(Calendar.HOUR_OF_DAY, 0);
52         current.set(Calendar.MINUTE, 0);
53         if (current.getTime().before(displayDate)) {
54         dateText = Pooka.getDateFormatter().todayFormat.format(displayDate);
55         } else {
56         current.add(Calendar.DAY_OF_YEAR, (current.getMaximum(Calendar.DAY_OF_WEEK) - 1) * -1);
57         if (current.getTime().before(displayDate)) {
58             dateText = Pooka.getDateFormatter().thisWeekFormat.format(displayDate);
59         } else {
60             dateText = Pooka.getDateFormatter().shortFormat.format(displayDate);
61         }
62         }
63
64         if (returnValue instanceof JLabel)
65         ((JLabel)returnValue).setText(dateText);
66         else {
67         JLabel label = new JLabel(dateText);
68         label.setBackground(returnValue.getBackground());
69         label.setForeground(returnValue.getForeground());
70         label.setFont(returnValue.getFont());
71         returnValue = label;
72         }
73     }
74
75
76     FolderTableModel ftm = null;
77
78     if (table.getModel() instanceof FolderTableModel) {
79         ftm = (FolderTableModel) table.getModel();
80         MessageProxy msg = ftm.getMessageProxy(row);
81
82         if ( msg != null) {
83         MessageFilter[] matchingFilters = msg.getMatchingFilters();
84         for (int i = 0; i < matchingFilters.length; i++)
85             ((DisplayFilter)matchingFilters[i].getAction()).apply(returnValue);
86         }
87     }
88     return returnValue;
89     }
90 } //end class DefaultFolderCellRenderer
91
Popular Tags