Revision 34111
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
InputCoordinatesPanel class. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.symbology.gui.InputCoordinatesPanel"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
|
|
26 |
<!-- |
|
27 |
By default, show only logging messages of INFO level or higher, |
|
28 |
through the previously configured CONSOLE appender. |
|
29 |
--> |
|
30 |
<root> |
|
31 |
<priority value="INFO" /> |
|
32 |
<appender-ref ref="CONSOLE" /> |
|
33 |
</root> |
|
34 |
</log4j:configuration> |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/TestCartographicSupportForSymbol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
import java.awt.geom.Rectangle2D; |
|
45 |
import java.util.ArrayList; |
|
46 |
import java.util.Random; |
|
47 |
|
|
48 |
import org.gvsig.compat.CompatLocator; |
|
49 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
50 |
import org.gvsig.fmap.geom.GeometryManager; |
|
51 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
52 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
53 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
54 |
import org.gvsig.fmap.geom.primitive.Point; |
|
55 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
56 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
57 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
58 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
|
59 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
60 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
61 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.AbstractSymbolTestCase; |
|
62 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleFillSymbolTest; |
|
63 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleLineSymbolTest; |
|
64 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleMarkerSymbolTest; |
|
65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
68 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
69 |
import org.gvsig.utils.IPersistence; |
|
70 |
import org.gvsig.utils.NotExistInXMLEntity; |
|
71 |
import org.gvsig.utils.XMLEntity; |
|
72 |
import org.gvsig.utils.XMLException; |
|
73 |
import org.slf4j.Logger; |
|
74 |
import org.slf4j.LoggerFactory; |
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* |
|
79 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
80 |
*/ |
|
81 |
public class TestCartographicSupportForSymbol extends AbstractLibraryAutoInitTestCase { |
|
82 |
private static GeometryManager geomManager; |
|
83 |
private static final Logger logger = LoggerFactory.getLogger(TestCartographicSupportForSymbol.class); |
|
84 |
|
|
85 |
/** |
|
86 |
* Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:23030</b> |
|
87 |
*/ |
|
88 |
public static Point valenciaUTM30 = null; |
|
89 |
|
|
90 |
/** |
|
91 |
* Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:4326</b> |
|
92 |
*/ |
|
93 |
public static Point valenciaGeo = null; |
|
94 |
|
|
95 |
public SymbolManager manager = MapContextLocator.getSymbolManager(); |
|
96 |
/** |
|
97 |
* Extent that covers the whole Comunitat Valenciana in <b>EPSG:23030</b> |
|
98 |
*/ |
|
99 |
public static final Rectangle2D TEST_UTM30_EXTENT = new Rectangle2D.Double(); |
|
100 |
{ |
|
101 |
TEST_UTM30_EXTENT.setFrameFromDiagonal( |
|
102 |
4191037.369934333, |
|
103 |
626674.7454557443, |
|
104 |
|
|
105 |
4519266.460824658, |
|
106 |
797903.2656794232 |
|
107 |
); |
|
108 |
} |
|
109 |
/** |
|
110 |
* Extent that covers the whole Comunitat Valenciana in <b>EPSG:4326</b> |
|
111 |
*/ |
|
112 |
|
|
113 |
public static final Rectangle2D TEST_GEO_EXTENT = new Rectangle2D.Double(); |
|
114 |
{ |
|
115 |
TEST_GEO_EXTENT.setFrameFromDiagonal( |
|
116 |
|
|
117 |
- (1 + (31/60) + (28.09/3600)), // Western egde |
|
118 |
37 + (50/60) + (48.05/3600), // Southern edge |
|
119 |
|
|
120 |
0 + (31/60) + (1.85/3600), // Eastern edge |
|
121 |
40 + (47/60) + (21.36/3600) // Northern edge |
|
122 |
|
|
123 |
); |
|
124 |
} |
|
125 |
|
|
126 |
public static final Rectangle2D TEST_EXTENT = new Rectangle2D.Double( |
|
127 |
4191037.369934333, |
|
128 |
626674.7454557443, |
|
129 |
|
|
130 |
4519266.460824658 - 4191037.369934333, |
|
131 |
797903.2656794232 - 626674.7454557443 |
|
132 |
); |
|
133 |
private static ArrayList symbolsToTest; //<AbstractSymbolTestCase> |
|
134 |
private ArrayList csSymbols; //<CartographicSupport> |
|
135 |
|
|
136 |
/** |
|
137 |
* Acceptable pixel tolerance error. 1 pixel of error is accetable since it is probably due to |
|
138 |
* the java.awt.Graphics |
|
139 |
*/ |
|
140 |
private static final double TOL = 1; |
|
141 |
|
|
142 |
double zooms[] = new double[] { |
|
143 |
1, |
|
144 |
2, |
|
145 |
1.2, |
|
146 |
10, |
|
147 |
0.5 |
|
148 |
}; |
|
149 |
|
|
150 |
protected void doSetUp() throws Exception { |
|
151 |
geomManager = GeometryLocator.getGeometryManager(); |
|
152 |
try { |
|
153 |
valenciaUTM30 = geomManager.createPoint(725846.080, 4373022.720, SUBTYPES.GEOM2D); |
|
154 |
valenciaGeo = geomManager.createPoint(- (0+ 22/60 + 27.919/3600), 39 + 28/60 + 35.4276/3600, SUBTYPES.GEOM2D); |
|
155 |
} catch (CreateGeometryException e) { |
|
156 |
// TODO Auto-generated catch block |
|
157 |
e.printStackTrace(); |
|
158 |
} |
|
159 |
|
|
160 |
addSymbolTest(new SimpleFillSymbolTest()); |
|
161 |
addSymbolTest(new SimpleLineSymbolTest()); |
|
162 |
addSymbolTest(new SimpleMarkerSymbolTest()); |
|
163 |
|
|
164 |
init(); |
|
165 |
} |
|
166 |
|
|
167 |
protected void init() { |
|
168 |
|
|
169 |
// take the symbols added to the TestISymbol test |
|
170 |
ISymbol[] symbols = getNewSymbolInstances(); |
|
171 |
|
|
172 |
csSymbols = new ArrayList(); //<CartographicSupport> |
|
173 |
for (int i = 0; i < symbols.length; i++) { |
|
174 |
if (symbols[i] instanceof CartographicSupport) { |
|
175 |
csSymbols.add((CartographicSupport) symbols[i]); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) { |
|
181 |
if (symbolsToTest == null) symbolsToTest = new ArrayList(); //<AbstractSymbolTestCase> |
|
182 |
symbolsToTest.add(symbolTestClass); |
|
183 |
} |
|
184 |
|
|
185 |
public static ISymbol[] getNewSymbolInstances() { |
|
186 |
ISymbol[] symbols = new ISymbol[symbolsToTest.size()]; |
|
187 |
for (int i = 0; i < symbols.length; i++) { |
|
188 |
symbols[i] = (ISymbol)((AbstractSymbolTestCase)symbolsToTest.get(i)).newInstance(); |
|
189 |
} |
|
190 |
return symbols; |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
public void testSymbolUnitDefinition() { |
|
195 |
for (int i = 0; i < csSymbols.size(); i++) { |
|
196 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(i); |
|
197 |
|
|
198 |
int aRandomUnit = new Random().nextInt(7); |
|
199 |
|
|
200 |
|
|
201 |
symbol.setUnit(aRandomUnit); |
|
202 |
XMLEntity xml=null; |
|
203 |
try { |
|
204 |
xml = ((IPersistence) symbol).getXMLEntity(); |
|
205 |
} catch (XMLException e) { |
|
206 |
// TODO Auto-generated catch block |
|
207 |
e.printStackTrace(); |
|
208 |
} |
|
209 |
String name = symbol.getClass().getName().substring( |
|
210 |
symbol.getClass().getName().lastIndexOf('.')+1, |
|
211 |
symbol.getClass().getName().length()); |
|
212 |
|
|
213 |
try { |
|
214 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly", |
|
215 |
symbol.getUnit() == xml.getIntProperty("unit")); |
|
216 |
} catch (NotExistInXMLEntity neiXMLEx) { |
|
217 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity"); |
|
218 |
} |
|
219 |
symbol.setUnit(5); |
|
220 |
try { |
|
221 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getUnit()== 5); |
|
222 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly", |
|
223 |
5 == ((IPersistence) symbol).getXMLEntity().getIntProperty("unit")); |
|
224 |
} catch (NotExistInXMLEntity neiXMLEx) { |
|
225 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity"); |
|
226 |
} catch (XMLException e) { |
|
227 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity"); |
|
228 |
} |
|
229 |
|
|
230 |
// xml.putProperty("unit", 3); |
|
231 |
// ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc")); |
|
232 |
// assertTrue("The application of the UNIT value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getUnit() == 3); |
|
233 |
} |
|
234 |
|
|
235 |
} |
|
236 |
|
|
237 |
|
|
238 |
public void testSymbolReferenceSystemDefinition() { |
|
239 |
for (int i = 0; i < csSymbols.size(); i++) { |
|
240 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(i); |
|
241 |
XMLEntity xml=null; |
|
242 |
try { |
|
243 |
xml = ((IPersistence) symbol).getXMLEntity(); |
|
244 |
} catch (XMLException e) { |
|
245 |
// TODO Auto-generated catch block |
|
246 |
e.printStackTrace(); |
|
247 |
} |
|
248 |
String name = symbol.getClass().getName().substring( |
|
249 |
symbol.getClass().getName().lastIndexOf('.')+1, |
|
250 |
symbol.getClass().getName().length()); |
|
251 |
try { |
|
252 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly", |
|
253 |
symbol.getReferenceSystem() == xml.getIntProperty("referenceSystem")); |
|
254 |
} catch (NotExistInXMLEntity neiXMLEx) { |
|
255 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity"); |
|
256 |
} |
|
257 |
symbol.setReferenceSystem(CartographicSupport.PAPER); |
|
258 |
try { |
|
259 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.PAPER); |
|
260 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly", |
|
261 |
CartographicSupport.PAPER == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem")); |
|
262 |
} catch (NotExistInXMLEntity neiXMLEx) { |
|
263 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")"); |
|
264 |
} catch (XMLException e) { |
|
265 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")"); |
|
266 |
} |
|
267 |
|
|
268 |
symbol.setReferenceSystem(CartographicSupport.WORLD); |
|
269 |
try { |
|
270 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.WORLD); |
|
271 |
assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly", |
|
272 |
CartographicSupport.WORLD == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem")); |
|
273 |
} catch (NotExistInXMLEntity neiXMLEx) { |
|
274 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity"); |
|
275 |
} catch (XMLException e) { |
|
276 |
fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity"); |
|
277 |
} |
|
278 |
|
|
279 |
// xml.putProperty("referenceSystem", CartographicSupport.PAPER); |
|
280 |
// ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc")); |
|
281 |
// assertTrue("The application of the REFERENCE SYSTEM value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getReferenceSystem() == CartographicSupport.PAPER); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
|
|
286 |
public void testDegreesUnits_MapReferenceSystem() throws Exception { |
|
287 |
for (int j = 0; j < csSymbols.size(); j++) { |
|
288 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
|
289 |
|
|
290 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_PROJECTION); |
|
291 |
ViewPort viewPort = mc.getViewPort(); |
|
292 |
|
|
293 |
int unit = 8; |
|
294 |
Dimension dim = new Dimension(600, 600); |
|
295 |
viewPort.setImageSize(dim); |
|
296 |
|
|
297 |
|
|
298 |
/* |
|
299 |
* will test with several extents but in the same map image size, so |
|
300 |
* the scale issue is exercised as well. |
|
301 |
*/ |
|
302 |
for (int i = 0; i < zooms.length; i++) { |
|
303 |
Envelope extent = geomManager.createEnvelope(-30, -30,dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
|
304 |
|
|
305 |
viewPort.setMapUnits(unit); |
|
306 |
viewPort.setEnvelope(extent); |
|
307 |
|
|
308 |
|
|
309 |
String name = ((IPersistence) symbol).getClassName().substring( |
|
310 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
|
311 |
((IPersistence) symbol).getClassName().length()); |
|
312 |
|
|
313 |
CartographicSupport csSym = (CartographicSupport) symbol; |
|
314 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
|
315 |
double size = 30; |
|
316 |
|
|
317 |
csSym.setUnit(unit); |
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
if (symbol instanceof IMarkerSymbol) { |
|
322 |
|
|
323 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
|
324 |
markerSym.setSize(size); |
|
325 |
csSym.toCartographicSize( |
|
326 |
viewPort, |
|
327 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
328 |
geomManager.createPoint( |
|
329 |
viewPort.getAdjustedExtent().getCenter(0), |
|
330 |
viewPort.getAdjustedExtent().getCenter(1), |
|
331 |
SUBTYPES.GEOM2D |
|
332 |
) |
|
333 |
); |
|
334 |
double mySize = markerSym.getSize(); |
|
335 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
336 |
"It returned "+markerSym.getSize()+" when expecting "+ |
|
337 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
338 |
} |
|
339 |
|
|
340 |
if (symbol instanceof ILineSymbol) { |
|
341 |
|
|
342 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
|
343 |
lineSym.setLineWidth(size); |
|
344 |
csSym.toCartographicSize( |
|
345 |
viewPort, |
|
346 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
347 |
geomManager.createPoint( |
|
348 |
viewPort.getAdjustedExtent().getCenter(0), |
|
349 |
viewPort.getAdjustedExtent().getCenter(1), |
|
350 |
SUBTYPES.GEOM2D |
|
351 |
) |
|
352 |
); |
|
353 |
double mySize = lineSym.getLineStyle().getLineWidth(); |
|
354 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
355 |
"It returned "+mySize+" when expecting "+ |
|
356 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
357 |
} |
|
358 |
|
|
359 |
if (symbol instanceof IFillSymbol) { |
|
360 |
// this tests if symbol applies the cartographic support to its |
|
361 |
// outline, since is the only thing that may be resized |
|
362 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
|
363 |
if (fillSym.getOutline() == null) { |
|
364 |
fillSym.setOutline((ILineSymbol) manager.createSymbol(ILineSymbol.SYMBOL_NAME)); |
|
365 |
} |
|
366 |
|
|
367 |
fillSym.getOutline().setLineWidth(size); |
|
368 |
|
|
369 |
csSym.toCartographicSize( |
|
370 |
viewPort, |
|
371 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
372 |
geomManager.createPoint( |
|
373 |
viewPort.getAdjustedExtent().getCenter(0), |
|
374 |
viewPort.getAdjustedExtent().getCenter(1), |
|
375 |
SUBTYPES.GEOM2D |
|
376 |
) |
|
377 |
); |
|
378 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth(); |
|
379 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
380 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
|
381 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
382 |
} |
|
383 |
|
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
|
|
389 |
public void testKilometersUnits_MapReferenceSystem() throws Exception { |
|
390 |
for (int j = 0; j < csSymbols.size(); j++) { |
|
391 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
|
392 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
|
393 |
ViewPort viewPort = mc.getViewPort(); |
|
394 |
|
|
395 |
int unit = 0; |
|
396 |
Dimension dim = new Dimension(60, 60); |
|
397 |
viewPort.setImageSize(dim); |
|
398 |
|
|
399 |
|
|
400 |
/* |
|
401 |
* will test with several extents but in the same map image size, so |
|
402 |
* the scale issue is exercised as well. |
|
403 |
*/ |
|
404 |
for (int i = 0; i < zooms.length; i++) { |
|
405 |
Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
|
406 |
|
|
407 |
viewPort.setMapUnits(unit); |
|
408 |
viewPort.setEnvelope(extent); |
|
409 |
|
|
410 |
|
|
411 |
String name = ((IPersistence) symbol).getClassName().substring( |
|
412 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
|
413 |
((IPersistence) symbol).getClassName().length()); |
|
414 |
|
|
415 |
CartographicSupport csSym = (CartographicSupport) symbol; |
|
416 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
|
417 |
double size = 30; |
|
418 |
|
|
419 |
csSym.setUnit(unit); |
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
if (symbol instanceof IMarkerSymbol) { |
|
425 |
|
|
426 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
|
427 |
markerSym.setSize(size); |
|
428 |
csSym.toCartographicSize( |
|
429 |
viewPort, |
|
430 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
431 |
geomManager.createPoint( |
|
432 |
viewPort.getAdjustedExtent().getCenter(0), |
|
433 |
viewPort.getAdjustedExtent().getCenter(1), |
|
434 |
SUBTYPES.GEOM2D |
|
435 |
) |
|
436 |
); |
|
437 |
double mySize = markerSym.getSize(); |
|
438 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
439 |
"It returned "+markerSym.getSize()+" when expecting "+ |
|
440 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
441 |
} |
|
442 |
|
|
443 |
if (symbol instanceof ILineSymbol) { |
|
444 |
|
|
445 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
|
446 |
lineSym.setLineWidth(size); |
|
447 |
csSym.toCartographicSize( |
|
448 |
viewPort, |
|
449 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
450 |
geomManager.createPoint( |
|
451 |
viewPort.getAdjustedExtent().getCenter(0), |
|
452 |
viewPort.getAdjustedExtent().getCenter(1), |
|
453 |
SUBTYPES.GEOM2D |
|
454 |
) |
|
455 |
); |
|
456 |
double mySize = lineSym.getLineStyle().getLineWidth(); |
|
457 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
458 |
"It returned "+lineSym.getLineWidth()+" when expecting "+ |
|
459 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
460 |
} |
|
461 |
|
|
462 |
if (symbol instanceof IFillSymbol) { |
|
463 |
// this tests if symbol applies the cartographic support to its |
|
464 |
// outline, since is the only thing that may be resized |
|
465 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
|
466 |
if (fillSym.getOutline() == null) { |
|
467 |
fillSym.setOutline((ILineSymbol) manager.createSymbol( |
|
468 |
ILineSymbol.SYMBOL_NAME)); |
|
469 |
} |
|
470 |
|
|
471 |
fillSym.getOutline().setLineWidth(size); |
|
472 |
|
|
473 |
csSym.toCartographicSize( |
|
474 |
viewPort, |
|
475 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
476 |
geomManager.createPoint( |
|
477 |
viewPort.getAdjustedExtent().getCenter(0), |
|
478 |
viewPort.getAdjustedExtent().getCenter(1), |
|
479 |
SUBTYPES.GEOM2D |
|
480 |
) |
|
481 |
); |
|
482 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth(); |
|
483 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
484 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
|
485 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
486 |
} |
|
487 |
|
|
488 |
} |
|
489 |
} |
|
490 |
|
|
491 |
} |
|
492 |
|
|
493 |
public void testMapInKilometersSymbolInMeters_MapReferenceSystem() throws Exception { |
|
494 |
for (int j = 0; j < csSymbols.size(); j++) { |
|
495 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
|
496 |
|
|
497 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
|
498 |
ViewPort viewPort = mc.getViewPort(); |
|
499 |
|
|
500 |
int mapUnit = 0; |
|
501 |
int symbolUnit = 1; |
|
502 |
Dimension dim = new Dimension(60, 60); |
|
503 |
viewPort.setImageSize(dim); |
|
504 |
|
|
505 |
|
|
506 |
/* |
|
507 |
* will test with several extents but in the same map image size, so |
|
508 |
* the scale issue is exercised as well. |
|
509 |
*/ |
|
510 |
for (int i = 0; i < zooms.length; i++) { |
|
511 |
Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
|
512 |
viewPort.setMapUnits(mapUnit); |
|
513 |
viewPort.setEnvelope(extent); |
|
514 |
double size = 30; |
|
515 |
|
|
516 |
|
|
517 |
String name = ((IPersistence) symbol).getClassName().substring( |
|
518 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
|
519 |
((IPersistence) symbol).getClassName().length()); |
|
520 |
|
|
521 |
|
|
522 |
CartographicSupport csSym = (CartographicSupport) symbol; |
|
523 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
|
524 |
|
|
525 |
csSym.setUnit(symbolUnit); |
|
526 |
|
|
527 |
if (symbol instanceof IMarkerSymbol) { |
|
528 |
|
|
529 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
|
530 |
markerSym.setSize(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km |
|
531 |
csSym.toCartographicSize( |
|
532 |
viewPort, |
|
533 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
534 |
geomManager.createPoint( |
|
535 |
viewPort.getAdjustedExtent().getCenter(0), |
|
536 |
viewPort.getAdjustedExtent().getCenter(1), |
|
537 |
SUBTYPES.GEOM2D |
|
538 |
) |
|
539 |
); |
|
540 |
double mySize = markerSym.getSize(); |
|
541 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
542 |
"It returned "+markerSym.getSize()+" when expecting "+ |
|
543 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
544 |
} |
|
545 |
|
|
546 |
if (symbol instanceof ILineSymbol) { |
|
547 |
|
|
548 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
|
549 |
lineSym.setLineWidth(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km |
|
550 |
csSym.toCartographicSize( |
|
551 |
viewPort, |
|
552 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
553 |
geomManager.createPoint( |
|
554 |
viewPort.getAdjustedExtent().getCenter(0), |
|
555 |
viewPort.getAdjustedExtent().getCenter(1), |
|
556 |
SUBTYPES.GEOM2D |
|
557 |
) |
|
558 |
); |
|
559 |
double mySize = lineSym.getLineStyle().getLineWidth(); |
|
560 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
561 |
"It returned "+lineSym.getLineWidth()+" when expecting "+ |
|
562 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
563 |
} |
|
564 |
|
|
565 |
if (symbol instanceof IFillSymbol) { |
|
566 |
// this tests if symbol applies the cartographic support to its |
|
567 |
// outline, since is the only thing that may be resized |
|
568 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
|
569 |
if (fillSym.getOutline() == null) { |
|
570 |
fillSym.setOutline((ILineSymbol) manager.createSymbol( |
|
571 |
ILineSymbol.SYMBOL_NAME)); |
|
572 |
} |
|
573 |
|
|
574 |
fillSym.getOutline().setLineWidth(size*MapContext.CHANGEM[mapUnit]); |
|
575 |
|
|
576 |
csSym.toCartographicSize( |
|
577 |
viewPort, |
|
578 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
|
579 |
geomManager.createPoint( |
|
580 |
viewPort.getAdjustedExtent().getCenter(0), |
|
581 |
viewPort.getAdjustedExtent().getCenter(1), |
|
582 |
SUBTYPES.GEOM2D |
|
583 |
) |
|
584 |
); |
|
585 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth(); |
|
586 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
|
587 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
|
588 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
|
589 |
} |
|
590 |
|
|
591 |
} |
|
592 |
} |
|
593 |
} |
|
594 |
|
|
595 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/AbstractSymbolTestCase.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import junit.framework.TestCase; |
|
44 |
|
|
45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
46 |
|
|
47 |
|
|
48 |
public abstract class AbstractSymbolTestCase extends TestCase { |
|
49 |
protected Class symClazz; |
|
50 |
|
|
51 |
public AbstractSymbolTestCase(Class symClazz) { |
|
52 |
this.symClazz = symClazz; |
|
53 |
} |
|
54 |
|
|
55 |
public ISymbol newInstance() { |
|
56 |
try { |
|
57 |
return (ISymbol) symClazz.newInstance(); |
|
58 |
} catch (Exception e) { |
|
59 |
fail("Failed installing symbol to test "+symClazz.getName()); |
|
60 |
return null; |
|
61 |
} |
|
62 |
} |
|
63 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleFillSymbolTest.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
|
44 |
|
|
45 |
public class SimpleFillSymbolTest extends AbstractSymbolTestCase{ |
|
46 |
public SimpleFillSymbolTest() { |
|
47 |
super(SimpleFillSymbol.class); |
|
48 |
} |
|
49 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleLineSymbolTest.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol; |
|
44 |
|
|
45 |
public class SimpleLineSymbolTest extends AbstractSymbolTestCase{ |
|
46 |
public SimpleLineSymbolTest() { |
|
47 |
super(SimpleLineSymbol.class); |
|
48 |
} |
|
49 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawFills.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
import java.awt.Graphics2D; |
|
45 |
import java.awt.geom.AffineTransform; |
|
46 |
import java.awt.geom.Point2D; |
|
47 |
import java.awt.image.BufferedImage; |
|
48 |
import java.io.File; |
|
49 |
import java.io.IOException; |
|
50 |
import java.util.ArrayList; |
|
51 |
|
|
52 |
import javax.imageio.ImageIO; |
|
53 |
|
|
54 |
import junit.framework.TestCase; |
|
55 |
|
|
56 |
import org.gvsig.compat.CompatLocator; |
|
57 |
import org.gvsig.fmap.geom.Geometry; |
|
58 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
59 |
import org.gvsig.fmap.geom.GeometryManager; |
|
60 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
61 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
62 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
63 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
64 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.AllTests; |
|
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
67 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
68 |
import org.slf4j.Logger; |
|
69 |
import org.slf4j.LoggerFactory; |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* Integration test to test that Fill symbols always draw in the same |
|
74 |
* place respecting size constraints. |
|
75 |
* |
|
76 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
77 |
*/ |
|
78 |
public class TestDrawFills extends AbstractLibraryAutoInitTestCase { |
|
79 |
private GeometryManager geomManager; |
|
80 |
private static final Logger logger = LoggerFactory.getLogger(TestDrawFills.class); |
|
81 |
private final Dimension sz = new Dimension(400, 400); |
|
82 |
private org.gvsig.fmap.geom.primitive.Point centerP = null; |
|
83 |
private static final int OUTTER_TOLERANCE = 1; |
|
84 |
private static final int INNER_TOLERANCE = 1; |
|
85 |
private IFillSymbol[] symbols; |
|
86 |
private IDrawFillSymbol[] drawFillSymbols; |
|
87 |
private static ArrayList classesToTest; |
|
88 |
|
|
89 |
private static final double sizes[] = new double[] { |
|
90 |
200, |
|
91 |
100, |
|
92 |
50, |
|
93 |
30, |
|
94 |
16, |
|
95 |
5, |
|
96 |
3, |
|
97 |
2, |
|
98 |
// smaller sizes don't make any sense |
|
99 |
|
|
100 |
}; |
|
101 |
|
|
102 |
|
|
103 |
private static ArrayList getClassesToTest() { |
|
104 |
if (classesToTest == null) { |
|
105 |
classesToTest = new ArrayList(); |
|
106 |
// TestDrawFills.addSymbolToTest(DrawLineFillSymbol.class); |
|
107 |
// TestDrawFills.addSymbolToTest(DrawPictureFillSymbol.class); |
|
108 |
} |
|
109 |
|
|
110 |
return classesToTest; |
|
111 |
} |
|
112 |
|
|
113 |
public static void addSymbolToTest(Class symbolClass) { |
|
114 |
try { |
|
115 |
IDrawFillSymbol sym = (IDrawFillSymbol) symbolClass.newInstance(); |
|
116 |
} catch (InstantiationException e) { |
|
117 |
// TODO Auto-generated catch block |
|
118 |
fail("Instantiating class, cannot test a non-instantiable symbol"); |
|
119 |
} catch (IllegalAccessException e) { |
|
120 |
// TODO Auto-generated catch block |
|
121 |
fail("Class not instantiable"); |
|
122 |
} catch (ClassCastException ccEx) { |
|
123 |
fail("Cannot test a non symbol class"); |
|
124 |
} |
|
125 |
getClassesToTest().add(symbolClass); |
|
126 |
} |
|
127 |
|
|
128 |
protected void doSetUp() throws Exception { |
|
129 |
geomManager = GeometryLocator.getGeometryManager(); |
|
130 |
centerP = geomManager.createPoint(sz.width/2, sz.height/2, SUBTYPES.GEOM2D); |
|
131 |
|
|
132 |
this.drawFillSymbols = new IDrawFillSymbol[getClassesToTest().size()]; |
|
133 |
|
|
134 |
for (int i = 0; i < drawFillSymbols.length; i++) { |
|
135 |
drawFillSymbols[i] = (IDrawFillSymbol) ((Class) getClassesToTest().get(i)).newInstance(); |
|
136 |
} |
|
137 |
|
|
138 |
TestISymbol.addSymbols(); |
|
139 |
ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances(); |
|
140 |
// Filter the marker ones |
|
141 |
ArrayList symbols = new ArrayList(); |
|
142 |
|
|
143 |
for (int i = 0; i < allSymbols.length; i++) { |
|
144 |
if (allSymbols[i] instanceof IFillSymbol) { |
|
145 |
IFillSymbol sym = (IFillSymbol) allSymbols[i]; |
|
146 |
symbols.add(sym); |
|
147 |
|
|
148 |
} |
|
149 |
} |
|
150 |
this.symbols = (IFillSymbol[]) symbols.toArray(new IFillSymbol[symbols.size()]); |
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
} |
|
155 |
|
|
156 |
public void testDraw() { |
|
157 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
|
158 |
|
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
public final void testNullColorAvoidsFilling() throws CreateGeometryException { |
|
163 |
|
|
164 |
for (int i = 0; i < symbols.length; i++) { |
|
165 |
|
|
166 |
for (int s = 0; s < sizes.length; s++) { |
|
167 |
|
|
168 |
BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width,sz.height, BufferedImage.TYPE_INT_ARGB); |
|
169 |
// the graphics for the image, so we can draw onto the buffered image |
|
170 |
Graphics2D g = bi.createGraphics(); |
|
171 |
|
|
172 |
IFillSymbol newSymbol = symbols[i]; |
|
173 |
newSymbol.setFillColor(null); |
|
174 |
newSymbol.setOutline(null); |
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
String name = newSymbol.getClass().getName().substring( |
|
180 |
newSymbol.getClass().getName().lastIndexOf('.')+1, |
|
181 |
newSymbol.getClass().getName().length()); |
|
182 |
|
|
183 |
|
|
184 |
Point2D firstPoint = new Point2D.Float((float)(centerP.getX()-sizes[s]/2-3),(float)(centerP.getY()-sizes[s]/2-3)); |
|
185 |
Point2D lastPoint = new Point2D.Float((float)(centerP.getX()+sizes[s]/2+3),(float)(centerP.getY()+sizes[s]/2+3)); |
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
GeneralPathX gpx = new GeneralPathX(); |
|
190 |
|
|
191 |
gpx.moveTo((float)firstPoint.getX(),(float) firstPoint.getY()); |
|
192 |
gpx.lineTo((float)lastPoint.getX(),(float) firstPoint.getY()); |
|
193 |
gpx.lineTo((float)lastPoint.getX(),(float) lastPoint.getY()); |
|
194 |
gpx.lineTo((float)firstPoint.getX(),(float) lastPoint.getY()); |
|
195 |
gpx.lineTo((float)firstPoint.getX(), (float)firstPoint.getY()); |
|
196 |
gpx.closePath(); |
|
197 |
|
|
198 |
|
|
199 |
for (int j = 0; j < drawFillSymbols.length; j++) { |
|
200 |
if (drawFillSymbols[j].isSuitableFor(newSymbol)) { |
|
201 |
newSymbol = drawFillSymbols[j].makeSymbolTransparent(newSymbol); |
|
202 |
break; |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
newSymbol.draw(g, new AffineTransform(), geomManager.createSurface(gpx, SUBTYPES.GEOM2D), null, null); |
|
208 |
|
|
209 |
try { |
|
210 |
|
|
211 |
File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/"); |
|
212 |
if (!dstDir.exists()) dstDir.mkdir(); |
|
213 |
ImageIO.write(bi, "png", |
|
214 |
new File(dstDir.getAbsoluteFile()+File.separator+ |
|
215 |
name+"_size_"+sizes[s] |
|
216 |
+".png")); |
|
217 |
} catch (IOException e) { |
|
218 |
e.printStackTrace(); |
|
219 |
fail(); |
|
220 |
} |
|
221 |
|
|
222 |
for (int j = 0; j < bi.getWidth(); j++) { |
|
223 |
for (int k = 0; k < bi.getHeight(); k++) { |
|
224 |
if (isInsideShape(geomManager.createSurface(gpx, SUBTYPES.GEOM2D), j, k)) { |
|
225 |
assertEquals("Failed, the fill is being painted when the color is null",bi.getRGB(j, k),0); |
|
226 |
|
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
private boolean isInsideShape(Geometry geom, int x, int y) { |
|
237 |
Point2D p = new Point2D.Float(x,y); |
|
238 |
if(geom.contains(p))return true; |
|
239 |
return false; |
|
240 |
} |
|
241 |
|
|
242 |
|
|
243 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawLines.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Dimension; |
|
45 |
import java.awt.Graphics2D; |
|
46 |
import java.awt.geom.AffineTransform; |
|
47 |
import java.awt.geom.Point2D; |
|
48 |
import java.awt.image.BufferedImage; |
|
49 |
import java.util.ArrayList; |
|
50 |
|
|
51 |
import junit.framework.TestCase; |
|
52 |
|
|
53 |
import org.gvsig.compat.CompatLocator; |
|
54 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
55 |
import org.gvsig.fmap.geom.GeometryManager; |
|
56 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
57 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
58 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
59 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
60 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
61 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
62 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
63 |
import org.slf4j.Logger; |
|
64 |
import org.slf4j.LoggerFactory; |
|
65 |
|
|
66 |
/** |
|
67 |
* Integration test to test that Line symbols always draw in the same |
|
68 |
* place respecting size constraints. |
|
69 |
* |
|
70 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
71 |
*/ |
|
72 |
public class TestDrawLines extends AbstractLibraryAutoInitTestCase { |
|
73 |
private GeometryManager geomManager; |
|
74 |
private static final Logger logger = LoggerFactory.getLogger(TestDrawLines.class); |
|
75 |
private ILineSymbol[] symbols; |
|
76 |
private final Dimension sz = new Dimension(401, 401); |
|
77 |
private Curve centerL; |
|
78 |
|
|
79 |
protected void doSetUp() throws Exception { |
|
80 |
geomManager = GeometryLocator.getGeometryManager(); |
|
81 |
|
|
82 |
GeneralPathX gp = new GeneralPathX(); |
|
83 |
gp.moveTo(0, sz.height / 2 ); |
|
84 |
gp.lineTo(sz.width, sz.height /2 ); |
|
85 |
|
|
86 |
try { |
|
87 |
centerL = geomManager.createCurve(gp, SUBTYPES.GEOM2D); |
|
88 |
} catch (CreateGeometryException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
|
|
92 |
ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances(); |
|
93 |
// Filter the marker ones |
|
94 |
ArrayList symbols = new ArrayList(); |
|
95 |
|
|
96 |
for (int i = 0; i < allSymbols.length; i++) { |
|
97 |
if (allSymbols[i] instanceof ILineSymbol) { |
|
98 |
ILineSymbol sym = (ILineSymbol) allSymbols[i]; |
|
99 |
symbols.add(sym); |
|
100 |
|
|
101 |
} |
|
102 |
} |
|
103 |
this.symbols = (ILineSymbol[]) symbols.toArray(new ILineSymbol[symbols.size()]); |
|
104 |
} |
|
105 |
private static final double sizes[] = new double[] { |
|
106 |
300, |
|
107 |
250, |
|
108 |
225, |
|
109 |
200, |
|
110 |
100, |
|
111 |
50, |
|
112 |
30, |
|
113 |
15, |
|
114 |
5, |
|
115 |
3, |
|
116 |
2, |
|
117 |
1, |
|
118 |
// smaller sizes don't make any sense |
|
119 |
}; |
|
120 |
|
|
121 |
private static final float INNER_TOLERANCE = 1F; |
|
122 |
private static final float OUTTER_TOLERANCE = 1F; |
|
123 |
|
|
124 |
public void testDrawingSize() { |
|
125 |
for (int i = 0; i < symbols.length; i++) { |
|
126 |
for (int j = 0; j < sizes.length; j++) { |
|
127 |
// new blank buffered image |
|
128 |
|
|
129 |
BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_ARGB); |
|
130 |
|
|
131 |
// the graphics for the image, so we can draw onto the buffered image |
|
132 |
Graphics2D g = bi.createGraphics(); |
|
133 |
|
|
134 |
ILineSymbol testSymbol = symbols[i]; |
|
135 |
testSymbol.setLineColor(Color.YELLOW); |
|
136 |
testSymbol.setLineWidth(sizes[j]); |
|
137 |
String name = testSymbol.getClass().getName().substring( |
|
138 |
testSymbol.getClass().getName().lastIndexOf('.')+1, |
|
139 |
testSymbol.getClass().getName().length()); |
|
140 |
|
|
141 |
Point2D upperP1 = new Point2D.Double(0, centerL.getBounds().getY() - sizes[j]*0.5); |
|
142 |
Point2D upperP2 = new Point2D.Double(centerL.getBounds().getWidth(), centerL.getBounds().getY() - sizes[j]*0.5); |
|
143 |
GeneralPathX gpUp = new GeneralPathX(); |
|
144 |
gpUp.moveTo(upperP1.getX(), upperP1.getY()); |
|
145 |
gpUp.lineTo(upperP2.getX(), upperP2.getY()); |
|
146 |
|
|
147 |
|
|
148 |
GeneralPathX gpDown = new GeneralPathX(); |
|
149 |
Point2D lowerP1 = new Point2D.Double(0, centerL.getBounds().getY() + sizes[j]*0.5); |
|
150 |
Point2D lowerP2 = new Point2D.Double(centerL.getBounds().getWidth(), centerL.getBounds().getY() + sizes[j]*0.5); |
|
151 |
gpDown.moveTo(lowerP1.getX(), lowerP1.getY()); |
|
152 |
gpDown.lineTo(lowerP2.getX(), lowerP2.getY()); |
|
153 |
|
|
154 |
|
|
155 |
testSymbol.draw(g, new AffineTransform(), centerL, null, null); |
|
156 |
|
|
157 |
/// per a borrar |
|
158 |
// g.setStroke(new BasicStroke()); |
|
159 |
// g.setColor(Color.RED); |
|
160 |
// |
|
161 |
// g.draw(gpUp); |
|
162 |
// |
|
163 |
// g.setColor(Color.BLUE); |
|
164 |
// g.draw(gpDown); |
|
165 |
// |
|
166 |
// try { |
|
167 |
// |
|
168 |
// File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/"); |
|
169 |
// if (!dstDir.exists()) dstDir.mkdir(); |
|
170 |
// ImageIO.write(bi, "png", |
|
171 |
// new File(dstDir.getAbsoluteFile()+File.separator+ |
|
172 |
// name+"_size_"+sizes[j] |
|
173 |
// +".png")); |
|
174 |
// } catch (IOException e) { |
|
175 |
// e.printStackTrace(); |
|
176 |
// fail(); |
|
177 |
// } |
|
178 |
/// fi per a borrar |
|
179 |
assertFalse("fails sizing line, too big ("+name+", "+sizes[j]+"px)", isOutsideRect(bi, upperP1, lowerP1, OUTTER_TOLERANCE )); |
|
180 |
assertTrue("fails sizing line, too small ("+name+", "+sizes[j]+"px) \n" + |
|
181 |
"\t - forgot to enable ANTIALIASING?", fitsInsideRect(bi, upperP1, lowerP1, INNER_TOLERANCE)); |
|
182 |
|
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
private boolean isOutsideRect(BufferedImage bi, Point2D upper, Point2D lower, float outterTolerance) { |
|
188 |
for (int i = 0; i < bi.getWidth(); i++) { |
|
189 |
for (int j = 0; j < bi.getHeight(); j++) { |
|
190 |
if (j<upper.getY()-outterTolerance && j>lower.getY()+outterTolerance) |
|
191 |
if (bi.getRGB(i,j) != 0) { |
|
192 |
System.out.println("too big In pixel ("+i+", "+j+")"); |
|
193 |
return true; |
|
194 |
} |
|
195 |
|
|
196 |
} |
|
197 |
} |
|
198 |
return false; |
|
199 |
} |
|
200 |
|
|
201 |
private boolean fitsInsideRect(BufferedImage bi,Point2D upper, Point2D lower , float innerTolerance) { |
|
202 |
for (int i = 0; i < bi.getWidth(); i++) { |
|
203 |
for (int j = 0; j < bi.getHeight(); j++) { |
|
204 |
if (j<upper.getY()+innerTolerance && j>lower.getY()-innerTolerance) |
|
205 |
if (bi.getRGB(i,j) == 0) { |
|
206 |
System.out.println("does not fit big In pixel ("+i+", "+j+")"); |
|
207 |
return false; |
|
208 |
} |
|
209 |
|
|
210 |
} |
|
211 |
} |
|
212 |
return true; |
|
213 |
} |
|
214 |
|
|
215 |
} |
tags/v2_0_0_Build_2021/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestMultiLayerSymbol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.util.Random; |
|
44 |
|
|
45 |
import junit.framework.TestCase; |
|
46 |
|
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
48 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
49 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
|
50 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
|
51 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
52 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.MultiLayerLineSymbol; |
|
53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol; |
|
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.MultiLayerMarkerSymbol; |
|
56 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
|
57 |
|
|
58 |
/** |
|
59 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
60 |
*/ |
|
61 |
public class TestMultiLayerSymbol extends TestCase { |
|
62 |
ISymbol[] symbols; |
|
63 |
|
|
64 |
public void setUp() { |
|
65 |
symbols = TestISymbol.getNewSymbolInstances(); |
|
66 |
} |
|
67 |
|
|
68 |
public void testLayerTypeAdditionFor_MARKERS() { |
|
69 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
70 |
for (int i = 0; i < symbols.length; i++) { |
|
71 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
72 |
try { |
|
73 |
IMarkerSymbol marker = (IMarkerSymbol) symbols[i]; |
|
74 |
multiLayer.addLayer(marker); |
|
75 |
} catch (Exception e) { |
|
76 |
fail("MultiLayerMarkerSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
77 |
} |
|
78 |
} else { |
|
79 |
try { |
|
80 |
multiLayer.addLayer(symbols[i]); |
|
81 |
fail("MultiLayerMarkerSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
82 |
} catch (ClassCastException ccEx){ |
|
83 |
// this is right |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
public void testLayerTypeAdditionFor_LINES() { |
|
90 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
91 |
for (int i = 0; i < symbols.length; i++) { |
|
92 |
if (symbols[i] instanceof ILineSymbol) { |
|
93 |
try { |
|
94 |
ILineSymbol line = (ILineSymbol) symbols[i]; |
|
95 |
multiLayer.addLayer(line); |
|
96 |
} catch (Exception e) { |
|
97 |
fail("MultiLayerLineSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
98 |
} |
|
99 |
} else { |
|
100 |
try { |
|
101 |
multiLayer.addLayer(symbols[i]); |
|
102 |
fail("MultiLayerLineSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
103 |
} catch (ClassCastException ccEx){ |
|
104 |
// this is right |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
public void testLayerTypeAdditionFor_FILL() { |
|
111 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
112 |
for (int i = 0; i < symbols.length; i++) { |
|
113 |
if (symbols[i] instanceof IFillSymbol) { |
|
114 |
try { |
|
115 |
IFillSymbol fill = (IFillSymbol) symbols[i]; |
|
116 |
multiLayer.addLayer(fill); |
|
117 |
} catch (Exception e) { |
|
118 |
fail("MultiLayerLineSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
119 |
} |
|
120 |
} else { |
|
121 |
try { |
|
122 |
multiLayer.addLayer(symbols[i]); |
|
123 |
fail("MultiLayerLineSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
124 |
} catch (ClassCastException ccEx){ |
|
125 |
// this is right |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
public void testLayerAdditionPositionConsistencyMultiLayer_MARKER_Symbol() { |
|
132 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
133 |
IMarkerSymbol sym1 = new SimpleMarkerSymbol(); |
|
134 |
IMarkerSymbol sym2 = new SimpleMarkerSymbol(); |
|
135 |
sym1.setDescription("sym1"); |
|
136 |
sym2.setDescription("sym2"); |
|
137 |
try { |
|
138 |
multiLayer.addLayer(sym1, 0); |
|
139 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
140 |
fail("MultiLayer should always accept adding at index 0, even when it is empty"); |
|
141 |
} |
|
142 |
|
|
143 |
try { |
|
144 |
multiLayer.addLayer(sym2, 3); |
|
145 |
fail("MultiLayer cannot accept adding at an index larger than the amount of layers already contained"); |
|
146 |
} catch (IndexOutOfBoundsException ioobEx){ |
|
147 |
// this is right |
|
148 |
} |
|
149 |
|
|
150 |
try { |
|
151 |
multiLayer.addLayer(sym1, multiLayer.getLayerCount()); |
|
152 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
153 |
fail("MultiLayer should accept adding at index less or equal to the layer count"); |
|
154 |
} |
|
155 |
|
|
156 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(1).getDescription().equals("sym2")); |
|
157 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(0).getDescription().equals("sym1")); |
|
158 |
} |
|
159 |
|
|
160 |
public void testLayerAdditionPositionConsistencyMultiLayer_LINE_Symbol() { |
|
161 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
162 |
ILineSymbol layer1 = new SimpleLineSymbol(); |
|
163 |
ILineSymbol layer2 = new SimpleLineSymbol(); |
|
164 |
layer1.setDescription("layer1"); |
|
165 |
layer2.setDescription("layer2"); |
|
166 |
|
|
167 |
try { |
|
168 |
multiLayer.addLayer(layer1, 0); |
|
169 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
170 |
fail("MultiLayer should always accept adding at index 0, even when it is empty"); |
|
171 |
} |
|
172 |
|
|
173 |
try { |
|
174 |
multiLayer.addLayer(layer2, 3); |
|
175 |
fail("MultiLayer cannot accept adding at an index larger than the amount of layers already contained"); |
|
176 |
} catch (IndexOutOfBoundsException ioobEx){ |
|
177 |
// this is right |
|
178 |
} |
|
179 |
|
|
180 |
try { |
|
181 |
multiLayer.addLayer(layer2, multiLayer.getLayerCount()); |
|
182 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
183 |
fail("MultiLayer should accept adding at index less or equal to the layer count"); |
|
184 |
} |
|
185 |
|
|
186 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(1).getDescription().equals("layer2")); |
|
187 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(0).getDescription().equals("layer1")); |
|
188 |
} |
|
189 |
|
|
190 |
public void testLayerAdditionPositionConsistencyMultiLayer_FILL_Symbol() { |
|
191 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
192 |
IFillSymbol layer1 = new SimpleFillSymbol(); |
|
193 |
IFillSymbol layer2 = new SimpleFillSymbol(); |
|
194 |
layer1.setDescription("layer1"); |
|
195 |
layer2.setDescription("layer2"); |
|
196 |
|
|
197 |
try { |
|
198 |
multiLayer.addLayer(layer1, 0); |
Also available in: Unified diff