01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.components;
20:
21: import java.awt.Component;
22: import java.awt.Font;
23:
24: import javax.swing.BorderFactory;
25: import javax.swing.JLabel;
26: import javax.swing.JList;
27: import javax.swing.JTable;
28: import javax.swing.ListCellRenderer;
29: import javax.swing.UIManager;
30: import javax.swing.border.Border;
31: import javax.swing.table.JTableHeader;
32:
33: /**
34: * Renderer for the row header for a given table
35: *
36: * @author Jeff Tassin
37: */
38: public class RowHeaderRenderer extends JLabel implements
39: ListCellRenderer {
40: private JTable m_table;
41: private Border m_selectedborder;
42: private Border m_normalborder;
43: private Font m_selectedfont;
44: private Font m_normalfont;
45:
46: RowHeaderRenderer(JTable table) {
47: this .m_table = table;
48: /** this needs to be updated if the LaF changes */
49: m_normalborder = UIManager.getBorder("TableHeader.cellBorder");
50: m_selectedborder = BorderFactory.createRaisedBevelBorder();
51: final JTableHeader header = m_table.getTableHeader();
52: m_normalfont = header.getFont();
53: m_selectedfont = m_normalfont.deriveFont(m_normalfont
54: .getStyle()
55: | Font.BOLD);
56: setForeground(header.getForeground());
57: setBackground(header.getBackground());
58: setOpaque(true);
59: setHorizontalAlignment(CENTER);
60: }
61:
62: public Component getListCellRendererComponent(JList list,
63: Object value, int index, boolean isSelected,
64: boolean cellHasFocus) {
65: if (list.getSelectionModel().isSelectedIndex(index)) {
66: setFont(m_selectedfont);
67: setBorder(m_selectedborder);
68: } else {
69: setFont(m_normalfont);
70: setBorder(m_normalborder);
71: }
72: String label = String.valueOf(index + 1);
73: setText(label);
74: return this;
75: }
76: }
|