001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.table.plugins;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Font;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.JLabel;
027: import javax.swing.JPanel;
028: import javax.swing.JTable;
029: import javax.swing.UIManager;
030: import javax.swing.border.Border;
031: import javax.swing.border.EmptyBorder;
032: import javax.swing.table.TableCellRenderer;
033:
034: import org.columba.api.plugin.IExtensionInterface;
035: import org.columba.mail.gui.message.viewer.HeaderSeparatorBorder;
036: import org.columba.mail.gui.table.model.MessageNode;
037: import org.columba.mail.message.ColumbaHeader;
038: import org.columba.mail.message.IColumbaHeader;
039: import org.columba.ristretto.message.Flags;
040:
041: /**
042: * MultiLine renderer uses a two-row JPanel to display as much information as
043: * possible in a very narrow JTable column.
044: * <p>
045: * Horrible experimental hack - you have been warned!
046: *
047: * @author fdietz
048: */
049: public class MultiLineRenderer extends JPanel implements
050: TableCellRenderer, IExtensionInterface {
051:
052: private static final java.util.logging.Logger LOG = java.util.logging.Logger
053: .getLogger("org.columba.mail.gui.table.plugins");
054:
055: private Font plainFont;
056:
057: private Font boldFont;
058:
059: private Font underlinedFont;
060:
061: protected static Border outterBorder = new EmptyBorder(2, 1, 2, 2);
062:
063: protected static Border lineBorder = new HeaderSeparatorBorder(
064: new Color(248, 248, 248));
065:
066: protected static Border noFocusBorder = BorderFactory
067: .createCompoundBorder(lineBorder, outterBorder);
068:
069: // We need a place to store the color the JLabel should be returned
070: // to after its foreground and background colors have been set
071: // to the selection background color.
072: // These ivars will be made protected when their names are finalized.
073: private Color unselectedForeground;
074:
075: private Color unselectedBackground;
076:
077: private JLabel subjectLabel;
078:
079: private AttachmentRenderer attachmentRenderer;
080:
081: private StatusRenderer statusRenderer;
082:
083: private FromRenderer fromRenderer;
084:
085: private DateRenderer dateRenderer;
086:
087: public MultiLineRenderer() {
088: boldFont = UIManager.getFont("Tree.font");
089: boldFont = boldFont.deriveFont(Font.BOLD);
090:
091: plainFont = UIManager.getFont("Tree.font");
092:
093: underlinedFont = UIManager.getFont("Tree.font");
094: underlinedFont = underlinedFont.deriveFont(Font.ITALIC);
095:
096: unselectedForeground = UIManager.getColor("Table.foreground");
097: unselectedBackground = UIManager.getColor("Table.background");
098:
099: setOpaque(true);
100: setBorder(noFocusBorder);
101:
102: setLayout(new BorderLayout());
103:
104: statusRenderer = new StatusRenderer();
105: fromRenderer = new FromRenderer();
106: dateRenderer = new DateRenderer();
107: attachmentRenderer = new AttachmentRenderer();
108:
109: subjectLabel = new JLabel();
110: subjectLabel.setForeground(Color.darkGray);
111:
112: JPanel p3 = new JPanel();
113: p3.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
114: p3.setOpaque(false);
115: p3.setLayout(new BorderLayout());
116: add(p3, BorderLayout.WEST);
117: p3.add(statusRenderer, BorderLayout.NORTH);
118:
119: JPanel p = new JPanel();
120: p.setOpaque(false);
121: p.setLayout(new BorderLayout());
122: add(p, BorderLayout.CENTER);
123:
124: JPanel p2 = new JPanel();
125: p2.setOpaque(false);
126: p2.setLayout(new BorderLayout());
127: // p2.setBorder(BorderFactory.createEmptyBorder(0,0,2,0));
128: p.add(p2, BorderLayout.NORTH);
129:
130: p2.add(fromRenderer, BorderLayout.CENTER);
131: p2.add(dateRenderer, BorderLayout.EAST);
132:
133: JPanel p4 = new JPanel();
134: p4.setOpaque(false);
135: p4.setLayout(new BorderLayout());
136: p.add(p4, BorderLayout.CENTER);
137:
138: p4.add(subjectLabel, BorderLayout.CENTER);
139: p4.add(attachmentRenderer, BorderLayout.EAST);
140:
141: }
142:
143: /**
144: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
145: * java.lang.Object, boolean, boolean, int, int)
146: */
147: public Component getTableCellRendererComponent(JTable table,
148: Object value, boolean isSelected, boolean hasFocus,
149: int row, int column) {
150:
151: if (isSelected) {
152: super .setForeground(table.getSelectionForeground());
153: super .setBackground(table.getSelectionBackground());
154: } else {
155: super
156: .setForeground((unselectedForeground != null) ? unselectedForeground
157: : table.getForeground());
158: super
159: .setBackground((unselectedBackground != null) ? unselectedBackground
160: : table.getBackground());
161: }
162:
163: setFont(table.getFont());
164:
165: if (hasFocus) {
166: // setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
167: if (table.isCellEditable(row, column)) {
168: super .setForeground(UIManager
169: .getColor("Table.focusCellForeground"));
170: super .setBackground(UIManager
171: .getColor("Table.focusCellBackground"));
172: }
173: } else {
174: // setBorder(noFocusBorder);
175: }
176:
177: setBorder(noFocusBorder);
178:
179: statusRenderer.getTableCellRendererComponent(table, value,
180: isSelected, hasFocus, row, column);
181: fromRenderer.getTableCellRendererComponent(table, value,
182: isSelected, hasFocus, row, column);
183: dateRenderer.getTableCellRendererComponent(table, value,
184: isSelected, hasFocus, row, column);
185: attachmentRenderer.getTableCellRendererComponent(table, value,
186: isSelected, hasFocus, row, column);
187:
188: // TreePath path = tree.getPathForRow(row);
189: MessageNode messageNode = (MessageNode) value;
190:
191: IColumbaHeader header = messageNode.getHeader();
192:
193: if (header == null) {
194: LOG.info("header is null"); //$NON-NLS-1$
195:
196: return this ;
197: }
198:
199: Flags flags = ((ColumbaHeader) header).getFlags();
200:
201: if (flags != null) {
202: // mark as bold if message is unseen
203: if (!flags.getSeen()) {
204: if (!getFont().equals(boldFont)) {
205: setFont(boldFont);
206: }
207: } else if (messageNode.isHasRecentChildren()) {
208: if (!getFont().equals(underlinedFont)) {
209: setFont(underlinedFont);
210: }
211: } else if (!getFont().equals(plainFont)) {
212: setFont(plainFont);
213: }
214: }
215:
216: Color msgColor = (Color) header.get("columba.color");
217:
218: if (isSelected)
219: setBackground(UIManager
220: .getColor("Table.selectionBackground"));
221: else
222: setBackground(table.getBackground());
223:
224: if (msgColor != null) {
225: if (isSelected)
226: setForeground(UIManager
227: .getColor("Table.selectionForeground"));
228: else {
229: if (msgColor.equals(Color.BLACK) == false)
230: setForeground(msgColor);
231: else
232: setForeground(table.getForeground());
233:
234: }
235: }
236:
237: String subject = (String) header.get("columba.subject");
238: if (isSelected)
239: subjectLabel.setForeground(UIManager
240: .getColor("Table.selectionForeground"));
241: else
242: subjectLabel.setForeground(Color.DARK_GRAY);
243:
244: subjectLabel.setText(subject);
245:
246: return this;
247: }
248:
249: }
|