Revision 36341

View differences:

tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/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" 
6
			  value="${org.gvsig.initial.build.basedir}/.."/>
7
	<property name="build.basedir" 
8
		      value="${workspace.basedir}/org.gvsig.maven.base.build"
9
		      description="Eclipse workspace location"/>
10
	<property name="build.jar.version" 
11
			 	  value="1.0.6-SNAPSHOT" />
12
	<property name="build.jar.file" 
13
		 	  value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
14
	
15
	<target name="check-maven-base-build-available">
16
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" 
17
				   property="maven-base-build-available"/>
18
	</target>
19
	
20
	<target name="get-maven-base-build-local" 
21
			depends="check-maven-base-build-available"
22
			if="maven-base-build-available">
23
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
24
		<unzip src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}"
25
		       dest="${workspace.basedir}">
26
		    <patternset>
27
		        <exclude name="META-INF/**"/>
28
		    </patternset>
29
		</unzip>	
30
	</target>
31
	
32
	<target name="get-maven-base-build-remote" 
33
			depends="check-maven-base-build-available"
34
			unless="maven-base-build-available">
35
		<!-- Download the build jar file -->
36
		<get src="http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" 
37
			 dest="target/${build.jar.file}"
38
			 verbose="true"/>
39
		
40
		<!-- Unzip de build jar file into the workspace root folder -->
41
		<unzip src="target/${build.jar.file}"
42
		       dest="${workspace.basedir}">
43
		    <patternset>
44
		        <exclude name="META-INF/**"/>
45
		    </patternset>
46
		</unzip>	
47
	</target>
48
	
49
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote">
50
		
51
		<mkdir dir="target"/>
52
	
53
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug"/>
54
		
55
		<!-- Copy the maven launchers to the workspace metadata folder -->
56
		<copy todir="${workspace.basedir}/.metadata">
57
		    <fileset dir="${build.basedir}/eclipse-launchers"/>
58
		</copy>
59
		
60
		<!-- Configure the eclipse workspace -->
61
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace"/>
62

  
63
		<!-- Configure the gvSIG profile -->
64
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" target="initialize"/>
65

  
66
		<!-- Compile, install and generate eclipse projects -->
67
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse"/>
68
		
69
		<echo>INFORMATION!!!</echo>
70
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
71
		
72
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
73
	</target>
74
 	
75
	<target name="clean">
76
		<delete dir="target"/>
77
	</target>
78

  
79
</project>
0 80

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/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
	<groupId>org.gvsig</groupId>
7
	<artifactId>org.gvsig.selectiontools.app</artifactId>
8
	<packaging>pom</packaging>
9
	<version>1.0.0-SNAPSHOT</version>
10
	<name>org.gvsig.selectiontools.app</name>
11
	<description>Advanced selection tools:
12
- select all
13
- by buffer
14
- by cicle
15
- by polilyne
16
</description>
17
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.selectiontools/${project.version}/basic/org.gvsig.selectiontools.app</url>
18
	<parent>
19
		<groupId>org.gvsig</groupId>
20
		<artifactId>gvsig-base-extension-pom</artifactId>
21
		<version>2.0-SNAPSHOT</version>
22
	</parent>
23

  
24
	<scm>
25
		<connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-selectiontools/org.gvsig.selectiontools/extension/trunk</connection>
26
		<developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-selectiontools/org.gvsig.selectiontools/extension/trunk</developerConnection>
27
		<url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.selectiontools/extension/trunk/?root=gvsig-selectiontools</url>
28
	</scm>
29

  
30
	<distributionManagement>
31
		<site>
32
			<id>gvsig-repository</id>
33
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.selectiontools/${project.version}/basic/org.gvsig.selectiontools.app</url>
34
		</site>
35
	</distributionManagement>
36
	<repositories>
37
		<repository>
38
			<id>gvsig-public-http-repository</id>
39
			<name>gvSIG maven public HTTP repository</name>
40
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
41
			<releases>
42
				<enabled>true</enabled>
43
				<updatePolicy>daily</updatePolicy>
44
				<checksumPolicy>warn</checksumPolicy>
45
			</releases>
46
			<snapshots>
47
				<enabled>true</enabled>
48
				<updatePolicy>daily</updatePolicy>
49
				<checksumPolicy>warn</checksumPolicy>
50
			</snapshots>
51
		</repository>
52
	</repositories>
53
	<build>
54
		<plugins>
55
			<plugin>
56
				<groupId>org.apache.maven.plugins</groupId>
57
				<artifactId>maven-release-plugin</artifactId>
58
				<configuration>
59
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-selectiontools/org.gvsig.selectiontools/extension/tags</tagBase>
60
				</configuration>
61
			</plugin>
62
		</plugins>
63
	</build>
64

  
65
	<modules>
66
		<module>org.gvsig.selectiontools.app.extension</module>
67
	</modules>
68
	<properties>
69
		<build-dir>${basedir}/../build</build-dir>
70
	</properties>
71

  
72
</project>
0 73

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/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_2035/extensions/org.gvsig.selectiontools.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Sep 01 13:26:10 CEST 2011
3
buildNumber=2043
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/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/maven-v4_0_0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.selectiontools.app.extension</artifactId>
7
	<packaging>jar</packaging>
8
	<name>Tools: Selection tools</name>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.selectiontools.app</artifactId>
12
		<version>1.0.0-SNAPSHOT</version>
13
	</parent>
14

  
15
	<dependencies>
16
		<dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.andami</artifactId>
19
            <scope>compile</scope>
20
		</dependency>
21
		<dependency>
22
			<groupId>org.gvsig</groupId>
23
			<artifactId>org.gvsig.i18n</artifactId>
24
            <scope>compile</scope>
25
		</dependency>
26
		<dependency>
27
			<groupId>org.gvsig</groupId>
28
			<artifactId>org.gvsig.tools.lib</artifactId>
29
            <scope>compile</scope>
30
		</dependency>
31
		<dependency>
32
			<groupId>org.gvsig</groupId>
33
			<artifactId>org.gvsig.app</artifactId>
34
			<version>2.0-SNAPSHOT</version>
35
            <scope>compile</scope>
36
		</dependency>
37
        <dependency>
38
            <groupId>org.gvsig</groupId>
39
            <artifactId>org.gvsig.about.api</artifactId>
40
            <scope>compile</scope>
41
        </dependency>
42
        <dependency>
43
            <groupId>org.gvsig</groupId>
44
            <artifactId>org.gvsig.fmap.dal</artifactId>
45
            <scope>compile</scope>
46
        </dependency>
47
        <dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>org.gvsig.fmap.geometry</artifactId>
50
            <scope>compile</scope>
51
        </dependency>
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.ui</artifactId>
55
            <scope>compile</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.fmap.mapcontext</artifactId>
60
            <scope>compile</scope>
61
        </dependency>
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>org.gvsig.fmap.control</artifactId>
65
            <scope>compile</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.utils</artifactId>
70
            <scope>compile</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.projection</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.slf4j</groupId>
84
            <artifactId>slf4j-api</artifactId>
85
            <scope>compile</scope>
86
        </dependency>
87
        <dependency>
88
            <groupId>com.vividsolutions</groupId>
89
            <artifactId>jts</artifactId>
90
            <scope>compile</scope>
91
        </dependency>
92
	</dependencies>
93
	<description>Advanced selection tools: 
94
- select all 
95
- by buffer 
96
- by cicle 
97
- by polilyne
98
</description>
99
	<profiles>
100
		<profile>
101
			<id>gvsig-install</id>
102
			<activation>
103
				<activeByDefault>true</activeByDefault>
104
			</activation>
105
			<properties>
106
				<!--
107
					Default gvSIG installation folder relative to the current workspace
108
				-->
109
				<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
110
			</properties>
111
		</profile>
112
	</profiles>
113
	<properties>
114
		<build-dir>${basedir}/../../build</build-dir>
115
	</properties>
116
</project>
0 117

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<!-- Estructure for the extension -->
8
		<fileSet>
9
			<directory>src/main/resources</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
	</fileSets>
14
	<files>
15
        <file>
16
            <source>package.info</source>
17
            <outputDirectory>${extension.install.dir.name}
18
            </outputDirectory>
19
        </file>
20
    </files>
21
    <dependencySets>
22
		<dependencySet>
23
			<outputDirectory>${extension.install.dir.name}/${library-dir}
24
			</outputDirectory>
25
			<includes>
26
				<include>org.gvsig:org.gvsig.selectiontools.app.extension</include>
27
			</includes>
28
		</dependencySet>
29
	</dependencySets>
30
</assembly>
0 31

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Thu Sep 01 13:26:11 CEST 2011
3
buildNumber=2035
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.selectiontools">
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_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/SelectByPolylineExtension.java
1
package org.gvsig.selectiontools.app.extension;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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 2
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
 */
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.view.ViewDocument;
29
import org.gvsig.app.project.documents.view.gui.IView;
30
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
31
import org.gvsig.fmap.mapcontext.MapContext;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
36
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
37
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior;
38
import org.gvsig.selectiontools.app.extension.tools.PolyLineSelectListener;
39

  
40
/**
41
 * <p>
42
 * Extension to add support for selecting the geometries of the active vector
43
 * layers that intersect with a polyline defined by the user.
44
 * </p>
45
 * 
46
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
47
 */
48
public class SelectByPolylineExtension extends Extension {
49

  
50
    public static final String POLYLINE_SELECTION_TOOL_NAME =
51
        "polylineSelection";
52

  
53
    /*
54
     * @see com.iver.andami.plugins.IExtension#initialize()
55
     */
56
    public void initialize() {
57
        registerIcons();
58
    }
59

  
60
    private void registerIcons() {
61
        PluginServices.getIconTheme().registerDefault("polyline-cursor-icon",
62
            this.getClass()
63
                .getClassLoader()
64
                .getResource("images/polyline-cursor-icon.png"));
65

  
66
        PluginServices.getIconTheme()
67
            .registerDefault("select-by-polyline-icon",
68
                this.getClass()
69
                    .getClassLoader()
70
                    .getResource("images/select-by-polyline-icon.png"));
71
    }
72

  
73
    /*
74
     * (non-Javadoc)
75
     * 
76
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
77
     */
78
    public void execute(String actionCommand) {
79
        if (actionCommand.equals("SELPOLYLINE")) {
80
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
81
            if (window instanceof IView) {
82
                IView view = (IView) window;
83
                // Selection by polyline
84
                MapControl mc = view.getMapControl();
85

  
86
                // If current's view MapControl doesn't have the
87
                // "CircleSelection" tool, adds it
88
                if (!mc.getNamesMapTools()
89
                    .containsKey(POLYLINE_SELECTION_TOOL_NAME)) {
90
                    PolyLineSelectListener polylineSelListener =
91
                        new PolyLineSelectListener(mc);
92
                    mc.addBehavior(POLYLINE_SELECTION_TOOL_NAME,
93
                        new Behavior[] {
94
                            new PolylineBehavior(polylineSelListener),
95
                            new MouseMovementBehavior(new StatusBarListener(mc)) });
96
                }
97

  
98
                mc.setTool(POLYLINE_SELECTION_TOOL_NAME);
99
            }
100
        }
101
    }
102

  
103
    /*
104
     * @see com.iver.andami.plugins.IExtension#isVisible()
105
     */
106
    public boolean isVisible() {
107
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
108

  
109
        if (f == null) {
110
            return false;
111
        }
112

  
113
        if (f instanceof IView) {
114
            IView vista = (IView) f;
115
            ViewDocument model = vista.getViewDocument();
116
            MapContext mapa = model.getMapContext();
117

  
118
            return mapa.getLayers().getLayersCount() > 0;
119
        }
120

  
121
        return false;
122
    }
123

  
124
    /*
125
     * @see com.iver.andami.plugins.IExtension#isEnabled()
126
     */
127
    public boolean isEnabled() {
128
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
129

  
130
        if (f == null) {
131
            return false;
132
        }
133

  
134
        if (f instanceof IView) {
135
            IView vista = (IView) f;
136
            ViewDocument model = vista.getViewDocument();
137
            MapContext mapa = model.getMapContext();
138

  
139
            FLayer layers[] = mapa.getLayers().getActives();
140
            FLayer layer;
141

  
142
            for (int i = 0; i < layers.length; i++) {
143
                layer = layers[i];
144

  
145
                if ((layer instanceof FLyrVect) && (layer.isAvailable())
146
                    && (layer.isActive()))
147
                    return true;
148
            }
149
        }
150

  
151
        return false;
152
    }
153
}
0 154

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/SelectionToolsExtension.java
1
package org.gvsig.selectiontools.app.extension;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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 2
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
 */
24

  
25
import org.gvsig.andami.plugins.Extension;
26

  
27
/**
28
 * Andami extension to show SelectionTools in the application.
29
 * 
30
 * @author gvSIG Team
31
 * @version $Id$
32
 */
33
public class SelectionToolsExtension extends Extension {
34

  
35
    public void initialize() {
36
        // Do nothing
37
    }
38

  
39
    @Override
40
    public void postInitialize() {
41
        super.postInitialize();
42
    }
43

  
44
    public void execute(String actionCommand) {
45
    }
46

  
47
    public boolean isEnabled() {
48
        return true;
49
    }
50

  
51
    public boolean isVisible() {
52
        return true;
53
    }
54

  
55
}
0 56

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/SelectAllExtension.java
1
package org.gvsig.selectiontools.app.extension;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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 2
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
 */
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.messages.NotificationManager;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.app.project.documents.view.ViewDocument;
30
import org.gvsig.app.project.documents.view.gui.IView;
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.fmap.dal.feature.FeatureStore;
33
import org.gvsig.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontext.layers.FLayer;
35
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
36
import org.gvsig.fmap.mapcontrol.MapControl;
37

  
38
/**
39
 * <p>
40
 * Extension to add support for selecting all the features of a vector layer.
41
 * </p>
42
 * 
43
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
44
 */
45
public class SelectAllExtension extends Extension {
46

  
47
    /*
48
     * @see com.iver.andami.plugins.IExtension#initialize()
49
     */
50
    public void initialize() {
51
        registerIcons();
52
    }
53

  
54
    private void registerIcons() {
55
        PluginServices.getIconTheme().registerDefault("select-all-icon",
56
            this.getClass()
57
                .getClassLoader()
58
                .getResource("images/select-all-icon.png"));
59
    }
60

  
61
    /*
62
     * (non-Javadoc)
63
     * 
64
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
65
     */
66
    public void execute(String actionCommand) {
67
        if (actionCommand.equals("SELALL")) {
68
            IWindow view = PluginServices.getMDIManager().getActiveWindow();
69
            if (view instanceof IView) {
70
                MapControl mc = ((IView) view).getMapControl();
71
                FLayer[] activeLayers =
72
                    mc.getMapContext().getLayers().getActives();
73

  
74
                FLayer layer;
75

  
76
                for (int i = 0; i < activeLayers.length; i++) {
77
                    layer = activeLayers[i];
78

  
79
                    if ((layer.isAvailable()) && (layer instanceof FLyrVect)) {
80
                        FLyrVect lyrVect = (FLyrVect) layer;
81

  
82
                        try {
83
                            FeatureStore fs = lyrVect.getFeatureStore();
84
                            fs.getFeatureSelection().selectAll();
85
                        } catch (DataException e) {
86
                            NotificationManager.showMessageError("Data exception",
87
                                e);
88
                        }
89
                    }
90
                }
91
            }
92
        }
93
    }
94

  
95
    /*
96
     * @see com.iver.andami.plugins.IExtension#isVisible()
97
     */
98
    public boolean isVisible() {
99
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
100

  
101
        if (f == null) {
102
            return false;
103
        }
104

  
105
        if (f instanceof IView) {
106
            IView vista = (IView) f;
107
            ViewDocument viewDocument = vista.getViewDocument(); // .getModel();
108
            MapContext mapa = viewDocument.getMapContext();
109

  
110
            return mapa.getLayers().getLayersCount() > 0;
111
        }
112

  
113
        return false;
114
    }
115

  
116
    /*
117
     * @see com.iver.andami.plugins.IExtension#isEnabled()
118
     */
119
    public boolean isEnabled() {
120
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
121

  
122
        if (f == null) {
123
            return false;
124
        }
125

  
126
        if (f instanceof IView) {
127
            IView vista = (IView) f;
128
            ViewDocument viewDocument = vista.getViewDocument();
129
            MapContext mapa = viewDocument.getMapContext();
130

  
131
            FLayer layers[] = mapa.getLayers().getActives();
132
            FLayer layer;
133

  
134
            for (int i = 0; i < layers.length; i++) {
135
                layer = layers[i];
136

  
137
                if ((layer instanceof FLyrVect) && (layer.isAvailable())
138
                    && (layer.isActive()))
139
                    return true;
140
            }
141
        }
142

  
143
        return false;
144
    }
145
}
0 146

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/SelectByCircleExtension.java
1
package org.gvsig.selectiontools.app.extension;
2

  
3
import org.gvsig.andami.PluginServices;
4
import org.gvsig.andami.plugins.Extension;
5
import org.gvsig.andami.ui.mdiManager.IWindow;
6
import org.gvsig.app.project.documents.view.ViewDocument;
7
import org.gvsig.app.project.documents.view.gui.IView;
8
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
9
import org.gvsig.fmap.mapcontext.MapContext;
10
import org.gvsig.fmap.mapcontext.layers.FLayer;
11
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
12
import org.gvsig.fmap.mapcontrol.MapControl;
13
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
14
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
15
import org.gvsig.selectiontools.app.extension.tools.CircleSelectListener;
16
import org.gvsig.selectiontools.app.extension.tools.behavior.CircleSelectionBehavior;
17

  
18
/* gvSIG. Geographic Information System of the Valencian Government
19
 *
20
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
21
 * of the Valencian Government (CIT)
22
 * 
23
 * This program is free software; you can redistribute it and/or
24
 * modify it under the terms of the GNU General Public License
25
 * as published by the Free Software Foundation; either version 2
26
 * of the License, or (at your option) any later version.
27
 * 
28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *  
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
36
 * MA  02110-1301, USA.
37
 * 
38
 */
39

  
40
/**
41
 * <p>
42
 * Extension to add support for selecting the geometries of the active vector
43
 * layers that intersect with a circle defined by the user.
44
 * </p>
45
 * 
46
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
47
 */
48
public class SelectByCircleExtension extends Extension {
49

  
50
    public static final String CIRCLE_SELECTION_TOOL_NAME = "circleSelection";
51

  
52
    /*
53
     * @see com.iver.andami.plugins.IExtension#initialize()
54
     */
55
    public void initialize() {
56
        registerIcons();
57
    }
58

  
59
    private void registerIcons() {
60
        PluginServices.getIconTheme().registerDefault("circle-cursor-icon",
61
            this.getClass()
62
                .getClassLoader()
63
                .getResource("images/circle-cursor-icon.png"));
64

  
65
        PluginServices.getIconTheme().registerDefault("select-by-circle-icon",
66
            this.getClass()
67
                .getClassLoader()
68
                .getResource("images/select-by-circle-icon.png"));
69
    }
70

  
71
    /*
72
     * (non-Javadoc)
73
     * 
74
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
75
     */
76
    public void execute(String actionCommand) {
77
        if (actionCommand.equals("SELCIRCLE")) {
78
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
79
            if (window instanceof IView) {
80
                IView view = (IView) window;
81
                // Selection by circle
82
                MapControl mc = view.getMapControl();
83

  
84
                // If current's view MapControl doesn't have the
85
                // "CircleSelection" tool, adds it
86
                if (!mc.getNamesMapTools()
87
                    .containsKey(CIRCLE_SELECTION_TOOL_NAME)) {
88
                    CircleSelectListener circleSelListener =
89
                        new CircleSelectListener(mc);
90
                    mc.addBehavior(CIRCLE_SELECTION_TOOL_NAME, new Behavior[] {
91
                        new CircleSelectionBehavior(circleSelListener),
92
                        new MouseMovementBehavior(new StatusBarListener(mc)) });
93
                }
94

  
95
                mc.setTool(CIRCLE_SELECTION_TOOL_NAME);
96
            }
97
        }
98
    }
99

  
100
    /*
101
     * @see com.iver.andami.plugins.IExtension#isVisible()
102
     */
103
    public boolean isVisible() {
104
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
105

  
106
        if (f == null) {
107
            return false;
108
        }
109

  
110
        if (f instanceof IView) {
111
            IView vista = (IView) f;
112
            ViewDocument model = vista.getViewDocument();
113
            MapContext mapa = model.getMapContext();
114

  
115
            return mapa.getLayers().getLayersCount() > 0;
116
        }
117

  
118
        return false;
119
    }
120

  
121
    /*
122
     * @see com.iver.andami.plugins.IExtension#isEnabled()
123
     */
124
    public boolean isEnabled() {
125
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
126

  
127
        if (f == null) {
128
            return false;
129
        }
130

  
131
        if (f instanceof IView) {
132
            IView vista = (IView) f;
133
            ViewDocument model = vista.getViewDocument();
134
            MapContext mapa = model.getMapContext();
135

  
136
            FLayer layers[] = mapa.getLayers().getActives();
137
            FLayer layer;
138

  
139
            for (int i = 0; i < layers.length; i++) {
140
                layer = layers[i];
141

  
142
                if ((layer instanceof FLyrVect) && (layer.isAvailable())
143
                    && (layer.isActive()))
144
                    return true;
145
            }
146
        }
147

  
148
        return false;
149
    }
150
}
0 151

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/AboutSelectionToolsExtension.java
1
package org.gvsig.selectiontools.app.extension;
2

  
3
import org.gvsig.about.AboutManager;
4
import org.gvsig.about.AboutParticipant;
5
import org.gvsig.andami.plugins.Extension;
6
import org.gvsig.app.ApplicationLocator;
7
import org.gvsig.app.ApplicationManager;
8

  
9
/* gvSIG. Geographic Information System of the Valencian Government
10
 *
11
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
12
 * of the Valencian Government (CIT)
13
 * 
14
 * This program is free software; you can redistribute it and/or
15
 * modify it under the terms of the GNU General Public License
16
 * as published by the Free Software Foundation; either version 2
17
 * of the License, or (at your option) any later version.
18
 * 
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *  
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
27
 * MA  02110-1301, USA.
28
 * 
29
 */
30

  
31
/**
32
 * <p>
33
 * Some selection tools for gvSIG of the <i>Consejer?a de Medio Ambiente de la
34
 * Junta de Castilla y Le?n.</i>
35
 * </p>
36
 * project.
37
 * 
38
 * @author Vicente Caballero Navarro (vicente.caballero@iver.es)
39
 * @author Jaume Dom?nguez Faus (jaume.dominguez@iver.es)
40
 * @author C?sar Mart?nez Izquierdo (cesar.martinez@iver.es)
41
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
42
 * @author Jos? Manuel Viv? Arnal (josemanuel.vivo@iver.es)
43
 */
44
public class AboutSelectionToolsExtension extends Extension {
45

  
46
    /*
47
     * (non-Javadoc)
48
     * 
49
     * @see com.iver.andami.plugins.IExtension#initialize()
50
     */
51
    public void initialize() {
52
    }
53

  
54
    public void postInitialize() {
55
        // Register the about panel
56
        ApplicationManager application = ApplicationLocator.getManager();
57

  
58
        AboutManager about = application.getAbout();
59

  
60
        about.addDeveloper("IVER", this.getClass().getClassLoader()
61
            .getResource("iver.html"), 1);
62

  
63
        AboutParticipant participant = about.getDeveloper("IVER");
64
        participant.addContribution("SelectionToolsExtension",
65
            "Selection tools", 2009, 1, 1, 2009, 12, 31);
66

  
67
        about.addSponsor("Junta de Castilla y Le?n", // Junta de Castilla y Le?n
68
            getClass().getClassLoader().getResource("jcyl.html"), 2);
69
    }
70

  
71
    /*
72
     * (non-Javadoc)
73
     * 
74
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
75
     */
76
    public void execute(String actionCommand) {
77
    }
78

  
79
    /*
80
     * (non-Javadoc)
81
     * 
82
     * @see com.iver.andami.plugins.IExtension#isEnabled()
83
     */
84
    public boolean isEnabled() {
85
        return false;
86
    }
87

  
88
    /*
89
     * (non-Javadoc)
90
     * 
91
     * @see com.iver.andami.plugins.IExtension#isVisible()
92
     */
93
    public boolean isVisible() {
94
        return false;
95
    }
96
}
0 97

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/CircleSelectionListener.java
1
package org.gvsig.selectiontools.app.extension.tools;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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 2
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
 */
24

  
25
import java.awt.Cursor;
26
import java.awt.Image;
27
import java.awt.Toolkit;
28
import java.awt.event.MouseEvent;
29

  
30
import javax.swing.ImageIcon;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.FeatureSelection;
36
import org.gvsig.fmap.dal.feature.FeatureSet;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
40
import org.gvsig.fmap.geom.Geometry.TYPES;
41
import org.gvsig.fmap.geom.GeometryManager;
42
import org.gvsig.fmap.geom.exception.CreateGeometryException;
43
import org.gvsig.fmap.geom.operation.GeometryOperationException;
44
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
45
import org.gvsig.fmap.geom.primitive.Point;
46
import org.gvsig.fmap.geom.primitive.Circle;
47
import org.gvsig.fmap.geom.primitive.GeneralPathX;
48
import org.gvsig.fmap.mapcontext.layers.FLayer;
49
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
50
import org.gvsig.fmap.mapcontrol.MapControl;
51
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
52
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
53
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener;
54

  
55
/**
56
 * <p>
57
 * Listener that selects all features of the active, available and vector layers
58
 * which intersect with the defined circle area in the associated
59
 * {@link MapControl MapControl} object.
60
 * </p>
61
 * 
62
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
63
 */
64
public class CircleSelectionListener implements CircleListener {
65

  
66
    /**
67
     * The image to display when the cursor is active.
68
     */
69
    private final Image img = new ImageIcon(this.getClass()
70
        .getClassLoader()
71
        .getResource("images/circle-cursor-icon.png")).getImage();
72

  
73
    /**
74
     * The cursor used to work with this tool listener.
75
     * 
76
     * @see #getCursor()
77
     */
78
    private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
79
        new java.awt.Point(16, 16),
80
        "");
81

  
82
    /**
83
     * Reference to the <code>MapControl</code> object that uses.
84
     */
85
    private MapControl mapCtrl;
86

  
87
    /**
88
     * <p>
89
     * Creates a new listener for selecting circular areas.
90
     * </p>
91
     * 
92
     * @param mc
93
     *            the <code>MapControl</code> object where the measures are made
94
     */
95
    public CircleSelectionListener(MapControl mc) {
96
        this.mapCtrl = mc;
97
    }
98

  
99
    /*
100
     * (non-Javadoc)
101
     * 
102
     * @see
103
     * com.iver.cit.gvsig.fmap.tools.Listeners.CircleListener#circle(com.iver
104
     * .cit.gvsig.fmap.tools.Events.MeasureEvent)
105
     */
106
    public void circle(MeasureEvent event) throws BehaviorException {
107
        if (event.getEvent().getID() == MouseEvent.MOUSE_RELEASED) {
108
            FLayer[] activeLayers =
109
                mapCtrl.getMapContext().getLayers().getActives();
110

  
111
            FLayer layer;
112
            FLyrVect lyrVect;
113

  
114
            Geometry geom = null;
115
            GeometryManager manager = GeometryLocator.getGeometryManager();
116
            Point center;
117
            try {
118
                center = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
119
                center.setX(event.getXs()[0].doubleValue());
120
                center.setY(event.getYs()[0].intValue());
121

  
122
                Point point2;
123
                point2 = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
124
                point2.setX(event.getXs()[1].doubleValue());
125
                point2.setY(event.getYs()[1].intValue());
126

  
127
                double radious = center.distance(point2);
128

  
129
                Circle circle = null;
130
                circle = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
131
                circle.setPoints(center, radious);
132
                geom = circle;
133
            } catch (CreateGeometryException e) {
134
                NotificationManager.showMessageError(PluginServices.getText(null,
135
                "Failed_creating_geometry"),
136
                e);
137
            } catch (GeometryOperationNotSupportedException e) {
138
                NotificationManager.showMessageError(PluginServices.getText(null,
139
                "Operation_not_supported"),
140
                e);
141
            } catch (GeometryOperationException e) {
142
                NotificationManager.showMessageError(PluginServices.getText(null,
143
                "Failed_performing_the_operation"),
144
                e);
145
            }
146
            if (geom == null)
147
                return;
148

  
149
            double flatness;
150

  
151
            // Creates the geometry
152
            // If the scale is < 500 -> approximates the circle with a polyline
153
            // with more points, as many as
154
            // smaller would be the scale
155
            if (mapCtrl.getMapContext().getScaleView() < 500) {
156
                GeneralPathX gP = new GeneralPathX();
157
                flatness = manager.getFlatness(); // ?????
158
                flatness =
159
                    mapCtrl.getMapContext().getScaleView() * flatness
160
                    / (500 * 2); // The number 2 forces to create the double
161
                // of points
162
                gP.append(geom.getPathIterator(null, flatness), true);
163
                try {
164
                    geom = manager.createSurface(gP, SUBTYPES.GEOM2D);
165
                } catch (CreateGeometryException e) {
166
                    NotificationManager.showMessageError(PluginServices.getText(null,
167
                    "Failed_creating_geometry"),
168
                    e);
169
                }
170
            } else {
171
                // Bigger scale -> Smaller flatness
172
                GeneralPathX gP = new GeneralPathX();
173
                flatness = manager.getFlatness(); // ?????
174
                flatness =
175
                    flatness / (mapCtrl.getMapContext().getScaleView() * 2);
176
                // *2 to reduce the number of lines of the polygon
177

  
178
                gP.append(geom.getPathIterator(null, flatness), true);
179
                try {
180
                    geom = manager.createSurface(gP, SUBTYPES.GEOM2D);
181
                } catch (CreateGeometryException e) {
182
                    NotificationManager.showMessageError(PluginServices.getText(null,
183
                    "Failed_creating_geometry"),
184
                    e);
185
                }
186
            }
187

  
188
            for (int i = 0; i < activeLayers.length; i++) {
189
                layer = activeLayers[i];
190

  
191
                if ((layer.isAvailable()) && (layer instanceof FLyrVect)) {
192
                    lyrVect = (FLyrVect) layer;
193
                    FeatureSet newSelection = null;
194

  
195
                    try {
196
                        newSelection =
197
                            lyrVect.queryByGeometry(geom,
198
                                lyrVect.getFeatureStore()
199
                                .getDefaultFeatureType());
200

  
201
                        if (event.getEvent().isControlDown()) {
202
                            ((FeatureSelection) lyrVect.getDataStore()
203
                                .getSelection()).select(newSelection);
204
                        } else {
205
                            lyrVect.getFeatureStore()
206
                            .setSelection(newSelection);
207
                        }
208

  
209
                    } catch (DataException e) {
210
                        NotificationManager.showMessageError(PluginServices.getText(null,
211
                            "Failed_selecting_geometries"),
212
                            e);
213
                    } finally {
214
                        newSelection.dispose();
215
                    }
216
                }
217
            }
218
        }
219
    }
220

  
221
    /*
222
     * (non-Javadoc)
223
     * 
224
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
225
     */
226
    public Cursor getCursor() {
227
        return cur;
228
    }
229

  
230
    /*
231
     * (non-Javadoc)
232
     * 
233
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
234
     */
235
    public boolean cancelDrawing() {
236
        return false;
237
    }
238

  
239
    public Image getImageCursor() {
240
        return img;
241
    }
242
}
0 243

  
tags/v2_0_0_Build_2035/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/behavior/CircleSelectionBehavior.java
1
package org.gvsig.selectiontools.app.extension.tools.behavior;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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 2
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
 */
24

  
25
import java.awt.Color;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.Point;
29
import java.awt.Rectangle;
30
import java.awt.event.MouseEvent;
31
import java.awt.geom.Arc2D;
32
import java.awt.geom.Point2D;
33
import java.awt.geom.Rectangle2D;
34
import java.awt.image.BufferedImage;
35

  
36
import org.gvsig.fmap.mapcontext.ViewPort;
37
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
38
import org.gvsig.fmap.mapcontrol.tools.Behavior.CircleBehavior;
39
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
40
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener;
41

  
42
/**
43
 * 
44
 * 
45
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
46
 */
47
public class CircleSelectionBehavior extends CircleBehavior {
48

  
49
    /**
50
	 * 
51
	 */
52
    private CircleListener listener;
53

  
54
    /**
55
     * Auxiliary point that represents a corner selected in image coordinates.
56
     */
57
    private Point2D m_PointAnt;
58

  
59
    public CircleSelectionBehavior(CircleListener zili) {
60
        super(zili);
61

  
62
        listener = zili;
63
    }
64

  
65
    /*
66
     * (non-Javadoc)
67
     * 
68
     * @see
69
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt
70
     * .Graphics)
71
     */
72
    public void paintComponent(Graphics g) {
73
        double radio;
74
        BufferedImage img = getMapControl().getImage();
75
        g.drawImage(img, 0, 0, null);
76
        g.setColor(Color.black);
77
        g.setXORMode(Color.white);
78
        if ((m_FirstPoint != null) && (m_LastPoint != null)) {
79
            radio = m_LastPoint.distance(m_FirstPoint);
80
            Arc2D.Double arc =
81
                new Arc2D.Double(m_FirstPoint.getX() - radio,
82
                    m_FirstPoint.getY() - radio,
83
                    2 * radio,
84
                    2 * radio,
85
                    0,
86
                    360,
87
                    Arc2D.OPEN);
88

  
89
            ((Graphics2D) g).draw(arc);
90
        }
91
    }
92

  
93
    /*
94
     * (non-Javadoc)
95
     * 
96
     * @see
97
     * com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt
98
     * .event.MouseEvent)
99
     */
100
    public void mousePressed(MouseEvent e) {
101

  
102
        Point pScreen = e.getPoint();
103
        m_PointAnt = pScreen;
104

  
105
        if ((!isClicked) && (e.getButton() == MouseEvent.BUTTON1)) {
106
            m_PointAnt = pScreen;
107
            m_FirstPoint = m_PointAnt;
108
            isClicked = true;
109
        }
110

  
111
        if (listener.cancelDrawing()) {
112
            getMapControl().cancelDrawing();
113
            isClicked = false;
114
        }
115
        getMapControl().repaint();
116
    }
117

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

Also available in: Unified diff