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.XSComplexTypeDefinition;
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 ComplexTypeCellRenderer implements TreeCellRenderer, ListCellRenderer {
44
45 private final static Icon icon = ((IconSource) Application.services().getService(IconSource.class)).getIcon("complexType.icon");
46
47 private final TreeCellRenderer treeCellRendererDelegate = new DefaultTreeCellRenderer();
48
49 private final ListCellRenderer listCellRendererDelegate = 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) treeCellRendererDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
61
62 ComplexTypeCellRenderer.renderComplexType(value, cell);
63
64 return cell;
65 }
66
67 @Override
68 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
69
70 JLabel cell = (JLabel) listCellRendererDelegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
71
72 ComplexTypeCellRenderer.renderComplexType(value, cell);
73
74 return cell;
75 }
76
77
78
79
80
81 private static void renderComplexType(final Object value, JLabel cell) {
82 if (value instanceof XSComplexTypeDefinition) {
83 XSComplexTypeDefinition complexType = ((XSComplexTypeDefinition) value).getAnonymous() ? AnonymousTypeFactory.getProxy((XSComplexTypeDefinition) value) : (XSComplexTypeDefinition) value;
84 StringBuilder sb = new StringBuilder();
85 sb.append(complexType.getName());
86 sb.append(", <");
87 sb.append(complexType.getNamespace());
88 sb.append(">");
89 cell.setText(sb.toString());
90 cell.setIcon(ComplexTypeCellRenderer.icon);
91 }
92 }
93
94 }