Revision 22359

View differences:

org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.raster.mainplugin" />
4
	<libraries library-dir="lib"/>
5
	<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.raster.tilecache.app.CacheExtension"
8
			description="Tile Cache support"
9
			active="true"
10
			priority="1">
11
		</extension>
12
	</extensions>
13
</plugin-config>
0 14

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/resources-plugin/install/install.xml
1
<project name="org.gvsig.plugin1" default="main" basedir=".">
2
	<target name="main" depends="copy_files, link1, link2"/>
3
    <target name="copy_files">
4
    	<copy todir="${gvsig_dir}">
5
    		<fileset dir="./files" includes="**"/>
6
		</copy>
7
	</target>
8
	<target name="link1" depends="gdal-properties" if="gdal.link1">
9
	  <exec executable="ln" >
10
      <arg value="-s"/>
11
      <arg value="${gdal.so}"/>
12
      <arg value="${gdal.link1}"/>
13
	  </exec>
14
	</target>
15
	<target name="link2" depends="gdal-properties" if="gdal.link2">
16
    <exec executable="ln" >
17
      <arg value="-s"/>
18
      <arg value="${gdal.so}"/>
19
      <arg value="${gdal.link2}"/>
20
    </exec>
21
	</target>
22
  <target name="gdal-properties" depends="checkgdal, gdal-properties.1.15.1, gdal-properties.1.13.0"/>
23
  <target name="gdal-properties.1.15.1" if="gdal.1.15.1">
24
    <property name="gdal.so" value="${gvsig_dir}/native/libgdal.so.1.15.1"/>
25
    <property name="gdal.link1" value="${gvsig_dir}/native/libgdal.so.1"/>
26
    <property name="gdal.link2" value="${gvsig_dir}/native/libgdal.so"/>
27
  </target>
28
  <target name="gdal-properties.1.13.0" if="gdal.1.13.0">
29
    <property name="gdal.so" value="${gvsig_dir}/native/libgdal.so.1.13.0"/>
30
    <property name="gdal.link1" value="${gvsig_dir}/native/libgdal.so.1"/>
31
    <property name="gdal.link2" value="${gvsig_dir}/native/libgdal.so"/>
32
  </target>
33
	<target name="checkgdal">
34
    <available file="${gvsig_dir}/native/libgdal.so.1.15.1" property="gdal.1.15.1"/>
35
    <available file="${gvsig_dir}/native/libgdal.so.1.13.0" property="gdal.1.13.0"/>
36
	</target>
37

  
38
  <!-- To add a new gdal so version:
39
       * add a new available in "checkgdal" target
40
       * create a new  "gdal-properties.x.xx.x" target with right property values
41
       * add the new "gda-properties.x.xx.x" into "gdal-properties" target depends list
42

  
43

  
44
  -->
45
</project>
0 46

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/resources-plugin/about/tilecache-about.html
1
<html>
2
	<head>
3
	<style type="text/css">
4
	BODY { background-image: url(logo.png); background-repeat: no-repeat; background-position: 100% 0% }
5
	</style>
6
	</head>
7
	<body>	
8
		<h2>Soporte PostGIS Raster para gvSIG</h2>	
9
		<p><b>Prodevelop S.L.</b> ha incorporado el soporte al formato raster en 
10
		base de datos <b>PostGres</b></p>
11
		
12
		<p><b>Desarrollo:</b></p>
13
		
14
		<p>Director del proyecto:</p>
15
		<ul>
16
			<li>Miguel Montesinos Lajara</li>
17
		</ul>
18
		<p>Equipo de desarrollo:</p>
19
		<ul>
20
			<li>Nacho Brodin</li>
21
		</ul>
22
		
23
		<p><b>Colaboradores:</b></p>
24
		
25
		<p>Deimos:</p>
26
		<ul>
27
			<li>Jorge Arevalo</li>
28
		</ul>
29

  
30
		<p>Build Number de la extensi&oacute;n: 1</p>
31
		<center>
32
			<p><b><a href="http://www.prodevelop.es" title="Prodevelop">http://www.prodevelop.es</a></b></p>
33
		</center>
34
		
35
	</body>
36
</html>
0 37

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/resources-plugin/text.properties
1
tiled_layer=?Deseas usar la cach? de tiles con las capas seleccionadas?
2
tiled_layer2=?Deseas cargar la capa de forma normal o cacheando datos en forma de teselas?
3
tiled=Teselada
4
all_normally=Todas normal
5
all_tiled=Todas teseladas
6
normally=Normal
7
tilecache=Tilecach?
8
preference_cache_warning=<html><center><b>ATENCI?N: Solo tocar esta secci?n si est? seguro de lo que est? haciendo</b></center></html>
9
tamanyo_max_tilecache=Tama?o m?ximo tile cache
10
res_levels=Niveles de resoluci?n
11
tilesize=Tama?o de tile
12
tilecache_struct=Estructura de directorios
13
remove_cache=Borrar cach?
14
path_tilecache=Ruta a los ficheros de la cach?
15
remove_directory=Borrar directorio
16
open_files=El directorio de cach? no puede ser eliminado.\n No debe tener ficheros abiertos. Cierre todas las capas.
17
path_not_exists=El directorio no existe
18
file=Fichero
0 19

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/resources-plugin/text_en.properties
1
tiled_layer=Would you like to use tile cache with the selected layers?
2
tiled_layer2=Would you like to load this layer normally or caching data as tiles?
3
tiled=Tiled
4
all_normally=Normally all
5
all_tiled=Tiled all
6
normally=Normally
7
tilecache=Tilecache
8
preference_cache_warning=<html><center><b>WARNING: You mustn't to change this section if you're not sure what you are doing</b></center></html>
9
tamanyo_max_tilecache=Maximum size of tilecache
10
res_levels=Resolution levels
11
tilesize=Tile size
12
tilecache_struct=Path structure
13
remove_cache=Remove cache
14
path_tilecache=Path to the files of cache 
15
remove_directory=Remove folder
16
open_files=The folder cannot be eliminated.\n It should not have open files. Close all layers
17
path_not_exists=The directory does not exists
18
file=File
0 19

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    	<file>
10
      		<source>target/${project.artifactId}-${project.version}.jar</source>
11
      		<outputDirectory>lib</outputDirectory>
12
    	</file>
13
    	<file>
14
      		<source>target/package.info</source>
15
    	</file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25

  
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
	  <useTransitiveDependencies>true</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
		<include>org.gvsig:org.gvsig.raster.tilecache.app:jar</include>
33
		<include>org.gvsig:org.gvsig.raster.tilecache.io:jar</include>
34
	  </includes>
35
	</dependencySet>
36
  </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/ConfigurationListener.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.tilecache.app;
23

  
24
import java.util.EventListener;
25

  
26
public interface ConfigurationListener extends EventListener {
27
	/**
28
	 * Evento que se dispara cuando cambia un valor de configuracion.
29
	 * @param e
30
	 */
31
	public void actionConfigurationChanged(ConfigurationEvent e);
32
}
0 33

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/CacheExtension.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.tilecache.app;
23

  
24
import java.awt.Component;
25
import java.util.prefs.Preferences;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.gvsig.about.AboutManager;
30
import org.gvsig.about.AboutParticipant;
31
import org.gvsig.andami.IconThemeHelper;
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.app.ApplicationLocator;
35
import org.gvsig.app.ApplicationManager;
36
import org.gvsig.app.project.documents.view.toc.ITocItem;
37
import org.gvsig.fmap.dal.coverage.RasterLibrary;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.raster.cache.tile.TileCache;
40
import org.gvsig.raster.cache.tile.TileCacheLibrary;
41
import org.gvsig.raster.cache.tile.TileCacheLocator;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.extensionpoint.ExtensionPoint;
44
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
45

  
46

  
47
/**
48
 * Tile cache extension for gvSIG
49
 * 
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class CacheExtension extends Extension implements ConfigurationListener {
53

  
54
	public void execute(String actionCommand) {
55
		
56
	}
57

  
58
//	private void addAboutInfo() {
59
//        ApplicationManager application = ApplicationLocator.getManager();
60
//        
61
//        AboutManager about = application.getAbout();
62
//        about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
63
//            .getResource("about/tilecache-about.html"), 2);
64
//
65
//        AboutParticipant participant = about.getDeveloper("PRODEVELOP");
66
//        participant.addContribution(
67
//            "Cach? de teselas",
68
//            "Cach? de teselas para fuentes de datos r?ster y remotas", 
69
//            2011,1,1, 
70
//            2011,1,30
71
//        );      
72
//    }
73

  
74
	public void initialize() {
75
		IconThemeHelper.registerIcon(null, "pref-tilecache-icon", this);
76
		
77
		Configuration.addValueChangedListener(this);
78
		Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
79
		prefs.put("DataFolder", System.getProperty("user.home"));
80
		
81
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
82
		ExtensionPoint point = extensionPoints.add("AplicationPreferences");
83
		point.append("TileCachePreferences", "", TileCachePreferences.class);
84
		
85
		TileCacheLibrary.DEFAULT_TILEWIDTH = Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH));
86
		TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
87
		
88
		TileCacheLibrary.ALTERNATIVE_TILESIZE = Configuration.getValue("tilesizewms", Integer.valueOf(TileCacheLibrary.ALTERNATIVE_TILESIZE));
89
		
90
		ApplicationManager appGvSigMan = ApplicationLocator.getManager();
91
		appGvSigMan.registerPrepareOpenLayer(new PrepareLayerAskUsingTiles());
92
		appGvSigMan.registerPrepareOpenDataStoreParameters(new PrepareLayerAskUsingTiles());
93
	}
94
	
95
	public boolean isEnabled() {
96
		return false;
97
	}
98

  
99
	public boolean isVisible() {
100
		return false;
101
	}
102

  
103
	public void actionConfigurationChanged(ConfigurationEvent e) {
104

  
105
		if (e.getKey().equals("path_tilecache")) {
106
			if(e.getValue() instanceof String) {
107
				String value = (String)e.getValue();
108
				if(value != null && value.compareTo("") != 0) {
109
					RasterLibrary.pathTileCache =  (String)e.getValue();
110
					TileCache tc = TileCacheLocator.getManager().getTileCache(RasterLibrary.pathTileCache);
111
					tc.updateBaseDirectory(RasterLibrary.pathTileCache);
112
				}
113
			}
114
			return;
115
		}
116
		
117
		if (e.getKey().equals("tile_levels")) {
118
			if(e.getValue() instanceof String)
119
				try {
120
					TileCacheLibrary.DEFAULT_LEVELS = new Integer((String) e
121
							.getValue()).intValue();
122
				} catch (NumberFormatException exc) {
123
					//Valor por defecto en la cache
124
				}
125
			if(e.getValue() instanceof Integer)
126
				TileCacheLibrary.DEFAULT_LEVELS = ((Integer) e.getValue()).intValue();
127
			return;
128
		}
129
		
130
		if (e.getKey().equals("tilesize")) {
131
			if(e.getValue() instanceof String) {
132
				try {
133
					String text = (String) e.getValue();
134
					text = text.replaceAll("\\.", "");
135
					text = text.replaceAll(",", "\\.");
136
					TileCacheLibrary.DEFAULT_TILEWIDTH = new Integer(text).intValue();
137
					TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
138
				} catch (NumberFormatException exc) {
139
					//Valor por defecto en la cache
140
				}
141
			}
142
			if(e.getValue() instanceof Integer) {
143
				TileCacheLibrary.DEFAULT_TILEWIDTH = ((Integer) e.getValue()).intValue();
144
				TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
145
			}
146
			return;
147
		}
148
		
149
		if (e.getKey().equals("tilesizewms")) {
150
			if(e.getValue() instanceof String) {
151
				try {
152
					String text = (String) e.getValue();
153
					text = text.replaceAll("\\.", "");
154
					text = text.replaceAll(",", "\\.");
155
					TileCacheLibrary.ALTERNATIVE_TILESIZE = new Integer(text).intValue();
156
				} catch (NumberFormatException exc) {
157
					//Valor por defecto en la cache
158
				}
159
			}
160
			if(e.getValue() instanceof Integer) {
161
				TileCacheLibrary.ALTERNATIVE_TILESIZE = ((Integer) e.getValue()).intValue();
162
			}
163
			return;
164
		}
165
		
166
		if (e.getKey().equals("tilecache_size")) {
167
			if(e.getValue() instanceof String)
168
				try {
169
					String text = (String) e.getValue();
170
					text = text.replaceAll("\\.", "");
171
					text = text.replaceAll(",", "\\.");
172
					TileCacheLibrary.MAX_CACHE_SIZE = new Integer((String) e
173
							.getValue()).intValue();
174
				} catch (NumberFormatException exc) {
175
					//Valor por defecto en la cache
176
				}
177
			if(e.getValue() instanceof Integer)
178
				TileCacheLibrary.MAX_CACHE_SIZE = ((Integer) e.getValue()).intValue();
179
			return;
180
		}
181
		
182
		if (e.getKey().equals("cache_struct")) {
183
			if(e.getValue() instanceof String)
184
				TileCacheLibrary.DEFAULT_STRUCTURE = (String)e.getValue();
185
			return;
186
		}
187
	}
188

  
189
	public void execute(ITocItem item, FLayer[] selectedItems) {
190

  
191
	}
192

  
193
	public void postInitialize() {
194
		super.postInitialize();
195
	//		storeLibrary.postInitialize();
196
//		addAboutInfo();
197
	}
198
	
199
	/**
200
	 * Shows an error dialog with a text and a accept button 
201
	 * @param msg Message to show in the dialog
202
	 * @param parentWindow Parent window
203
	 */
204
	public static void messageBoxError(String msg, Object parentWindow){
205
		String string = PluginServices.getText(parentWindow, "accept");
206
		Object[] options = {string};
207
		JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
208
					"<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
209
					PluginServices.getText(parentWindow, "confirmacion"),
210
					JOptionPane.OK_OPTION,
211
					JOptionPane.ERROR_MESSAGE,
212
					null,
213
					options,
214
					string);
215
	}
216
	
217
	/**
218
	 * Shows an error dialog with a text and a YesOrNot button 
219
	 * @param msg Message to show in the dialog.
220
	 * @param parentWindow Parent window
221
	 * @return Selected button by the button. Returns true if the user has selected Yes
222
	 * and false if he has selected No. 
223
	 */
224
	public static boolean messageBoxYesOrNot(String msg, Object parentWindow){
225
		String string1 = PluginServices.getText(parentWindow, "yes");
226
		String string2 = PluginServices.getText(parentWindow, "no");
227
		Object[] options = {string1, string2};
228
		int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
229
					"<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
230
					PluginServices.getText(parentWindow, "confirmacion"),
231
					JOptionPane.YES_NO_OPTION,
232
					JOptionPane.QUESTION_MESSAGE,
233
					null,
234
					options,
235
					string1);
236
		if (n == JOptionPane.YES_OPTION)
237
			return true;
238
		else
239
			return false;
240
	}
241
}
0 242

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/PrepareLayerAskUsingTiles.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.tilecache.app;
23

  
24
import java.awt.Component;
25
import java.util.Map;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.app.prepareAction.PrepareContext;
31
import org.gvsig.app.prepareAction.PrepareContextView;
32
import org.gvsig.app.prepareAction.PrepareDataStoreParameters;
33
import org.gvsig.app.prepareAction.PrepareLayer;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
38
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
39
import org.gvsig.fmap.dal.exception.CloseException;
40
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
41
import org.gvsig.fmap.mapcontext.MapContextLocator;
42
import org.gvsig.fmap.mapcontext.MapContextManager;
43
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
44
import org.gvsig.fmap.mapcontext.layers.FLayer;
45
import org.gvsig.i18n.Messages;
46
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
47
import org.gvsig.raster.fmap.layers.FLyrRaster;
48
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
49
import org.gvsig.tools.exception.BaseException;
50

  
51
public class PrepareLayerAskUsingTiles implements PrepareDataStoreParameters, PrepareLayer {
52
	private boolean askMe    = true;
53
	private boolean answer   = false;
54
	
55
	public DataStoreParameters prepare(DataStoreParameters storeParameters,
56
			PrepareContext context) throws BaseException {
57
		if(!(storeParameters instanceof RasterDataParameters))
58
			return storeParameters;
59
		if(askMe) {
60
			String file = null;
61
			if(storeParameters instanceof AbstractRasterFileDataParameters) {
62
				file = ((AbstractRasterFileDataParameters)storeParameters).getFile().getName();
63
			}
64
			messageBoxYesOrNot("tiled_layer2", file);
65
		}
66
		
67
		if(answer) {
68
			DataManager manager = DALLocator.getDataManager();
69
			TileDataParameters tileParams = null;
70
			tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
71
			((FilesystemStoreParameters) tileParams).setFile(((FilesystemStoreParameters)storeParameters).getFile());
72
			tileParams.setDataParameters(storeParameters);
73
			return tileParams;
74
		}
75
		
76
		return storeParameters;
77
	}
78
	
79
	public void post(DataStoreParameters storeParameters, PrepareContext context) {
80
		askMe = true;
81
	}
82
	
83
	public void pre(DataStoreParameters storeParameters, PrepareContext context) {
84
	}
85
	
86
	public boolean askMe() {
87
		return askMe;
88
	}
89
	
90
	public void setAskMe(boolean askMe) {
91
		this.askMe = askMe;
92
	}
93
	
94
	public FLayer prepare(FLayer layer, PrepareContextView context) {
95
		if(layer instanceof FLyrRaster) {
96
			FLyrRaster lyrRaster = (FLyrRaster)layer;
97
			//Raster without georeferencing are not tiled
98
			if(lyrRaster.getDataStore().getParameters() instanceof TileDataParameters) {
99
				if(	lyrRaster.getFullEnvelope().getMinimum(0) == 0 &&
100
						lyrRaster.getFullEnvelope().getMinimum(1) == 0 &&
101
						lyrRaster.getFullEnvelope().getMaximum(0) == lyrRaster.getDataStore().getWidth() &&
102
						lyrRaster.getFullEnvelope().getMaximum(1) == lyrRaster.getDataStore().getHeight()) {
103
					MapContextManager mcm = MapContextLocator.getMapContextManager();
104
					try {
105
						FLyrRaster newLayer = (DefaultFLyrRaster) mcm.createLayer(lyrRaster.getName(), 
106
								(DataStoreParameters)((TileDataParameters)lyrRaster.getDataStore().getParameters()).getDataParameters());
107
						lyrRaster.getDataStore().close();
108
						return newLayer;
109
					} catch (LoadLayerException e) {
110
						return lyrRaster;
111
					} catch (CloseException e) {
112
					}
113
				}
114
			}
115
		}
116
		return layer;
117
	}
118
	
119
	
120

  
121
	public void end(Object param) {
122
		
123
	}
124

  
125
	public String getDescription() {
126
		return "Prepare Tiles for Raster Layer";
127
	}
128

  
129
	public String getName() {
130
		return "PrepareRasterLayerAskUsingTiles";
131
	}
132

  
133
	public Object create() {
134
		return this;
135
	}
136

  
137
	public Object create(Object[] args) {
138
		return this;
139
	}
140

  
141
	@SuppressWarnings("rawtypes")
142
	public Object create(Map args) {
143
		return this;
144
	}
145

  
146
	public void interrupted() {
147
	}
148
	
149
	/**
150
	 * Muestra un dialogo con un texto y un bot?n Si o No.
151
	 * @param msg Mensaje a mostrar en el dialogo.
152
	 * @param parentWindow Ventana desde la que se lanza el dialogo
153
	 * @return El bot?n seleccionado por el usuario. true si ha seleccionado "si"
154
	 *         y false si ha seleccionado "no"
155
	 */
156
	public void messageBoxYesOrNot(String msg, String file){
157
		String string1 = Messages.getText("tiled");
158
		String string2 = Messages.getText("normally");
159
		String string3 = Messages.getText("all_tiled");
160
		String string4 = Messages.getText("all_normally");
161
		Object[] options = {string1, string2, string3, string4};
162
		int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
163
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "<br><br>" + Messages.getText("file") + ": " + file + "</html>",
164
					Messages.getText("confirmacion"),
165
					JOptionPane.YES_NO_OPTION,
166
					JOptionPane.QUESTION_MESSAGE,
167
					null,
168
					options,
169
					string1);
170
		answer = false;
171
		if (n == 0) 
172
			answer = true;
173
		if (n == 2) {
174
			askMe = false;
175
			answer = true;
176
		}
177
		if (n == 3) 
178
			askMe = false;
179
	}
180
}
0 181

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/TileCachePreferences.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.tilecache.app;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27

  
28
import javax.swing.ImageIcon;
29
import javax.swing.JPanel;
30
import javax.swing.JScrollPane;
31
import javax.swing.border.EmptyBorder;
32

  
33
import org.gvsig.andami.IconThemeHelper;
34
import org.gvsig.andami.preferences.AbstractPreferencePage;
35
import org.gvsig.andami.preferences.StoreException;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.i18n.I18nManager;
38

  
39
/**
40
 * Preferences for tile cache
41
 * @author Nacho Brodin (nachobrodin@gmail.com
42
 */
43
public class TileCachePreferences extends AbstractPreferencePage {
44
	private static final long         serialVersionUID = -1689657253810393874L;
45

  
46
	protected static String           id        = TileCachePreferences.class.getName();
47
	private ImageIcon                 icon;
48

  
49
	private TileCachePreferencesPanel tilecache = null;
50

  
51
	private I18nManager i18n = ToolsLocator.getI18nManager();
52

  
53
	/**
54
	 * Constructor de la clase RasterPreferences
55
	 */
56
	public TileCachePreferences() {
57
		super();
58
		icon = IconThemeHelper.getImageIcon("pref-tilecache-icon");
59
		initialize();
60
	}
61

  
62
	/**
63
	 * Inicializacion del panel de preferencias.
64
	 */
65
	private void initialize() {
66
		setTitle("Frame");
67

  
68
		GridBagConstraints gridBagConstraints;
69

  
70
		JScrollPane scrollPane = new JScrollPane();
71

  
72
		scrollPane.getVerticalScrollBar().setUnitIncrement(20);
73

  
74
		JPanel panel = new JPanel();
75

  
76
		panel.setLayout(new GridBagLayout());
77

  
78
		gridBagConstraints = new GridBagConstraints();
79
		gridBagConstraints.gridx = 0;
80
		gridBagConstraints.gridy = 0;
81
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
82
		panel.add(getPreferenceTileCache(), gridBagConstraints);
83

  
84
		gridBagConstraints = new GridBagConstraints();
85
		gridBagConstraints.gridx = 0;
86
		gridBagConstraints.gridy = 7;
87
		gridBagConstraints.weightx = 1.0;
88
		gridBagConstraints.weighty = 1.0;
89
		panel.add(new JPanel(), gridBagConstraints);
90

  
91
		panel.setBorder(new EmptyBorder(5, 5, 5, 5));
92

  
93
		scrollPane.setViewportView(panel);
94

  
95
		setLayout(new BorderLayout());
96
		add(scrollPane, BorderLayout.CENTER);
97
	}
98

  
99
	/**
100
	 * Gets a tile cache configuration panel
101
	 * @return tile cache configuration panel
102
	 */
103
	private TileCachePreferencesPanel getPreferenceTileCache() {
104
		if (tilecache == null) {
105
			tilecache = new TileCachePreferencesPanel();
106
		}
107
		return tilecache;
108
	}
109

  
110
	/*
111
	 * (non-Javadoc)
112
	 * @see com.iver.andami.preferences.IPreference#initializeValues()
113
	 */
114
	public void initializeValues() {
115
		getPreferenceTileCache().initializeValues();
116
	}
117

  
118
	/*
119
	 * (non-Javadoc)
120
	 * @see com.iver.andami.preferences.AbstractPreferencePage#storeValues()
121
	 */
122
	public void storeValues() throws StoreException {
123
		getPreferenceTileCache().storeValues();
124
	}
125

  
126
	/*
127
	 * (non-Javadoc)
128
	 * @see com.iver.andami.preferences.IPreference#initializeDefaults()
129
	 */
130
	public void initializeDefaults() {
131
		getPreferenceTileCache().initializeDefaults();
132
	}
133

  
134
	/*
135
	 * (non-Javadoc)
136
	 * @see com.iver.andami.preferences.AbstractPreferencePage#isResizeable()
137
	 */
138
	public boolean isResizeable() {
139
		return true;
140
	}
141

  
142
	/*
143
	 * (non-Javadoc)
144
	 * @see com.iver.andami.preferences.IPreference#getID()
145
	 */
146
	public String getID() {
147
		return id;
148
	}
149

  
150
	/*
151
	 * (non-Javadoc)
152
	 * @see com.iver.andami.preferences.IPreference#getIcon()
153
	 */
154
	public ImageIcon getIcon() {
155
		return icon;
156
	}
157

  
158
	/*
159
	 * (non-Javadoc)
160
	 * @see com.iver.andami.preferences.IPreference#getPanel()
161
	 */
162
	public JPanel getPanel() {
163
		return this;
164
	}
165

  
166
	/*
167
	 * (non-Javadoc)
168
	 * @see com.iver.andami.preferences.IPreference#getTitle()
169
	 */
170
	public String getTitle() {
171
		return i18n.getTranslation("tilecache");
172
	}
173

  
174
	/*
175
	 * (non-Javadoc)
176
	 * @see com.iver.andami.preferences.IPreference#isValueChanged()
177
	 */
178
	public boolean isValueChanged() {
179
		return true;
180
	}
181

  
182
	public void setChangesApplied() {}
183
}
0 184

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/TileCachePreferencesPanel.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.tilecache.app;
23

  
24
import java.awt.Color;
25
import java.awt.Dimension;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.io.File;
32
import java.text.NumberFormat;
33

  
34
import javax.swing.BorderFactory;
35
import javax.swing.DefaultComboBoxModel;
36
import javax.swing.JButton;
37
import javax.swing.JComboBox;
38
import javax.swing.JFormattedTextField;
39
import javax.swing.JLabel;
40
import javax.swing.JTextField;
41
import javax.swing.SwingConstants;
42
import javax.swing.text.DefaultFormatterFactory;
43
import javax.swing.text.NumberFormatter;
44

  
45
import org.gvsig.andami.PluginServices;
46
import org.gvsig.andami.preferences.DlgPreferences;
47
import org.gvsig.andami.ui.mdiManager.IWindow;
48
import org.gvsig.fmap.dal.coverage.RasterLibrary;
49
import org.gvsig.i18n.Messages;
50
import org.gvsig.raster.cache.tile.TileCacheLibrary;
51
import org.gvsig.raster.util.BasePanel;
52
/**
53
 * This class provides a panel for tile cache configuration
54
 * 
55
 * @author Nacho Brodin (nachobrodin@gmail.com)
56
 */
57
public class TileCachePreferencesPanel extends BasePanel implements ActionListener {
58
	protected static final long serialVersionUID      = 1L;
59
	private static int          TILE_SIZE_WMS         = 1024;              
60
	private JLabel              labelWarning          = null;
61
	private JLabel              labelCacheSize        = null;
62
	private JLabel              labelLevels           = null;
63
	private JLabel              labelStruct           = null;
64
	private JLabel              labelTileSize         = null;
65
	private JLabel              labelWMSTileSize      = null;
66
	private JLabel              labelPath             = null;
67
	private JFormattedTextField textFieldCacheSize    = null;
68
	private JFormattedTextField textFieldLevels       = null;
69
	private JFormattedTextField textFieldTileSize     = null;
70
	private JFormattedTextField textFieldWMSTileSize  = null;
71
	private JTextField          textFieldPath         = null;
72
	private JComboBox           comboBoxStruct        = null;
73
	private JButton             buttonRemove          = null;
74

  
75
	/**
76
	 *Inicializa componentes gr?ficos y traduce
77
	 */
78
	public TileCachePreferencesPanel() {
79
		init();
80
		translate();
81
	}
82

  
83
	/**
84
	 * Define todas las traducciones de PreferenceCache
85
	 */
86
	protected void translate() {
87
		setBorder(BorderFactory.createTitledBorder(getText(this, "tilecache")));
88
		getLabelWarning().setText(getText(this, "preference_cache_warning"));
89
		getLabelCacheSize().setText(getText(this, "tamanyo_max_tilecache") + ":");
90
		getLabelLevels().setText(getText(this, "res_levels") + ":");
91
		getLabelTileSize().setText(getText(this, "tilesize") + ":");
92
		getLabelWMSTileSize().setText("WMS/WCS " + getText(this, "tilesize") + ":");
93
		getLabelStruct().setText(getText(this, "tilecache_struct") + ":");
94
		getButtonRemove().setText(getText(this, "remove_cache"));
95
		getLabelPath().setText(getText(this, "path_tilecache"));
96
	}
97

  
98
	protected void init() {
99
		GridBagConstraints gridBagConstraints;
100

  
101
		setLayout(new GridBagLayout());
102

  
103
		gridBagConstraints = new GridBagConstraints();
104
		gridBagConstraints.gridwidth = 2;
105
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
106
		gridBagConstraints.weightx = 1.0;
107
		gridBagConstraints.insets = new Insets(5, 5, 2, 5);
108
		add(getLabelWarning(), gridBagConstraints);
109

  
110
		gridBagConstraints = new GridBagConstraints();
111
		gridBagConstraints.gridx = 0;
112
		gridBagConstraints.gridy = 1;
113
		gridBagConstraints.anchor = GridBagConstraints.EAST;
114
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
115
		add(getLabelCacheSize(), gridBagConstraints);
116
		
117
		gridBagConstraints = new GridBagConstraints();
118
		gridBagConstraints.gridx = 0;
119
		gridBagConstraints.gridy = 2;
120
		gridBagConstraints.anchor = GridBagConstraints.EAST;
121
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
122
		add(getLabelLevels(), gridBagConstraints);
123
		
124
		gridBagConstraints = new GridBagConstraints();
125
		gridBagConstraints.gridx = 0;
126
		gridBagConstraints.gridy = 3;
127
		gridBagConstraints.anchor = GridBagConstraints.EAST;
128
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
129
		add(getLabelTileSize(), gridBagConstraints);
130
		
131
		gridBagConstraints = new GridBagConstraints();
132
		gridBagConstraints.gridx = 0;
133
		gridBagConstraints.gridy = 4;
134
		gridBagConstraints.anchor = GridBagConstraints.EAST;
135
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
136
		add(getLabelWMSTileSize(), gridBagConstraints);
137
		
138
		gridBagConstraints = new GridBagConstraints();
139
		gridBagConstraints.gridx = 0;
140
		gridBagConstraints.gridy = 5;
141
		gridBagConstraints.anchor = GridBagConstraints.EAST;
142
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
143
		add(getLabelStruct(), gridBagConstraints);
144
		
145
		gridBagConstraints = new GridBagConstraints();
146
		gridBagConstraints.gridx = 0;
147
		gridBagConstraints.gridy = 6;
148
		gridBagConstraints.gridwidth = 2;
149
		gridBagConstraints.anchor = GridBagConstraints.WEST;
150
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
151
		add(getButtonRemove(), gridBagConstraints);
152
		
153
		gridBagConstraints = new GridBagConstraints();
154
		gridBagConstraints.gridx = 0;
155
		gridBagConstraints.gridy = 7;
156
		gridBagConstraints.anchor = GridBagConstraints.EAST;
157
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
158
		add(getLabelPath(), gridBagConstraints);
159

  
160
		gridBagConstraints = new GridBagConstraints();
161
		gridBagConstraints.gridx = 1;
162
		gridBagConstraints.gridy = 1;
163
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
164
		gridBagConstraints.anchor = GridBagConstraints.WEST;
165
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
166
		add(getTextFieldCacheSize(), gridBagConstraints);
167
		
168
		gridBagConstraints = new GridBagConstraints();
169
		gridBagConstraints.gridx = 1;
170
		gridBagConstraints.gridy = 2;
171
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
172
		gridBagConstraints.anchor = GridBagConstraints.WEST;
173
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
174
		add(getTextFieldLevels(), gridBagConstraints);
175
		
176
		gridBagConstraints = new GridBagConstraints();
177
		gridBagConstraints.gridx = 1;
178
		gridBagConstraints.gridy = 3;
179
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
180
		gridBagConstraints.anchor = GridBagConstraints.WEST;
181
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
182
		add(getTextFieldTileSize(), gridBagConstraints);
183
		
184
		gridBagConstraints = new GridBagConstraints();
185
		gridBagConstraints.gridx = 1;
186
		gridBagConstraints.gridy = 4;
187
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
188
		gridBagConstraints.anchor = GridBagConstraints.WEST;
189
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
190
		add(getTextFieldWMSTileSize(), gridBagConstraints);
191
		
192
		gridBagConstraints = new GridBagConstraints();
193
		gridBagConstraints.gridx = 1;
194
		gridBagConstraints.gridy = 5;
195
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
196
		gridBagConstraints.anchor = GridBagConstraints.WEST;
197
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
198
		add(getComboBoxStruct(), gridBagConstraints);
199
		
200
		gridBagConstraints = new GridBagConstraints();
201
		gridBagConstraints.gridx = 1;
202
		gridBagConstraints.gridy = 7;
203
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
204
		gridBagConstraints.anchor = GridBagConstraints.WEST;
205
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
206
		add(getTextFieldPath(), gridBagConstraints);
207
		
208
	}
209

  
210
	private JLabel getLabelWarning() {
211
		if (labelWarning == null) {
212
			labelWarning = new JLabel();
213
			labelWarning.setForeground(new Color(255, 0, 0));
214
			labelWarning.setHorizontalAlignment(SwingConstants.CENTER);
215
			labelWarning.setPreferredSize(new Dimension(0, 32));
216
		}
217
		return labelWarning;
218
	}
219

  
220
	private JButton getButtonRemove() {
221
		if(buttonRemove == null) {
222
			buttonRemove = new JButton();
223
			buttonRemove.addActionListener(this);
224
		}
225
		return buttonRemove;
226
	}
227
	
228
	private JComboBox getComboBoxStruct() {
229
		if (comboBoxStruct == null) {
230
			comboBoxStruct = new JComboBox();
231
			comboBoxStruct.setModel(new DefaultComboBoxModel(new String[] { "FLATX" }));
232
		}
233
		return comboBoxStruct;
234
	}
235
	
236
	private JTextField getTextFieldPath() {
237
		if (textFieldPath == null) {
238
			textFieldPath = new JTextField();
239
		}
240
		return textFieldPath;
241
	}
242
	
243
	private JFormattedTextField getTextFieldCacheSize() {
244
		if (textFieldCacheSize == null) {
245
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
246
			integerFormat.setParseIntegerOnly(true);
247
			textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory(
248
					new NumberFormatter(integerFormat),
249
					new NumberFormatter(integerFormat),
250
					new NumberFormatter(integerFormat)));
251
		}
252
		return textFieldCacheSize;
253
	}
254
	
255
	private JFormattedTextField getTextFieldTileSize() {
256
		if (textFieldTileSize == null) {
257
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
258
			integerFormat.setParseIntegerOnly(true);
259
			textFieldTileSize = new JFormattedTextField(new DefaultFormatterFactory(
260
					new NumberFormatter(integerFormat),
261
					new NumberFormatter(integerFormat),
262
					new NumberFormatter(integerFormat)));
263
		}
264
		return textFieldTileSize;
265
	}
266
	
267
	private JFormattedTextField getTextFieldWMSTileSize() {
268
		if (textFieldWMSTileSize == null) {
269
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
270
			integerFormat.setParseIntegerOnly(true);
271
			textFieldWMSTileSize = new JFormattedTextField(new DefaultFormatterFactory(
272
					new NumberFormatter(integerFormat),
273
					new NumberFormatter(integerFormat),
274
					new NumberFormatter(integerFormat)));
275
		}
276
		return textFieldWMSTileSize;
277
	}
278
	
279
	private JFormattedTextField getTextFieldLevels() {
280
		if (textFieldLevels == null) {
281
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
282
			integerFormat.setParseIntegerOnly(true);
283
			textFieldLevels = new JFormattedTextField(new DefaultFormatterFactory(
284
					new NumberFormatter(integerFormat),
285
					new NumberFormatter(integerFormat),
286
					new NumberFormatter(integerFormat)));
287
		}
288
		return textFieldLevels;
289
	}
290

  
291
	private JLabel getLabelPath() {
292
		if (labelPath == null)
293
			labelPath = new JLabel();
294
		return labelPath;
295
	}
296
	
297
	private JLabel getLabelCacheSize() {
298
		if (labelCacheSize == null)
299
			labelCacheSize = new JLabel();
300
		return labelCacheSize;
301
	}
302
	
303
	private JLabel getLabelLevels() {
304
		if (labelLevels == null)
305
			labelLevels = new JLabel();
306
		return labelLevels;
307
	}
308
	
309
	private JLabel getLabelStruct() {
310
		if (labelStruct == null)
311
			labelStruct = new JLabel();
312
		return labelStruct;
313
	}
314
	
315
	private JLabel getLabelTileSize() {
316
		if (labelTileSize == null)
317
			labelTileSize = new JLabel();
318
		return labelTileSize;
319
	}
320
	
321
	private JLabel getLabelWMSTileSize() {
322
		if (labelWMSTileSize == null)
323
			labelWMSTileSize = new JLabel();
324
		return labelWMSTileSize;
325
	}
326

  
327
	/**
328
	 * Establece los valores por defecto de la Cache
329
	 */
330
	public void initializeDefaults() {
331
		getTextFieldCacheSize().setValue(Configuration.getDefaultValue("tilecache_size"));
332
		getTextFieldTileSize().setValue(Configuration.getDefaultValue("tilesize"));
333
		getTextFieldWMSTileSize().setValue(Configuration.getDefaultValue("tilesizewms"));
334
		getTextFieldLevels().setValue(Configuration.getDefaultValue("tile_levels"));
335
		getTextFieldPath().setText(Configuration.getDefaultValue("path_tilecache").toString());
336
		String struct = (String) Configuration.getDefaultValue("cache_struct");
337
		if(struct != null) {
338
			for (int i = 0; i < getComboBoxStruct().getItemCount(); i++)
339
				if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
340
					getComboBoxStruct().setSelectedIndex(i);
341
					break;
342
				}
343
		}
344
	}
345

  
346
	/**
347
	 * Establece los valores que ha definido el usuario de la Cache
348
	 */
349
	public void initializeValues() {
350
		getTextFieldCacheSize().setValue(Configuration.getValue("tilecache_size", Integer.valueOf(TileCacheLibrary.MAX_CACHE_SIZE)));
351
		getTextFieldTileSize().setValue(Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH)));
352
		getTextFieldWMSTileSize().setValue(Configuration.getValue("tilesizewms", TILE_SIZE_WMS));
353
		getTextFieldLevels().setValue(Configuration.getValue("tile_levels", Integer.valueOf(TileCacheLibrary.DEFAULT_LEVELS)));
354
		getTextFieldPath().setText(Configuration.getValue("path_tilecache", RasterLibrary.pathTileCache));
355
		String struct = Configuration.getValue("cache_struct", TileCacheLibrary.DEFAULT_STRUCTURE);
356
		if(struct != null) {
357
			for (int i = 0; i < getComboBoxStruct().getItemCount(); i++)
358
				if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
359
					getComboBoxStruct().setSelectedIndex(i);
360
					break;
361
				}
362
		}
363
	}
364

  
365
	/**
366
	 * Guarda los valores de la cache establecidos por el usuario
367
	 */
368
	public void storeValues() {
369
		Integer tilecachesize = null;
370
		try {
371
			String s = getTextFieldCacheSize().getText().replaceAll(",", "");
372
			tilecachesize = new Integer(s);
373
			Configuration.setValue("tilecache_size", tilecachesize);
374
		} catch (NumberFormatException e)  {
375
			
376
		}
377
		
378
		Integer tilesize = null;
379
		try {
380
			String s = getTextFieldTileSize().getText().replaceAll(",", "");
381
			tilesize = new Integer(s);
382
			Configuration.setValue("tilesize", tilesize);
383
		} catch (NumberFormatException e)  {
384
			
385
		}
386
		
387
		Integer tilesizewms = null;
388
		try {
389
			String s = getTextFieldWMSTileSize().getText().replaceAll(",", "");
390
			tilesizewms = new Integer(s);
391
			Configuration.setValue("tilesizewms", tilesizewms);
392
		} catch (NumberFormatException e)  {
393
			
394
		}
395
		
396
		Integer tilelevels = null;
397
		try {
398
			String s = getTextFieldLevels().getText().replaceAll(",", "");
399
			tilelevels = new Integer(s);
400
			Configuration.setValue("tile_levels", tilelevels);
401
		} catch (NumberFormatException e)  {
402
			
403
		}
404
		
405
		Configuration.setValue("cache_struct", getComboBoxStruct().getSelectedItem() != null ? getComboBoxStruct().getSelectedItem().toString() : TileCacheLibrary.DEFAULT_STRUCTURE);
406
		Configuration.setValue("path_tilecache", getTextFieldPath().getText());
407
	}
408

  
409
	public void actionPerformed(ActionEvent e) {
410
		String path = getTextFieldPath().getText();
411
		IWindow parent = PluginServices.getMDIManager().getActiveWindow();
412
		IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
413
		for (int i = 0; i < wList.length; i++) {
414
			if(wList[i] instanceof DlgPreferences)
415
				parent = wList[i];
416
		}
417
		
418
		if(CacheExtension.messageBoxYesOrNot(Messages.getText("remove_directory") + "<BR>" + path, parent)) {
419
			File f = new File(path);
420
			if(f.exists()) {
421
				if(!deleteDirectory(f)) {
422
					CacheExtension.messageBoxError("open_files", parent);
423
				}
424
			}else
425
				CacheExtension.messageBoxError("path_not_exists", parent);
426
		}
427
	}
428

  
429
	public boolean deleteDirectory(File directory) {  
430
		File[] files = directory.listFiles();  
431
		for(int i = 0; i < files.length; i++) {  
432
			if(files[i].isDirectory()) {  
433
				this.deleteDirectory(files[i]);  
434
			} else {  
435
				files[i].delete();  
436
			}  
437
		}  
438
		return directory.delete();  
439
	}  
440
}
0 441

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.240/org.gvsig.raster.tilecache.app/src/main/java/org/gvsig/raster/tilecache/app/Configuration.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.tilecache.app;
23

  
24
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.Iterator;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.raster.fmap.layers.IConfiguration;
30
import org.gvsig.utils.XMLEntity;
31

  
32
/**
33
 * La clase <code>Configuration</code> sirve para poder leer y escribir valores en el entorno
34
 * de raster a nivel de configuraci?n. Para leer o escribir hay que usar los
35
 * metodos getValue y setValue, estos metodos lanzan eventos en el caso de
36
 * cambiar el valor que habia establecido. Forma de uso:<p>
37
 *
38
 * En la lectura es recomendable pasar un valor por defecto en el get, para que
39
 * si no existe o si existe pero no corresponde el tipo de datos devolvera el
40
 * valor por defecto<p>
41
 *
42
 * <code>Boolean valor = Configuration.getValue("valorBooleano", Boolean.valueOf(true));</code><p>
43
 *
44
 * <code>Configuration.setValue("valorBooleano", Boolean.valueOf(false));</code><p>
45
 *
46
 * Solo se pueden usar los siguientes tipos de datos:<br>
47
 *  - <b>Boolean</b>, <b>Double</b>, <b>Float</b>, <b>Integer</b>, <b>Long</b>
48
 *  y <b>String</b>.<p>
49
 *
50
 * Otra funcionalidad que tiene, es que puedes agregar un manejador de eventos
51
 * para controlar los cambios de las variables y actuar en consecuencia si cambia
52
 * la que deseas.
53
 *
54
 * @version 07/12/2007
55
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
56
 */
57
public class Configuration implements IConfiguration {
58
	static private Configuration singleton              = new Configuration();
59
	private ArrayList<ConfigurationListener>            
60
	                             actionCommandListeners = new ArrayList<ConfigurationListener>();
61
	private XMLEntity            xml                    = null;
62
	private HashMap<String, Object>
63
	                             hashMap                = new HashMap<String, Object>();
64

  
65
	/**
66
	 * Constructor privado. Nos aseguramos de que nadie pueda crear una instancia
67
	 * desde fuera, la configuraci?n es ?nica para todos.
68
	 */
69
	private Configuration() {
70
		try {
71
			PluginServices ps = PluginServices.getPluginServices("org.gvsig.raster.tilecache.app");
72
			xml = ps.getPersistentXML();
73
		} catch (NullPointerException e) {
74
			//No est? inicializado Configuration
75
			xml = new XMLEntity();
76
		}
77
	}
78

  
79
	/**
80
	 * Devuelve un valor Boolean para el key especificado
81
	 * @param key
82
	 * @param defaultValue
83
	 * @return
84
	 */
85
	static public Boolean getValue(String key, Boolean defaultValue) {
86
		singleton.saveDefaultValue(key, defaultValue);
87
		try {
88
			return Boolean.valueOf(getXMLEntity().getStringProperty(key));
89
		} catch (Exception e) {
90
		}
91
		try {
92
			getXMLEntity().putProperty(key, defaultValue.booleanValue());
93
		} catch(NullPointerException e) {
94
			//No est? inicializada la configuraci?n. Devuelve el default
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff