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.XSAttributeDeclaration;
32 import org.springframework.richclient.application.Application;
33 import org.springframework.richclient.image.IconSource;
34
35
36
37
38
39
40
41 public class AttributeRenderer implements TreeCellRenderer, ListCellRenderer {
42
43 private final static Icon icon = ((IconSource) Application.services().getService(IconSource.class)).getIcon("attribute.icon");
44
45 private final TreeCellRenderer treeCellRendererDelegate = new DefaultTreeCellRenderer();
46
47 private final ListCellRenderer listCellRendererDelegate = new DefaultListCellRenderer();
48
49
50
51
52
53
54
55 @Override
56 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
57
58 JLabel cell = (JLabel) treeCellRendererDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
59
60 AttributeRenderer.renderAttributeType(value, cell);
61
62 return cell;
63 }
64
65
66
67
68
69
70
71 @Override
72 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
73
74 JLabel cell = (JLabel) listCellRendererDelegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
75
76 AttributeRenderer.renderAttributeType(value, cell);
77
78 return cell;
79 }
80
81
82
83
84
85 private static void renderAttributeType(final Object value, JLabel cell) {
86 if (value instanceof XSAttributeDeclaration) {
87 XSAttributeDeclaration attribute = (XSAttributeDeclaration) value;
88 StringBuilder sb = new StringBuilder();
89 sb.append(attribute.getName());
90 sb.append(", <");
91 final String namespace = attribute.getNamespace();
92 sb.append((null == namespace) ? "default namespace" : namespace);
93 sb.append(">");
94 cell.setText(sb.toString());
95 cell.setIcon(AttributeRenderer.icon);
96 }
97 }
98
99 }