1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.plugin;
21
22 import java.awt.Component;
23 import java.awt.Font;
24
25 import javax.swing.Icon;
26 import javax.swing.JTree;
27 import javax.swing.UIManager;
28 import javax.swing.tree.DefaultMutableTreeNode;
29 import javax.swing.tree.DefaultTreeCellRenderer;
30
31 import org.xnap.gui.util.IconHelper;
32 import org.xnap.pkg.PackageSection;
33
34 /***
35 * This class provides a list renderer for {@link PluginInfo} objects.
36 * An icon is shown if an update is available.
37 */
38 public class PluginTreeCellRenderer extends DefaultTreeCellRenderer
39 {
40
41
42
43 public static final Icon ICON_ENABLED
44 = IconHelper.getIcon("ok.png", 16);
45 public static final Icon ICON_NOT_INSTALLED
46 = IconHelper.getIcon("noball.png", 16);
47 public static final Icon ICON_INSTALLED
48 = IconHelper.getIcon("tick.png", 16);
49 public static final Icon ICON_NEW
50 = IconHelper.getIcon("snew.png", 16);
51 public static final Icon ICON_UPDATE_AVAILABLE
52 = IconHelper.getIcon("supdated.png", 16, false);
53
54
55
56
57
58 public PluginTreeCellRenderer()
59 {
60 }
61
62
63
64 public Component getTreeCellRendererComponent(JTree tree, Object value,
65 boolean sel,
66 boolean expanded,
67 boolean leaf, int row,
68 boolean hasFocus)
69 {
70 super.getTreeCellRendererComponent
71 (tree, value, sel, expanded, leaf, row, hasFocus);
72
73 Font font = UIManager.getFont("Label.font");
74 if (value instanceof PluginNode) {
75
76 PluginNode node = (PluginNode)value;
77 setFont(font);
78 if (node.getPluginInfo() != null) {
79 setIcon(node.isUpdateAvailable()
80 ? ICON_UPDATE_AVAILABLE
81 : node.getPluginInfo().isEnabled()
82 ? ICON_ENABLED
83 : ICON_INSTALLED);
84 }
85 else {
86 setIcon(node.getPackageInfo().isNew()
87 ? ICON_NEW
88 : node.getPackageInfo().isInstalled()
89 ? ICON_INSTALLED
90 : ICON_NOT_INSTALLED);
91 }
92 if (node.isActionChanged()) {
93 font = getFont();
94 setFont((font != null) ? font.deriveFont(Font.ITALIC) : null);
95 }
96 setText(node.getPackageInfo().getName());
97 }
98 else if (value instanceof DefaultMutableTreeNode) {
99 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
100 if (node.getUserObject() instanceof PackageSection) {
101 PackageSection s = (PackageSection)node.getUserObject();
102
103 setFont((font != null) ? font.deriveFont(Font.BOLD) : null);
104 setText(s.getName());
105 setIcon(s.getIcon());
106 }
107 }
108
109 return this;
110 }
111
112 }