Revision 35224

View differences:

tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/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.
0 9

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
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
	org.gvsig.tools packages.
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.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.annotation">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/test/java/org/gvsig/annotation/impl/DefaultAnnotationManagerTest.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
package org.gvsig.annotation.impl;
23

  
24
import org.gvsig.annotation.AnnotationManager;
25
import org.gvsig.annotation.AnnotationManagerTest;
26

  
27
/**
28
 * {@link AnnotationManager} API compatibility tests for the
29
 * {@link DefaultAnnotationManager} implementation.
30
 * 
31
 * @author gvSIG Team
32
 * @version $Id$
33
 */
34
public class DefaultAnnotationManagerTest extends AnnotationManagerTest {
35

  
36
    // Nothing to add
37
}
0 38

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/test/java/org/gvsig/annotation/impl/DefaultAnnotationCreationServiceTest.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
package org.gvsig.annotation.impl;
23

  
24
import org.gvsig.annotation.AnnotationCreationService;
25
import org.gvsig.annotation.AnnotationCreationServiceTest;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.geom.GeometryLocator;
28
import org.gvsig.fmap.geom.GeometryManager;
29
import org.gvsig.fmap.geom.exception.CreateGeometryException;
30

  
31
/**
32
 * {@link AnnotationCreationService} API compatibility tests for the
33
 * {@link DefaultAnnotationCreationService} implementation.
34
 * 
35
 * @author gvSIG Team
36
 * @version $Id$
37
 */
38
public class DefaultAnnotationCreationServiceTest extends AnnotationCreationServiceTest {
39
		
40
	public DefaultAnnotationCreationServiceTest() {
41
		super();		
42
	}
43

  
44
	@Override
45
	public TextPointPairList getResult() throws CreateGeometryException {
46
		GeometryManager geometryManager = GeometryLocator.getGeometryManager();
47
		TextPointPairList textPointPairList = new TextPointPairList();
48
		textPointPairList.addPoint("Sevilla", geometryManager.createPoint(262760.53, 4146732.91, Geometry.SUBTYPES.GEOM2D));
49
		return textPointPairList;
50
	}
51
}
0 52

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.annotation package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Annotation library API default implementation.</p>
11

  
12
</body>
13
</html>
0 14

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/DefaultAnnotationCreationService.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
package org.gvsig.annotation.impl;
23

  
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.FileOutputStream;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.io.OutputStream;
30

  
31
import org.gvsig.annotation.AnnotationCreationException;
32
import org.gvsig.annotation.AnnotationCreationFinishAction;
33
import org.gvsig.annotation.AnnotationCreationService;
34
import org.gvsig.annotation.AnnotationCreationServiceNotification;
35
import org.gvsig.annotation.AnnotationDataTypes;
36
import org.gvsig.annotation.AnnotationManager;
37
import org.gvsig.annotation.calculator.AnnotationPositionCalculationException;
38
import org.gvsig.annotation.calculator.AnnotationPositionCalculator;
39
import org.gvsig.annotation.calculator.AnnotationPositionCalculatorCreationException;
40
import org.gvsig.fmap.dal.DALLocator;
41
import org.gvsig.fmap.dal.DataManager;
42
import org.gvsig.fmap.dal.DataTypes;
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
46
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
47
import org.gvsig.fmap.dal.feature.EditableFeature;
48
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
49
import org.gvsig.fmap.dal.feature.EditableFeatureType;
50
import org.gvsig.fmap.dal.feature.Feature;
51
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
52
import org.gvsig.fmap.dal.feature.FeatureSet;
53
import org.gvsig.fmap.dal.feature.FeatureStore;
54
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
55
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
56
import org.gvsig.fmap.geom.Geometry;
57
import org.gvsig.tools.dispose.DisposableIterator;
58
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61

  
62

  
63
/**
64
 * Default {@link AnnotationCreationService} implementation.
65
 * 
66
 * @author gvSIG Team
67
 * @version $Id$
68
 */
69
public class DefaultAnnotationCreationService implements AnnotationCreationService {
70
	private static final Logger LOG = LoggerFactory.getLogger(DefaultAnnotationCreationService.class);
71
	private static DataManager dataManager = DALLocator.getDataManager();
72

  
73
	private AnnotationManager manager;
74
	private FeatureStore sourceStore;
75

  
76
	private int sourceFontTypeAttribute = -1;
77
	private int sourceFontStyleAttribute = -1;
78
	private int sourceFontColorAttribute = -1;
79
	private int sourceRotationAttribute = -1;
80
	private int sourceHeigthAttribute = -1;
81
	private AnnotationPositionCalculator annotationPositionCalculator = null;
82

  
83
	private String destinationGeometryAttributeName = null;
84

  
85
	private AnnotationCreationServiceNotification annotationCreationServiceNotification = null;
86
	private AnnotationCreationFinishAction annotationCreationFinishAction = null; 
87

  
88
	/**
89
	 * {@link DefaultAnnotationCreationService} constructor with a
90
	 * {@link AnnotationManager}.
91
	 * 
92
	 * @param manager
93
	 *            to use in the service
94
	 * @throws DataException 
95
	 */
96
	public DefaultAnnotationCreationService(FeatureStore featureStore, AnnotationManager manager) throws DataException {
97
		this.sourceStore = featureStore; 
98
		this.manager = manager;
99
		destinationGeometryAttributeName = featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
100
	}
101

  
102
	public AnnotationManager getManager() {
103
		return this.manager;
104
	}
105

  
106
	public FeatureStore createAnnotationStore(String destinationShapeFile, int textValueAttribute)
107
	throws AnnotationCreationException {		
108
		try {
109
			if (destinationShapeFile == null){
110
				throw new AnnotationCreationException("File can not be null");
111
			}	
112

  
113
			String destinationShapeFileWithoutExtension = destinationShapeFile.toLowerCase().replaceAll("\\.shp", "");
114
			if (destinationShapeFileWithoutExtension.length() == destinationShapeFile.length()-4){
115
				destinationShapeFileWithoutExtension =  destinationShapeFile.substring(0, destinationShapeFile.length()-4);
116
			}else{
117
				destinationShapeFileWithoutExtension = destinationShapeFile;
118
			}			
119

  
120
			NewFeatureStoreParameters newFeatureStoreParameters = (NewFeatureStoreParameters)dataManager.createNewStoreParameters("FilesystemExplorer", "Shape");
121
			newFeatureStoreParameters.setDynValue("shpfile", destinationShapeFileWithoutExtension + ".shp");
122
			newFeatureStoreParameters.setDynValue("dbffile", destinationShapeFileWithoutExtension + ".dbf");
123
			newFeatureStoreParameters.setDynValue("shxfile", destinationShapeFileWithoutExtension + ".shx");
124
			newFeatureStoreParameters.setDynValue("crs", sourceStore.getDefaultFeatureType().getDefaultSRS());
125

  
126
			EditableFeatureType editableFeatureType = sourceStore.getDefaultFeatureType().getEditable();//newFeatureStoreParameters.getDefaultFeatureType().getEditable();
127
			FeatureAttributeDescriptor[] featureAttributeDescriptors = editableFeatureType.getAttributeDescriptors();
128
			for (int i=featureAttributeDescriptors.length-1  ; i>=0 ; i--){
129
				editableFeatureType.remove(i);
130
			}
131
			initializeFeatureType(editableFeatureType);
132
			newFeatureStoreParameters.setDefaultFeatureType(editableFeatureType);
133

  
134
			dataManager.newStore("FilesystemExplorer", "Shape", newFeatureStoreParameters, true);
135

  
136
			//If there is not an annotationPositionCalculator it gets the default 
137
			if (annotationPositionCalculator == null){
138
				annotationPositionCalculator = manager.getDefaultAnnotationPositionCalculator();
139
			}	
140

  
141
			FeatureStore destinationStore = (FeatureStore) dataManager.openStore("Shape", newFeatureStoreParameters);
142

  
143
			copyFeatureStore(sourceStore, 
144
					destinationStore,
145
					textValueAttribute);	
146

  
147
			try {
148
				copyLegend(destinationStore);
149
			} catch (IOException e) {
150
				LOG.error("Error copying the legend");
151
			}
152

  
153
			if (annotationCreationFinishAction != null){
154
				annotationCreationFinishAction.finished(destinationStore);
155
			}
156

  
157
			return destinationStore;
158
		} catch (InitializeException e) {
159
			throw new AnnotationCreationException(e);
160
		} catch (ProviderNotRegisteredException e) {
161
			throw new AnnotationCreationException(e);
162
		} catch (ValidateDataParametersException e) {
163
			throw new AnnotationCreationException(e);
164
		} catch (DynFieldNotFoundException e) {
165
			throw new AnnotationCreationException(e);
166
		} catch (DataException e) {
167
			throw new AnnotationCreationException(e);
168
		} catch (AnnotationPositionCalculatorCreationException e) {
169
			throw new AnnotationCreationException(e);
170
		} 			
171
	}	
172

  
173
	public FeatureStore createAnnotationStore(String destinationShapeFile,
174
			String textValueAttributeName) throws AnnotationCreationException {
175
		try {
176
			return createAnnotationStore(destinationShapeFile, getIndex(textValueAttributeName));
177
		} catch (DataException e) {
178
			throw new AnnotationCreationException(e);
179
		}			
180
	}
181

  
182
	private void initializeFeatureType(EditableFeatureType editableFeatureType) throws DataException
183
	{		
184
		EditableFeatureAttributeDescriptor geometryType = editableFeatureType.add(destinationGeometryAttributeName, DataTypes.GEOMETRY);
185
		geometryType.setAllowNull(false);		
186
		geometryType.setGeometryType(Geometry.TYPES.POINT).setGeometrySubType(Geometry.SUBTYPES.GEOM2D);
187
		geometryType.setSRS(sourceStore.getDefaultFeatureType().getDefaultSRS());
188
		geometryType.setObjectClass(Geometry.class);
189

  
190
		editableFeatureType.add(AnnotationManager.TEXTVALUE_ATTRIBUTE_NAME, AnnotationDataTypes.TEXT, 256).setAllowNull(true);
191
		editableFeatureType.add(AnnotationManager.FONTTYPE_ATTRIBUTE_NAME, AnnotationDataTypes.FONTTYPE, 30).setAllowNull(true);
192
		editableFeatureType.add(AnnotationManager.FONTSTYLE_ATTRIBUTE_NAME, AnnotationDataTypes.FONTSTYLE, 30).setAllowNull(true);
193
		editableFeatureType.add(AnnotationManager.FONTCOLOR_ATTRIBUTE_NAME, AnnotationDataTypes.FONTCOLOR, 20).setAllowNull(true);
194
		editableFeatureType.add(AnnotationManager.FONTROTATION_ATTRIBUTE_NAME, AnnotationDataTypes.FONTROTATION, 5).setAllowNull(true);
195
		editableFeatureType.add(AnnotationManager.FONTHEGTH_ATTRIBUTE_NAME, AnnotationDataTypes.FONTHEIGHT, 5).setAllowNull(true);
196
	}
197

  
198
	private AttributeInserter createInserter(int attributePosition, Object defaultValue)
199
	{
200
		if (attributePosition > -1){
201
			return new StoreAttributeInserter(attributePosition);
202
		}else{
203
			return new DefaultAttributeInserter(defaultValue);
204
		}
205
	}
206

  
207
	private void copyFeatureStore(FeatureStore sourceStore,
208
			FeatureStore destinationStore, int textAttribute)
209
	throws AnnotationCreationException, DataException {
210
		if (annotationCreationServiceNotification != null){
211
			annotationCreationServiceNotification.initializing();
212
		}
213

  
214
		//Start the edition
215
		destinationStore.edit();
216

  
217
		//Copy data
218
		FeatureSet featureSet = sourceStore.getFeatureSet();
219
		DisposableIterator iterator = featureSet.iterator();
220

  
221
		//Create the attribute inserter's
222
		AttributeInserter fontTypeAttributeInserter = createInserter(sourceFontTypeAttribute, manager.getDefaultFontType());		
223
		AttributeInserter fontStyleAttributeInserter = createInserter(sourceFontStyleAttribute, manager.getDefaultFontStyle());		
224
		AttributeInserter fontColorAttributeInserter = createInserter(sourceFontColorAttribute, manager.getDefaultFontColor());		
225
		AttributeInserter fontRotationAttributeInserter = createInserter(sourceRotationAttribute, manager.getDefaultFontRotation());		
226
		AttributeInserter fontHeigthAttributeInserter = createInserter(sourceHeigthAttribute, manager.getDefaultFontHeight());		
227

  
228
		Feature sourceFeature;
229
		while (iterator.hasNext()) {			
230
			sourceFeature = (Feature) iterator.next();
231

  
232
			EditableFeature destinationFeature = destinationStore.createNewFeature().getEditable();
233
			try {
234
				destinationFeature.set(destinationGeometryAttributeName, annotationPositionCalculator.getAnnotationPosition(sourceFeature));
235
			} catch (AnnotationPositionCalculationException e) {
236
				LOG.error("Not possible to get the point for the geometry", e);				
237
			}
238
			destinationFeature.set(AnnotationManager.TEXTVALUE_ATTRIBUTE_NAME, sourceFeature.get(textAttribute));
239
			destinationFeature.set(AnnotationManager.FONTTYPE_ATTRIBUTE_NAME, fontTypeAttributeInserter.getValue(sourceFeature));
240
			destinationFeature.set(AnnotationManager.FONTSTYLE_ATTRIBUTE_NAME, fontStyleAttributeInserter.getValue(sourceFeature));
241
			destinationFeature.set(AnnotationManager.FONTCOLOR_ATTRIBUTE_NAME, fontColorAttributeInserter.getValue(sourceFeature));
242
			destinationFeature.set(AnnotationManager.FONTROTATION_ATTRIBUTE_NAME, fontRotationAttributeInserter.getValue(sourceFeature));
243
			destinationFeature.set(AnnotationManager.FONTHEGTH_ATTRIBUTE_NAME, fontHeigthAttributeInserter.getValue(sourceFeature));
244

  
245
			destinationStore.insert(destinationFeature);
246
			if (annotationCreationServiceNotification != null){
247
				annotationCreationServiceNotification.next();
248
				if (annotationCreationServiceNotification.isCanceled()){
249
					break;
250
				}
251
			}
252
		}
253

  
254
		//Finish the edition
255
		destinationStore.finishEditing();
256

  
257
		//Dispose resources
258
		iterator.dispose();		
259
		featureSet.dispose();				
260

  
261
		if (annotationCreationServiceNotification != null){
262
			annotationCreationServiceNotification.finished();
263
		}		
264
	}
265

  
266
	private void copyLegend(FeatureStore destinationStore) throws ValidateDataParametersException, DataException, IOException {
267
		FilesystemServerExplorer filesystemServerExplorer = (FilesystemServerExplorer)destinationStore.getExplorer();
268
		File target = filesystemServerExplorer.getResourcePath(destinationStore, "gvl");
269

  
270
		//Copy the template
271
		File source = new File(getClass().getClassLoader().getResource("legend.template.gvl").getFile());
272
		InputStream in = null;
273
		OutputStream out = null;
274

  
275
		in = new FileInputStream(source);
276
		out = new FileOutputStream(target);
277

  
278
		byte[] buf = new byte[1024];
279
		int len;
280
		while ((len = in.read(buf)) > 0) { 
281
			out.write(buf, 0, len); 
282
		} 
283
		in.close();
284
		out.close(); 		
285
	}
286

  
287
	private void checkAttribute(int index, int type) throws DataException{
288
		if (index >= sourceStore.getDefaultFeatureType().size()){
289
			throw new IllegalArgumentException("Attribute not found");
290
		}
291
		if (sourceStore.getDefaultFeatureType().getAttributeDescriptor(index).getDataType().getType() != type){
292
			throw new IllegalArgumentException("The Attribute has not have the fine type");
293
		}
294
	}
295

  
296

  
297
	public void setFontTypetAttribute(int index) throws DataException {
298
		checkAttribute(index, AnnotationDataTypes.FONTTYPE);
299
		this.sourceFontTypeAttribute = index;		
300
	}
301

  
302
	public void setFontStyleAttribute(int index) throws DataException {
303
		checkAttribute(index, AnnotationDataTypes.FONTSTYLE);
304
		this.sourceFontStyleAttribute = index;		
305
	}
306

  
307
	public void setFontColorAttribute(int index) throws DataException {
308
		checkAttribute(index, AnnotationDataTypes.FONTCOLOR);
309
		this.sourceFontColorAttribute = index;		
310
	}
311

  
312
	public void setFontHeigthAttribute(int index) throws DataException {
313
		checkAttribute(index, AnnotationDataTypes.FONTHEIGHT);
314
		this.sourceHeigthAttribute = index;		
315
	}
316

  
317
	public void setFontRotationAttribute(int index) throws DataException {
318
		checkAttribute(index, AnnotationDataTypes.FONTROTATION);
319
		this.sourceRotationAttribute = index;		
320
	}
321

  
322
	public void setAnnotationPositionCalculator(
323
			AnnotationPositionCalculator annotationPositionCalculator) {		
324
		this.annotationPositionCalculator = annotationPositionCalculator;		
325
	}
326

  
327
	public int getIndex(String attributeName) throws DataException{
328
		FeatureAttributeDescriptor featureAttributeDescriptor = sourceStore.getDefaultFeatureType().getAttributeDescriptor(attributeName);
329
		if (featureAttributeDescriptor != null){
330
			return featureAttributeDescriptor.getIndex();
331
		}
332
		return -1;
333
	}
334

  
335
	public void setFontColorAttribute(String attributeName) throws DataException {
336
		setFontColorAttribute(getIndex(attributeName));		
337
	}
338

  
339
	public void setFontHeigthAttribute(String attributeName) throws DataException {
340
		setFontHeigthAttribute(getIndex(attributeName));				
341
	}
342

  
343
	public void setFontRotationAttribute(String attributeName) throws DataException {
344
		setFontRotationAttribute(getIndex(attributeName));				
345
	}
346

  
347
	public void setFontStyleAttribute(String attributeName) throws DataException {
348
		setFontStyleAttribute(getIndex(attributeName));				
349
	}
350

  
351
	public void setFontTypetAttribute(String attributeName) throws DataException {
352
		setFontTypetAttribute(getIndex(attributeName));				
353
	}
354

  
355

  
356
	public FeatureStore getFeatureStore() {
357
		return sourceStore;
358
	}
359

  
360
	private interface AttributeInserter{
361
		public Object getValue(Feature feature);
362
	}
363

  
364

  
365
	private class StoreAttributeInserter implements AttributeInserter{
366
		private int attributePosition = -1;
367

  
368
		public StoreAttributeInserter(int attributePosition) {
369
			super();
370
			this.attributePosition = attributePosition;			
371
		}
372

  
373
		public Object getValue(Feature feature){
374
			return feature.get(attributePosition);
375
		}
376
	}
377

  
378
	private class DefaultAttributeInserter implements AttributeInserter{
379
		private Object defaultValue = null;
380

  
381
		public DefaultAttributeInserter(Object defaultValue) {
382
			super();	
383
			this.defaultValue = defaultValue;
384
		}
385

  
386
		public Object getValue(Feature feature){
387
			return defaultValue;
388
		}
389
	}
390

  
391
	public AnnotationCreationFinishAction getAnnotationCreationFinishAction() {
392
		return annotationCreationFinishAction;
393
	}
394

  
395
	public AnnotationCreationServiceNotification getAnnotationCreationServiceNotification() {
396
		return annotationCreationServiceNotification;
397
	}
398

  
399
	public void setAnnotationCreationFinishAction(
400
			AnnotationCreationFinishAction annotationCreationFinishAction) {
401
		this.annotationCreationFinishAction = annotationCreationFinishAction;	
402
	}
403

  
404
	public void setAnnotationCreationServiceNotification(AnnotationCreationServiceNotification annotationCreationServiceNotification) {
405
		this.annotationCreationServiceNotification = annotationCreationServiceNotification;		
406
	}
407

  
408
}
0 409

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/AnnotationDefaultImplLibrary.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
package org.gvsig.annotation.impl;
23

  
24
import java.awt.Color;
25

  
26
import org.gvsig.annotation.AnnotationLibrary;
27
import org.gvsig.annotation.AnnotationLocator;
28
import org.gvsig.annotation.AnnotationManager;
29
import org.gvsig.annotation.impl.calculator.CentroidPositionCalculatior;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
33

  
34
/**
35
 * Library for default implementation initialization and configuration.
36
 * 
37
 * @author gvSIG team
38
 * @version $Id$
39
 */
40
public class AnnotationDefaultImplLibrary extends AbstractLibrary {
41
	  	
42
    @Override
43
    public void doRegistration() {
44
        registerAsImplementationOf(AnnotationLibrary.class);
45
    }
46

  
47
	@Override
48
    protected void doInitialize() throws LibraryException {
49
		AnnotationLocator.registerManager(DefaultAnnotationManager.class);           
50
    }
51

  
52
    @Override
53
    protected void doPostInitialize() throws LibraryException {
54
        AnnotationManager annotationManager = AnnotationLocator.getManager();
55
                
56
        if (annotationManager == null) {
57
            throw new ReferenceNotRegisteredException(
58
                AnnotationLocator.MANAGER_NAME, AnnotationLocator
59
                    .getInstance());
60
        }
61
        
62
        annotationManager.registerDefaultAnnotationPositionCalculator(CentroidPositionCalculatior.class);
63
       
64
        //Adding font types
65
        annotationManager.addFontType("Arial");
66
        annotationManager.addFontType("Dialog");
67
        annotationManager.addFontType("DialogInput");
68
        annotationManager.addFontType("Serif");
69
        annotationManager.addFontType("SansSerif");
70
        annotationManager.addFontType("Monospaced");
71
        annotationManager.addFontType("Courier");
72
        annotationManager.addFontType("TimesRoman");
73
        annotationManager.addFontType("Helvetica");
74
        
75
           //Adding font styles
76
        annotationManager.addFontStyle("Plain");
77
        annotationManager.addFontStyle("Italic");
78
        annotationManager.addFontStyle("Bold");
79
        
80
        //Setting the default values if there are not registered
81
        if (annotationManager.getDefaultTextValue() == null){
82
        	annotationManager.setDefaultTextValue("Text");
83
        }
84
        
85
        if (annotationManager.getDefaultFontColor() == -1){
86
        	annotationManager.setDefaultFontColor(Color.BLACK);
87
        }
88
        
89
        if (annotationManager.getDefaultFontHeight() == -1){
90
        	annotationManager.setDefaultFontHeight(10);
91
        }
92
        
93
        if (annotationManager.getDefaultFontRotation() == -1){
94
        	annotationManager.setDefaultFontRotation(0);
95
        }
96
        
97
        if (annotationManager.getDefaultFontStyle() == null){
98
        	annotationManager.setDefaultFontStyle("Plain");
99
        }
100
        
101
        if (annotationManager.getDefaultFontType() == null){
102
        	annotationManager.setDefaultFontType("Arial");
103
        }        
104
    }
105

  
106
}
0 107

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/calculator/CentroidPositionCalculatior.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
* 2010 {Prodevelop}   {Task}
26
*/
27
 
28
package org.gvsig.annotation.impl.calculator;
29

  
30
import org.gvsig.annotation.calculator.AnnotationPositionCalculationException;
31
import org.gvsig.annotation.calculator.AnnotationPositionCalculator;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.fmap.geom.primitive.Point;
36
import org.gvsig.i18n.Messages;
37

  
38
/**
39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
40
 */
41
public class CentroidPositionCalculatior implements AnnotationPositionCalculator{
42

  
43
	public Point getAnnotationPosition(Feature feature) throws AnnotationPositionCalculationException {
44
		try {
45
			return feature.getDefaultGeometry().centroid();
46
		} catch (GeometryOperationNotSupportedException e) {
47
			throw new AnnotationPositionCalculationException(e);
48
		} catch (GeometryOperationException e) {
49
			throw new AnnotationPositionCalculationException(e);
50
		}
51
	}
52

  
53
	public String getName() {
54
		return Messages.getText("centroid");
55
	}
56
}
57

  
0 58

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/DefaultAnnotationManager.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
package org.gvsig.annotation.impl;
23

  
24
import java.awt.Color;
25
import java.util.ArrayList;
26
import java.util.Collections;
27
import java.util.List;
28

  
29
import org.gvsig.annotation.AnnotationCreationService;
30
import org.gvsig.annotation.AnnotationCreationServiceException;
31
import org.gvsig.annotation.AnnotationManager;
32
import org.gvsig.annotation.calculator.AnnotationPositionCalculator;
33
import org.gvsig.annotation.calculator.AnnotationPositionCalculatorCreationException;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.extensionpoint.ExtensionPoint;
38
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
39
import org.gvsig.tools.service.ServiceException;
40

  
41
/**
42
 * Default {@link AnnotationManager} implementation.
43
 * 
44
 * @author gvSIG Team
45
 * @version $Id$
46
 */
47
public class DefaultAnnotationManager implements AnnotationManager {
48
	private static final String ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT = "AnnotationPositionCalculatorExtensionPoint";
49
	private ExtensionPointManager extensionPointManager = ToolsLocator.getExtensionPointManager();
50
	private static final String DEFAULT_ANNOTATION_POSITION_CALCULATOR = "DefaultAnnotationPositionCalculator";
51
	
52
	private String defaultTextValue = null;
53
	private int defaultFontColor = -1;
54
	private double defaultFontHeight = -1;
55
	private double defaultFontRotation = -1;
56
	private String defaultFontStyle = null;
57
	private String defaultFontType = null;
58
	
59
	private List<String> fontTypes = Collections.synchronizedList(new ArrayList<String>());
60
	private List<String> fontStyles = Collections.synchronizedList(new ArrayList<String>());
61
	
62
	
63
    public AnnotationCreationService getAnnotationCreationService(FeatureStore featureStore)
64
        throws ServiceException {
65
        AnnotationCreationService fc;
66
		try {
67
			fc = new DefaultAnnotationCreationService(featureStore, this);
68
		} catch (DataException e) {
69
			throw new AnnotationCreationServiceException("Impossible to create the annotation service", e);
70
		}
71
        return fc;
72
    }
73

  
74
	public AnnotationPositionCalculator getAnnotationPositionCalculator(
75
			String name) throws AnnotationPositionCalculatorCreationException {
76
		if (extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).has(name)){
77
			try {
78
				return (AnnotationPositionCalculator)extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).create(name);
79
			} catch (InstantiationException e) {
80
				throw new AnnotationPositionCalculatorCreationException(name, e);
81
			} catch (IllegalAccessException e) {
82
				throw new AnnotationPositionCalculatorCreationException(name, e);
83
			}
84
		}else{
85
			throw new IllegalArgumentException("There is not an annotation position calculator registered with this name"); 
86
		}		
87
	}
88

  
89
	public List<String> getAnnotationPositionCalculatorList() {
90
		return extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).getNames();
91
	}
92

  
93
	public AnnotationPositionCalculator getDefaultAnnotationPositionCalculator() throws AnnotationPositionCalculatorCreationException {
94
		return getAnnotationPositionCalculator(DEFAULT_ANNOTATION_POSITION_CALCULATOR);
95
	}
96

  
97
	public void registerAnnotationPositionCalculator(String name,
98
			Class annotationPositionCalculatorClass) {
99
		if (!AnnotationPositionCalculator.class.isAssignableFrom(annotationPositionCalculatorClass)) {
100
			throw new IllegalArgumentException(annotationPositionCalculatorClass.getName()
101
					+ " must implement the AnnotationPositionCalculator interface");
102
		}
103
		
104
		ExtensionPoint extensionPoint = extensionPointManager.add(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT, "");
105
		extensionPoint.append(name, name, annotationPositionCalculatorClass);		
106
	}
107

  
108
	public void registerDefaultAnnotationPositionCalculator(Class annotationPositionCalculatorClass) {
109
		registerAnnotationPositionCalculator(DEFAULT_ANNOTATION_POSITION_CALCULATOR,
110
				annotationPositionCalculatorClass);
111
	}
112

  
113
	public void addFontStyle(String fontStyle) {
114
		fontStyles.add(fontStyle);		
115
	}
116

  
117
	public void addFontType(String fontType) {
118
		fontTypes.add(fontType);		
119
	}
120

  
121
	public int getDefaultFontColor() {
122
		return defaultFontColor;
123
	}
124

  
125
	public double getDefaultFontHeight() {
126
		return defaultFontHeight;
127
	}
128

  
129
	public double getDefaultFontRotation() {
130
		return defaultFontRotation;
131
	}
132

  
133
	public String getDefaultFontStyle() {
134
		return defaultFontStyle;
135
	}
136

  
137
	public String getDefaultFontType() {
138
		return defaultFontType;
139
	}
140

  
141
	public String getDefaultTextValue() {
142
		return defaultTextValue;
143
	}
144

  
145
	public List<String> getFontStyles() {
146
		return fontStyles;
147
	}
148

  
149
	public List<String> getFontTypes() {
150
		return fontTypes;
151
	}
152

  
153
	public void setDefaultFontColor(int fontColor) {
154
		this.defaultFontColor = fontColor;		
155
	}
156
	
157
	public void setDefaultFontColor(Color fontColor) {
158
		this.defaultFontColor = fontColor.getRGB();		
159
	}
160

  
161
	public void setDefaultFontHeight(double fontHeight) {
162
		this.defaultFontHeight = fontHeight;		
163
	}
164

  
165
	public void setDefaultFontRotation(double fontRotation) {
166
		this.defaultFontRotation = fontRotation;		
167
	}
168

  
169
	public void setDefaultFontStyle(String fontStyle) {
170
		this.defaultFontStyle = fontStyle;		
171
	}
172

  
173
	public void setDefaultFontType(String fontType) {
174
		this.defaultFontType = fontType;		
175
	}
176

  
177
	public void setDefaultTextValue(String textValue) {
178
		this.defaultTextValue = textValue;		
179
	}
180

  
181

  
182
}
0 183

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/resources/locale/text.properties
1
# Resource bundle texts for the Spanish language locale (es)
2
centroid=Centroide
3

  
0 4

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/resources/locale/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
infofile_exception=Exception in installation file install.info
3
infofile_not_found=File install.info not found
4
infofile_property_not_found=The property %(propertyName) is mandatory but it is not in the install.info file
5
infofile_found=File install.info exists
6
infofile_reading_error=Error reading the install.info file
7
infofile_writing_error=Error writing the install.info file
8
plugin_to_install=Plugin to install
9
plugin_description=Plugin description
10
advanced_mode_selection=Advanced options
11
ant_script=Ant script
12
files_to_copy=Files to copy
13
output_options=Output options
14
progress=Install progress
15
advanced_mode=The advanced mode option allows to copy resources that are located out of the plugin directory. We don't recommend to use this option.
16
initializing=Inicializando 
17
create_output_file_exception=Error creating the output file
18
select_installer=Select the installer
19
select_plugins=Select the plugins to install
20
execute_adding_error=Error adding a resource
21
name=Name
22
description=Description
23
version=Version
24
build=Build
25
is_official=Is official
26
status=Status
27
code=Code
28
enable_advanced_mode=Enable the advanced mode
29
compressing=Compressing
30
finished=Finished
31
standard_installation=Standard installation
32
installation_from_file=Installation from file
33
official=Official
34
not_official=Not official
35
application_directory_not_found=Application directory not found
36
package_not_found=The package has not been found
37
make_plugin_package_exception=Exception creating the package for a plugin
38
not_valid_xml=The XML is not a valid XML
39

  
0 40

  
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.annotation.impl.AnnotationDefaultImplLibrary
tags/v2_0_0_Build_2026/org.gvsig.annotation.lib.impl/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.annotation.lib.impl</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.annotation.lib.impl</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.annotation.lib</artifactId>
11
		<version>1.0.0-SNAPSHOT</version>
12
	</parent>
13
	<dependencies>
14
		<dependency>
15
			<groupId>org.gvsig</groupId>
16
			<artifactId>org.gvsig.annotation.lib.api</artifactId>
17
			<version>1.0.0-SNAPSHOT</version>
18
            <scope>compile</scope>
19
		</dependency>	
20
		<dependency>
21
			<groupId>org.gvsig</groupId>
22
			<artifactId>org.gvsig.fmap.dal</artifactId>			
23
            <scope>compile</scope>
24
		</dependency>
25
		<dependency>
26
			<groupId>org.gvsig</groupId>
27
			<artifactId>org.gvsig.i18n</artifactId>		
28
            <scope>compile</scope>
29
		</dependency>
30
			<dependency>
31
			<groupId>org.gvsig</groupId>
32
			<artifactId>org.gvsig.projection</artifactId>
33
            <scope>compile</scope>
34
		</dependency>
35
		<dependency>
36
			<groupId>org.gvsig</groupId>
37
			<artifactId>org.gvsig.fmap.geometry</artifactId>			
38
            <scope>compile</scope>
39
		</dependency>				
40
		<dependency>
41
			<groupId>org.gvsig</groupId>
42
			<artifactId>org.gvsig.fmap.geometry</artifactId>
43
			<classifier>operation</classifier>		
44
            <scope>compile</scope>
45
		</dependency>	
46
        <dependency>
47
            <groupId>org.gvsig</groupId>
48
            <artifactId>org.gvsig.tools.lib</artifactId>            
49
            <scope>compile</scope>
50
        </dependency>               
51
        <dependency>
52
            <groupId>org.gvsig</groupId>
53
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>            
54
            <scope>compile</scope>
55
        </dependency>               
56
		<dependency>
57
			<groupId>org.opengis</groupId>
58
		    <artifactId>geoapi</artifactId>
59
			<scope>runtime</scope>
60
		</dependency>
61
		<dependency>
62
			<groupId>org.geotools</groupId>
63
			<artifactId>gt2-main</artifactId>
64
			<scope>runtime</scope>
65
		</dependency>
66
		<dependency>
67
			<groupId>javax.media</groupId>
68
			<artifactId>jai_core</artifactId>
69
			<scope>runtime</scope>
70
		</dependency>
71
		<dependency>
72
			<groupId>javax.media</groupId>
73
			<artifactId>jai_codec</artifactId>
74
			<scope>runtime</scope>
75
		</dependency>		
76
		<dependency>
77
			<groupId>org.gvsig</groupId>
78
			<artifactId>org.gvsig.annotation.lib.api</artifactId>
79
			<version>1.0.0-SNAPSHOT</version>
80
			<type>test-jar</type>
81
			<scope>test</scope>
82
		</dependency>	
83
		<dependency>
84
			<groupId>org.gvsig</groupId>
85
			<artifactId>org.gvsig.fmap.dal</artifactId>
86
			<classifier>spi</classifier>
87
			<scope>runtime</scope>		
88
		</dependency>
89
		<dependency>
90
			<groupId>org.gvsig</groupId>
91
			<artifactId>org.gvsig.fmap.dal</artifactId>			
92
			<classifier>impl</classifier>
93
			<scope>runtime</scope>
94
		</dependency>	
95
		<dependency>
96
			<groupId>org.gvsig</groupId>
97
			<artifactId>org.gvsig.fmap.dal.file</artifactId>		
98
            <scope>compile</scope>
99
		</dependency>	
100
		<dependency>
101
			<groupId>org.gvsig</groupId>
102
			<artifactId>org.gvsig.fmap.dal.file</artifactId>
103
			<classifier>store.shp</classifier>
104
			<scope>test</scope>	
105
		</dependency>	
106
		<dependency>
107
			<groupId>org.gvsig</groupId>
108
			<artifactId>org.gvsig.fmap.dal.file</artifactId>
109
			<classifier>store.dbf</classifier>
110
			<scope>test</scope>	
111
		</dependency>
112
		<dependency>
113
            <groupId>org.gvsig</groupId>
114
            <artifactId>org.gvsig.projection</artifactId>  
115
            <classifier>cresques-impl</classifier>
116
            <scope>runtime</scope>		
117
		</dependency>	
118
		<dependency>
119
			<groupId>org.gvsig</groupId>
120
			<artifactId>org.gvsig.fmap.geometry</artifactId>			
121
			<classifier>impl</classifier>
122
			<scope>runtime</scope>		
123
		</dependency>
124
		<dependency>
125
			<groupId>org.gvsig</groupId>
126
			<artifactId>org.gvsig.compat</artifactId>			
127
			<scope>runtime</scope>		
128
		</dependency>
129
		<dependency>
130
			<groupId>org.gvsig</groupId>
131
			<artifactId>org.gvsig.compat</artifactId>			
132
			<classifier>se</classifier>		
133
			<scope>runtime</scope>		
134
		</dependency>	
135
		<dependency>
136
			<groupId>org.gvsig</groupId>
137
			<artifactId>org.gvsig.fmap.dal.index.spatial</artifactId>
138
			<classifier>jts</classifier>
139
			<scope>runtime</scope>
140
		</dependency>		
141
        <dependency>
142
            <groupId>org.gvsig</groupId>
143
            <artifactId>org.gvsig.i18n</artifactId>           
144
            <scope>compile</scope>      
145
        </dependency>   
146
	</dependencies>
147
    <properties>
148
        <build-dir>${basedir}/../../../build</build-dir>
149
    </properties>
150
</project>
0 151

  

Also available in: Unified diff