KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > table > plugins > DefaultLabelRenderer


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.table.plugins;
17
18 import java.awt.Color JavaDoc;
19 import java.awt.Component JavaDoc;
20 import java.awt.Font JavaDoc;
21
22 import javax.swing.JTable JavaDoc;
23 import javax.swing.UIManager JavaDoc;
24 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
25
26 import org.columba.api.plugin.IExtensionInterface;
27 import org.columba.mail.gui.table.model.MessageNode;
28 import org.columba.mail.message.ColumbaHeader;
29 import org.columba.mail.message.IColumbaHeader;
30 import org.columba.ristretto.message.Flags;
31
32 /**
33  *
34  *
35  * The is basic class every renderer should inherite
36  *
37  * It is responsible for paint the background/foreground and borders and gives
38  * us a central place for optimization
39  *
40  * @author dietz
41  */

42
43 public class DefaultLabelRenderer extends DefaultTableCellRenderer JavaDoc implements
44         IExtensionInterface {
45     
46     private static final java.util.logging.Logger JavaDoc LOG =
47         java.util.logging.Logger.getLogger("org.columba.mail.gui.table.plugins"); //$NON-NLS-1$
48

49     // private Border unselectedBorder = null;
50
//
51
// private Border selectedBorder = null;
52
//
53
// private Color background;
54
//
55
// private Color foreground;
56

57     private Font JavaDoc plainFont;
58
59     private Font JavaDoc boldFont;
60
61     private Font JavaDoc underlinedFont;
62
63     // private boolean isBordered = true;
64

65     /**
66      * Constructor for DefaultLabelRenderer.
67      */

68     public DefaultLabelRenderer() {
69         super();
70
71         boldFont = UIManager.getFont("Tree.font");
72         boldFont = boldFont.deriveFont(Font.BOLD);
73
74         plainFont = UIManager.getFont("Tree.font");
75
76         underlinedFont = UIManager.getFont("Tree.font");
77         underlinedFont = underlinedFont.deriveFont(Font.ITALIC);
78
79     }
80
81     /**
82      * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
83      * java.lang.Object, boolean, boolean, int, int)
84      */

85     public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
86             boolean isSelected, boolean hasFocus, int row, int column) {
87
88         super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
89                 row, column);
90
91         setBorder(null);
92
93         // TreePath path = tree.getPathForRow(row);
94
MessageNode messageNode = (MessageNode) value;
95
96         IColumbaHeader header = messageNode.getHeader();
97
98         if (header == null) {
99             LOG.info("header is null"); //$NON-NLS-1$
100

101             return this;
102         }
103
104         Flags flags = ((ColumbaHeader) header).getFlags();
105
106         if (flags != null) {
107             // mark as bold if message is unseen
108
if (!flags.getSeen()) {
109                 if (!getFont().equals(boldFont)) {
110                     setFont(boldFont);
111                 }
112             } else if (messageNode.isHasRecentChildren()) {
113                 if (!getFont().equals(underlinedFont)) {
114                     setFont(underlinedFont);
115                 }
116             } else if (!getFont().equals(plainFont)) {
117                 setFont(plainFont);
118             }
119         }
120
121         Color JavaDoc msgColor = (Color JavaDoc) header.get("columba.color");
122
123         if (isSelected)
124             setBackground(UIManager.getColor("Table.selectionBackground"));
125         else
126             setBackground(table.getBackground());
127
128         if (msgColor != null) {
129             if (isSelected)
130                 setForeground(UIManager.getColor("Table.selectionForeground"));
131             else {
132                 if (msgColor.equals(Color.BLACK) == false)
133                     setForeground(msgColor);
134                 else
135                     setForeground(table.getForeground());
136
137             }
138         }
139
140         return this;
141     }
142
143 }
144
Popular Tags