Revision 41379

View differences:

tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.buildtools/src/main/resources/gvsig/checkstyle.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE module PUBLIC
28
    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
29
    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
30

  
31
<!--
32

  
33
  Checkstyle configuration that checks the sun coding conventions from:
34

  
35
    - the Java Language Specification at
36
      http://java.sun.com/docs/books/jls/second_edition/html/index.html
37

  
38
    - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
39

  
40
    - the Javadoc guidelines at
41
      http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
42

  
43
    - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
44

  
45
    - some best practices
46

  
47
  Checkstyle is very configurable. Be sure to read the documentation at
48
  http://checkstyle.sf.net (or in your downloaded distribution).
49

  
50
  Most Checks are configurable, be sure to consult the documentation.
51

  
52
  To completely disable a check, just comment it out or delete it from the file.
53

  
54
  Finally, it is worth reading the documentation.
55

  
56
-->
57

  
58
<module name="Checker">
59
    <!--
60
        If you set the basedir property below, then all reported file
61
        names will be relative to the specified directory. See
62
        http://checkstyle.sourceforge.net/5.x/config.html#Checker
63

  
64
        <property name="basedir" value="${basedir}"/>
65
    -->
66
    <!-- gvSIG: All project files have the ISO-8859-1 charset -->
67
	<property name="charset" value="ISO-8859-1" />
68

  
69
    <!-- Checks that a package-info.java file exists for each package.     -->
70
    <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
71
	<module name="JavadocPackage">
72
		<property name="allowLegacy" value="true" />
73
	</module>
74

  
75
    <!-- Checks whether files end with a new line.                        -->
76
    <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
77
    <module name="NewlineAtEndOfFile"/>
78

  
79
    <!-- Checks that property files contain the same keys.         -->
80
    <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
81
    <module name="Translation"/>
82
    
83
    <!-- Checks for Size Violations.                    -->
84
    <!-- See http://checkstyle.sf.net/config_sizes.html -->
85
    <module name="FileLength"/>
86
    
87
    <!-- Checks for whitespace                               -->
88
    <!-- See http://checkstyle.sf.net/config_whitespace.html -->
89
    <module name="FileTabCharacter"/>
90

  
91

  
92
    <module name="TreeWalker">
93

  
94
	    <!-- Miscellaneous other checks.                   -->
95
	    <!-- See http://checkstyle.sf.net/config_misc.html -->
96
	    <!-- gvSIG: apply only to java files -->
97
	    <module name="RegexpSinglelineJava">
98
	       <property name="format" value="\s+$"/>
99
	       <property name="minimum" value="0"/>
100
	       <property name="maximum" value="0"/>
101
	       <property name="message" value="Line has trailing spaces."/>
102
	       <property name="ignoreComments" value="true"/>
103
	    </module>
104
	    
105
        <!-- Checks for Javadoc comments.                     -->
106
        <!-- See http://checkstyle.sf.net/config_javadoc.html -->
107
		<!--
108
			gvSIG rule 3: All protected or public classes must have a Javadoc comments,
109
			except getters and setters
110
		-->
111
		<module name="JavadocMethod">
112
			<property name="scope" value="protected" />
113
			<property name="allowMissingPropertyJavadoc" value="true" />
114
		</module>
115
		<!--
116
			gvSIG rule 9: All classes must have a Javadoc comment
117
			with the "@author tag" and the "@version $Id$" tag included 
118
		-->
119
		<module name="JavadocType">
120
			<property name="scope" value="private" />
121
			<property name="authorFormat" value="\S" />
122
			<property name="versionFormat" value="\$Id.*\$"/>
123
		</module>
124
        <module name="JavadocVariable">
125
			<property name="scope" value="protected" />
126
		</module>
127
		<!-- gvSIG rule 3: Check correctly formatted Javadoc -->
128
		<module name="JavadocStyle">
129
			<property name="scope" value="protected" />
130
		</module>
131

  
132

  
133
        <!-- Checks for Naming Conventions.                  -->
134
        <!-- See http://checkstyle.sf.net/config_naming.html -->
135
        <module name="ConstantName"/>
136
        <module name="LocalFinalVariableName"/>
137
        <module name="LocalVariableName"/>
138
        <module name="MemberName"/>
139
        <module name="MethodName"/>
140
		<!-- gvSIG rule 15: All packages must begin with org.gvsig.  -->
141
		<module name="PackageName">
142
			<property name="format" value="^org\.gvsig(\.[a-z][a-z0-9]*)+$" />
143
		</module>
144
		<!-- gvSIG advised rule 1: Abstract class names must begin with Abstract. -->
145
		<!-- module name="AbstractClassName" /-->
146
        <module name="ParameterName"/>
147
        <module name="StaticVariableName"/>
148
        <module name="TypeName"/>
149

  
150
        <!-- Checks for imports                              -->
151
        <!-- See http://checkstyle.sf.net/config_import.html -->
152
        <module name="AvoidStarImport"/>
153
        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
154
        <module name="RedundantImport"/>
155
        <module name="UnusedImports"/>
156

  
157

  
158
        <!-- Checks for Size Violations.                    -->
159
        <!-- See http://checkstyle.sf.net/config_sizes.html -->
160
        <module name="LineLength"/>
161
        <module name="MethodLength"/>
162
        <module name="ParameterNumber"/>
163

  
164

  
165
        <!-- Checks for whitespace                               -->
166
        <!-- See http://checkstyle.sf.net/config_whitespace.html -->
167
        <module name="EmptyForIteratorPad"/>
168
        <module name="GenericWhitespace"/>
169
        <module name="MethodParamPad"/>
170
        <module name="NoWhitespaceAfter"/>
171
        <module name="NoWhitespaceBefore"/>
172
        <module name="OperatorWrap"/>
173
        <module name="ParenPad"/>
174
        <module name="TypecastParenPad"/>
175
        <module name="WhitespaceAfter"/>
176
        <module name="WhitespaceAround"/>
177

  
178

  
179
        <!-- Modifier Checks                                    -->
180
        <!-- See http://checkstyle.sf.net/config_modifiers.html -->
181
        <module name="ModifierOrder"/>
182
        <module name="RedundantModifier"/>
183

  
184

  
185
        <!-- Checks for blocks. You know, those {}'s         -->
186
        <!-- See http://checkstyle.sf.net/config_blocks.html -->
187
        <module name="AvoidNestedBlocks"/>
188
        <module name="EmptyBlock"/>
189
        <module name="LeftCurly"/>
190
        <module name="NeedBraces"/>
191
        <module name="RightCurly"/>
192

  
193

  
194
        <!-- Checks for common coding problems               -->
195
        <!-- See http://checkstyle.sf.net/config_coding.html -->
196
        <module name="AvoidInlineConditionals"/>
197
        <module name="DoubleCheckedLocking"/>    <!-- MY FAVOURITE -->
198
        <module name="EmptyStatement"/>
199
        <module name="EqualsHashCode"/>
200
        <module name="HiddenField"/>
201
        <module name="IllegalInstantiation"/>
202
        <module name="InnerAssignment"/>
203
        <module name="MagicNumber"/>
204
        <module name="MissingSwitchDefault"/>
205
        <module name="RedundantThrows"/>
206
        <module name="SimplifyBooleanExpression"/>
207
        <module name="SimplifyBooleanReturn"/>
208

  
209
		<!-- gvSIG: Check for some common programming errors -->
210
		<module name="CovariantEquals" />
211
		<module name="StringLiteralEquality" />
212

  
213
        <!-- Checks for class design                         -->
214
        <!-- See http://checkstyle.sf.net/config_design.html -->
215
        <module name="DesignForExtension"/>
216
        <module name="FinalClass"/>
217
        <module name="HideUtilityClassConstructor"/>
218
        <module name="InterfaceIsType"/>
219
        <module name="VisibilityModifier"/>
220

  
221

  
222
        <!-- Miscellaneous other checks.                   -->
223
        <!-- See http://checkstyle.sf.net/config_misc.html -->
224
        <module name="ArrayTypeStyle"/>
225
        <!-- gvSIG: removed -->
226
        <!-- module name="FinalParameters"/-->
227
        <module name="TodoComment"/>
228
        <module name="UpperEll"/>
229
				
230
	    <!-- gvSIG rule 2: Sun style with 4 spaces -->
231
	    <module name="Indentation">
232
	    	<property name="basicOffset" value="4"/>
233
		    <property name="caseIndent" value="0"/>
234
		</module>
235
        
236
        <!-- gvSIG rule 10: Do not use System.out/err to log -->
237
		<module name="Regexp">
238
		    <!-- . matches any character, so we need to escape it and use \. 
239
		    to match dots.-->
240
		    <property name="format" value="System\.[out|err]\.println"/>
241
		    <property name="illegalPattern" value="true"/>
242
		</module>
243
		
244
		<!-- gvSIG rule 11: Try to avoid catching Throwable or 
245
		Exception and catch specific exceptions instead. -->
246
		<module name="IllegalCatch"/>
247
		
248
		<!-- gvSIG rule 13: Use interfaces in the declaration of 
249
		methods and variables.
250
        By default only avoids usage of Classes:
251
			"java.util.GregorianCalendar, java.util.Hashtable, 
252
		  	java.util.HashSet, java.util.HashMap, java.util.ArrayList, 
253
		  	java.util.LinkedList, java.util.LinkedHashMap, 
254
		  	java.util.LinkedHashSet, java.util.TreeSet, 
255
		  	java.util.TreeMap, java.util.Vector" -->
256
		<module name="IllegalType">
257
		    <property name="ignoredMethodNames" value="getInstance"/>
258
		</module>
259
		
260
    </module>
261

  
262
	<!--  gvSIG rule 1: check for the gvSIG header -->
263
    <!-- Uneeded, use the maven-license-plugin instead
264
	<module name="RegexpHeader"> -->
265
		<!-- The follow property value demonstrates the ability     -->
266
		<!-- to have access to ANT properties. In this case it uses -->
267
		<!-- the ${basedir} property to allow Checkstyle to be run  -->
268
		<!-- from any directory within a project. See property      -->
269
		<!-- expansion,                                             -->
270
		<!-- http://checkstyle.sf.net/config.html#properties        -->
271
    <!--
272
		<property name="headerFile" value="${checkstyle.header.file}" />
273
	</module>
274
    -->
275

  
276
</module>
0 277

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.buildtools/src/main/resources/header.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2013 gvSIG Association.
4
  
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 3
8
of the License, or (at your option) any later version.
9
  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
 
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
MA  02110-1301, USA.
19

  
20
For any additional information, do not hesitate to contact us 
21
at info AT gvsig.com, or visit our website www.gvsig.com.
0 22

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.buildtools/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <groupId>org.gvsig</groupId>
5
  <artifactId>org.gvsig.desktop.buildtools</artifactId>
6
  <version>1.0.0</version>
7
  <packaging>jar</packaging>
8
  <name>${project.artifactId}</name>
9
  <description>Resources used for build gvsig desktop</description>
10

  
11

  
12
<!-- No puede ser hijo de org.gvsig.desktop para evitar referencas circulares -->
13
<!--
14
  <parent>
15
    <groupId>org.gvsig</groupId>
16
    <artifactId>org.gvsig.desktop</artifactId>
17
    <version>2.0.10-SNAPSHOT</version>
18
  </parent>  
19
-->
20

  
21

  
22
    <licenses>
23
        <license>
24
            <name>GPLv3</name>
25
            <url>http://www.gnu.org/licenses/gpl.html</url>
26
            <distribution>repo</distribution>
27
            <comments>
28
			"GPL" stands for "General Public License". The most widespread such
29
			license is the GNU General Public License, or GNU GPL for short.
30
			This can be further shortened to "GPL", when it is understood that
31
			the GNU GPL is the one intended.
32
	      	</comments>
33
        </license>
34
    </licenses>
35

  
36
    <organization>
37
        <name>gvSIG Association</name>
38
        <url>http://www.gvsig.com/</url>
39
    </organization>
40

  
41
    <scm>
42
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/trunk</connection>
43
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/trunk</developerConnection>
44
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/trunk</url>
45
    </scm>
46
    
47
    <repositories>
48
      <repository>
49
        <id>gvsig-public-http-repository</id>
50
        <name>gvSIG maven public HTTP repository</name>
51
        <url>http://devel.gvsig.org/m2repo/j2se</url>
52
        <releases>
53
          <enabled>true</enabled>
54
          <updatePolicy>daily</updatePolicy>
55
          <checksumPolicy>warn</checksumPolicy>
56
        </releases>
57
        <snapshots>
58
          <enabled>true</enabled>
59
          <updatePolicy>daily</updatePolicy>
60
          <checksumPolicy>warn</checksumPolicy>
61
        </snapshots>
62
      </repository>
63
    </repositories>
64

  
65
    <distributionManagement>
66
      <site>
67
        <id>gvsig-repository</id>
68
        <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
69
      </site>
70
      <repository>
71
          <id>gvsig-repository</id>
72
          <name>gvSIG maven repository</name>
73
          <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
74
          <uniqueVersion>false</uniqueVersion>
75
      </repository>
76
      <snapshotRepository>
77
          <id>gvsig-repository</id>
78
          <name>gvSIG maven repository</name>
79
          <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
80
          <uniqueVersion>false</uniqueVersion>
81
      </snapshotRepository>
82
    </distributionManagement>
83
    
84
    <issueManagement>
85
      <system>redmine</system>
86
      <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop</url>
87
    </issueManagement>
88

  
89
    <mailingLists>
90
      <mailingList>
91
        <name>User List</name>
92
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_usuarios</subscribe>
93
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_usuarios</unsubscribe>
94
        <post>gvsig_usuarios@listserv.gva.es</post>
95
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
96
        <otherArchives>
97
          <otherArchive>http://www.mail-archive.com/gvsig_usuarios@runas.cap.gva.es</otherArchive>
98
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
99
        </otherArchives>
100
      </mailingList>
101
      <mailingList>
102
        <name>Developer List</name>
103
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</subscribe>
104
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</unsubscribe>
105
        <post>gvsig_desarrolladores@listserv.gva.es</post>
106
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
107
        <otherArchives>
108
          <otherArchive>http://www.mail-archive.com/gvsig_desarrolladores@runas.cap.gva.es</otherArchive>
109
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
110
        </otherArchives>
111
      </mailingList>
112
      <mailingList>
113
        <name>International List</name>
114
        <subscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</subscribe>
115
        <unsubscribe>http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</unsubscribe>
116
        <post>gvsig_internacional@listserv.gva.es</post>
117
        <archive>http://www.gvsig.org/web/community/mailing-lists/gvsig-nabble</archive>
118
        <otherArchives>
119
          <otherArchive>http://www.mail-archive.com/gvsig_internacional@runas.cap.gva.es</otherArchive>
120
          <otherArchive>http://dir.gmane.org/index.php?prefix=gmane.comp.gis.gvsig</otherArchive>
121
        </otherArchives>
122
      </mailingList>
123
    </mailingLists>
124
    
125
    <build>
126
        <extensions>
127
            <extension>
128
                <groupId>org.apache.maven.wagon</groupId>
129
                <artifactId>wagon-webdav-jackrabbit</artifactId>
130
                <version>1.0-beta-7</version>
131
            </extension>
132
        </extensions>
133
    </build>
134

  
135
</project>
0 136

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/src/main/java/org/gvsig/annotation/main/Main.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.annotation.main;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.annotation.AnnotationCreationService;
30
import org.gvsig.annotation.AnnotationLocator;
31
import org.gvsig.annotation.AnnotationManager;
32
import org.gvsig.annotation.swing.AnnotationSwingLocator;
33
import org.gvsig.annotation.swing.AnnotationSwingManager;
34
import org.gvsig.annotation.swing.AnnotationWindowManager;
35
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel;
36
import org.gvsig.fmap.crs.CRSFactory;
37
import org.gvsig.fmap.dal.DALLocator;
38
import org.gvsig.fmap.dal.DataManager;
39
import org.gvsig.fmap.dal.DataStoreParameters;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
42

  
43
/**
44
 * Main executable class for testing the Annotation library.
45
 * 
46
 * @author gvSIG Team
47
 * @version $Id$
48
 */
49
public class Main {
50

  
51
    private static final Logger LOG = LoggerFactory.getLogger(Main.class);
52

  
53
    private AnnotationManager annotationManager;
54
    private AnnotationSwingManager annotationSwingManager;
55
    private DataManager dataManager;
56

  
57
    public static void main(String args[]) throws Exception {
58
        new DefaultLibrariesInitializer().fullInitialize();
59
        Main main = new Main();
60
        main.show();
61
    }    
62
    
63
    @SuppressWarnings("serial")
64
    public void show() throws Exception {
65
        annotationManager = AnnotationLocator.getManager();
66
        annotationSwingManager = AnnotationSwingLocator.getSwingManager();
67
        dataManager = DALLocator.getDataManager();
68
        
69
        
70
        JAnnotationCreationServicePanel annotationCreationService = annotationSwingManager.createAnnotation(createService());
71
        annotationSwingManager.getWindowManager().showWindow(annotationCreationService, "Annotation App. example", AnnotationWindowManager.MODE_DIALOG);
72
    }   
73
    
74
    /**
75
     * Returns an instance of the {@link AnnotationCreationService}.
76
     * 
77
     * @return a {@link AnnotationCreationService} instance
78
     * @throws Exception
79
     *             if there is any error creating the instance
80
     */
81
    protected AnnotationCreationService createService() throws Exception {
82
    	String sourceFileName = getClass().getClassLoader().getResource("org/gvsig/annotation/data/andalucia.shp").getFile();
83
    	DataStoreParameters sourceParameters = dataManager.createStoreParameters("Shape");
84
     	sourceParameters.setDynValue("shpfile", sourceFileName);
85
     	sourceParameters.setDynValue("crs", CRSFactory.getCRS("EPSG:23030"));
86
     	FeatureStore sourceStore = (FeatureStore) dataManager.openStore("Shape", sourceParameters);
87
    	return annotationManager.getAnnotationCreationService(sourceStore);
88
    }
89

  
90
}
0 91

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/src/main/java/org/gvsig/annotation/main/PreferencesMain.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.annotation.main;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.annotation.AnnotationCreationService;
30
import org.gvsig.annotation.AnnotationLocator;
31
import org.gvsig.annotation.AnnotationManager;
32
import org.gvsig.annotation.swing.AnnotationSwingLocator;
33
import org.gvsig.annotation.swing.AnnotationSwingManager;
34
import org.gvsig.annotation.swing.AnnotationWindowManager;
35
import org.gvsig.annotation.swing.JAnnotationPreferencesPanel;
36
import org.gvsig.fmap.crs.CRSFactory;
37
import org.gvsig.fmap.dal.DALLocator;
38
import org.gvsig.fmap.dal.DataManager;
39
import org.gvsig.fmap.dal.DataStoreParameters;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
42

  
43
/**
44
 * Main executable class for testing the Annotation library.
45
 * 
46
 * @author gvSIG Team
47
 * @version $Id$
48
 */
49
public class PreferencesMain {
50

  
51
    private static final Logger LOG = LoggerFactory.getLogger(PreferencesMain.class);
52

  
53
    private AnnotationManager annotationManager;
54
    private AnnotationSwingManager annotationSwingManager;
55
    private DataManager dataManager;
56

  
57
    public static void main(String args[]) throws Exception {
58
        new DefaultLibrariesInitializer().fullInitialize();
59
        PreferencesMain main = new PreferencesMain();
60
        main.show();
61
    }    
62
    
63
    @SuppressWarnings("serial")
64
    public void show() throws Exception {
65
        annotationManager = AnnotationLocator.getManager();
66
        annotationSwingManager = AnnotationSwingLocator.getSwingManager();
67
        dataManager = DALLocator.getDataManager();
68
        
69
        
70
        JAnnotationPreferencesPanel annotationPreferencesPanel = annotationSwingManager.createAnnotationPreferences();
71
        annotationSwingManager.getWindowManager().showPreferencesWindow(annotationPreferencesPanel, "Annotation Preferences. example", AnnotationWindowManager.MODE_DIALOG);
72
    }   
73
    
74
    /**
75
     * Returns an instance of the {@link AnnotationCreationService}.
76
     * 
77
     * @return a {@link AnnotationCreationService} instance
78
     * @throws Exception
79
     *             if there is any error creating the instance
80
     */
81
    protected AnnotationCreationService createService() throws Exception {
82
    	String sourceFileName = getClass().getClassLoader().getResource("org/gvsig/annotation/data/andalucia.shp").getFile();
83
    	DataStoreParameters sourceParameters = dataManager.createStoreParameters("Shape");
84
     	sourceParameters.setDynValue("shpfile", sourceFileName);
85
     	sourceParameters.setDynValue("crs", CRSFactory.getCRS("EPSG:23030"));
86
     	FeatureStore sourceStore = (FeatureStore) dataManager.openStore("Shape", sourceParameters);
87
    	return annotationManager.getAnnotationCreationService(sourceStore);
88
    }
89

  
90
}
0 91

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/src/main/java/org/gvsig/annotation/main/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
28
<html xmlns="http://www.w3.org/1999/xhtml">
29
<head>
30
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31
<title>org.gvsig.annotation package documentation</title>
32
</head>
33
<body>
34

  
35
	<p>Annotation library testing and demo application.</p>
36

  
37
</body>
38
</html>
0 39

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/src/main/resources/README.txt
1
Put into this folder the resources needed by your classes.
2

  
3
This folder is added to the 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 classes.
0 9

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/src/main/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<!-- 
30
Log4J configuration file for unit tests execution.
31
 -->
32
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
33

  
34
	<!-- Appender configuration to show logging messages through the console -->
35
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
36
		<layout class="org.apache.log4j.PatternLayout">
37
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
38
		</layout>
39
	</appender>
40

  
41
	<!-- 
42
	Activate logging messages of DEBUG level of higher only for the
43
	org.gvsig.tools packages.
44
	You can put full classes names or packages instead, to configure
45
	logging for all the classes and subpackages of the package.
46
	-->
47
	<category name="org.gvsig.tools">
48
		<priority value="DEBUG" />
49
	</category>
50
	<category name="org.gvsig.annotation">
51
		<priority value="DEBUG" />
52
	</category>
53

  
54
	<!-- 
55
	By default, show only logging messages of INFO level or higher, 
56
	through the previously configured CONSOLE appender. 
57
	-->
58
	<root>
59
		<priority value="INFO" />
60
		<appender-ref ref="CONSOLE" />
61
	</root>
62
</log4j:configuration>
0 63

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.main/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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.annotation.main</artifactId>
5
  <packaging>jar</packaging>
6
  <name>${project.artifactId}</name>
7
  <parent>
8
    <groupId>org.gvsig</groupId>
9
    <artifactId>org.gvsig.annotation</artifactId>
10
    <version>2.0.36</version>
11
  </parent>
12
  <dependencies>
13
    <dependency>
14
      <groupId>org.gvsig</groupId>
15
      <artifactId>org.gvsig.annotation.lib.api</artifactId>
16
      <scope>compile</scope>
17
    </dependency>
18
    <dependency>
19
      <groupId>org.gvsig</groupId>
20
      <artifactId>org.gvsig.annotation.swing.api</artifactId>
21
      <scope>compile</scope>
22
    </dependency>
23
    <dependency>
24
        <groupId>org.gvsig</groupId>
25
        <artifactId>org.gvsig.tools.lib</artifactId>
26
        <scope>compile</scope>
27
    </dependency>
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.fmap.dal.api</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    <dependency>
34
        <groupId>org.gvsig</groupId>
35
        <artifactId>org.gvsig.projection.api</artifactId>
36
        <scope>compile</scope>
37
    </dependency>
38
    <dependency>
39
        <groupId>org.gvsig</groupId>
40
        <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
41
        <scope>compile</scope>
42
    </dependency>
43
  </dependencies>
44
</project>
0 45

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.lib/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/DefaultAnnotationManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.annotation.impl;
25

  
26
import java.awt.Color;
27
import java.util.ArrayList;
28
import java.util.Collections;
29
import java.util.List;
30

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

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

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

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

  
95
	public AnnotationPositionCalculator getDefaultAnnotationPositionCalculator() throws AnnotationPositionCalculatorCreationException {
96
		return getAnnotationPositionCalculator(DEFAULT_ANNOTATION_POSITION_CALCULATOR);
97
	}
98

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

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

  
115
	public void addFontStyle(String fontStyle) {
116
		fontStyles.add(fontStyle);		
117
	}
118

  
119
	public void addFontType(String fontType) {
120
		fontTypes.add(fontType);		
121
	}
122

  
123
	public int getDefaultFontColor() {
124
		return defaultFontColor;
125
	}
126

  
127
	public double getDefaultFontHeight() {
128
		return defaultFontHeight;
129
	}
130

  
131
	public double getDefaultFontRotation() {
132
		return defaultFontRotation;
133
	}
134

  
135
	public String getDefaultFontStyle() {
136
		return defaultFontStyle;
137
	}
138

  
139
	public String getDefaultFontType() {
140
		return defaultFontType;
141
	}
142

  
143
	public String getDefaultTextValue() {
144
		return defaultTextValue;
145
	}
146

  
147
	public List<String> getFontStyles() {
148
		return fontStyles;
149
	}
150

  
151
	public List<String> getFontTypes() {
152
		return fontTypes;
153
	}
154

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

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

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

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

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

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

  
183

  
184
}
0 185

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.lib/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
28
<html xmlns="http://www.w3.org/1999/xhtml">
29
<head>
30
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31
<title>org.gvsig.annotation package documentation</title>
32
</head>
33
<body>
34

  
35
	<p>Annotation library API default implementation.</p>
36

  
37
</body>
38
</html>
0 39

  
tags/org.gvsig.desktop-2.0.36/org.gvsig.desktop.library/org.gvsig.annotation/org.gvsig.annotation.lib/org.gvsig.annotation.lib.impl/src/main/java/org/gvsig/annotation/impl/DefaultAnnotationCreationService.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.annotation.impl;
25

  
26
import java.io.File;
27
import java.io.FileOutputStream;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.OutputStream;
31

  
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

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

  
64

  
65
/**
66
 * Default {@link AnnotationCreationService} implementation.
67
 * 
68
 * @author gvSIG Team
69
 * @version $Id$
70
 */
71
public class DefaultAnnotationCreationService extends AbstractMonitorableTask implements AnnotationCreationService {
72
	private static final Logger LOG = LoggerFactory.getLogger(DefaultAnnotationCreationService.class);
73
	private static final String TEMPLATE_NAME = "template.gvslab";
74
	private static DataManager dataManager = DALLocator.getDataManager();
75

  
76
	private AnnotationManager manager;
77
	private FeatureStore sourceStore;
78

  
79
	private int sourceFontTypeAttribute = -1;
80
	private int sourceFontStyleAttribute = -1;
81
	private int sourceFontColorAttribute = -1;
82
	private int sourceRotationAttribute = -1;
83
	private int sourceHeigthAttribute = -1;
84
	private AnnotationPositionCalculator annotationPositionCalculator = null;
85

  
86
	private String destinationGeometryAttributeName = null;
87

  
88
	private AnnotationCreationFinishAction annotationCreationFinishAction = null; 
89

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

  
105
	public AnnotationManager getManager() {
106
		return this.manager;
107
	}
108

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

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

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

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

  
137
			dataManager.newStore("FilesystemExplorer", "Shape", newFeatureStoreParameters, true);
138

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

  
144
			FeatureStore destinationStore = (FeatureStore) dataManager.openStore("Shape", newFeatureStoreParameters);
145

  
146
			copyFeatureStore(sourceStore, 
147
					destinationStore,
148
					textValueAttribute);	
149

  
150
			try {
151
				copyLegend(destinationStore);
152
			} catch (IOException e) {
153
				LOG.error("Error copying the legend");
154
			}
155

  
156
			if (annotationCreationFinishAction != null){
157
				annotationCreationFinishAction.finished(destinationStore);
158
			}
159

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

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

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

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

  
202
	private AttributeInserter createInserter(int attributePosition, Object defaultValue)
203
	{
204
		if (attributePosition > -1){
205
			return new StoreAttributeInserter(attributePosition);
206
		}else{
207
			return new DefaultAttributeInserter(defaultValue);
208
		}
209
	}
210

  
211
	private void copyFeatureStore(FeatureStore sourceStore,
212
			FeatureStore destinationStore, int textAttribute)
213
	throws AnnotationCreationException, DataException {		
214

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

  
218
		//Copy data
219
		FeatureSet featureSet = sourceStore.getFeatureSet();
220
		DisposableIterator iterator = featureSet.iterator();
221
		
222
		taskStatus.setRangeOfValues(0, featureSet.getSize());
223

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

  
231
		Feature sourceFeature;
232
		long featureCount = 0;
233
		while (iterator.hasNext()) {			
234
			sourceFeature = (Feature) iterator.next();
235

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

  
249
			destinationStore.insert(destinationFeature);
250
    		featureCount++;  
251
    		this.taskStatus.setCurValue(featureCount);
252
    
253
            if (this.taskStatus.isCancellationRequested()) {
254
                return;
255
            }
256
		}
257

  
258
		//Finish the edition
259
		destinationStore.finishEditing();
260

  
261
		//Dispose resources
262
		iterator.dispose();		
263
		featureSet.dispose();
264
		
265
		this.taskStatus.terminate();
266
        this.taskStatus.remove();		
267
	}
268

  
269
	private void copyLegend(FeatureStore destinationStore) throws ValidateDataParametersException, DataException, IOException {
270
		FilesystemServerExplorer filesystemServerExplorer = (FilesystemServerExplorer)destinationStore.getExplorer();
271
		File target = filesystemServerExplorer.getResourcePath(destinationStore, "gvslab");
272

  
273
		//Copy the template
274
		InputStream in = getClass().getClassLoader().getResourceAsStream(TEMPLATE_NAME);
275
		OutputStream out = null;
276

  
277
		out = new FileOutputStream(target);
278

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

  
288
	private void checkAttribute(int index, int[] type) throws DataException{
289
		if (index >= sourceStore.getDefaultFeatureType().size()){
290
			throw new IllegalArgumentException("Attribute not found");
291
		}
292
		int datatype = sourceStore.getDefaultFeatureType().getAttributeDescriptor(index).getDataType().getType();
293
		
294
		boolean validType = false;
295
		if(type != null) {
296
			for (int i = 0; i < type.length; i++) {
297
				if(datatype == type[i]) {
298
					validType = true;
299
				}
300
			}
301
		}
302
		
303
		if (!validType) {
304
			throw new IllegalArgumentException("The Attribute has not have the fine type");
305
		}
306
	}
307

  
308

  
309
	public void setFontTypeAttribute(int index) throws DataException {
310
		checkAttribute(index, new int[]{AnnotationDataTypes.FONTTYPE});
311
		this.sourceFontTypeAttribute = index;		
312
	}
313

  
314
	public void setFontStyleAttribute(int index) throws DataException {
315
		checkAttribute(index, new int[]{AnnotationDataTypes.FONTSTYLE});
316
		this.sourceFontStyleAttribute = index;		
317
	}
318

  
319
	public void setFontColorAttribute(int index) throws DataException {
320
		checkAttribute(index, new int[]{AnnotationDataTypes.FONTCOLOR});
321
		this.sourceFontColorAttribute = index;		
322
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff