1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.ui.renderer;
19
20 import java.awt.Component;
21
22 import javax.swing.Icon;
23 import javax.swing.JLabel;
24 import javax.swing.JTree;
25 import javax.swing.tree.DefaultTreeCellRenderer;
26 import javax.swing.tree.TreeCellRenderer;
27
28 import org.apache.xerces.xs.XSElementDeclaration;
29 import org.springframework.richclient.application.Application;
30 import org.springframework.richclient.image.IconSource;
31
32
33
34
35
36
37
38 public class ElementRenderer implements TreeCellRenderer {
39
40 private final static Icon icon = ((IconSource) Application.services().getService(IconSource.class)).getIcon("element.icon");
41
42 private final TreeCellRenderer delegateTreeCellRenderer = new DefaultTreeCellRenderer();
43
44
45
46
47
48
49
50 @Override
51 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
52
53 JLabel cell = (JLabel) delegateTreeCellRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
54
55 if (value instanceof XSElementDeclaration) {
56 XSElementDeclaration xselem = (XSElementDeclaration) value;
57 StringBuilder sb = new StringBuilder();
58 sb.append(xselem.getName());
59 sb.append(":");
60 sb.append(xselem.getTypeDefinition().getName());
61 sb.append(", <");
62 sb.append(xselem.getNamespace());
63 sb.append(">");
64 cell.setText(sb.toString());
65 cell.setIcon(ElementRenderer.icon);
66 }
67
68 return cell;
69 }
70
71 }