Revision 2415

View differences:

org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/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

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3

  
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.raster.cache</artifactId>
6
    <packaging>pom</packaging>
7
    <name>org.gvsig.raster.cache</name>
8
    <description>Cache management for raster files</description>
9
    <version>2.1.0-SNAPSHOT</version>
10
    <scm>
11
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/trunk/org.gvsig.raster.cache</connection>
12
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/trunk/org.gvsig.raster.cache</developerConnection>
13
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/trunk/org.gvsig.raster.cache</url>
14
    </scm>
15
    
16
    <repositories>
17
      <repository>
18
        <id>gvsig-public-http-repository</id>
19
        <name>gvSIG maven public HTTP repository</name>
20
        <url>http://devel.gvsig.org/m2repo/j2se</url>
21
        <releases>
22
          <enabled>true</enabled>
23
          <updatePolicy>daily</updatePolicy>
24
          <checksumPolicy>warn</checksumPolicy>
25
        </releases>
26
        <snapshots>
27
          <enabled>true</enabled>
28
          <updatePolicy>daily</updatePolicy>
29
          <checksumPolicy>warn</checksumPolicy>
30
        </snapshots>
31
      </repository>
32
    </repositories>
33
    
34
    <parent>
35
      <groupId>org.gvsig</groupId>
36
      <artifactId>org.gvsig.desktop</artifactId>
37
      <version>2.0.22</version>
38
    </parent>
39
    <developers>
40
        <developer>
41
            <id>nbrodin</id>
42
            <name>Nacho Brodin</name>
43
            <email>nachobrodin@gmail.com</email>
44
            <roles>
45
                <role>Architect</role>
46
                <role>Developer</role>
47
            </roles>
48
        </developer>
49
    </developers>
50
     <dependencyManagement>
51
        <dependencies>
52
	        <!--<dependency>
53
				<groupId>org.gvsig</groupId>
54
				<artifactId>org.gvsig.jgdal</artifactId>
55
				<version>2.0.4-SNAPSHOT</version>
56
			</dependency>
57
	        <dependency>
58
	            <groupId>org.gvsig</groupId>
59
	            <artifactId>org.gvsig.jgdal</artifactId>
60
	            <version>2.0.4-SNAPSHOT</version>
61
	            <classifier>${native_classifier}</classifier>
62
	            <type>tar.gz</type>
63
	        </dependency>-->
64
		    <dependency>
65
				<groupId>org.gvsig</groupId>
66
				<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
67
				<version>2.1.0-SNAPSHOT</version>
68
			</dependency>
69
        </dependencies>
70
    </dependencyManagement>
71
    <dependencies>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.tools.lib</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
    </dependencies>
78
    <build>
79
        <plugins>
80
            <plugin>
81
                <groupId>org.apache.maven.plugins</groupId>
82
                <artifactId>maven-release-plugin</artifactId>
83
                <configuration>
84
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase>
85
                    <goals>deploy</goals>
86
                </configuration>
87
            </plugin>
88
            <plugin>
89
				<groupId>org.apache.maven.plugins</groupId>
90
				<artifactId>maven-compiler-plugin</artifactId>
91
				<configuration>
92
					<source>1.5</source>
93
					<target>1.5</target>
94
				</configuration>
95
			</plugin>
96
			<plugin>
97
                <groupId>org.codehaus.mojo</groupId>
98
                <artifactId>animal-sniffer-maven-plugin</artifactId>
99
                <configuration>
100
                    <skip>true</skip>
101
                </configuration>
102
            </plugin>
103
        </plugins>
104
    </build>
105
    <modules>
106
        <module>org.gvsig.raster.cache.lib.api</module>
107
        <module>org.gvsig.raster.cache.lib.impl</module>
108
    </modules>
109
</project>
0 110

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

  
24

  
25
import java.io.File;
26

  
27
import junit.framework.TestCase;
28

  
29
import org.gvsig.raster.cache.tile.exception.TileGettingException;
30
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
31
import org.gvsig.raster.cache.tile.pool.ThreadPool;
32
import org.gvsig.raster.cache.tile.provider.Downloader;
33
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
34

  
35
/**
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class TestThreadPool extends TestCase {
40
	private static final int  WIDTH           = 3;
41
	private static final int  HEIGHT          = 3;
42
	private static final int  DOWNLOAD_TIME   = 500;
43
	
44
	public class MyDownloader implements Downloader {
45

  
46
		public Tile downloadTile(Tile tile) {
47
			//tile.getFile() -> Aqui se guarda el fichero descargado
48
			try {
49
				Thread.sleep(DOWNLOAD_TIME);
50
			} catch (InterruptedException e) {
51
				e.printStackTrace();
52
			}
53
			return tile;
54
		}
55

  
56
		public Tile readTileFromDisk(Tile tile) throws TileGettingException {
57
			// TODO Auto-generated method stub
58
			return null;
59
		}
60
		
61
		/*
62
		 * (non-Javadoc)
63
		 * @see org.gvsig.raster.cache.tile.provider.Downloader#cancelDownloading(boolean)
64
		 */
65
		public void cancelDownloading(boolean cancel) {
66
			
67
		}
68

  
69
		public Object[] getCrashImage(int w, int h) {
70
			// TODO Auto-generated method stub
71
			return null;
72
		}
73

  
74
		public Object[] getDownloadingImage(int w, int h) {
75
			// TODO Auto-generated method stub
76
			return null;
77
		}
78
		
79
	}
80
	
81
	public void start() {
82
		try {
83
			this.doSetUp();
84
		} catch (Exception e) {
85
			e.printStackTrace();
86
		}
87
		this.testStack();
88
	}
89
	
90
	protected void doSetUp() throws Exception {
91
		System.err.println("TestThreadPool running...");
92
	}
93
	
94
	public void testStack() {
95
		new DefaultLibrariesInitializer().fullInitialize(true);
96
		ThreadPool pool = new ThreadPoolImpl(false);
97
		MyDownloader d = new MyDownloader();
98
		
99
		for (int x = 0; x < HEIGHT; x++) {
100
			for (int y = 0; y < WIDTH; y++) {
101
				Tile t = TileCacheLocator.getManager().createTile(0, x, y);
102
				t.setSharedPipe(pool.getTilePipe());
103
				t.setDownloader(d);
104
				t.setFile(new File(""));
105
				pool.addTask(t);
106
			}
107
		}
108
		
109
		int nCollected = 0;
110
		while (nCollected < (WIDTH * HEIGHT)) {
111
			Tile tile = (Tile)pool.getTilePipe().getAtomicTask();
112
			System.out.println("Getting " + tile.getRow() + " " + tile.getCol() + " P:" + tile.getPriority());
113
			nCollected ++;
114
		}
115
		if(pool != null)
116
			pool.destroyPool();
117
	}
118

  
119
}
0 120

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/java/org/gvsig/raster/cache/tile/impl/provider/TestCacheStruct.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.raster.cache.tile.impl.provider;
23

  
24
import junit.framework.TestCase;
25

  
26
/**
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class TestCacheStruct extends TestCase {
31

  
32
	public void start() {
33
		this.setUp();
34
		this.testStack();
35
	}
36
	
37
	public void setUp() {
38
		System.err.println("TestCacheStruct running...");
39

  
40
	}
41
	
42
	public void testStack() {
43
        System.err.println("TODO: SOLVE THIS TEST");
44

  
45
        // int levels = 25;
46
        // FlatXFileSystemStrategy strat = new FlatXFileSystemStrategy();
47
        // DefaultCacheStruct struct = new DefaultCacheStruct(
48
        // CacheStruct.FLAT,
49
        // levels,
50
        // new Rectangle2D.Double(142671.0, 4194630.0, 228883.5, 255217.5),
51
        // 28.5,
52
        // 256,
53
        // 256,
54
        // "myLayer",
55
        // strat,
56
        // "baseDir",
57
        // "tif");
58
        // System.out.println("***World***");
59
        // for (int i = 0; i < levels; i++) {
60
        // System.out.println("-Level:" + i + " " +
61
        // struct.getWorldWidthOfTileMatrixByLevel(i) + " X " +
62
        // struct.getWorldHeightOfTileMatrixByLevel(i) + " : " +
63
        // struct.getPixelSizeByLevel(i));
64
        // }
65
        //
66
        // System.out.println("***Layer***");
67
        // for (int i = 0; i < levels; i++) {
68
        // System.out.println("Level:" + i +
69
        // " X:" + struct.getLayerInitXTilePositionByLevel(i) +
70
        // " Y:" + struct.getLayerInitYTilePositionByLevel(i) + ", " +
71
        // struct.getLayerWidthOfTileMatrixByLevel(i) + " X " +
72
        // struct.getLayerHeightOfTileMatrixByLevel(i));
73
        // }
74
	}
75
}
0 76

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/java/org/gvsig/raster/cache/tile/impl/download/TestThreadPool.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.raster.cache.tile.impl.download;
23

  
24
import java.io.File;
25

  
26
import junit.framework.TestCase;
27

  
28
import org.gvsig.raster.cache.tile.Tile;
29
import org.gvsig.raster.cache.tile.exception.TileGettingException;
30
import org.gvsig.raster.cache.tile.impl.TileImpl;
31
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
32
import org.gvsig.raster.cache.tile.pool.ThreadPool;
33
import org.gvsig.raster.cache.tile.provider.Downloader;
34

  
35
/**
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class TestThreadPool extends TestCase {
40
	private static final int  WIDTH           = 3;
41
	private static final int  HEIGHT          = 3;
42
	private static final int  DOWNLOAD_TIME   = 500;
43
	
44
	public class MyDownloader implements Downloader {
45

  
46
		public Tile downloadTile(Tile tile) {
47
			//tile.getFile() -> Aqui se guarda el fichero descargado
48
			try {
49
				Thread.sleep(DOWNLOAD_TIME);
50
			} catch (InterruptedException e) {
51
				e.printStackTrace();
52
			}
53
			return tile;
54
		}
55

  
56
		public Tile readTileFromDisk(Tile tile) throws TileGettingException {
57
			// TODO Auto-generated method stub
58
			return null;
59
		}
60

  
61
		public void cancelDownloading(boolean cancel) {
62
			// TODO Auto-generated method stub
63
			
64
		}
65

  
66
		public Object[] getCrashImage(int w, int h) {
67
			// TODO Auto-generated method stub
68
			return null;
69
		}
70

  
71
		public Object[] getDownloadingImage(int w, int h) {
72
			// TODO Auto-generated method stub
73
			return null;
74
		}
75
	}
76
	
77
	public void start() {
78
		this.setUp();
79
		this.testStack();
80
	}
81
	
82
	public void setUp() {
83
		System.err.println("TestThreadPool running...");
84

  
85
	}
86
	
87
	public void testStack() {
88
		ThreadPool pool = new ThreadPoolImpl(false);
89
		MyDownloader d = new MyDownloader();
90
		
91
		for (int x = 0; x < HEIGHT; x++) {
92
			for (int y = 0; y < WIDTH; y++) {
93
				TileImpl t = new TileImpl(0, x, y);
94
				t.setSharedPipe(pool.getTilePipe());
95
				t.setDownloader(d);
96
				t.setFile(new File(""));
97
				pool.addTask(t);
98
			}
99
		}
100
		
101
		int nCollected = 0;
102
		while (nCollected < (WIDTH * HEIGHT)) {
103
			Tile tile = (Tile)pool.getTilePipe().getAtomicTask();
104
			System.out.println("Getting " + tile.getRow() + " " + tile.getCol() + " P:" + tile.getPriority());
105
			nCollected ++;
106
		}
107
		if(pool != null)
108
			pool.destroyPool();
109
	}
110
}
0 111

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/java/org/gvsig/raster/cache/tile/impl/download/TestThreadPoolWithPriorities.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.raster.cache.tile.impl.download;
23

  
24
import java.io.File;
25
import java.util.Random;
26

  
27
import junit.framework.TestCase;
28

  
29
import org.gvsig.raster.cache.tile.Tile;
30
import org.gvsig.raster.cache.tile.exception.TileGettingException;
31
import org.gvsig.raster.cache.tile.impl.TileImpl;
32
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
33
import org.gvsig.raster.cache.tile.pool.ThreadPool;
34
import org.gvsig.raster.cache.tile.provider.Downloader;
35

  
36
/**
37
 * 
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class TestThreadPoolWithPriorities extends TestCase {
41
	private static final int  WIDTH           = 3;
42
	private static final int  HEIGHT          = 3;
43
	private static final int  DOWNLOAD_TIME   = 500;
44
	
45
	public class MyDownloader implements Downloader {
46

  
47
		public Tile downloadTile(Tile tile) {
48
			//tile.getFile() -> Aqui se guarda el fichero descargado
49
			try {
50
				Thread.sleep(DOWNLOAD_TIME);
51
			} catch (InterruptedException e) {
52
				e.printStackTrace();
53
			}
54
			return tile;
55
		}
56

  
57
		public Tile readTileFromDisk(Tile tile) throws TileGettingException {
58
			// TODO Auto-generated method stub
59
			return null;
60
		}
61
		
62
		/*
63
		 * (non-Javadoc)
64
		 * @see org.gvsig.raster.cache.tile.provider.Downloader#cancelDownloading(boolean)
65
		 */
66
		public void cancelDownloading(boolean cancel) {
67
			
68
		}
69

  
70
		public Object[] getCrashImage(int w, int h) {
71
			// TODO Auto-generated method stub
72
			return null;
73
		}
74

  
75
		public Object[] getDownloadingImage(int w, int h) {
76
			// TODO Auto-generated method stub
77
			return null;
78
		}
79
		
80
	}
81
	
82
	public void start() {
83
		this.setUp();
84
		this.testStack();
85
	}
86
	
87
	public void setUp() {
88
		System.err.println("TestThreadPool running...");
89

  
90
	}
91
	
92
	public void testStack() {
93
		ThreadPool pool = new ThreadPoolImpl();
94
		MyDownloader d = new MyDownloader();
95
		Random r = new Random();
96
		
97
		for (int x = 0; x < HEIGHT; x++) {
98
			for (int y = 0; y < WIDTH; y++) {
99
				TileImpl t = new TileImpl(0, x, y);
100
				t.setSharedPipe(pool.getTilePipe());
101
				t.setDownloader(d);
102
				t.setFile(new File(""));
103
				t.setPriority(r.nextInt());
104
				pool.addTask(t);
105
			}
106
		}
107
		
108
		((ThreadPoolImpl)pool).init();
109
		
110
		int nCollected = 0;
111
		while (nCollected < (WIDTH * HEIGHT)) {
112
			Tile tile = (Tile)pool.getTilePipe().getAtomicTask();
113
			System.out.println("Getting " + tile.getRow() + " " + tile.getCol() + " P:" + tile.getPriority());
114
			nCollected ++;
115
		}
116
		if(pool != null)
117
			pool.destroyPool();
118
	}
119
}
0 120

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/java/org/gvsig/raster/cache/tile/impl/pool/TestThreadPoolWithPriorities.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.raster.cache.tile.impl.pool;
23

  
24
import java.io.File;
25
import java.util.Random;
26

  
27
import junit.framework.TestCase;
28

  
29
import org.gvsig.raster.cache.tile.Tile;
30
import org.gvsig.raster.cache.tile.exception.TileGettingException;
31
import org.gvsig.raster.cache.tile.impl.TileImpl;
32
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
33
import org.gvsig.raster.cache.tile.provider.Downloader;
34

  
35
/**
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class TestThreadPoolWithPriorities extends TestCase {
40
	private static final int  WIDTH           = 3;
41
	private static final int  HEIGHT          = 3;
42
	private static final int  DOWNLOAD_TIME   = 500;
43
	
44
	public class MyDownloader implements Downloader {
45

  
46
		public Tile downloadTile(Tile tile) {
47
			//tile.getFile() -> Aqui se guarda el fichero descargado
48
			try {
49
				Thread.sleep(DOWNLOAD_TIME);
50
			} catch (InterruptedException e) {
51
				e.printStackTrace();
52
			}
53
			return tile;
54
		}
55

  
56
		public Tile readTileFromDisk(Tile tile) throws TileGettingException {
57
			// TODO Auto-generated method stub
58
			return null;
59
		}
60
		
61
		/*
62
		 * (non-Javadoc)
63
		 * @see org.gvsig.raster.cache.tile.provider.Downloader#cancelDownloading(boolean)
64
		 */
65
		public void cancelDownloading(boolean cancel) {
66
			
67
		}
68

  
69
		public Object[] getCrashImage(int w, int h) {
70
			// TODO Auto-generated method stub
71
			return null;
72
		}
73

  
74
		public Object[] getDownloadingImage(int w, int h) {
75
			// TODO Auto-generated method stub
76
			return null;
77
		}
78
		
79
	}
80
	
81
	public void start() {
82
		this.setUp();
83
		this.testStack();
84
	}
85
	
86
	public void setUp() {
87
		System.err.println("TestThreadPool running...");
88

  
89
	}
90
	
91
	public void testStack() {
92
		ThreadPoolImpl pool = new ThreadPoolImpl();
93
		MyDownloader d = new MyDownloader();
94
		org.gvsig.raster.cache.tile.impl.pool.TilePipeImpl pipe = new org.gvsig.raster.cache.tile.impl.pool.TilePipeImpl();
95
		Random r = new Random();
96
		
97
		for (int x = 0; x < HEIGHT; x++) {
98
			for (int y = 0; y < WIDTH; y++) {
99
				TileImpl t = new TileImpl(0, x, y);
100
				t.setSharedPipe(pipe);
101
				t.setDownloader(d);
102
				t.setFile(new File(""));
103
				t.setPriority(r.nextInt());
104
				pool.addTask(t);
105
			}
106
		}
107
		
108
		pool.init();
109
		
110
		int nCollected = 0;
111
		while (nCollected < (WIDTH * HEIGHT)) {
112
			Tile tile = (Tile)pipe.getAtomicTask();
113
			System.out.println("Getting " + tile.getRow() + " " + tile.getCol() + " P:" + tile.getPriority());
114
			nCollected ++;
115
		}
116
		if(pool != null)
117
			pool.destroyPool();
118
	}
119
}
0 120

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/java/org/gvsig/raster/cache/tile/impl/pool/TestThreadPool.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.raster.cache.tile.impl.pool;
23

  
24
import java.io.File;
25

  
26
import junit.framework.TestCase;
27

  
28
import org.gvsig.raster.cache.tile.Tile;
29
import org.gvsig.raster.cache.tile.exception.TileGettingException;
30
import org.gvsig.raster.cache.tile.impl.TileImpl;
31
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
32
import org.gvsig.raster.cache.tile.provider.Downloader;
33

  
34
/**
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class TestThreadPool extends TestCase {
39
	private static final int  WIDTH           = 3;
40
	private static final int  HEIGHT          = 3;
41
	private static final int  DOWNLOAD_TIME   = 500;
42
	
43
	public class MyDownloader implements Downloader {
44

  
45
		public Tile downloadTile(Tile tile) {
46
			//tile.getFile() -> Aqui se guarda el fichero descargado
47
			try {
48
				Thread.sleep(DOWNLOAD_TIME);
49
			} catch (InterruptedException e) {
50
				e.printStackTrace();
51
			}
52
			return tile;
53
		}
54

  
55
		public Tile readTileFromDisk(Tile tile) throws TileGettingException {
56
			// TODO Auto-generated method stub
57
			return null;
58
		}
59
		
60
		/*
61
		 * (non-Javadoc)
62
		 * @see org.gvsig.raster.cache.tile.provider.Downloader#cancelDownloading(boolean)
63
		 */
64
		public void cancelDownloading(boolean cancel) {
65
			
66
		}
67

  
68
		public Object[] getCrashImage(int w, int h) {
69
			// TODO Auto-generated method stub
70
			return null;
71
		}
72

  
73
		public Object[] getDownloadingImage(int w, int h) {
74
			// TODO Auto-generated method stub
75
			return null;
76
		}
77
		
78
	}
79
	
80
	public void start() {
81
		this.setUp();
82
		this.testStack();
83
	}
84
	
85
	public void setUp() {
86
		System.err.println("TestThreadPool running...");
87

  
88
	}
89
	
90
	public void testStack() {
91
		ThreadPoolImpl pool = new ThreadPoolImpl(false);
92
		MyDownloader d = new MyDownloader();
93
		org.gvsig.raster.cache.tile.impl.pool.TilePipeImpl pipe = new org.gvsig.raster.cache.tile.impl.pool.TilePipeImpl();
94
		
95
		for (int x = 0; x < HEIGHT; x++) {
96
			for (int y = 0; y < WIDTH; y++) {
97
				TileImpl t = new TileImpl(0, x, y);
98
				t.setSharedPipe(pipe);
99
				t.setDownloader(d);
100
				t.setFile(new File(""));
101
				pool.addTask(t);
102
			}
103
		}
104
		
105
		int nCollected = 0;
106
		while (nCollected < (WIDTH * HEIGHT)) {
107
			Tile tile = (Tile)pipe.getAtomicTask();
108
			System.out.println("Getting " + tile.getRow() + " " + tile.getCol() + " P:" + tile.getPriority());
109
			nCollected ++;
110
		}
111
		if(pool != null)
112
			pool.destroyPool();
113
	}
114
}
0 115

  
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/resources/image/prueba.rmf
1
<?xml version="1.0" encoding="ISO-8859-15"?>
2
<RasterMetaFile>
3
<FLyrGeoRaster>
4
	<Extent>
5
			<X>0.0</X>
6
			<Y>3.0</Y>
7
			<RotationX>0.0</RotationX>
8
			<RotationY>0.0</RotationY>
9
			<PixelSizeX>1.0</PixelSizeX>
10
			<PixelSizeY>-1.0</PixelSizeY>
11
			<Width>3.0</Width>
12
			<Height>3.0</Height>
13
	</Extent>
14
	<Dimension>
15
			<ImagePxWidth>3.0</ImagePxWidth>
16
			<ImagePxHeight>3.0</ImagePxHeight>
17
	</Dimension>
18
</FLyrGeoRaster>
19
</RasterMetaFile>
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/test/resources/image/001m09_1_0.rmf
1
<?xml version="1.0" encoding="ISO-8859-15"?>
2
<RasterMetaFile>
3
<Statistics>
4
	<BandCount>3</BandCount>
5
	<Band>
6
		<Max>124.0</Max>
7
		<Min>-125.0</Min>
8
		<SecondMax>118.0</SecondMax>
9
		<SecondMin>-119.0</SecondMin>
10
		<MaxRGB>255.0</MaxRGB>
11
		<MinRGB>0.0</MinRGB>
12
		<SecondMaxRGB>249.0</SecondMaxRGB>
13
		<SecondMinRGB>6.0</SecondMinRGB>
14
		<Mean>10.724756162873467</Mean>
15
		<Variance>3732.9921559140375</Variance>
16
	</Band>
17
	<Band>
18
		<Max>120.0</Max>
19
		<Min>-128.0</Min>
20
		<SecondMax>113.0</SecondMax>
21
		<SecondMin>-121.0</SecondMin>
22
		<MaxRGB>255.0</MaxRGB>
23
		<MinRGB>0.0</MinRGB>
24
		<SecondMaxRGB>248.0</SecondMaxRGB>
25
		<SecondMinRGB>8.0</SecondMinRGB>
26
		<Mean>-5.959546810839912</Mean>
27
		<Variance>3170.059813419536</Variance>
28
	</Band>
29
	<Band>
30
		<Max>115.0</Max>
31
		<Min>-128.0</Min>
32
		<SecondMax>102.0</SecondMax>
33
		<SecondMin>-116.0</SecondMin>
34
		<MaxRGB>255.0</MaxRGB>
35
		<MinRGB>0.0</MinRGB>
36
		<SecondMaxRGB>242.0</SecondMaxRGB>
37
		<SecondMinRGB>13.0</SecondMinRGB>
38
		<Mean>29.884241606350802</Mean>
39
		<Variance>5352.010158331949</Variance>
40
	</Band>
41
</Statistics>
42
<FLyrGeoRaster>
43
	<Extent>
44
			<X>687369.0</X>
45
			<Y>5292882.0</Y>
46
			<RotationX>0.0</RotationX>
47
			<RotationY>0.0</RotationY>
48
			<PixelSizeX>15.0</PixelSizeX>
49
			<PixelSizeY>-15.0</PixelSizeY>
50
			<Width>38565.0</Width>
51
			<Height>29130.0</Height>
52
	</Extent>
53
	<Dimension>
54
			<ImagePxWidth>2571.0</ImagePxWidth>
55
			<ImagePxHeight>1942.0</ImagePxHeight>
56
	</Dimension>
57
</FLyrGeoRaster>
58
<Histogram>
59
	<BandCount>3</BandCount>
60
	<DataType>0</DataType>
61
	<Band>
62
		<Min>-128.0</Min>
63
		<Max>127.0</Max>
64
		<Values>0 0 0 91443 0 0 0 0 0 87582 0 0 0 0 0 83416 0 0 0 0 0 80242 0 0 0 0 0 77785 0 0 0 0 0 0 76043 0 0 0 0 0 75204 0 0 0 0 0 73991 0 0 0 0 0 72935 0 0 0 0 0 0 71374 0 0 0 0 0 68978 0 0 0 0 0 65623 0 0 0 0 0 62017 0 0 0 0 0 57527 0 0 0 0 0 0 52522 0 0 0 0 0 46880 0 0 0 0 0 40535 0 0 0 0 0 34249 0 0 0 0 0 0 28144 0 0 0 0 0 21973 0 0 0 0 0 66785 154890 0 0 0 0 0 213232 0 0 0 0 0 332313 0 0 0 0 0 0 439405 0 0 0 0 0 495390 0 0 0 0 0 447438 0 0 0 0 0 330266 0 0 0 0 0 0 218374 0 0 0 0 0 143093 0 0 0 0 0 94619 0 0 0 0 0 63522 0 0 0 0 0 48709 0 0 0 0 0 0 46991 0 0 0 0 0 52318 0 0 0 0 0 60650 0 0 0 0 0 69485 0 0 0 0 0 0 77576 0 0 0 0 0 86087 0 0 0 0 0 92322 0 0 0 0 0 96139 0 0 0 0 0 94815 0 0 0</Values>
65
	</Band>
66
	<Band>
67
		<Min>-128.0</Min>
68
		<Max>127.0</Max>
69
		<Values>60432 0 0 0 0 0 0 75527 0 0 0 0 0 0 0 92307 0 0 0 0 0 0 110369 0 0 0 0 0 0 0 126309 0 0 0 0 0 0 139939 0 0 0 0 0 0 0 149451 0 0 0 0 0 0 154194 0 0 0 0 0 0 0 154621 0 0 0 0 0 0 148426 0 0 0 0 0 0 0 136584 0 0 0 0 0 0 120553 0 0 0 0 0 0 0 102244 0 0 0 0 0 0 82065 0 0 0 0 0 0 0 62891 0 0 0 0 0 0 45204 0 0 0 0 0 0 0 30684 0 0 0 0 0 0 58527 198081 0 0 0 0 0 0 0 294634 0 0 0 0 0 0 463009 0 0 0 0 0 0 0 573354 0 0 0 0 0 0 531548 0 0 0 0 0 0 0 374029 0 0 0 0 0 0 232874 0 0 0 0 0 0 0 139815 0 0 0 0 0 0 78379 0 0 0 0 0 0 0 42064 0 0 0 0 0 0 28627 0 0 0 0 0 0 0 24092 0 0 0 0 0 0 23115 0 0 0 0 0 0 0 25295 0 0 0 0 0 0 29655 0 0 0 0 0 0 0 37025 0 0 0 0 0 0 46959 0 0 0 0 0 0 0</Values>
70
	</Band>
71
	<Band>
72
		<Min>-128.0</Min>
73
		<Max>127.0</Max>
74
		<Values>243210 0 0 0 0 0 0 0 0 0 0 0 189162 0 0 0 0 0 0 0 0 0 0 0 0 158442 0 0 0 0 0 0 0 0 0 0 0 0 136969 0 0 0 0 0 0 0 0 0 0 0 0 117646 0 0 0 0 0 0 0 0 0 0 0 97359 0 0 0 0 0 0 0 0 0 0 0 0 77068 0 0 0 0 0 0 0 0 0 0 0 0 57309 0 0 0 0 0 0 0 0 0 0 0 0 39587 0 0 0 0 0 0 0 0 0 0 0 26383 0 0 0 0 0 0 0 0 0 0 0 0 51062 133876 0 0 0 0 0 0 0 0 0 0 0 0 135257 0 0 0 0 0 0 0 0 0 0 0 0 251799 0 0 0 0 0 0 0 0 0 0 0 385960 0 0 0 0 0 0 0 0 0 0 0 0 499935 0 0 0 0 0 0 0 0 0 0 0 0 575464 0 0 0 0 0 0 0 0 0 0 0 0 571982 0 0 0 0 0 0 0 0 0 0 0 500034 0 0 0 0 0 0 0 0 0 0 0 0 418372 0 0 0 0 0 0 0 0 0 0 0 0 326006 0 0 0 0 0 0 0 0 0 0 0 0</Values>
75
	</Band>
76
</Histogram>
77
</RasterMetaFile>
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary
org.gvsig.raster.cache/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/TileImpl.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.raster.cache.tile.impl;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.NoninvertibleTransformException;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28
import java.io.File;
29
import java.io.IOException;
30
import java.util.HashMap;
31

  
32
import org.gvsig.compat.net.ICancellable;
33
import org.gvsig.raster.cache.tile.Tile;
34
import org.gvsig.raster.cache.tile.pool.AtomicTask;
35
import org.gvsig.raster.cache.tile.pool.TilePipe;
36
import org.gvsig.raster.cache.tile.provider.Downloader;
37

  
38
/**
39
 * Main implementation for the tile cache
40
 *
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class TileImpl implements Tile {
44
	private boolean             corrupt           = false;
45
	private int                 level             = 0;
46
	private int                 col               = 0;
47
	private int                 row               = 0;
48
	private String              var               = "V";
49
	private String              z                 = "Z";
50
	private String              time              = "T";
51
	private int                 widthPx           = 0;
52
	private int                 heightPx          = 0;
53
	private Point2D             ul                = null;
54
	private Point2D             lr                = null;
55
	private Rectangle2D         coordPx           = null;
56
	
57
	private File                file              = null;
58
	private Downloader          downloader        = null;
59
	private HashMap<String, Object>    
60
                                downloaderParams  = new HashMap<String, Object>();
61
	private TilePipe            sharedPipe        = null;
62
	private int                 priority          = 0;
63
	private Object[]            data              = null;
64
	protected CancelTaskImpl    cancelDownloading = null;
65
	
66
	/**
67
	 * All tasks which use libRemoteServices need an object that implements ICancellable
68
	 * to cancel processes.
69
	 * @author Nacho Brodin (nachobrodin@gmail.com)
70
	 */
71
	public class CancelTaskImpl implements ICancellable {
72
		private boolean       cancel = false;
73
		
74
		public CancelTaskImpl() {
75
		}
76
		
77
		public Object getID() {
78
			return this;
79
		}
80

  
81
		public boolean isCanceled() {
82
			return cancel;
83
		}
84
		
85
		/**
86
		 * Cancel the task
87
		 * @param cancel
88
		 * @throws IOException 
89
		 */
90
		public void setCanceled(boolean cancel) {
91
			this.cancel = cancel;
92
		}
93

  
94
	}
95
	
96
	public TileImpl(int level, int col, int row) {
97
		this.level = level;
98
		this.col = col;
99
		this.row = row;
100
		cancelDownloading = new CancelTaskImpl();
101
	}
102
	
103
	public TileImpl(int wPx, int hPx, int row, int col, Point2D ul, Point2D lr) {
104
		this.row = row;
105
		this.col = col;
106
		this.ul = ul;
107
		this.lr = lr;
108
		this.widthPx = wPx;
109
		this.heightPx = hPx;
110
		cancelDownloading = new CancelTaskImpl();
111
	}
112
	
113
	public Object[] getDownloadingImage() {
114
		return downloader.getDownloadingImage(getWidthPx(), getHeightPx());
115
	}
116
	
117
	public Object[] getCrashImage() {
118
		return downloader.getCrashImage(getWidthPx(), getHeightPx());
119
	}
120
	
121
	public Object getDownloadingARGB() {
122
		Object[] result = downloader.getDownloadingImage(getWidthPx(), getHeightPx());
123
		if(result != null && result.length >= 1)
124
			return result[0];
125
		return null;
126
	}
127
	
128
	public Object getCrashARGB() {
129
		Object[] result = downloader.getCrashImage(getWidthPx(), getHeightPx());
130
		if(result != null && result.length >= 1)
131
			return result[0];
132
		return null;
133
	}
134
	
135
	/**
136
	 * Convierte un punto desde del mundo a coordenadas pixel.
137
	 * @param pt Punto a transformar
138
	 * @return punto transformado en coordenadas pixel
139
	 */
140
	public Point2D worldToRaster(Point2D pt) {
141
		Point2D p = new Point2D.Double();
142
		double psX = (lr.getX() - ul.getX()) / widthPx;
143
		double psY = (lr.getY() - ul.getY()) / heightPx;
144
		AffineTransform t = new AffineTransform(psX, 0, 0, psY, ul.getX() - (psX / 2), ul.getY() + (psY / 2));
145
		try {
146
			t.inverseTransform(pt, p);
147
		} catch (NoninvertibleTransformException e) {
148
			return pt;
149
		}
150
		return p;
151
	}
152
	
153
	public Tile cloneTile() {
154
		TileImpl newTile = new TileImpl(widthPx, heightPx, row, col, (Point2D)ul.clone(), (Point2D)lr.clone());
155
		newTile.file = file;
156
		return newTile;
157
	}
158
	
159
	public String getVariable() {
160
		return var;
161
	}
162
	
163
	public String getZ() {
164
		return z;
165
	}
166
	
167
	public String getTimeInstant() {
168
		return time;
169
	}
170
	
171
	public void setVariable(String var) {
172
		this.var = var;
173
	}
174
	
175
	public void setZ(String z) {
176
		this.z = z;
177
	}
178
	
179
	public int getLevel() {
180
		return level;
181
	}
182
	
183
	public void setTimeInstant(String t) {
184
		this.time = t;
185
	}
186

  
187
	public int getCol() {
188
		return col;
189
	}
190

  
191
	public int getRow() {
192
		return row;
193
	}
194
	
195
	public void setCol(int col) {
196
		this.col = col;
197
	}
198
	
199
	public void setRow(int row) {
200
		this.row = row;
201
	}
202
	
203
	public void setLevel(int level) {
204
		this.level = level;
205
	}
206
	
207
	public Rectangle2D getCoordsPx() {
208
		return coordPx;
209
	}
210
	
211
	public void setCoordsPx(Rectangle2D r) {
212
		this.coordPx = r;
213
	}
214

  
215
	public int getWidthPx() {
216
		return widthPx;
217
	}
218

  
219
	public void setWidthPx(int widthPx) {
220
		this.widthPx = widthPx;
221
	}
222

  
223
	public int getHeightPx() {
224
		return heightPx;
225
	}
226

  
227
	public void setHeightPx(int heightPx) {
228
		this.heightPx = heightPx;
229
	}
230
	
231
	public Rectangle2D getExtent() {
232
		return new Rectangle2D.Double(ul.getX(), ul.getY(), 
233
				Math.abs(ul.getX() - lr.getX()), Math.abs(ul.getY() - lr.getY()));
234
	}
235

  
236
	public Point2D getUl() {
237
		return ul;
238
	}
239

  
240
	public void setUl(Point2D ul) {
241
		this.ul = ul;
242
	}
243

  
244
	public Point2D getLr() {
245
		return lr;
246
	}
247

  
248
	public void setLr(Point2D lr) {
249
		this.lr = lr;
250
	}
251

  
252
	public File getFile() {
253
		return file;
254
	}
255

  
256
	public void setFile(File file) {
257
		this.file = file;
258
	}
259

  
260
	/**
261
	 * Gets the downloader for this tile
262
	 * @return
263
	 */
264
	public Downloader getDownloader() {
265
		return downloader;
266
	}
267

  
268
	public void setDownloader(Downloader downloader) {
269
		this.downloader = downloader;
270
	}
271

  
272
	public Object getDownloaderParams(String key) {
273
		return downloaderParams.get(key.toUpperCase());
274
	}
275

  
276
	public void setDownloaderParams(String key, Object value) {
277
		this.downloaderParams.put(key.toUpperCase(), value);
278
	}
279
	
280
	public void setCorrupt(boolean corrupt) {
281
		this.corrupt = corrupt;
282
	}
283
	
284
	public boolean isCorrupt() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff