KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > table > renderer > DefaultHeaderRenderer


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21
22 import javax.swing.ImageIcon JavaDoc;
23 import javax.swing.JTable JavaDoc;
24 import javax.swing.SwingConstants JavaDoc;
25 import javax.swing.UIManager JavaDoc;
26 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
27 import javax.swing.table.JTableHeader JavaDoc;
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 JavaDoc {
38
39     private String JavaDoc name;
40
41     private ImageIcon JavaDoc ascending = new AscendingIcon();
42
43     private ImageIcon JavaDoc descending = new DescendingIcon();
44
45     private SortDecorator sorter;
46
47     public DefaultHeaderRenderer(SortDecorator sorter, String JavaDoc 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 JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc str,
62             boolean isSelected, boolean hasFocus, int row, int column) {
63
64         if (table != null) {
65             JTableHeader JavaDoc header = table.getTableHeader();
66
67             if (header != null) {
68                 setForeground(header.getForeground());
69                 setBackground(header.getBackground());
70                 setFont(header.getFont());
71             }
72         }
73
74         if (sorter.getColumnName(sorter.getSelectedColumn()).equals(
75                 (String JavaDoc) str)) {
76             if (sorter.isSortOrder()) {
77                 setIcon(descending);
78             } else {
79                 setIcon(ascending);
80             }
81         } else {
82             setIcon(null);
83         }
84
85         setText(this.name);
86
87         return this;
88     }
89 }
Popular Tags