1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
35
36
37 public class SortHeaderRenderer extends DefaultTableCellRenderer {
38
39
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
52
53 public SortHeaderRenderer() {
54 setHorizontalTextPosition(LEFT);
55 setHorizontalAlignment(CENTER);
56 }
57
58
59
60
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 }