01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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.Component;
19:
20: import javax.swing.ImageIcon;
21: import javax.swing.JTable;
22: import javax.swing.SwingConstants;
23: import javax.swing.UIManager;
24: import javax.swing.table.DefaultTableCellRenderer;
25: import javax.swing.table.JTableHeader;
26:
27: import org.columba.core.gui.base.AscendingIcon;
28: import org.columba.core.gui.base.DescendingIcon;
29: import org.columba.mail.gui.table.model.TableModelSorter;
30:
31: public class BasicHeaderRenderer extends DefaultTableCellRenderer {
32: private TableModelSorter sorter;
33: private ImageIcon ascending = new AscendingIcon();
34: private ImageIcon descending = new DescendingIcon();
35: private String name;
36:
37: public BasicHeaderRenderer(String name, TableModelSorter sorter) {
38: super ();
39:
40: this .name = name;
41: this .sorter = sorter;
42:
43: setHorizontalAlignment(SwingConstants.LEFT);
44: setHorizontalTextPosition(SwingConstants.LEFT);
45: }
46:
47: public Component getTableCellRendererComponent(JTable table,
48: Object value, boolean isSelected, boolean hasFocus,
49: int row, int column) {
50: if (table != null) {
51: JTableHeader header = table.getTableHeader();
52:
53: if (header != null) {
54: setForeground(header.getForeground());
55: setBackground(header.getBackground());
56: setFont(header.getFont());
57: }
58: }
59:
60: setText((value == null) ? "" : value.toString());
61: setBorder(UIManager.getBorder("TableHeader.cellBorder"));
62:
63: if (sorter.getSortingColumn().equals(name)) {
64: if (sorter.getSortingOrder()) {
65: setIcon(descending);
66: } else {
67: setIcon(ascending);
68: }
69: } else {
70: setIcon(null);
71: }
72:
73: return this;
74: }
75: }
|