Lines 12-35
Link Here
|
12 |
|
12 |
|
13 |
package org.eclipse.gmf.tests.gen; |
13 |
package org.eclipse.gmf.tests.gen; |
14 |
|
14 |
|
|
|
15 |
import java.lang.reflect.Field; |
15 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
16 |
import java.util.List; |
17 |
import java.util.List; |
17 |
|
18 |
|
|
|
19 |
import org.eclipse.draw2d.Graphics; |
18 |
import org.eclipse.draw2d.IFigure; |
20 |
import org.eclipse.draw2d.IFigure; |
19 |
import org.eclipse.draw2d.geometry.PointList; |
21 |
import org.eclipse.draw2d.geometry.PointList; |
20 |
import org.eclipse.gmf.gmfgraph.BasicFont; |
22 |
import org.eclipse.gmf.gmfgraph.BasicFont; |
|
|
23 |
import org.eclipse.gmf.gmfgraph.Border; |
21 |
import org.eclipse.gmf.gmfgraph.Color; |
24 |
import org.eclipse.gmf.gmfgraph.Color; |
22 |
import org.eclipse.gmf.gmfgraph.ColorConstants; |
25 |
import org.eclipse.gmf.gmfgraph.CompoundBorder; |
23 |
import org.eclipse.gmf.gmfgraph.ConstantColor; |
26 |
import org.eclipse.gmf.gmfgraph.ConstantColor; |
24 |
import org.eclipse.gmf.gmfgraph.Dimension; |
27 |
import org.eclipse.gmf.gmfgraph.Dimension; |
25 |
import org.eclipse.gmf.gmfgraph.Figure; |
28 |
import org.eclipse.gmf.gmfgraph.Figure; |
26 |
import org.eclipse.gmf.gmfgraph.Font; |
29 |
import org.eclipse.gmf.gmfgraph.Font; |
27 |
import org.eclipse.gmf.gmfgraph.FontStyle; |
30 |
import org.eclipse.gmf.gmfgraph.FontStyle; |
28 |
import org.eclipse.gmf.gmfgraph.GMFGraphPackage; |
31 |
import org.eclipse.gmf.gmfgraph.GMFGraphPackage; |
|
|
32 |
import org.eclipse.gmf.gmfgraph.Insets; |
29 |
import org.eclipse.gmf.gmfgraph.Label; |
33 |
import org.eclipse.gmf.gmfgraph.Label; |
|
|
34 |
import org.eclipse.gmf.gmfgraph.LineBorder; |
35 |
import org.eclipse.gmf.gmfgraph.LineKind; |
36 |
import org.eclipse.gmf.gmfgraph.MarginBorder; |
30 |
import org.eclipse.gmf.gmfgraph.Point; |
37 |
import org.eclipse.gmf.gmfgraph.Point; |
31 |
import org.eclipse.gmf.gmfgraph.Polyline; |
38 |
import org.eclipse.gmf.gmfgraph.Polyline; |
32 |
import org.eclipse.gmf.gmfgraph.RGBColor; |
39 |
import org.eclipse.gmf.gmfgraph.RGBColor; |
|
|
40 |
import org.eclipse.gmf.gmfgraph.Shape; |
33 |
import org.eclipse.swt.SWT; |
41 |
import org.eclipse.swt.SWT; |
34 |
import org.eclipse.swt.graphics.FontData; |
42 |
import org.eclipse.swt.graphics.FontData; |
35 |
import org.eclipse.swt.graphics.RGB; |
43 |
import org.eclipse.swt.graphics.RGB; |
Lines 46-57
Link Here
|
46 |
checkFigure(myGMFRootFigure, figure); |
54 |
checkFigure(myGMFRootFigure, figure); |
47 |
} |
55 |
} |
48 |
|
56 |
|
49 |
private void checkFigure(Figure gmfFigure, IFigure d2dFigure){ |
57 |
protected void checkFigure(Figure gmfFigure, IFigure d2dFigure){ |
50 |
checkFigureItself(gmfFigure, d2dFigure); |
58 |
checkFigureItself(gmfFigure, d2dFigure); |
51 |
checkFigureChildren(gmfFigure, d2dFigure); |
59 |
checkFigureChildren(gmfFigure, d2dFigure); |
52 |
} |
60 |
} |
53 |
|
61 |
|
54 |
private void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure){ |
62 |
protected void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure){ |
55 |
List gmfChildren = gmfFigure.getChildren(); |
63 |
List gmfChildren = gmfFigure.getChildren(); |
56 |
List d2dChildren = d2dFigure.getChildren(); |
64 |
List d2dChildren = d2dFigure.getChildren(); |
57 |
assertNotNull(gmfChildren); |
65 |
assertNotNull(gmfChildren); |
Lines 68-84
Link Here
|
68 |
} |
76 |
} |
69 |
} |
77 |
} |
70 |
|
78 |
|
71 |
private void checkFigureItself(Figure gmfFigure, IFigure d2dFigure){ |
79 |
protected void checkFigureItself(Figure gmfFigure, IFigure d2dFigure){ |
72 |
checkSize(gmfFigure, d2dFigure); |
80 |
checkSize(gmfFigure, d2dFigure); |
|
|
81 |
//XXX: checkLocation(gmfFigure, d2dFigure); |
82 |
checkMaximumSize(gmfFigure, d2dFigure); |
83 |
checkMinimumSize(gmfFigure, d2dFigure); |
73 |
checkPreferredSize(gmfFigure, d2dFigure); |
84 |
checkPreferredSize(gmfFigure, d2dFigure); |
74 |
checkFont(gmfFigure, d2dFigure); |
85 |
checkFont(gmfFigure, d2dFigure); |
75 |
checkForeground(gmfFigure, d2dFigure); |
86 |
checkForeground(gmfFigure, d2dFigure); |
76 |
checkBackgroud(gmfFigure, d2dFigure); |
87 |
checkBackgroud(gmfFigure, d2dFigure); |
|
|
88 |
checkInsets(gmfFigure, d2dFigure); |
89 |
checkBorder(gmfFigure, d2dFigure); |
90 |
checkShapeProperties(gmfFigure, d2dFigure); |
77 |
checkLabelText(gmfFigure, d2dFigure); |
91 |
checkLabelText(gmfFigure, d2dFigure); |
78 |
checkPolylinePoints(gmfFigure, d2dFigure); |
92 |
checkPolylinePoints(gmfFigure, d2dFigure); |
79 |
} |
93 |
} |
|
|
94 |
|
95 |
private void checkShapeProperties(Figure gmfFigure, IFigure figure) { |
96 |
if (gmfFigure instanceof Shape){ |
97 |
Shape eShape = (Shape)gmfFigure; |
98 |
assertTrue(figure instanceof org.eclipse.draw2d.Shape); |
99 |
org.eclipse.draw2d.Shape d2dShape = (org.eclipse.draw2d.Shape)figure; |
100 |
checkLineKind(eShape, d2dShape); |
101 |
checkLineWidth(eShape, d2dShape); |
102 |
} |
103 |
} |
104 |
|
105 |
protected void checkLineWidth(Shape eShape, org.eclipse.draw2d.Shape d2dShape) { |
106 |
if (eShape.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineWidth())){ |
107 |
int expected = eShape.getLineWidth(); |
108 |
assertEquals(expected, d2dShape.getLineWidth()); |
109 |
} |
110 |
} |
111 |
|
112 |
protected void checkLineKind(Shape eShape, org.eclipse.draw2d.Shape d2dShape) { |
113 |
if (eShape.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineKind())){ |
114 |
LineKind expected = eShape.getLineKind(); |
115 |
assertEquals(transformLineKind(expected), d2dShape.getLineStyle()); |
116 |
} |
117 |
} |
80 |
|
118 |
|
81 |
private void checkPolylinePoints(Figure gmfFigure, IFigure d2dFigure) { |
119 |
private int transformLineKind(LineKind kind){ |
|
|
120 |
Object d2dValue = getStaticFieldValue("Unknown LineKind: " + kind, Graphics.class, kind.getName()); |
121 |
assertTrue(d2dValue instanceof Integer); |
122 |
return ((Integer)d2dValue).intValue(); |
123 |
} |
124 |
|
125 |
protected final void checkDimension(Dimension eDimension, org.eclipse.draw2d.geometry.Dimension d2dDimension){ |
126 |
assertEquals(new org.eclipse.draw2d.geometry.Dimension(eDimension.getDx(), eDimension.getDy()), d2dDimension); |
127 |
} |
128 |
|
129 |
protected void checkPolylinePoints(Figure gmfFigure, IFigure d2dFigure) { |
82 |
if (gmfFigure instanceof Polyline && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getPolyline_Template())){ |
130 |
if (gmfFigure instanceof Polyline && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getPolyline_Template())){ |
83 |
Polyline gmfPolyline = (Polyline)gmfFigure; |
131 |
Polyline gmfPolyline = (Polyline)gmfFigure; |
84 |
assertTrue(d2dFigure instanceof org.eclipse.draw2d.Polyline); |
132 |
assertTrue(d2dFigure instanceof org.eclipse.draw2d.Polyline); |
Lines 98-104
Link Here
|
98 |
|
146 |
|
99 |
} |
147 |
} |
100 |
|
148 |
|
101 |
private void checkLabelText(Figure gmfFigure, IFigure d2dFigure) { |
149 |
protected void checkLabelText(Figure gmfFigure, IFigure d2dFigure) { |
102 |
if (gmfFigure instanceof Label && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getLabel_Text())){ |
150 |
if (gmfFigure instanceof Label && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getLabel_Text())){ |
103 |
assertTrue(d2dFigure instanceof org.eclipse.draw2d.Label); |
151 |
assertTrue(d2dFigure instanceof org.eclipse.draw2d.Label); |
104 |
org.eclipse.draw2d.Label d2dLabel = (org.eclipse.draw2d.Label)d2dFigure; |
152 |
org.eclipse.draw2d.Label d2dLabel = (org.eclipse.draw2d.Label)d2dFigure; |
Lines 107-125
Link Here
|
107 |
} |
155 |
} |
108 |
} |
156 |
} |
109 |
|
157 |
|
110 |
private void checkBackgroud(Figure gmfFigure, IFigure figure) { |
158 |
protected void checkBackgroud(Figure gmfFigure, IFigure figure) { |
111 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())){ |
159 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())){ |
112 |
checkColor(gmfFigure.getBackgroundColor(), figure.getBackgroundColor()); |
160 |
checkColor(gmfFigure.getBackgroundColor(), figure.getBackgroundColor()); |
113 |
} |
161 |
} |
114 |
} |
162 |
} |
115 |
|
163 |
|
116 |
private void checkForeground(Figure gmfFigure, IFigure figure) { |
164 |
protected void checkForeground(Figure gmfFigure, IFigure figure) { |
117 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())){ |
165 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())){ |
118 |
checkColor(gmfFigure.getForegroundColor(), figure.getForegroundColor()); |
166 |
checkColor(gmfFigure.getForegroundColor(), figure.getForegroundColor()); |
119 |
} |
167 |
} |
120 |
} |
168 |
} |
121 |
|
169 |
|
122 |
private void checkColor(Color eColor, org.eclipse.swt.graphics.Color swtColor){ |
170 |
protected final void checkColor(Color eColor, org.eclipse.swt.graphics.Color swtColor){ |
123 |
assertNotNull(swtColor); |
171 |
assertNotNull(swtColor); |
124 |
assertNotNull(eColor); |
172 |
assertNotNull(eColor); |
125 |
|
173 |
|
Lines 134-147
Link Here
|
134 |
assertEquals(expectedRGB, swtColor.getRGB()); |
182 |
assertEquals(expectedRGB, swtColor.getRGB()); |
135 |
} |
183 |
} |
136 |
|
184 |
|
137 |
private void checkFont(Figure gmfFigure, IFigure figure) { |
185 |
protected void checkFont(Figure gmfFigure, IFigure figure) { |
138 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())){ |
186 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())){ |
139 |
Font eFont = gmfFigure.getFont(); |
187 |
Font eFont = gmfFigure.getFont(); |
140 |
checkFont(eFont, figure.getFont()); |
188 |
checkFont(eFont, figure.getFont()); |
141 |
} |
189 |
} |
142 |
} |
190 |
} |
143 |
|
191 |
|
144 |
private void checkFont(Font gmfFont, org.eclipse.swt.graphics.Font actual){ |
192 |
protected final void checkFont(Font gmfFont, org.eclipse.swt.graphics.Font actual){ |
145 |
assertNotNull(actual); |
193 |
assertNotNull(actual); |
146 |
if (gmfFont instanceof BasicFont && actual.getFontData().length == 1){ |
194 |
if (gmfFont instanceof BasicFont && actual.getFontData().length == 1){ |
147 |
BasicFont expected = (BasicFont)gmfFont; |
195 |
BasicFont expected = (BasicFont)gmfFont; |
Lines 164-186
Link Here
|
164 |
} |
212 |
} |
165 |
|
213 |
|
166 |
private org.eclipse.swt.graphics.Color transformConstantColor(ConstantColor color) { |
214 |
private org.eclipse.swt.graphics.Color transformConstantColor(ConstantColor color) { |
167 |
switch(color.getValue().getValue()){ |
215 |
Class d2dClass = org.eclipse.draw2d.ColorConstants.class; |
168 |
case ColorConstants.BLACK : return org.eclipse.draw2d.ColorConstants.black; |
216 |
Object d2dValue = getStaticFieldValue("Unknown color: " + color, d2dClass, color.getValue().getLiteral()); |
169 |
case ColorConstants.BLUE : return org.eclipse.draw2d.ColorConstants.blue; |
217 |
assertTrue(d2dValue instanceof org.eclipse.swt.graphics.Color); |
170 |
case ColorConstants.CYAN : return org.eclipse.draw2d.ColorConstants.cyan; |
218 |
return (org.eclipse.swt.graphics.Color)d2dValue; |
171 |
case ColorConstants.DARK_BLUE : return org.eclipse.draw2d.ColorConstants.darkBlue; |
219 |
} |
172 |
case ColorConstants.DARK_GRAY: return org.eclipse.draw2d.ColorConstants.darkGray; |
220 |
|
173 |
case ColorConstants.DARK_GREEN: return org.eclipse.draw2d.ColorConstants.darkGreen; |
221 |
private Object getStaticFieldValue(String failureMessage, Class clazz, String fieldName){ |
174 |
case ColorConstants.GRAY: return org.eclipse.draw2d.ColorConstants.gray; |
222 |
try { |
175 |
case ColorConstants.GREEN: return org.eclipse.draw2d.ColorConstants.green; |
223 |
Field constant = clazz.getField(fieldName); |
176 |
case ColorConstants.LIGHT_BLUE: return org.eclipse.draw2d.ColorConstants.lightBlue; |
224 |
assertNotNull(failureMessage, constant); |
177 |
case ColorConstants.LIGHT_GRAY: return org.eclipse.draw2d.ColorConstants.lightGray; |
225 |
Object value = constant.get(null); |
178 |
case ColorConstants.LIGHT_GREEN: return org.eclipse.draw2d.ColorConstants.lightGreen; |
226 |
assertNotNull(failureMessage, value); |
179 |
case ColorConstants.ORANGE: return org.eclipse.draw2d.ColorConstants.orange; |
227 |
return value; |
180 |
case ColorConstants.RED: return org.eclipse.draw2d.ColorConstants.red; |
228 |
} catch (Exception e) { |
181 |
case ColorConstants.WHITE: return org.eclipse.draw2d.ColorConstants.white; |
229 |
fail(failureMessage + "\n" + e.toString()); |
182 |
case ColorConstants.YELLOW: return org.eclipse.draw2d.ColorConstants.yellow; |
230 |
throw new InternalError("Unreachable"); |
183 |
default: throw new IllegalArgumentException("Unknown Color: " + color); |
|
|
184 |
} |
231 |
} |
185 |
} |
232 |
} |
186 |
|
233 |
|
Lines 188-205
Link Here
|
188 |
return new RGB(color.getRed(), color.getGreen(), color.getBlue()); |
235 |
return new RGB(color.getRed(), color.getGreen(), color.getBlue()); |
189 |
} |
236 |
} |
190 |
|
237 |
|
191 |
private void checkPreferredSize(Figure gmfFigure, IFigure figure) { |
238 |
protected void checkPreferredSize(Figure gmfFigure, IFigure figure) { |
192 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())){ |
239 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())){ |
193 |
Dimension ePreferredSize = gmfFigure.getPreferredSize(); |
240 |
Dimension ePreferredSize = gmfFigure.getPreferredSize(); |
194 |
assertEquals(new org.eclipse.draw2d.geometry.Dimension(ePreferredSize.getDx(), ePreferredSize.getDy()), figure.getPreferredSize()); |
241 |
checkDimension(ePreferredSize, figure.getPreferredSize()); |
195 |
} |
242 |
} |
196 |
} |
243 |
} |
197 |
|
244 |
|
198 |
private void checkSize(Figure gmfFigure, IFigure figure) { |
245 |
protected void checkSize(Figure gmfFigure, IFigure figure) { |
199 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())){ |
246 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())){ |
200 |
Point eSize = gmfFigure.getSize(); |
247 |
Point eSize = gmfFigure.getSize(); |
201 |
assertEquals(new org.eclipse.draw2d.geometry.Dimension(eSize.getX(), eSize.getY()), figure.getSize()); |
248 |
assertEquals(new org.eclipse.draw2d.geometry.Dimension(eSize.getX(), eSize.getY()), figure.getSize()); |
202 |
} |
249 |
} |
203 |
} |
250 |
} |
|
|
251 |
|
252 |
protected void checkMaximumSize(Figure gmfFigure, IFigure figure) { |
253 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())){ |
254 |
Dimension eSize = gmfFigure.getMaximumSize(); |
255 |
checkDimension(eSize, figure.getMaximumSize()); |
256 |
} |
257 |
} |
258 |
|
259 |
protected void checkMinimumSize(Figure gmfFigure, IFigure figure) { |
260 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())){ |
261 |
Dimension eSize = gmfFigure.getMinimumSize(); |
262 |
checkDimension(eSize, figure.getMinimumSize()); |
263 |
} |
264 |
} |
265 |
|
266 |
|
267 |
protected void checkBorder(Figure gmfFigure, IFigure figure) { |
268 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())){ |
269 |
Border eBorder = gmfFigure.getBorder(); |
270 |
checkBorder(eBorder, figure.getBorder(), figure); |
271 |
} |
272 |
} |
273 |
|
274 |
protected final void checkBorder(Border eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure){ |
275 |
assertNotNull(eBorder); |
276 |
assertNotNull(d2dBorder); |
277 |
if (eBorder instanceof LineBorder){ |
278 |
checkLineBorder((LineBorder)eBorder, d2dBorder); |
279 |
} else if (eBorder instanceof CompoundBorder){ |
280 |
checkCompoundBorder((CompoundBorder)eBorder, d2dBorder, mainD2DFigure); |
281 |
} else if (eBorder instanceof MarginBorder){ |
282 |
checkMarginBorder((MarginBorder)eBorder, d2dBorder, mainD2DFigure); |
283 |
} |
284 |
} |
285 |
|
286 |
protected final void checkMarginBorder(MarginBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) { |
287 |
assertTrue(d2dBorder instanceof org.eclipse.draw2d.MarginBorder); |
288 |
org.eclipse.draw2d.MarginBorder actual = (org.eclipse.draw2d.MarginBorder)d2dBorder; |
289 |
if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getMarginBorder_Insets())){ |
290 |
Insets eInsets = eBorder.getInsets(); |
291 |
checkInsets(eInsets, actual.getInsets(mainD2DFigure)); |
292 |
} |
293 |
} |
294 |
|
295 |
protected final void checkCompoundBorder(CompoundBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure){ |
296 |
assertTrue(d2dBorder instanceof org.eclipse.draw2d.CompoundBorder); |
297 |
org.eclipse.draw2d.CompoundBorder actual = (org.eclipse.draw2d.CompoundBorder)d2dBorder; |
298 |
if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getCompoundBorder_Inner())){ |
299 |
checkBorder(eBorder.getInner(), actual.getInnerBorder(), mainD2DFigure); |
300 |
} |
301 |
if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getCompoundBorder_Outer())){ |
302 |
checkBorder(eBorder.getOuter(), actual.getOuterBorder(), mainD2DFigure); |
303 |
} |
304 |
} |
305 |
|
306 |
protected final void checkLineBorder(LineBorder eBorder, org.eclipse.draw2d.Border d2dBorder){ |
307 |
assertTrue(d2dBorder instanceof org.eclipse.draw2d.LineBorder); |
308 |
org.eclipse.draw2d.LineBorder actual = (org.eclipse.draw2d.LineBorder)d2dBorder; |
309 |
//intentionally always checked, there is a default value mathcing default value in d2d |
310 |
assertEquals(eBorder.getWidth(), actual.getWidth()); |
311 |
|
312 |
if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color())){ |
313 |
checkColor(eBorder.getColor(), actual.getColor()); |
314 |
} |
315 |
} |
316 |
|
317 |
protected void checkInsets(Figure gmfFigure, IFigure figure) { |
318 |
if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())){ |
319 |
checkInsets(gmfFigure.getInsets(), figure.getInsets()); |
320 |
} |
321 |
} |
322 |
|
323 |
protected final void checkInsets(Insets eInsets, org.eclipse.draw2d.geometry.Insets d2dInsets){ |
324 |
assertNotNull(d2dInsets); |
325 |
assertNotNull(eInsets); |
326 |
assertEquals(new org.eclipse.draw2d.geometry.Insets(eInsets.getTop(), eInsets.getLeft(), eInsets.getBottom(), eInsets.getRight()), d2dInsets); |
327 |
} |
204 |
|
328 |
|
205 |
} |
329 |
} |