1 //
2 // $Id: SortHeaderRenderer.java 95 2007-05-02 03:27:05Z
3 // /C=DE/ST=Baden-Wuerttemberg/O=ISDN4Linux/OU=Fritz
4 // Elfert/CN=svn-felfert@isdn4linux.de/emailAddress=fritz@fritz-elfert.de $
5 //
6 // jupload - A file upload applet.
7 // Copyright 2007 The JUpload Team
8 //
9 // Created: ?
10 // Creator: William JinHua Kwong
11 // Last modified: $Date: 2015-03-10 20:59:42 +0100 (mar., 10 mars 2015) $
12 //
13 // This program is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free Software
15 // Foundation; either version 2 of the License, or (at your option) any later
16 // version. This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 // details. You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software Foundation, Inc.,
21 // 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 package wjhk.jupload2.gui.filepanel;
24
25 import java.awt.Component;
26
27 import javax.swing.Icon;
28 import javax.swing.JTable;
29 import javax.swing.UIManager;
30 import javax.swing.table.DefaultTableCellRenderer;
31 import javax.swing.table.JTableHeader;
32
33 /**
34 * Technical class, to display the column headers, for column that may be
35 * sorted.
36 */
37 public class SortHeaderRenderer extends DefaultTableCellRenderer {
38
39 /** A generated serialVersionUID, to avoid warning during compilation */
40 private static final long serialVersionUID = -4104776293873798189L;
41
42 private static final Icon NONSORTED = new SortArrowIcon(SortArrowIcon.NONE);
43
44 private static final Icon ASCENDING = new SortArrowIcon(
45 SortArrowIcon.ASCENDING);
46
47 private static final Icon DESCENDING = new SortArrowIcon(
48 SortArrowIcon.DESCENDING);
49
50 /**
51 * Creates a new instance.
52 */
53 public SortHeaderRenderer() {
54 setHorizontalTextPosition(LEFT);
55 setHorizontalAlignment(CENTER);
56 }
57
58 /**
59 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
60 * java.lang.Object, boolean, boolean, int, int)
61 */
62 @Override
63 public Component getTableCellRendererComponent(JTable table, Object value,
64 boolean isSelected, boolean hasFocus, int row, int col) {
65 int index = -1;
66 boolean ascending = true;
67 if (table instanceof FilePanelJFlatTable) {
68 FilePanelJFlatTable sortTable = (FilePanelJFlatTable) table;
69 index = sortTable.getSortedColumnIndex();
70 ascending = sortTable.isSortedColumnAscending();
71 }
72 if (table != null) {
73 JTableHeader header = table.getTableHeader();
74 if (header != null) {
75 setForeground(header.getForeground());
76 setBackground(header.getBackground());
77 setFont(header.getFont());
78 }
79 }
80 Icon icon = ascending ? ASCENDING : DESCENDING;
81 setIcon(col == index ? icon : NONSORTED);
82 setText((value == null) ? "" : value.toString());
83 setBorder(UIManager.getBorder("TableHeader.cellBorder"));
84 return this;
85 }
86 }