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.io.File;
24
25 import javax.swing.Icon;
26 import javax.swing.JTree;
27 import javax.swing.tree.DefaultTreeCellRenderer;
28
29 import org.xnap.gui.util.IconHelper;
30
31 /***
32 * Renders tree nodes of type {@link File} and {@link String}.
33 *
34 * Files are displayed as green folders, Strings as yellow folders.
35 */
36 public class FileCellRenderer extends DefaultTreeCellRenderer
37 {
38
39 public static final Icon[] folders = {
40 IconHelper.getMenuIcon("folder.png"),
41 IconHelper.getMenuIcon("folder_open.png"),
42 IconHelper.getMenuIcon("folder_yellow.png"),
43 IconHelper.getMenuIcon("folder_yellow_open.png")
44 };
45
46
47
48 public FileCellRenderer()
49 {
50 }
51
52
53
54 public Component getTreeCellRendererComponent(JTree tree, Object node,
55 boolean sel,
56 boolean expanded,
57 boolean leaf, int row,
58 boolean hasFocus)
59 {
60 super.getTreeCellRendererComponent(tree, node, sel, expanded, leaf,
61 row, hasFocus);
62
63 if (node instanceof File || (node instanceof SearchPathNode)) {
64 if (expanded) {
65 setIcon(folders[1]);
66 }
67 else {
68 setIcon(folders[0]);
69 }
70 }
71 else if (node instanceof String) {
72 if (expanded) {
73 setIcon(folders[3]);
74 }
75 else {
76 setIcon(folders[2]);
77 }
78 }
79 return this;
80 }
81 }