01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.addressbook.gui.table.renderer;
19:
20: import java.awt.Component;
21:
22: import javax.swing.ImageIcon;
23: import javax.swing.JTable;
24: import javax.swing.SwingConstants;
25: import javax.swing.UIManager;
26: import javax.swing.table.DefaultTableCellRenderer;
27: import javax.swing.table.JTableHeader;
28:
29: import org.columba.addressbook.gui.table.model.SortDecorator;
30: import org.columba.core.gui.base.AscendingIcon;
31: import org.columba.core.gui.base.DescendingIcon;
32:
33: /**
34: * @author fdietz
35: */
36:
37: public class DefaultHeaderRenderer extends DefaultTableCellRenderer {
38:
39: private String name;
40:
41: private ImageIcon ascending = new AscendingIcon();
42:
43: private ImageIcon descending = new DescendingIcon();
44:
45: private SortDecorator sorter;
46:
47: public DefaultHeaderRenderer(SortDecorator sorter, String name) {
48: super ();
49:
50: this .name = name;
51: this .sorter = sorter;
52:
53: setHorizontalAlignment(SwingConstants.LEFT);
54: setHorizontalTextPosition(SwingConstants.LEFT);
55:
56: setOpaque(true); // MUST do this for background to show up.
57:
58: setBorder(UIManager.getBorder("TableHeader.cellBorder"));
59: }
60:
61: public Component getTableCellRendererComponent(JTable table,
62: Object str, boolean isSelected, boolean hasFocus, int row,
63: int column) {
64:
65: if (table != null) {
66: JTableHeader header = table.getTableHeader();
67:
68: if (header != null) {
69: setForeground(header.getForeground());
70: setBackground(header.getBackground());
71: setFont(header.getFont());
72: }
73: }
74:
75: if (sorter.getColumnName(sorter.getSelectedColumn()).equals(
76: (String) str)) {
77: if (sorter.isSortOrder()) {
78: setIcon(descending);
79: } else {
80: setIcon(ascending);
81: }
82: } else {
83: setIcon(null);
84: }
85:
86: setText(this.name);
87:
88: return this;
89: }
90: }
|