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.JLabel;
23 import javax.swing.JTable;
24 import javax.swing.table.DefaultTableCellRenderer;
25 import javax.swing.table.TableCellRenderer;
26
27 import org.apache.xerces.xs.StringList;
28 import org.apache.xerces.xs.XSComplexTypeDefinition;
29 import org.apache.xerces.xs.XSConstants;
30 import org.apache.xerces.xs.XSTypeDefinition;
31
32 import com.l2fprod.common.propertysheet.PropertyRendererFactory;
33 import com.l2fprod.common.propertysheet.PropertyRendererRegistry;
34 import com.l2fprod.common.propertysheet.PropertySheetTableModel;
35 import com.l2fprod.common.propertysheet.PropertySheetTableModel.Item;
36
37
38
39
40
41
42
43
44
45 public class XSRenderFactory extends PropertyRendererRegistry implements PropertyRendererFactory {
46
47
48
49
50 public XSRenderFactory() {
51 super();
52 this.registerRenderer(XSTypeDefinition.class, getXSTypeDefinitionRenderer());
53 this.registerRenderer(short.class, getXSShortRenderer());
54 this.registerRenderer(StringList.class, getXSStringListRenderer());
55 }
56
57
58
59
60
61
62 private XSTypeDefinitionRenderer getXSTypeDefinitionRenderer() {
63 return new XSTypeDefinitionRenderer();
64 }
65
66
67
68
69
70
71 private XSShortRenderer getXSShortRenderer() {
72 return new XSShortRenderer();
73 }
74
75
76
77
78
79
80 private XSStringListRenderer getXSStringListRenderer() {
81 return new XSStringListRenderer();
82 }
83
84
85
86
87
88
89
90
91 private class XSShortRenderer extends DefaultTableCellRenderer {
92
93 @Override
94 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
95
96 final JLabel cell = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
97
98 PropertySheetTableModel tableModel = (PropertySheetTableModel) table.getModel();
99
100 Item item = tableModel.getPropertySheetElement(row);
101
102 String name = item.getName();
103
104 if ("contentType".equals(name)) {
105 short id = (Short) value;
106 switch (id) {
107 case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
108 cell.setText("element");
109 break;
110 case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
111 cell.setText("empty");
112 break;
113 case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
114 cell.setText("mixed");
115 break;
116 case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
117 cell.setText("simple");
118 break;
119
120 }
121 }
122 else if ("derivationMethod".equals(name)) {
123 short id = (Short) value;
124 switch (id) {
125 case XSConstants.DERIVATION_EXTENSION:
126 cell.setText("extension");
127 break;
128 case XSConstants.DERIVATION_LIST:
129 cell.setText("list");
130 break;
131 case XSConstants.DERIVATION_NONE:
132 cell.setText("none");
133 break;
134 case XSConstants.DERIVATION_RESTRICTION:
135 cell.setText("restriction");
136 break;
137 case XSConstants.DERIVATION_SUBSTITUTION:
138 cell.setText("substitution");
139 break;
140 case XSConstants.DERIVATION_UNION:
141 cell.setText("union");
142 break;
143 }
144 }
145 return cell;
146 }
147
148 }
149
150
151
152
153
154
155
156
157 private class XSTypeDefinitionRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
158
159 @Override
160 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
161
162 final JLabel cell = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
163
164 if (value instanceof XSTypeDefinition) {
165 XSTypeDefinition def = (XSTypeDefinition) value;
166 cell.setText("{" + def.getNamespace() + "}:" + def.getName());
167 }
168
169 return cell;
170 }
171 }
172
173
174
175
176
177
178
179
180 private class XSStringListRenderer extends DefaultTableCellRenderer {
181
182 @Override
183 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
184 final JLabel cell = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
185
186 if (value instanceof StringList) {
187 StringList def = (StringList) value;
188 StringBuilder sb = new StringBuilder();
189 for (int i = 0; i < def.getLength(); ++i) {
190 sb.append(def.item(i));
191 if (i < (def.getLength() - 1)) {
192 sb.append(", ");
193 }
194 }
195 cell.setText(sb.toString());
196 }
197
198 return cell;
199 }
200 }
201 }