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.DefaultListCellRenderer;
23 import javax.swing.Icon;
24 import javax.swing.JLabel;
25 import javax.swing.JList;
26 import javax.swing.JTree;
27 import javax.swing.ListCellRenderer;
28 import javax.swing.tree.DefaultTreeCellRenderer;
29 import javax.swing.tree.TreeCellRenderer;
30
31 import org.apache.xerces.xs.XSSimpleTypeDefinition;
32 import org.springframework.richclient.application.Application;
33 import org.springframework.richclient.image.IconSource;
34
35 import de.mindcrimeilab.xsanalyzer.xsext.AnonymousTypeFactory;
36
37
38
39
40
41
42
43 public class SimpleTypeCellRenderer implements TreeCellRenderer, ListCellRenderer {
44
45 private final static Icon icon = ((IconSource) Application.services().getService(IconSource.class)).getIcon("simpleType.icon");
46
47 private final TreeCellRenderer delegateTreeCellRenderer = new DefaultTreeCellRenderer();
48
49 private final ListCellRenderer delegateListCellRenderer = new DefaultListCellRenderer();
50
51
52
53
54
55
56
57 @Override
58 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
59
60 JLabel cell = (JLabel) delegateTreeCellRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
61
62 SimpleTypeCellRenderer.renderSimpleType(value, cell);
63 return cell;
64 }
65
66
67
68
69
70
71
72 @Override
73 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
74 JLabel cell = (JLabel) delegateListCellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
75 SimpleTypeCellRenderer.renderSimpleType(value, cell);
76 return cell;
77 }
78
79
80
81
82
83 private static void renderSimpleType(Object value, JLabel cell) {
84 if (value instanceof XSSimpleTypeDefinition) {
85 XSSimpleTypeDefinition xsSimple = ((XSSimpleTypeDefinition) value).getAnonymous() ? AnonymousTypeFactory.getProxy((XSSimpleTypeDefinition) value) : (XSSimpleTypeDefinition) value;
86 StringBuilder sb = new StringBuilder();
87 sb.append(xsSimple.getName());
88 sb.append(", <");
89 sb.append(xsSimple.getNamespace());
90 sb.append(">");
91 cell.setText(sb.toString());
92 cell.setIcon(SimpleTypeCellRenderer.icon);
93 }
94 }
95
96 }