Revision 33006

View differences:

tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
                      http://maven.apache.org/maven-v4_0_0.xsd">
6
	<modelVersion>4.0.0</modelVersion>
7
	<groupId>org.gvsig</groupId>
8
	<artifactId>org.gvsig.fmap.mapcontext</artifactId>
9
	<packaging>jar</packaging>
10
	<version>2.0-SNAPSHOT</version>
11
	<name>libFMap_mapcontext</name>
12
	<url>http://gvsig.org</url>
13
	<parent>
14
		<groupId>org.gvsig</groupId>
15
		<artifactId>gvsig-base-library-pom</artifactId>
16
		<version>2.0-SNAPSHOT</version>
17
	</parent>	
18
	<distributionManagement>
19
		<site>
20
			<id>gvsig-repository</id>
21
			<url>${site-repository}/</url>
22
		</site>
23
	</distributionManagement>
24

  
25
	<dependencies>
26
		<dependency>
27
			<groupId>org.gvsig</groupId>
28
			<artifactId>org.gvsig.tools.lib</artifactId>
29
		</dependency>
30
		
31
		<dependency>
32
			<groupId>org.gvsig</groupId>
33
			<artifactId>org.gvsig.tools.lib</artifactId>
34
			<classifier>tests</classifier>
35
			<scope>test</scope>
36
		</dependency>
37

  
38
		<dependency>
39
			<groupId>org.gvsig</groupId>
40
			<artifactId>org.gvsig.compat</artifactId>
41
			<version>2.0-SNAPSHOT</version>
42
		</dependency>
43
		<dependency>
44
			<groupId>org.gvsig</groupId>
45
			<artifactId>org.gvsig.projection</artifactId>
46
			<version>2.0-SNAPSHOT</version>
47
		</dependency>
48
		<dependency>
49
			<groupId>org.gvsig</groupId>
50
			<artifactId>org.gvsig.fmap.geometry</artifactId>
51
			<version>2.0-SNAPSHOT</version>
52
		</dependency>
53
		<dependency>
54
			<groupId>org.gvsig</groupId>
55
			<artifactId>org.gvsig.fmap.geometry</artifactId>
56
			<version>2.0-SNAPSHOT</version>
57
			<classifier>operation</classifier>
58
		</dependency>
59
		<dependency>
60
			<groupId>org.gvsig</groupId>
61
			<artifactId>org.gvsig.fmap.dal</artifactId>
62
			<version>2.0-SNAPSHOT</version>
63
		</dependency>
64
		<dependency>
65
			<groupId>com.vividsolutions</groupId>
66
			<artifactId>jts</artifactId>
67
		</dependency>
68
		<dependency>
69
			<groupId>easymock</groupId>
70
			<artifactId>easymock</artifactId>
71
			<version>1.2_Java1.3</version>
72
			<scope>test</scope>
73
		</dependency>
74
		
75
	</dependencies>
76
	<properties>
77
		<build-dir>${basedir}/../build</build-dir>
78
	</properties>
79
	<build>
80
		<sourceDirectory>src</sourceDirectory>
81
		<testSourceDirectory>src-test</testSourceDirectory>
82
		<resources>
83
			<resource>
84
				<directory>src</directory>
85
				<includes>
86
					<include>**/*.gif</include>
87
					<include>**/*.png</include>
88
					<include>**/*.PNG</include>
89
					<include> **/*.bmp</include>
90
					<include> **/*.jpg</include>
91
					<include> **/*.jpeg</include>
92
				</includes>
93
			</resource>
94
		</resources>
95
		<testResources>
96
			<testResource>
97
				<directory>resources-test</directory>
98
			</testResource>
99
		</testResources>	
100
	</build>
101
	<profiles>
102
		<profile>
103
			<id>se</id>
104
			<activation>
105
				<activeByDefault>true</activeByDefault>
106
			</activation>
107
			<dependencies>
108
				<dependency>
109
					<groupId>org.gvsig</groupId>
110
					<artifactId>org.gvsig.tools.lib</artifactId>
111
					<classifier>tests</classifier>
112
					<scope>test</scope>
113
				</dependency>
114

  
115
				<dependency>
116
					<groupId>org.gvsig</groupId>
117
					<artifactId>org.gvsig.compat</artifactId>
118
					<version>2.0-SNAPSHOT</version>
119
					<classifier>se</classifier>
120
					<scope>test</scope>
121
				</dependency>
122
				<dependency>
123
					<groupId>org.gvsig</groupId>
124
					<artifactId>org.gvsig.projection</artifactId>
125
					<version>2.0-SNAPSHOT</version>
126
					<classifier>cresques-impl</classifier>
127
					<scope>test</scope>
128
				</dependency>
129
				<dependency>
130
					<groupId>org.gvsig</groupId>
131
					<artifactId>org.gvsig.fmap.geometry</artifactId>
132
					<version>2.0-SNAPSHOT</version>
133
					<classifier>impl</classifier>
134
					<scope>test</scope>
135
				</dependency>
136
				<dependency>
137
					<groupId>org.gvsig</groupId>
138
					<artifactId>org.gvsig.fmap.dal</artifactId>
139
					<version>2.0-SNAPSHOT</version>
140
					<classifier>spi</classifier>
141
					<scope>test</scope>
142
				</dependency>
143
				<dependency>
144
					<groupId>org.gvsig</groupId>
145
					<artifactId>org.gvsig.fmap.dal</artifactId>
146
					<version>2.0-SNAPSHOT</version>
147
					<classifier>impl</classifier>
148
					<scope>test</scope>
149
				</dependency>
150
				<dependency>
151
					<groupId>org.gvsig</groupId>
152
					<artifactId>org.gvsig.metadata</artifactId>
153
					<version>2.0-SNAPSHOT</version>
154
					<classifier>simple</classifier>
155
					<scope>test</scope>
156
				</dependency>	
157
				<dependency>
158
					<groupId>org.geotools</groupId>
159
					<artifactId>gt2-main</artifactId>
160
					<scope>test</scope>
161
				</dependency>
162
				<dependency>
163
					<groupId>org.geotools</groupId>
164
					<artifactId>gt2-legacy</artifactId>
165
				</dependency>
166
				<dependency>
167
					<groupId>org.opengis</groupId>
168
				    <artifactId>geoapi</artifactId>
169
					<scope>test</scope>
170
				</dependency>
171
							
172
			</dependencies>
173
			<build>
174

  
175
				<plugins>
176
					<plugin>
177
						<groupId>org.apache.maven.plugins</groupId>
178
						<artifactId>maven-compiler-plugin</artifactId>
179
						<configuration>
180
							<source>1.4</source>
181
							<target>1.4</target>
182
							<!-- put your configurations here -->
183
							<encoding>ISO-8859-1</encoding>
184
						</configuration>
185
					</plugin>
186
					<plugin>
187
						<groupId>org.apache.maven.plugins</groupId>
188
						<artifactId>maven-jar-plugin</artifactId>
189
						<!--
190
							Generates a jar file only with the mapcontext API
191
							TODO: make a good configuration of excludes and 
192
							includes, when the api and implementation of
193
							the mapcontext library would be performed. 
194
						-->
195
						<configuration>
196
						  <excludes>
197
							<exclude>org/gvsig/fmap/geom/**</exclude>
198
						  </excludes>
199
						</configuration>		
200
						<executions>
201
							<!--
202
								Generates a jar file only with the mapcontext implementation
203
							-->
204
							<execution>
205
								<id>impl</id>
206
								<phase>package</phase>
207
								<goals>
208
									<goal>jar</goal>
209
								</goals>
210
								<configuration>
211
									<classifier>impl</classifier>
212
									<excludes>
213
										<exclude>**/**</exclude>
214
									</excludes>
215
								</configuration>
216
							</execution>
217
							<!--
218
								Generates a jar file only with the mapcontext geometries operations
219
							-->
220
							<execution>
221
								<id>operation</id>
222
								<phase>package</phase>
223
								<goals>
224
									<goal>jar</goal>
225
								</goals>
226
								<configuration>
227
									<classifier>operation</classifier>
228
									<excludes>
229
										<exclude>NONE</exclude>
230
									</excludes>
231
									<includes>
232
										<include>org/gvsig/fmap/geom/**</include>
233
									</includes>
234
								</configuration>
235
							</execution>
236
							<execution>
237
								<goals>
238
									<goal>test-jar</goal>
239
								</goals>
240
							</execution>
241
						</executions>
242
					</plugin>
243
					<plugin>
244
						<artifactId>maven-antrun-plugin</artifactId>
245
						<executions>
246
							<execution>
247
								<id>services</id>
248
								<phase>package</phase>
249
								<goals>
250
									<goal>run</goal>
251
								</goals>
252
								<configuration>
253
									<tasks>
254
										<jar destfile="${project.build.directory}/${project.build.finalName}.jar"
255
											update="true">
256
											<fileset dir="${basedir}/resources/api" />
257
										</jar>
258
										<jar destfile="${project.build.directory}/${project.build.finalName}-impl.jar"
259
											update="true">
260
											<fileset dir="${basedir}/resources/impl" />
261
										</jar>
262
										<jar destfile="${project.build.directory}/${project.build.finalName}-operation.jar"
263
											update="true">
264
											<fileset dir="${basedir}/resources/operation" />
265
										</jar>
266
									</tasks>
267
								</configuration>
268
							</execution>
269
						</executions>
270
					</plugin>
271
					<plugin>
272
						<groupId>org.apache.maven.plugins</groupId>
273
						<artifactId>maven-surefire-plugin</artifactId>
274
						<configuration>
275
							<additionalClasspathElements>
276
								<additionalClasspathElement>${basedir}/resources/api</additionalClasspathElement>
277
								<additionalClasspathElement>${basedir}/resources/impl</additionalClasspathElement>
278
								<additionalClasspathElement>${basedir}/resources/operation</additionalClasspathElement>
279
							</additionalClasspathElements>
280
						</configuration>
281
					</plugin>
282
				</plugins>
283
			</build>
284

  
285
		</profile>
286
		<profile>
287
			<id>cdc</id>
288
			<activation>
289
				<activeByDefault>false</activeByDefault>
290
			</activation>
291
			
292
			<dependencies>
293
				<dependency>
294
					<groupId>org.gvsig</groupId>
295
					<artifactId>org.gvsig.tools.lib</artifactId>
296
					<classifier>tests</classifier>
297
					<scope>test</scope>
298
				</dependency>
299
				<dependency>
300
				  <groupId>org.gvsig.mobile</groupId>
301
				  <artifactId>org.gvsig.mobile.compat</artifactId>
302
				  <version>2.0-SNAPSHOT</version>
303
				  <scope>test</scope>
304
				</dependency>
305
				<dependency>
306
					<groupId>org.gvsig.mobile</groupId>
307
					<artifactId>org.gvsig.mobile.libProjection</artifactId>
308
					<version>0.0.1-SNAPSHOT</version>
309
					<scope>test</scope>
310
				</dependency>
311
<dependency>
312
					<groupId>org.gvsig</groupId>
313
					<artifactId>org.gvsig.fmap.geometry</artifactId>
314
					<version>2.0-SNAPSHOT</version>
315
					<classifier>impl</classifier>
316
					<scope>test</scope>
317
				</dependency>
318
				
319
				<dependency>
320
					<groupId>org.gvsig</groupId>
321
					<artifactId>org.gvsig.fmap.dal</artifactId>
322
					<version>2.0-SNAPSHOT</version>
323
					<classifier>spi</classifier>
324
					<scope>test</scope>
325
				</dependency>
326
				<dependency>
327
					<groupId>org.gvsig</groupId>
328
					<artifactId>org.gvsig.fmap.dal</artifactId>
329
					<version>2.0-SNAPSHOT</version>
330
					<classifier>impl</classifier>
331
					<scope>test</scope>
332
				</dependency>
333
				
334
				<dependency>
335
					<groupId>org.gvsig</groupId>
336
					<artifactId>org.gvsig.metadata</artifactId>
337
					<version>2.0-SNAPSHOT</version>
338
					<classifier>simple</classifier>
339
					<scope>test</scope>
340
				</dependency>
341
			</dependencies>
342

  
343
			<build>
344
				<plugins>
345
					<plugin>
346
						<groupId>org.apache.maven.plugins</groupId>
347
						<artifactId>maven-compiler-plugin</artifactId>
348
						<configuration>
349
							<source>1.4</source>
350
							<target>1.4</target>
351
							<!-- put your configurations here -->
352
							<encoding>ISO-8859-1</encoding>
353
						</configuration>
354
					</plugin>
355
					<plugin>
356
						<groupId>org.apache.maven.plugins</groupId>
357
						<artifactId>maven-jar-plugin</artifactId>
358
						<!--
359
							Generates a jar file only with the mapcontext API
360
							TODO: make a good configuration of excludes and 
361
							includes, when the api and implementation of
362
							the mapcontext library would be performed. 
363
						-->
364
						<configuration>
365
						  <excludes>
366
							<exclude>org/gvsig/fmap/geom/**</exclude>
367
						  </excludes>
368
						</configuration>		
369
						<executions>
370
							<!--
371
								Generates a jar file only with the mapcontext implementation
372
							-->
373
							<execution>
374
								<id>impl</id>
375
								<phase>package</phase>
376
								<goals>
377
									<goal>jar</goal>
378
								</goals>
379
								<configuration>
380
									<classifier>impl</classifier>
381
									<excludes>
382
										<exclude>**/**</exclude>
383
									</excludes>
384
								</configuration>
385
							</execution>
386
							<!--
387
								Generates a jar file only with the mapcontext geometries operations
388
							-->
389
							<execution>
390
								<id>operation</id>
391
								<phase>package</phase>
392
								<goals>
393
									<goal>jar</goal>
394
								</goals>
395
								<configuration>
396
									<classifier>operation</classifier>
397
									<excludes>
398
										<exclude>NONE</exclude>
399
									</excludes>
400
									<includes>
401
										<include>org/gvsig/fmap/geom/**</include>
402
									</includes>
403
								</configuration>
404
							</execution>
405
						</executions>
406
					</plugin>
407
					<plugin>
408
						<artifactId>maven-antrun-plugin</artifactId>
409
						<executions>
410
							<execution>
411
								<id>services</id>
412
								<phase>package</phase>
413
								<goals>
414
									<goal>run</goal>
415
								</goals>
416
								<configuration>
417
									<tasks>
418
										<jar destfile="${project.build.directory}/${project.build.finalName}.jar"
419
											update="true">
420
											<fileset dir="${basedir}/resources/api" />
421
										</jar>
422
										<jar destfile="${project.build.directory}/${project.build.finalName}-impl.jar"
423
											update="true">
424
											<fileset dir="${basedir}/resources/impl" />
425
										</jar>
426
										<jar destfile="${project.build.directory}/${project.build.finalName}-operation.jar"
427
											update="true">
428
											<fileset dir="${basedir}/resources/operation" />
429
										</jar>
430
									</tasks>
431
								</configuration>
432
							</execution>
433
						</executions>
434
					</plugin>
435
					<plugin>
436
						<groupId>org.apache.maven.plugins</groupId>
437
						<artifactId>maven-surefire-plugin</artifactId>
438
						<configuration>
439
							<additionalClasspathElements>
440
								<additionalClasspathElement>${basedir}/resources/api</additionalClasspathElement>
441
								<additionalClasspathElement>${basedir}/resources/impl</additionalClasspathElement>
442
								<additionalClasspathElement>${basedir}/resources/operation</additionalClasspathElement>
443
							</additionalClasspathElements>
444
						</configuration>
445
					</plugin>
446
				</plugins>
447
			</build>
448

  
449
		</profile>
450
		<profile>
451
			<id>eclipse-project</id>
452
			<build>
453
				<defaultGoal>antrun:run</defaultGoal>
454
				<plugins>
455
					<plugin>
456
						<artifactId>maven-antrun-plugin</artifactId>
457
						<configuration>
458
							<tasks>
459
								<ant antfile="${build-dir}/ant-tasks/eclipse-tasks.xml"
460
									target="eclipse.all"/>
461
							</tasks>
462
						</configuration>
463
					</plugin>
464
				</plugins>
465
			</build>				
466
		</profile>		
467
	</profiles>
468
</project>
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/resources/api/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.mapcontext.MapContextLibrary
2
org.gvsig.fmap.mapcontext.impl.MapContextImplLibrary
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/resources/operation/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.geom.operation.MapContextGeomOperationsLibrary
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/ExtentHistoryTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext;
28

  
29
import java.awt.Rectangle;
30
import java.awt.geom.Rectangle2D;
31

  
32
import junit.framework.TestCase;
33

  
34
/**
35
 * Unit tests for the class {@link ExtentHistory}.
36
 * 
37
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
38
 */
39
public class ExtentHistoryTest extends TestCase {
40

  
41
	protected void setUp() throws Exception {
42
		super.setUp();
43
	}
44

  
45
	/**
46
	 * Test method for
47
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#put(java.awt.geom.Rectangle2D)}
48
	 * .
49
	 */
50
	public void testPut() {
51
		ExtentHistory history = new ExtentHistory();
52

  
53
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
54
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
55
		Rectangle2D rectangle3 = new Rectangle2D.Double(3, 3, 4, 4);
56
		history.put(rectangle3);
57
		history.put(rectangle2);
58
		history.put(rectangle);
59

  
60
		assertEquals(rectangle, history.get());
61

  
62
		history = new ExtentHistory(2);
63

  
64
		history.put(rectangle);
65
		history.put(rectangle2);
66
		history.put(rectangle3);
67

  
68
		assertEquals(rectangle3, history.get());
69
	}
70

  
71
	/**
72
	 * Test method for
73
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasPrevious()}.
74
	 */
75
	public void testHasPrevious() {
76
		ExtentHistory history = new ExtentHistory();
77

  
78
		assertFalse(history.hasPrevious());
79

  
80
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
81
		history.put(rectangle);
82

  
83
		assertTrue(history.hasPrevious());
84

  
85
		history.removePrev();
86
		assertFalse(history.hasPrevious());
87
	}
88

  
89
	/**
90
	 * Test method for {@link org.gvsig.fmap.mapcontext.ExtentHistory#get()}.
91
	 */
92
	public void testGet() {
93
		ExtentHistory history = new ExtentHistory();
94

  
95
		assertNull("The ExtentHistory has got an element without adding one",
96
				history.get());
97

  
98
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
99
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
100

  
101
		history.put(rectangle);
102
		assertEquals(rectangle, history.get());
103

  
104
		history.put(rectangle2);
105
		assertEquals(rectangle2, history.get());
106

  
107
		history.removePrev();
108
		assertEquals(rectangle, history.get());
109

  
110
		history.removePrev();
111
		assertNull("The ExtentHistory has got an element, "
112
				+ "but all have been previously removed", history.get());
113
	}
114

  
115
	/**
116
	 * Test method for
117
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#removePrev()}.
118
	 */
119
	public void testRemovePrev() {
120
		ExtentHistory history = new ExtentHistory();
121

  
122
		assertNull(
123
				"The ExtentHistory allows removing an element without adding "
124
						+ "at least one", history.removePrev());
125

  
126
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
127
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
128

  
129
		history.put(rectangle);
130
		history.put(rectangle2);
131

  
132
		history.removePrev();
133
		assertEquals(rectangle, history.get());
134

  
135
		history.removePrev();
136
		assertNull("The ExtentHistory allows to remove the last element, "
137
				+ "but all have been previously removed", history.removePrev());
138
	}
139
}
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/rendering/symbol/DummyVectorLegend.java
1
package org.gvsig.fmap.mapcontext.rendering.symbol;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.image.BufferedImage;
6
import java.util.Iterator;
7
import java.util.Map;
8

  
9
import org.cresques.cts.ICoordTrans;
10
import org.gvsig.compat.print.PrintAttributes;
11
import org.gvsig.fmap.dal.exception.DataException;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureSet;
14
import org.gvsig.fmap.dal.feature.FeatureStore;
15
import org.gvsig.fmap.geom.Geometry.TYPES;
16
import org.gvsig.fmap.mapcontext.ViewPort;
17
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
18
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
19
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
20
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
21
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
22
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
23
import org.gvsig.tools.ToolsLocator;
24
import org.gvsig.tools.dynobject.DynStruct;
25
import org.gvsig.tools.observer.Observer;
26
import org.gvsig.tools.persistence.PersistenceManager;
27
import org.gvsig.tools.persistence.PersistentState;
28
import org.gvsig.tools.persistence.exception.PersistenceException;
29
import org.gvsig.tools.task.Cancellable;
30

  
31
public class DummyVectorLegend implements IVectorLegend {
32

  
33
	private long shpType = -1;
34

  
35
	private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID);
36

  
37
	public DummyVectorLegend() {
38
		shpType = System.currentTimeMillis() % 1000000;
39
	}
40
	
41
	public DummyVectorLegend(int type) {
42
		shpType = type; // System.currentTimeMillis() % 1000000;
43
	}
44
	
45
	public void draw(BufferedImage image, Graphics2D graphics2D,
46
			ViewPort viewPort, Cancellable cancel, double scale,
47
			Map queryParameters, ICoordTrans coordTrans,
48
			FeatureStore featureStore) throws LegendException {
49
		
50
		try {
51
			FeatureSet fs = featureStore.getFeatureSet();
52
			Iterator iter = fs.iterator();
53
			Feature feat = null;
54
			ISymbol symb = null;
55
			while (iter.hasNext()) {
56
				feat = (Feature) iter.next();
57
				symb = this.getSymbolByFeature(feat);
58
				symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null);
59
			}
60
		} catch (DataException e) {
61
			// TODO Auto-generated catch block
62
			e.printStackTrace();
63
		}
64
		// TODO Auto-generated method stub
65

  
66
	}
67

  
68
	public int getShapeType() {
69
		// TODO Auto-generated method stub
70
		return (int) shpType;
71
	}
72

  
73
	public ISymbol getSymbolByFeature(Feature feat) {
74
		return sym;
75
	}
76

  
77
	public boolean isSuitableForShapeType(int shapeType) {
78
		return sym.getSymbolType() == shapeType;
79
	}
80

  
81
	public boolean isUseDefaultSymbol() {
82
		return true;
83
	}
84

  
85
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
86
			double scale, Object object, ICoordTrans coordTrans,
87
			FeatureStore featureStore, PrintAttributes properties)
88
			throws LegendException {
89
		// TODO Auto-generated method stub
90

  
91
	}
92

  
93
	public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
94
		sym = s;
95
	}
96

  
97
	public void setShapeType(int shapeType) {
98
		shpType = shapeType;
99
	}
100

  
101
	public void useDefaultSymbol(boolean b) {
102
	}
103

  
104
	public void addLegendListener(LegendContentsChangedListener listener) {
105
		// TODO Auto-generated method stub
106

  
107
	}
108

  
109
	public ILegend cloneLegend() {
110
		// TODO Auto-generated method stub
111
		return null;
112
	}
113

  
114
	public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
115
		// TODO Auto-generated method stub
116

  
117
	}
118

  
119
	public ISymbol getDefaultSymbol() {
120
		return sym;
121
	}
122

  
123
	public LegendContentsChangedListener[] getListeners() {
124
		// TODO Auto-generated method stub
125
		return null;
126
	}
127

  
128
	public void removeLegendListener(LegendContentsChangedListener listener) {
129
		// TODO Auto-generated method stub
130

  
131
	}
132

  
133
	public String getClassName() {
134
		return this.getClass().getName();
135
	}
136

  
137

  
138

  
139

  
140
	public void addDrawingObserver(Observer observer) {
141
		// TODO Auto-generated method stub
142

  
143
	}
144

  
145
	public void deleteDrawingObserver(Observer observer) {
146
		// TODO Auto-generated method stub
147

  
148
	}
149

  
150
	public void deleteDrawingObservers() {
151
		// TODO Auto-generated method stub
152

  
153
	}
154

  
155
	public void loadFromState(PersistentState state) throws PersistenceException {
156
		shpType = state.getLong("shpType");
157
	}
158

  
159

  
160
	public void saveToState(PersistentState state) throws PersistenceException {
161
		state.set("shpType", shpType);
162
	}
163

  
164
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
165
			double scale, Map queryParameters, ICoordTrans coordTrans,
166
			FeatureStore featureStore, PrintAttributes properties)
167
			throws LegendException {
168
		// TODO Auto-generated method stub
169
		
170
	}
171
	
172
	public static void registerPersistent() {
173
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
174
		DynStruct definition = manager.addDefinition(
175
				DummyVectorLegend.class,
176
				"DummyVectorLegend",
177
				"DummyVectorLegend Persistence definition",
178
				null, 
179
				null
180
		);
181
		definition.addDynFieldLong("shpType")
182
			.setMandatory(true);
183
	}
184

  
185

  
186
	public Object clone() throws CloneNotSupportedException {
187
		return super.clone();
188
	}
189

  
190

  
191
}
0 192

  
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/rendering/symbol/DummySymbol.java
1
package org.gvsig.fmap.mapcontext.rendering.symbol;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.awt.geom.AffineTransform;
7
import java.awt.geom.PathIterator;
8
import java.util.ArrayList;
9

  
10
import org.gvsig.compat.print.PrintAttributes;
11
import org.gvsig.fmap.dal.feature.Feature;
12
import org.gvsig.fmap.geom.Geometry;
13
import org.gvsig.fmap.geom.Geometry.TYPES;
14
import org.gvsig.fmap.geom.primitive.Point;
15
import org.gvsig.fmap.mapcontext.ViewPort;
16
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
17
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
18
import org.gvsig.tools.persistence.PersistentState;
19
import org.gvsig.tools.persistence.exception.PersistenceException;
20
import org.gvsig.tools.task.Cancellable;
21

  
22
public class DummySymbol implements ISymbol {
23

  
24
	private Color color = Color.GREEN;
25
	private int type = TYPES.SOLID;
26
	
27
	public DummySymbol(Color c, int geomtype) {
28
		color = c;
29
		type = geomtype;
30
	}
31
	
32
	public Object clone() {
33
		return null;
34
	}
35
	
36
	public void draw(Graphics2D g, AffineTransform affineTransform,
37
			Geometry geom, Feature f, Cancellable cancel) {
38
		
39
		g.setColor(color);
40
		
41
		if (geom instanceof Point) {
42
			Point p = (Point) geom;
43
			p.transform(affineTransform);
44
			g.drawRect((int) p.getX(), (int) p.getY(), 3, 3);
45
		} else {
46
			PathIterator piter = geom.getPathIterator(affineTransform); 
47
			drawPathIterator(g, piter);
48
		}
49
	}
50

  
51
	public void drawInsideRectangle(Graphics2D g,
52
			AffineTransform scaleInstance, Rectangle r,
53
			PrintAttributes properties) throws SymbolDrawingException {
54
		// TODO Auto-generated method stub
55

  
56
	}
57

  
58
	public Color getColor() {
59
		return color;
60
	}
61

  
62
	public String getDescription() {
63
		return "a dummy symbol";
64
	}
65

  
66
	public int getOnePointRgb() {
67
		return color.getRGB();
68
	}
69

  
70
	public void getPixExtentPlus(Geometry geom, float[] distances,
71
			ViewPort viewPort, int dpi) {
72
		// TODO Auto-generated method stub
73

  
74
	}
75

  
76
	public ISymbol getSymbolForSelection() {
77
		return new DummySymbol(Color.YELLOW, type);
78
	}
79

  
80
	public int getSymbolType() {
81
		return type;
82
	}
83

  
84
	public boolean isOneDotOrPixel(Geometry geom,
85
			double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
86
		// TODO Auto-generated method stub
87
		return false;
88
	}
89

  
90
	public boolean isShapeVisible() {
91
		return true;
92
	}
93

  
94
	public boolean isSuitableFor(Geometry geom) {
95
		return type == geom.getType();
96
	}
97

  
98
	public void setColor(Color c) {
99
		color = c;
100
	}
101

  
102
	public void setDescription(String desc) {
103
	}
104

  
105
	public void loadFromState(PersistentState state)
106
			throws PersistenceException {
107
	}
108

  
109
	public void saveToState(PersistentState state) throws PersistenceException {
110
	}
111

  
112
	public void print(Graphics2D g, AffineTransform at, Geometry shape,
113
			PrintAttributes properties) {
114
	}
115
	
116
	
117
	
118
	/**
119
	 * Draws the general path on the graphics object with the given affine transformation
120
	 * @param g the graphics object
121
	 * @param gp the general path
122
	 */
123
	public static void drawPathIterator(Graphics2D g, PathIterator pit) {
124
		
125
		ArrayList x = new ArrayList();
126
		ArrayList y = new ArrayList();
127
		double[] current = new double[6];
128
		
129
		while (!pit.isDone()) {
130
			pit.currentSegment(current);
131
			x.add(new Integer((int) current[0]));
132
			y.add(new Integer((int) current[1]));
133
			pit.next();
134
		}
135
		
136
		int[] gx = integerArrayListToIntArray(x);
137
		int[] gy = integerArrayListToIntArray(y);
138

  
139
		g.drawPolyline(gx, gy, gx.length);
140
	}
141
	
142
	
143
	/**
144
	 * Converts array list of Integer objects into array of int
145
	 * @param l
146
	 * @return array of int
147
	 */
148
	public static int[] integerArrayListToIntArray(ArrayList l) {
149

  
150
		int size = l.size();
151
		int[] resp = new int[size];
152
		for (int i=0; i<size; i++) {
153
			resp[i] = ((Integer) l.get(i)).intValue();
154
		}
155
		return resp;
156
	}
157

  
158
}
0 159

  
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/FontPersistenceFactoryTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext.tools.persistence;
28

  
29
import java.awt.Font;
30

  
31
import org.easymock.MockControl;
32
import org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory;
33
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
34
import org.gvsig.tools.persistence.PersistentState;
35

  
36
/**
37
 * Unit tests for the class {@link FontPersistenceFactory}.
38
 * 
39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 */
41
public class FontPersistenceFactoryTest extends AbstractLibraryAutoInitTestCase {
42

  
43
	private FontPersistenceFactory factory;
44
	private MockControl stateControl;
45
	private PersistentState state;
46
	private Font font;
47

  
48
	protected void doSetUp() throws Exception {
49
		factory = new FontPersistenceFactory();
50
		stateControl = MockControl.createNiceControl(PersistentState.class);
51
		state = (PersistentState) stateControl.getMock();
52
		font = new Font("Arial", Font.BOLD, 18);
53
	}
54

  
55
	/**
56
	 * Test method for
57
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
58
	 * .
59
	 */
60
	public void testCreateFromState() throws Exception {
61
		stateControl.expectAndReturn(state
62
				.getString(FontPersistenceFactory.FIELD_NAME), font.getName());
63
		stateControl.expectAndReturn(state
64
				.getInt(FontPersistenceFactory.FIELD_STYLE), font.getStyle());
65
		stateControl.expectAndReturn(state
66
				.getInt(FontPersistenceFactory.FIELD_SIZE), font.getSize());
67
		stateControl.replay();
68

  
69
		Font newFont = (Font) factory.createFromState(state);
70
		assertTrue(newFont.equals(font));
71

  
72
		stateControl.verify();
73
	}
74

  
75
	/**
76
	 * Test method for
77
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
78
	 * .
79
	 */
80
	public void testSaveToState() throws Exception {
81
		state.set(FontPersistenceFactory.FIELD_NAME, font.getName());
82
		state.set(FontPersistenceFactory.FIELD_STYLE, font.getStyle());
83
		state.set(FontPersistenceFactory.FIELD_SIZE, font.getSize());
84
		stateControl.replay();
85

  
86
		factory.saveToState(state, font);
87

  
88
		stateControl.verify();
89
	}
90

  
91
}
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/ColorPersistenceFactoryTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext.tools.persistence;
28

  
29
import java.awt.Color;
30

  
31
import org.easymock.MockControl;
32
import org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory;
33
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
34
import org.gvsig.tools.persistence.PersistentState;
35

  
36
/**
37
 * Unit tests for the class {@link ColorPersistenceFactory}.
38
 * 
39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 */
41
public class ColorPersistenceFactoryTest extends
42
		AbstractLibraryAutoInitTestCase {
43

  
44
	private ColorPersistenceFactory factory;
45
	private MockControl stateControl;
46
	private PersistentState state;
47
	private Color color;
48

  
49
	protected void doSetUp() throws Exception {
50
		factory = new ColorPersistenceFactory();
51
		stateControl = MockControl.createNiceControl(PersistentState.class);
52
		state = (PersistentState) stateControl.getMock();
53
		color = Color.magenta;
54
	}
55

  
56
	/**
57
	 * Test method for
58
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
59
	 * .
60
	 */
61
	public void testCreateFromState() throws Exception {
62
		stateControl.expectAndReturn(state
63
				.getInt(ColorPersistenceFactory.FIELD_RED), color.getRed());
64
		stateControl.expectAndReturn(state
65
				.getInt(ColorPersistenceFactory.FIELD_GREEN), color.getGreen());
66
		stateControl.expectAndReturn(state
67
				.getInt(ColorPersistenceFactory.FIELD_BLUE), color.getBlue());
68
		stateControl.expectAndReturn(state
69
				.getInt(ColorPersistenceFactory.FIELD_ALPHA), color.getAlpha());
70
		stateControl.replay();
71

  
72
		Color newColor = (Color) factory.createFromState(state);
73
		assertTrue(newColor.equals(color));
74

  
75
		stateControl.verify();
76
	}
77

  
78
	/**
79
	 * Test method for
80
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
81
	 * .
82
	 */
83
	public void testSaveToState() throws Exception {
84
		state.set(ColorPersistenceFactory.FIELD_RED, color.getRed());
85
		state.set(ColorPersistenceFactory.FIELD_GREEN, color.getGreen());
86
		state.set(ColorPersistenceFactory.FIELD_BLUE, color.getBlue());
87
		state.set(ColorPersistenceFactory.FIELD_ALPHA, color.getAlpha());
88
		stateControl.replay();
89

  
90
		factory.saveToState(state, color);
91

  
92
		stateControl.verify();
93
	}
94

  
95
}
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/Point2DPersistenceFactoryTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext.tools.persistence;
28

  
29
import java.awt.geom.Point2D;
30

  
31
import org.easymock.MockControl;
32
import org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory;
33
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
34
import org.gvsig.tools.persistence.PersistentState;
35

  
36
/**
37
 * Unit tests for the class {@link Point2DPersistenceFactory}.
38
 * 
39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 */
41
public class Point2DPersistenceFactoryTest extends
42
		AbstractLibraryAutoInitTestCase {
43

  
44
	private Point2DPersistenceFactory factory;
45
	private MockControl stateControl;
46
	private PersistentState state;
47
	private Point2D point;
48

  
49
	protected void doSetUp() throws Exception {
50
		factory = new Point2DPersistenceFactory();
51
		stateControl = MockControl.createNiceControl(PersistentState.class);
52
		state = (PersistentState) stateControl.getMock();
53
		double x = Math.random() * 1000d;
54
		double y = Math.random() * 1000d;
55
		point = new Point2D.Double(x, y);
56
	}
57

  
58
	/**
59
	 * Test method for
60
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)}
61
	 * .
62
	 */
63
	public void testCreateFromState() throws Exception {
64
		stateControl.expectAndReturn(state
65
				.getDouble(Point2DPersistenceFactory.FIELD_X), point.getX());
66
		stateControl.expectAndReturn(state
67
				.getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY());
68
		stateControl.replay();
69

  
70
		Point2D newPoint = (Point2D) factory.createFromState(state);
71
		assertTrue(newPoint.equals(point));
72

  
73
		stateControl.verify();
74
	}
75

  
76
	/**
77
	 * Test method for
78
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
79
	 * .
80
	 */
81
	public void testSaveToState() throws Exception {
82
		state.set(Point2DPersistenceFactory.FIELD_X, point.getX());
83
		state.set(Point2DPersistenceFactory.FIELD_Y, point.getY());
84
		stateControl.replay();
85

  
86
		factory.saveToState(state, point);
87

  
88
		stateControl.verify();
89
	}
90
}
tags/v2_0_0_Build_2008/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManagerTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {DiSiD Technologies}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext.impl;
28

  
29
import java.awt.Graphics2D;
30
import java.awt.image.BufferedImage;
31
import java.util.Map;
32

  
33
import org.cresques.cts.ICoordTrans;
34
import org.gvsig.compat.print.PrintAttributes;
35
import org.gvsig.fmap.crs.CRSFactory;
36
import org.gvsig.fmap.dal.exception.ReadException;
37
import org.gvsig.fmap.dal.feature.Feature;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.mapcontext.MapContext;
40
import org.gvsig.fmap.mapcontext.MapContextDrawer;
41
import org.gvsig.fmap.mapcontext.MapContextException;
42
import org.gvsig.fmap.mapcontext.MapContextRuntimeException;
43
import org.gvsig.fmap.mapcontext.ViewPort;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
46
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
47
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
48
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader;
49
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
50
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
51
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
52
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
53
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
54
import org.gvsig.tools.observer.Observer;
55
import org.gvsig.tools.persistence.PersistentState;
56
import org.gvsig.tools.persistence.exception.PersistenceException;
57
import org.gvsig.tools.task.Cancellable;
58

  
59
/**
60
 * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
61
 */
62
public class DefaultMapContextManagerTest extends
63
		AbstractLibraryAutoInitTestCase {
64

  
65
	private DefaultMapContextManager manager;
66

  
67
	protected void doSetUp() throws Exception {
68
		manager = new DefaultMapContextManager();
69
		
70
		manager.registerLegend("DummyLegend", DummyVectorLegend.class);
71
		manager.setDefaultVectorLegend("DummyLegend");
72
		manager.registerLegendReader("Dummy", DummyLegendReader.class);
73
		manager.registerLegendWriter("DummyLegend", "Dummy", DummyLegendWriter.class);
74
	}
75

  
76
	protected void tearDown() throws Exception {
77
		super.tearDown();
78
	}
79

  
80
	/**
81
	 * Test method for
82
	 * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()}
83
	 * .
84
	 */
85
	public void testGetDefaultMapContextDrawerInstance() throws Exception {
86

  
87
		manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
88

  
89
		MapContextDrawer drawer = manager
90
				.createDefaultMapContextDrawerInstance();
91

  
92
		assertNotNull("The created MapContextDrawer instance can't be null",
93
				drawer);
94
		assertTrue(
95
				"The created MapContextDrawer is not instance of the registered class"
96
						+ DummyMapContextDrawer.class,
97
				drawer instanceof DummyMapContextDrawer);
98
	}
99

  
100
	/**
101
	 * Test method for
102
	 * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)}
103
	 * .
104
	 */
105
	public void testSetDefaultMapContextDrawer() throws Exception {
106

  
107
		// First, try to register an invalid class
108
		try {
109
			manager.setDefaultMapContextDrawer(Object.class);
110
			fail("Error, a class that does not implement the MapContextDrawer "
111
					+ "interface has been accepted");
112
		} catch (MapContextRuntimeException e) {
113
			// OK
114
		}
115

  
116
		// Next, try to register a valid class
117
		manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
118
	}
119

  
120
	public void testCreateGraphicsLayer() throws Exception {
121
		assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030")));
122
	}
123

  
124
	public void testCreateDefaultVectorLegend() throws Exception {
125

  
126
		IVectorLegend legend = manager.createDefaultVectorLegend(1);
127
		assertNotNull(legend);
128
		assertTrue(legend instanceof DummyVectorLegend);
129
	}
130

  
131
	public void testRegisterCreateLegend() throws Exception {
132

  
133
		manager.registerLegend("DummyLegend", DummyVectorLegend.class);
134

  
135
		ILegend legend = manager.createLegend("DummyLegend");
136
		assertNotNull(legend);
137
		assertTrue(legend instanceof DummyVectorLegend);
138

  
139
		assertNull(manager.createLegend("NONE"));
140
	}
141

  
142
	public void testRegisterCreateLegendReader() throws Exception {
143

  
144
		manager.registerLegendReader("Dummy", DummyLegendReader.class);
145

  
146
		ILegendReader legendReader = manager.createLegendReader("Dummy");
147
		assertNotNull(legendReader);
148
		assertTrue(legendReader instanceof DummyLegendReader);
149

  
150
		assertNull(manager.createLegendReader("NONE"));
151
	}
152

  
153
	public void testRegisterCreateLegendWriter() throws Exception {
154

  
155
		manager.registerLegend("DummyLegend", DummyVectorLegend.class);
156

  
157
		manager.registerLegendWriter("DummyLegend", "Dummy",
158
				DummyLegendWriter.class);
159

  
160
		// Test the registered writer is created
161
		ILegendWriter legendWriter = manager.createLegendWriter("DummyLegend",
162
				"Dummy");
163
		assertNotNull(legendWriter);
164
		assertTrue(legendWriter instanceof DummyLegendWriter);
165

  
166
		// Test non registered cases
167
		assertNull(manager.createLegendWriter("NONE", "Dummy"));
168
		assertNull(manager.createLegendWriter("DummyLegend", "NONE"));
169
		assertNull(manager.createLegendWriter("NONE", "NONE"));
170
	}
171

  
172
	public static class DummyMapContextDrawer implements MapContextDrawer {
173

  
174
		public void dispose() {
175
		}
176

  
177
		public void draw(FLayers root, BufferedImage image, Graphics2D g,
178
				Cancellable cancel, double scale) throws ReadException {
179
		}
180

  
181
		public void print(FLayers root, Graphics2D g, Cancellable cancel,
182
				double scale, PrintAttributes properties) throws ReadException {
183
		}
184

  
185
		public void setMapContext(MapContext mapContext) {
186
		}
187

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff