01: /*
02: * SortableHeaderRenderer.java
03: *
04: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package org.underworldlabs.swing.table;
23:
24: import java.awt.Color;
25: import java.awt.Component;
26: import javax.swing.JLabel;
27: import javax.swing.JTable;
28:
29: import javax.swing.table.TableCellRenderer;
30: import org.underworldlabs.Constants;
31:
32: // Header renderer for the table sorter model
33: /* ----------------------------------------------------------
34: * CVS NOTE: Changes to the CVS repository prior to the
35: * release of version 3.0.0beta1 has meant a
36: * resetting of CVS revision numbers.
37: * ----------------------------------------------------------
38: */
39:
40: /**
41: *
42: * @author Takis Diakoumis
43: * @version $Revision: 1.5 $
44: * @date $Date: 2006/07/15 16:36:53 $
45: */
46: public class SortableHeaderRenderer extends DefaultTableHeaderRenderer
47: implements TableCellRenderer {
48:
49: /** the up arrow icon */
50: private ArrowIcon upIcon;
51:
52: /** the down arrow icon */
53: private ArrowIcon downIcon;
54:
55: /** the table sorter for this header */
56: private TableSorter sorter;
57:
58: /** the light gradient colour 1 */
59: private Color colour1;
60:
61: /** the dark gradient colour 2 */
62: private Color colour2;
63:
64: public SortableHeaderRenderer(TableSorter sorter) {
65: super (DEFAULT_HEIGHT);
66:
67: this .sorter = sorter;
68:
69: // init the icons
70: upIcon = new ArrowIcon(ArrowIcon.UP);
71: downIcon = new ArrowIcon(ArrowIcon.DOWN);
72:
73: // set the sort icon to the right of the text
74: setHorizontalTextPosition(JLabel.LEFT);
75: }
76:
77: public Component getTableCellRendererComponent(JTable table,
78: Object value, boolean isSelected, boolean hasFocus,
79: int row, int column) {
80: int modelColumn = table.convertColumnIndexToModel(column);
81: int iconType = sorter.getHeaderRendererIcon(modelColumn);
82: if (iconType == -1) {
83: setIcon(null);
84: } else {
85: setIcon(iconType == ArrowIcon.UP ? upIcon : downIcon);
86: }
87:
88: return super.getTableCellRendererComponent(table, value,
89: isSelected, hasFocus, row, column);
90: }
91:
92: }
|