001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.table;
017:
018: import java.awt.Color;
019: import java.awt.Component;
020: import java.awt.Font;
021:
022: import javax.swing.JTable;
023: import javax.swing.JTree;
024: import javax.swing.UIManager;
025: import javax.swing.table.TableColumn;
026: import javax.swing.tree.DefaultTreeCellRenderer;
027:
028: import org.columba.mail.gui.table.model.MessageNode;
029: import org.columba.mail.message.ColumbaHeader;
030: import org.columba.mail.message.IColumbaHeader;
031: import org.columba.ristretto.message.Flags;
032:
033: /**
034: * Renderer for the JTree in the JTable, which is responsible for displaying the
035: * Subject: headerfield.
036: * <p>
037: * I'm still not convinced which method to calculate the bounds of the table
038: * column is faster. <br>
039: * The first one overwrites paint() and layout(), the other just overwrites
040: * setBounds() only, using the passed JTableColumn. Personally, I prefer the
041: * second version, because it should be much faster than calculating the column
042: * size, based on the text and font settings.
043: *
044: *
045: * @author fdietz
046: */
047: public class SubjectTreeRenderer extends DefaultTreeCellRenderer {
048: private Font plainFont;
049:
050: private Font boldFont;
051:
052: private Font underlinedFont;
053:
054: private JTable table;
055:
056: private TableColumn tc;
057:
058: /**
059: * @param table
060: */
061: public SubjectTreeRenderer(JTable table) {
062: super ();
063:
064: this .table = table;
065:
066: boldFont = UIManager.getFont("Label.font");
067: boldFont = boldFont.deriveFont(Font.BOLD);
068:
069: plainFont = UIManager.getFont("Label.font");
070:
071: underlinedFont = UIManager.getFont("Tree.font");
072: underlinedFont = underlinedFont.deriveFont(Font.ITALIC);
073:
074: setOpaque(true);
075:
076: setBackground(null);
077: setBackgroundNonSelectionColor(null);
078: }
079:
080: public void setBounds(int x, int y, int w, int h) {
081: if (tc == null) {
082: tc = table.getColumn("Subject");
083: }
084:
085: super .setBounds(x, y, tc.getWidth() - x, h);
086: }
087:
088: /**
089: *
090: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
091: * java.lang.Object, boolean, boolean, int, int)
092: */
093: public Component getTreeCellRendererComponent(JTree tree,
094: Object value, boolean selected, boolean expanded,
095: boolean leaf, int row, boolean hasFocus) {
096: super .getTreeCellRendererComponent(tree, value, selected,
097: expanded, leaf, row, hasFocus);
098:
099: MessageNode messageNode = (MessageNode) value;
100:
101: if (messageNode.getUserObject().equals("root")) {
102: setText("...");
103: setIcon(null);
104:
105: return this ;
106: }
107:
108: IColumbaHeader header = messageNode.getHeader();
109:
110: if (header == null) {
111: return this ;
112: }
113:
114: Flags flags = ((ColumbaHeader) header).getFlags();
115:
116: if (flags != null) {
117: if (!flags.getSeen()) {
118: if (!getFont().equals(boldFont)) {
119: setFont(boldFont);
120: }
121: } else if (messageNode.isHasRecentChildren()) {
122: if (!getFont().equals(underlinedFont)) {
123: setFont(underlinedFont);
124: }
125: } else {
126: if (!getFont().equals(plainFont)) {
127: setFont(plainFont);
128: }
129: }
130: }
131:
132: Color msgColor = (Color) header.get("columba.color");
133:
134: if (selected)
135: setBackground(UIManager
136: .getColor("Table.selectionBackground"));
137: else
138: setBackground(table.getBackground());
139:
140: if (msgColor != null) {
141: if (selected)
142: setForeground(UIManager
143: .getColor("Table.selectionForeground"));
144: else {
145: if (msgColor.equals(Color.BLACK) == false)
146: setForeground(msgColor);
147: else
148: setForeground(table.getForeground());
149:
150: }
151: }
152:
153: String subject = (String) header.get("columba.subject");
154:
155: if (subject != null) {
156: setText(subject);
157: } else {
158: setText("null");
159: }
160:
161: setIcon(null);
162:
163: return this;
164: }
165:
166: }
|