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.plugins;
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.UIManager;
024: import javax.swing.table.DefaultTableCellRenderer;
025:
026: import org.columba.api.plugin.IExtensionInterface;
027: import org.columba.mail.gui.table.model.MessageNode;
028: import org.columba.mail.message.ColumbaHeader;
029: import org.columba.mail.message.IColumbaHeader;
030: import org.columba.ristretto.message.Flags;
031:
032: /**
033: *
034: *
035: * The is basic class every renderer should inherite
036: *
037: * It is responsible for paint the background/foreground and borders and gives
038: * us a central place for optimization
039: *
040: * @author dietz
041: */
042:
043: public class DefaultLabelRenderer extends DefaultTableCellRenderer
044: implements IExtensionInterface {
045:
046: private static final java.util.logging.Logger LOG = java.util.logging.Logger
047: .getLogger("org.columba.mail.gui.table.plugins"); //$NON-NLS-1$
048:
049: // private Border unselectedBorder = null;
050: //
051: // private Border selectedBorder = null;
052: //
053: // private Color background;
054: //
055: // private Color foreground;
056:
057: private Font plainFont;
058:
059: private Font boldFont;
060:
061: private Font underlinedFont;
062:
063: // private boolean isBordered = true;
064:
065: /**
066: * Constructor for DefaultLabelRenderer.
067: */
068: public DefaultLabelRenderer() {
069: super ();
070:
071: boldFont = UIManager.getFont("Tree.font");
072: boldFont = boldFont.deriveFont(Font.BOLD);
073:
074: plainFont = UIManager.getFont("Tree.font");
075:
076: underlinedFont = UIManager.getFont("Tree.font");
077: underlinedFont = underlinedFont.deriveFont(Font.ITALIC);
078:
079: }
080:
081: /**
082: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
083: * java.lang.Object, boolean, boolean, int, int)
084: */
085: public Component getTableCellRendererComponent(JTable table,
086: Object value, boolean isSelected, boolean hasFocus,
087: int row, int column) {
088:
089: super .getTableCellRendererComponent(table, value, isSelected,
090: hasFocus, row, column);
091:
092: setBorder(null);
093:
094: // TreePath path = tree.getPathForRow(row);
095: MessageNode messageNode = (MessageNode) value;
096:
097: IColumbaHeader header = messageNode.getHeader();
098:
099: if (header == null) {
100: LOG.info("header is null"); //$NON-NLS-1$
101:
102: return this ;
103: }
104:
105: Flags flags = ((ColumbaHeader) header).getFlags();
106:
107: if (flags != null) {
108: // mark as bold if message is unseen
109: if (!flags.getSeen()) {
110: if (!getFont().equals(boldFont)) {
111: setFont(boldFont);
112: }
113: } else if (messageNode.isHasRecentChildren()) {
114: if (!getFont().equals(underlinedFont)) {
115: setFont(underlinedFont);
116: }
117: } else if (!getFont().equals(plainFont)) {
118: setFont(plainFont);
119: }
120: }
121:
122: Color msgColor = (Color) header.get("columba.color");
123:
124: if (isSelected)
125: setBackground(UIManager
126: .getColor("Table.selectionBackground"));
127: else
128: setBackground(table.getBackground());
129:
130: if (msgColor != null) {
131: if (isSelected)
132: setForeground(UIManager
133: .getColor("Table.selectionForeground"));
134: else {
135: if (msgColor.equals(Color.BLACK) == false)
136: setForeground(msgColor);
137: else
138: setForeground(table.getForeground());
139:
140: }
141: }
142:
143: return this;
144: }
145:
146: }
|