1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.tree;
21
22 import java.awt.Component;
23 import java.awt.Font;
24 import java.awt.event.MouseEvent;
25 import javax.swing.Icon;
26 import javax.swing.JTree;
27 import javax.swing.UIManager;
28 import javax.swing.tree.DefaultTreeCellRenderer;
29 import org.xnap.gui.table.TransferWrapper;
30 import org.xnap.gui.table.TreeTableModel;
31 import org.xnap.transfer.Transfer;
32
33 public class TransferTreeCellRenderer extends DefaultTreeCellRenderer
34 {
35
36 private Font plainFont;
37 private Font boldFont;
38 private TreeTableModel ttm;
39 private Transfer transfer;
40 private boolean highlightRunning;
41
42 public TransferTreeCellRenderer(TreeTableModel ttm,
43 boolean highlightRunning)
44 {
45 this.ttm = ttm;
46 this.highlightRunning = highlightRunning;
47
48 plainFont = UIManager.getFont("Label.font");
49 if (plainFont != null) {
50 boldFont = plainFont.deriveFont(Font.BOLD);
51 }
52 }
53
54 public Component getTreeCellRendererComponent(JTree tree, Object value,
55 boolean sel,
56 boolean expanded,
57 boolean leaf, int row,
58 boolean hasFocus)
59 {
60 super.getTreeCellRendererComponent
61 (tree, value, sel, expanded, leaf, row, hasFocus);
62
63 setIcon((Icon)ttm.getValueAt(value, 0));
64
65 TransferWrapper container = (TransferWrapper)ttm.getValueAt(value, 1);
66 if (container == null) {
67 transfer = null;
68 return this;
69 }
70
71 transfer = container.transfer;
72 setText(transfer.getFilename());
73
74 if (highlightRunning && transfer.isRunning()) {
75 setFont(boldFont);
76 }
77 else {
78 setFont(plainFont);
79 }
80
81 return this;
82 }
83
84 /***
85 * @see javax.swing.JComponent#getToolTipText()
86 */
87 public String getToolTipText(MouseEvent event)
88 {
89 if (transfer == null) {
90 return null;
91 }
92 String description = transfer.getDescription();
93 return (description != null) ? description : transfer.getFilename();
94 }
95
96 }