Revision 38684

View differences:

tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.8-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<mkdir dir="target" />
29

  
30
		<!-- Download the build jar file -->
31
		<get src="http://devel.gvsig.org/m2repo/j2se/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
		</copy>
41

  
42
	</target>
43
	
44
	<target name="find.depends.natives.file">
45
	    <condition property="depends.natives.file.exists">
46
            <available file="${org.gvsig.initial.build.basedir}/DEPENDS_ON_NATIVE_LIBRARIES"/>
47
	    </condition>	
48
	</target>
49
	
50
	<target name="find.gvsig.platform.properties.file" 
51
			depends="find.depends.natives.file"
52
			if="depends.natives.file.exists">
53
	    <condition property="gvsig.platform.exists">
54
            <available file="${user.home}/.gvsig.platform.properties"/>
55
	    </condition>	
56
	</target>
57
	
58
	<target name="check.gvsig.platform.properties" 
59
			depends="find.gvsig.platform.properties.file">
60
		<fail if="depends.natives.file.exists" unless="gvsig.platform.exists">
61
ERROR!!
62
	
63
You have to define your gvSIG platform properties, 
64
by creating the file: ${user.home}/.gvsig.platform.properties
65
with the following content:
66

  
67
native_platform=linux
68
native_distribution=all
69
native_compiler=gcc4
70
native_arch=i386
71
native_libraryType=dynamic
72
export native_classifier=${native_platform}-${native_distribution}-${native_compiler}-${native_arch}-${native_libraryType}
73

  
74
Replace the fifth initial variables values with the ones appropiate 
75
to your platform.
76
	
77
If you use maven in the command line, you can use the previous file also
78
to define the MAVEN_OPTS environment variable, by adding to your 
79
.bash_rc file something like this:
80

  
81
if [ -f "${HOME}/.gvsig.platform.properties" ]
82
then
83
    . ${HOME}/.gvsig.platform.properties
84
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m -Dnative-classifier=${native_classifier}"
85
else
86
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m"
87
fi
88

  
89
It will work if you use the bash shell. In any other case or platform, you'll
90
have to define your MAVEN_OPTS environment variable and set the 
91
"native-classifier" parameter directly.
92
		</fail>			
93
	
94
	</target>
95

  
96
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote,check.gvsig.platform.properties">
97

  
98
		<mkdir dir="target" />
99

  
100
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
101

  
102
		<!-- Copy the maven launchers to the workspace metadata folder -->
103
		<copy todir="${workspace.basedir}/.metadata">
104
			<fileset dir="${build.basedir}/eclipse-launchers">
105
				<exclude name="**/org.eclipse.jdt.core.prefs" />
106
				<exclude name="**/org.eclipse.core.variables.prefs" />
107
			</fileset>
108
		</copy>
109

  
110
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
111
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
112
		</concat>
113
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
114
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
115
		</concat>
116

  
117
		<!-- Configure the eclipse workspace -->
118
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
119

  
120
		<!-- Configure the gvSIG profile -->
121
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" />
122

  
123
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
124

  
125
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
126
			<classpath>
127
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
128
			</classpath>
129
		</taskdef>
130

  
131
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
132
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
133
		</xmltask>
134

  
135
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
136
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
137

  
138
		<!-- Compile, install and generate eclipse projects -->
139
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
140

  
141
		<echo>INFORMATION!!!</echo>
142
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
143

  
144
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
145
	</target>
146

  
147
	<target name="clean">
148
		<delete dir="target" />
149
	</target>
150
	
151
</project>
0 152

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.annotation</artifactId>
7
	<packaging>pom</packaging>
8
	<version>1.0.0-SNAPSHOT</version>
9
	<name>org.gvsig.annotation</name>
10
	<description>Annotation example project</description>
11
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.maven.base.pom</artifactId>
14
        <version>1.0.8-SNAPSHOT</version>
15
    </parent>
16
    
17
	<scm>
18
		<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/libraries/org.gvsig.annotation</connection>
19
		<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/libraries/org.gvsig.annotation</developerConnection>
20
		<url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/libraries/org.gvsig.annotation</url>
21
	</scm>
22

  
23
	<developers>
24
		<developer>
25
			<id>jpiera</id>
26
			<name>Jorge Piera</name>
27
			<email>jpiera@gvsig.org</email>
28
			<roles>
29
				<role>Architect</role>
30
				<role>Developer</role>
31
			</roles>
32
		</developer>
33
		<developer>
34
			<id>jjdelcerro</id>
35
			<name>Joaqu?n Jos? del Cerro</name>
36
			<email>jjdelcerro@gvsig.org</email>
37
			<roles>
38
				<role>Architect</role>			
39
			</roles>
40
		</developer>		
41
	</developers>
42
	<repositories>
43
		<repository>
44
			<id>gvsig-public-http-repository</id>
45
			<name>gvSIG maven public HTTP repository</name>
46
            <url>http://devel.gvsig.org/m2repo/j2se</url>
47
			<releases>
48
				<enabled>true</enabled>
49
				<updatePolicy>daily</updatePolicy>
50
				<checksumPolicy>warn</checksumPolicy>
51
			</releases>
52
			<snapshots>
53
				<enabled>true</enabled>
54
				<updatePolicy>daily</updatePolicy>
55
				<checksumPolicy>warn</checksumPolicy>
56
			</snapshots>
57
		</repository>
58
	</repositories>
59
	<build>
60
		<plugins>
61
            <!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION -->
62
            <plugin>
63
                <groupId>org.apache.maven.plugins</groupId>
64
                <artifactId>maven-surefire-plugin</artifactId>
65
                <configuration>
66
                    <skipTests>true</skipTests>
67
                </configuration>
68
            </plugin>
69
        </plugins>        
70
	</build>
71
    <dependencyManagement>
72
        <dependencies>          
73
            <dependency>
74
                <groupId>org.gvsig</groupId>
75
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
76
                <version>2.0.1-SNAPSHOT</version>
77
                <type>pom</type>
78
                <scope>import</scope>
79
            </dependency>
80
        </dependencies>
81
    </dependencyManagement>
82
	<dependencies>
83
		<dependency>
84
			<groupId>org.gvsig</groupId>
85
			<artifactId>org.gvsig.tools.lib</artifactId>
86
		</dependency>
87
		<dependency>
88
			<groupId>org.gvsig</groupId>
89
			<artifactId>org.gvsig.tools.lib</artifactId>
90
			<type>test-jar</type>
91
		</dependency>
92
        <dependency>
93
            <groupId>org.slf4j</groupId>
94
            <artifactId>slf4j-api</artifactId>
95
            <scope>compile</scope>
96
        </dependency>        	
97
	</dependencies>
98

  
99
	<modules>
100
		<module>org.gvsig.annotation.lib</module>
101
		<module>org.gvsig.annotation.swing</module>
102
		<module>org.gvsig.annotation.main</module>
103
	</modules>
104
</project>
0 105

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/README.txt
1
The first time you checkout the current project to a new workspace, 
2
you have to prepare it to be able to work easily with maven from
3
eclipse itself.
4

  
5
Perform the following steps:
6

  
7
1.- Launch the *prepare-workspace.xml* ant build file. 
8
    You can do it by loading the file into the ant view, 
9
    and running the default task, or right-clicking the 
10
    file from the package explorer or the navigator and
11
    select the option: *Run as > Ant build*. 
12
    
13
2.- Restart eclipse.
14

  
15
3.- Import the subprojects of the project you have just checked out.
16

  
17
Those steps are only needed once per workspace.     
18

  
0 19

  
tags/v2_0_0_Build_2050/libraries/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"
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.main</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.annotation.main</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.annotation</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.annotation.lib.impl</artifactId>
23
			<version>1.0.0-SNAPSHOT</version>
24
			<scope>runtime</scope>
25
		</dependency>
26
		<dependency>
27
			<groupId>org.gvsig</groupId>
28
			<artifactId>org.gvsig.annotation.swing.api</artifactId>
29
			<version>1.0.0-SNAPSHOT</version>
30
            <scope>compile</scope>
31
		</dependency>
32
		<dependency>
33
			<groupId>org.gvsig</groupId>
34
			<artifactId>org.gvsig.annotation.swing.impl</artifactId>
35
			<version>1.0.0-SNAPSHOT</version>
36
			<scope>runtime</scope>
37
		</dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
            <artifactId>org.gvsig.tools.lib</artifactId>
41
            <scope>compile</scope>
42
        </dependency>
43
        <dependency>
44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
46
            <scope>runtime</scope>
47
        </dependency>
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
50
            <artifactId>org.gvsig.fmap.dal</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.gvsig</groupId>
55
            <artifactId>org.gvsig.projection</artifactId>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
61
            <scope>compile</scope>
62
        </dependency>
63
	</dependencies>
64
</project>
0 65

  
tags/v2_0_0_Build_2050/libraries/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/v2_0_0_Build_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.main/src/main/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_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.main/src/main/java/org/gvsig/annotation/main/Main.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.main;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

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

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

  
49
    private static final Logger LOG = LoggerFactory.getLogger(Main.class);
50

  
51
    private AnnotationManager annotationManager;
52
    private AnnotationSwingManager annotationSwingManager;
53
    private DataManager dataManager;
54

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

  
88
}
0 89

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.main/src/main/java/org/gvsig/annotation/main/PreferencesMain.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.main;
23

  
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

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

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

  
49
    private static final Logger LOG = LoggerFactory.getLogger(PreferencesMain.class);
50

  
51
    private AnnotationManager annotationManager;
52
    private AnnotationSwingManager annotationSwingManager;
53
    private DataManager dataManager;
54

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

  
88
}
0 89

  
tags/v2_0_0_Build_2050/libraries/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
<!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 testing and demo application.</p>
11

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

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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.gvsig</groupId>
58
            <artifactId>org.gvsig.timesupport.lib.api</artifactId>
59
            <scope>compile</scope>
60
        </dependency>             
61
		<dependency>
62
			<groupId>org.opengis</groupId>
63
		    <artifactId>geoapi</artifactId>
64
			<scope>runtime</scope>
65
		</dependency>
66
		<dependency>
67
			<groupId>org.geotools</groupId>
68
			<artifactId>gt2-main</artifactId>
69
			<scope>runtime</scope>
70
		</dependency>
71
		<dependency>
72
			<groupId>javax.media</groupId>
73
			<artifactId>jai_core</artifactId>
74
			<scope>runtime</scope>
75
		</dependency>
76
		<dependency>
77
			<groupId>javax.media</groupId>
78
			<artifactId>jai_codec</artifactId>
79
			<scope>runtime</scope>
80
		</dependency>		
81
		<dependency>
82
			<groupId>org.gvsig</groupId>
83
			<artifactId>org.gvsig.annotation.lib.api</artifactId>
84
			<version>1.0.0-SNAPSHOT</version>
85
			<type>test-jar</type>
86
			<scope>test</scope>
87
		</dependency>	
88
		<dependency>
89
			<groupId>org.gvsig</groupId>
90
			<artifactId>org.gvsig.fmap.dal</artifactId>
91
			<classifier>spi</classifier>
92
			<scope>runtime</scope>		
93
		</dependency>
94
		<dependency>
95
			<groupId>org.gvsig</groupId>
96
			<artifactId>org.gvsig.fmap.dal</artifactId>			
97
			<classifier>impl</classifier>
98
			<scope>runtime</scope>
99
		</dependency>	
100
		<dependency>
101
			<groupId>org.gvsig</groupId>
102
			<artifactId>org.gvsig.fmap.dal.file</artifactId>		
103
            <scope>compile</scope>
104
		</dependency>	
105
		<dependency>
106
			<groupId>org.gvsig</groupId>
107
			<artifactId>org.gvsig.fmap.dal.file</artifactId>
108
			<classifier>store.shp</classifier>
109
			<scope>test</scope>	
110
		</dependency>	
111
		<dependency>
112
			<groupId>org.gvsig</groupId>
113
			<artifactId>org.gvsig.fmap.dal.file</artifactId>
114
			<classifier>store.dbf</classifier>
115
			<scope>test</scope>	
116
		</dependency>
117
		<dependency>
118
            <groupId>org.gvsig</groupId>
119
            <artifactId>org.gvsig.projection</artifactId>  
120
            <classifier>cresques-impl</classifier>
121
            <scope>runtime</scope>		
122
		</dependency>	
123
		<dependency>
124
			<groupId>org.gvsig</groupId>
125
			<artifactId>org.gvsig.fmap.geometry</artifactId>			
126
			<classifier>impl</classifier>
127
			<scope>runtime</scope>		
128
		</dependency>
129
		<dependency>
130
			<groupId>org.gvsig</groupId>
131
			<artifactId>org.gvsig.compat</artifactId>			
132
			<scope>runtime</scope>		
133
		</dependency>
134
		<dependency>
135
			<groupId>org.gvsig</groupId>
136
			<artifactId>org.gvsig.compat</artifactId>			
137
			<classifier>se</classifier>		
138
			<scope>runtime</scope>		
139
		</dependency>	
140
		<dependency>
141
			<groupId>org.gvsig</groupId>
142
			<artifactId>org.gvsig.fmap.dal.index.spatial</artifactId>
143
			<classifier>jts</classifier>
144
			<scope>runtime</scope>
145
		</dependency>		
146
        <dependency>
147
            <groupId>org.gvsig</groupId>
148
            <artifactId>org.gvsig.i18n</artifactId>           
149
            <scope>compile</scope>      
150
        </dependency>   
151
	</dependencies>
152
</project>
0 153

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/org.gvsig.annotation.lib.impl/src/main/resources/locale/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
centroid=Centroid
3

  
0 4

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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_2050/libraries/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
<!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_2050/libraries/org.gvsig.annotation/org.gvsig.annotation.lib/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.FileOutputStream;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.io.OutputStream;
29

  
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

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

  
62

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

  
74
	private AnnotationManager manager;
75
	private FeatureStore sourceStore;
76

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

  
84
	private String destinationGeometryAttributeName = null;
85

  
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
		super("annotation");
98
	    this.sourceStore = featureStore; 
99
		this.manager = manager;
100
		destinationGeometryAttributeName = featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
101
	}
102

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
256
		//Finish the edition
257
		destinationStore.finishEditing();
258

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

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

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

  
275
		out = new FileOutputStream(target);
276

  
277
		byte[] buf = new byte[1024];
278
		int len;
279
		while ((len = in.read(buf)) > 0) { 
280
			out.write(buf, 0, len); 
281
		} 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff