Revision 3893

View differences:

org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/buildNumber.properties
1
#Fri Oct 09 11:26:48 CEST 2015
2
buildNumber=64
0 3

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/test/java/org/gvsig/raster/app/extension/TestNoDataPanel.java
1
package org.gvsig.raster.app.extension;
2

  
3
import javax.swing.JFrame;
4

  
5
import org.gvsig.raster.tools.app.basic.tool.properties.panel.NoDataPanel;
6

  
7
public class TestNoDataPanel {
8
		private int                          w        = 510;
9
		private int                          h        = 300;
10
		private JFrame                       frame    = new JFrame();
11
		private NoDataPanel               desc     = null;
12

  
13
		public TestNoDataPanel() {
14
			desc = new NoDataPanel();
15
			frame.getContentPane().add(desc);
16
			frame.setSize(w, h);
17
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
18
			frame.setVisible(true);
19
		}
20

  
21
		public static void main(String[] args) {
22
			new TestNoDataPanel();
23
		}
24
	}
0 25

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/test/java/org/gvsig/raster/app/extension/TestClipPanel.java
1
package org.gvsig.raster.app.extension;
2

  
3
import javax.swing.JFrame;
4

  
5
import org.gvsig.raster.tools.app.basic.tool.clip.ui.ClippingPanel;
6
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
7

  
8
public class TestClipPanel {
9
		private int                          w        = 510;
10
		private int                          h        = 300;
11
		private JFrame                       frame    = new JFrame();
12
		private ClippingPanel               desc     = null;
13

  
14
		public TestClipPanel() {
15
			new DefaultLibrariesInitializer().fullInitialize(true);
16
			desc = new ClippingPanel(null);
17
			frame.getContentPane().add(desc);
18
			frame.setSize(w, h);
19
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
20
			frame.setVisible(true);
21
		}
22

  
23
		public static void main(String[] args) {
24
			new TestClipPanel();
25
		}
26
	}
0 27

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

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

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

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

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

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

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.raster">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/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>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
				<include>org.gvsig:org.gvsig.raster.tools.app.basic:jar</include>
33
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.layerdatatype:jar</include>
34
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.saveraster:jar</include>
35
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include>
36
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include>
37
				<include>org.gvsig:org.gvsig.raster.tools.toolbox.algorithm:jar</include>
38
	  </includes>
39
	</dependencySet>
40
  </dependencySets>
41
</assembly>
0 42

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Raster gvSIG extension</p>
11
	
12
	<p>
13
	Shows Raster into gvSIG.
14
	</p>
15

  
16
</body>
17
</html>
0 18

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/RasterToolsUtil.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.tools.app.basic;
23

  
24
import java.awt.Component;
25
import java.awt.Dimension;
26
import java.awt.Point;
27
import java.io.File;
28
import java.util.ArrayList;
29

  
30
import javax.swing.ImageIcon;
31
import javax.swing.JOptionPane;
32

  
33
import org.gvsig.andami.IconThemeHelper;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.app.project.Project;
37
import org.gvsig.app.project.ProjectManager;
38
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
39
import org.gvsig.fmap.dal.DALLocator;
40
import org.gvsig.fmap.dal.DataManager;
41
import org.gvsig.fmap.dal.DataStore;
42
import org.gvsig.fmap.dal.coverage.RasterLocator;
43
import org.gvsig.fmap.dal.coverage.datastruct.Param;
44
import org.gvsig.fmap.dal.coverage.datastruct.Params;
45
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
46
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
47
import org.gvsig.fmap.dal.exception.InitializeException;
48
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
49
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
50
import org.gvsig.fmap.mapcontext.MapContextLocator;
51
import org.gvsig.fmap.mapcontext.MapContextManager;
52
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
53
import org.gvsig.fmap.mapcontext.layers.FLayer;
54
import org.gvsig.fmap.mapcontext.layers.FLayers;
55
import org.gvsig.gui.beans.propertiespanel.PropertiesComponent;
56
import org.gvsig.gui.beans.propertiespanel.PropertyStruct;
57
import org.gvsig.i18n.Messages;
58
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
59
import org.gvsig.raster.util.RasterNotLoadException;
60

  
61
/**
62
 * Herramientas de uso general y que son dependientes de gvSIG, FMap o de
63
 * libUIComponents. En caso de no serlo existe una clase independiente de
64
 * cualquier proyecto dentro de libRaster para este tipo de funciones.
65
 *
66
 * @author Nacho Brodin (nachobrodin@gmail.com)
67
 */
68
public class RasterToolsUtil {
69

  
70
	/**
71
	 * Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira
72
	 * dentro de la agrupaci?n.
73
	 * @param srcLyrs FLayers de la vista
74
	 * @param destLyrs Lista de capas 
75
	 * @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen
76
	 * en la lista es de abajo a arriba las que aparecen en el TOC.
77
	 */
78
	public static ArrayList<FLayer> getRasterLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) {
79
		if(destLyrs == null)
80
			destLyrs = new ArrayList<FLayer>();
81
		for (int i = 0; i < srcLyrs.getLayersCount(); i++) {
82
			if(srcLyrs.getLayer(i) instanceof DefaultFLyrRaster)
83
				destLyrs.add(srcLyrs.getLayer(i));
84
			if(srcLyrs.getLayer(i) instanceof FLayers)
85
				destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs);
86
		}
87
		return destLyrs;
88
	}
89
	
90
	/**
91
	 * Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira
92
	 * dentro de la agrupaci?n.
93
	 * @param srcLyrs FLayers de la vista
94
	 * @param destLyrs Lista de capas 
95
	 * @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen
96
	 * en la lista es de abajo a arriba las que aparecen en el TOC.
97
	 */
98
	public static ArrayList<FLayer> getLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) {
99
		if(srcLyrs == null)
100
			return null;
101
		if(destLyrs == null)
102
			destLyrs = new ArrayList<FLayer>();
103
		for (int i = 0; i < srcLyrs.getLayersCount(); i++) {
104
			if(srcLyrs.getLayer(i) instanceof FLayers)
105
				destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs);
106
			else 
107
				destLyrs.add(srcLyrs.getLayer(i));
108
		}
109
		return destLyrs;
110
	}
111
	
112
	/**
113
	 * Obtiene el nombre de la vista donde est? cargada la capa que se pasa por par?metro
114
	 * @param layer Capa cargada en una vista
115
	 * @return Nombre de la vista donde est? cargada la capa.
116
	 */
117
	public static String getView(FLayer layer) {
118
//		Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
119
		Project p = ProjectManager.getInstance().getCurrentProject();
120
		return p.getViewName(layer);	
121
	}
122
	
123
	/**
124
	 * Devuelve la traducci?n de un texto. En caso de no existir la traducci?n al idioma seleccionado
125
	 * devolver? la cadena de entrada.
126
	 * @param parent Ventana padre que contiene el objeto con la traducci?n
127
	 * @param text Texto a traducir
128
	 * @return Texto traducido o cadena de entrada en caso de no encontrar una traducci?n
129
	 */
130
	public static String getText(Object parent, String text) {
131
		return PluginServices.getText(parent, text);
132
	}
133
	
134
	/**
135
	 * Obtiene un icono definido por la etiqueta que se especifica en el 
136
	 * par?metro
137
	 * @param ico Etiqueta del icono
138
	 * @return Icono
139
	 */
140
	public static ImageIcon getIcon(String ico) {
141
		return IconThemeHelper.getImageIcon(ico);	
142
	}
143
	
144
	/**
145
	 * A?ade una ventana al gestor de ventanas
146
	 * @param window
147
	 */
148
	public static void addWindow(IWindow window) {
149
		PluginServices.getMDIManager().addWindow(window);
150
	}
151
	
152
	/**
153
	 * Elimina una ventana al gestor de ventanas
154
	 * @param window
155
	 */
156
	public static void closeWindow(IWindow window) {
157
		PluginServices.getMDIManager().closeWindow(window);
158
	}
159
	
160
	/**
161
	 * Selecciona los controles del panel de propiedades a partir de los par?mtros
162
	 * obtenidos del driver. Este m?todo realiza una transformaci?n entre Params
163
	 * obtenido del driver de escritura y los par?metros del panel de propiedades.
164
	 * @param panel Panel de propiedades
165
	 * @param params Par?metros del driver
166
	 * @param notTakeIntoAccount Nombre de par?metros que no hay que tener en cuenta. Si es null se tienen en cuenta todos.
167
	 */
168
	public static void loadPropertiesFromWriterParams(PropertiesComponent pComp, Params params, String[] notTakeIntoAccount) {
169
		for (int i = 0; i < params.getNumParams(); i++) {
170
			Param p = params.getParam(i);
171
			String name = getText(null, p.getId());
172
			String key = p.getId();
173

  
174
			//Miramos si el par?metro coincide con  alguno en la lista de parametros que no hay que
175
			//tener en cuenta. Si es as? no lo a?adimos
176
			if(notTakeIntoAccount != null && notTakeIntoAccount.length > 0) {
177
				boolean jump = false;
178
				for (int j = 0; j < notTakeIntoAccount.length; j++) {
179
					if (key.equals(notTakeIntoAccount[j]))
180
						jump = true;
181
				}
182
				if(jump)
183
					continue;
184
			}
185

  
186
			Object[] types = null;
187
			int selectedValue = 0;
188

  
189
			switch (p.getType()) {
190
				case Params.CHECK:
191
					pComp.addValue(name, key, p.getDefaultValue(), types);
192
					break;
193
				case Params.CHOICE:
194
					ArrayList<String> list = new ArrayList<String>();
195
					for (int j = 0; j < p.getList().length; j++) {
196
						list.add(p.getList()[j]);
197
						if (p.getDefaultValue() instanceof Integer)
198
							if (((Integer) p.getDefaultValue()).intValue() == j)
199
								selectedValue = j;
200
					}
201
					types = new Object[] { new Integer(PropertiesComponent.TYPE_COMBO), list };
202
					pComp.addValue(name, key, new Integer(selectedValue), types);
203
					break;
204
				case Params.SLIDER:
205
					types = new Object[] { new Integer(PropertiesComponent.TYPE_SLIDER), new Integer(p.getList()[0]), new Integer(p.getList()[1]) };
206
					pComp.addValue(name, key, p.getDefaultValue(), types);
207
					break;
208
				default:
209
					pComp.addValue(getText(null, ((Param)params.getParam(i)).getId()), params.getParam(i).getId(), params.getParam(i).getDefaultValue(), null);
210
					break;
211
			}
212
		}
213
	}
214

  
215
	/**
216
	 * Carga los par?metros del escritor WriterParams con los valores obtenidos
217
	 * de la ventana de propiedades.
218
	 */
219
	@SuppressWarnings("unchecked")
220
	public static void loadWriterParamsFromPropertiesPanel(PropertiesComponent pComp, Params params) {
221
		ArrayList<PropertyStruct> values = pComp.getValues();
222
		for (int iParam = 0; iParam < params.getNumParams(); iParam++) {
223
			Param p = params.getParam(iParam);
224
			for (int iValue = 0; iValue < values.size(); iValue++) {
225
				PropertyStruct prop = values.get(iValue);
226
				if (p.getId().compareTo(prop.getKey()) == 0) {
227
					switch (p.getType()) {
228
						case Params.CHECK:
229
							p.setDefaultValue((Boolean) prop.getNewValue());
230
							break;
231
						case Params.CHOICE:
232
							p.setDefaultValue(((Integer) prop.getNewValue()));//p.list[((Integer) prop.getNewValue()).intValue()];
233
							break;
234
						case Params.SLIDER:
235
							try {
236
								p.setDefaultValue((Integer)prop.getNewValue());
237
							} catch (NumberFormatException e) {}
238
					}
239
					break;
240
				}
241
			}
242
		}
243
	}
244

  
245
	/**
246
	 * Funci?n que devuelve true si se tiene permiso de escritura en la ruta
247
	 * indicada en el par?metro path y false si no los tiene.
248
	 * @param path Ruta a comprobar los permisosv
249
	 * @param pluginObject si es distinto de null se obtiene un mensaje de
250
	 *          advertencia y sirve como par?metro para getText de la traducci?n.
251
	 *          Si es null no se mostrar? ventana de advertencia
252
	 * @return true si se tiene permiso de escritura en la ruta indicada en el
253
	 *         par?metro path y false si no los tiene.
254
	 */
255
	public static boolean canWrite(String path) {
256
		File f = new File(path);
257
		if(f.exists() && f.canWrite())
258
			return true;
259
		else {
260
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
261
						Messages.getText("error_writing_raster_file"));
262
			return false;
263
		}
264
	}
265

  
266
	/**
267
	 * Carga una capa raster en una vista de gvSIG.
268
	 * @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la
269
	 * primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n.
270
	 * @param fileName Nombre del fichero a cargar. No debe ser nulo nunca.
271
	 * @param layerName Nombre de la capa. Si es null se asignar? el nombre del
272
	 * fichero sin extensi?n.
273
	 * @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa
274
	 * por alg?n motivo.
275
	 */
276
	@SuppressWarnings("deprecation")
277
	public static FLayer loadLayer(String viewName, String fileName, String layerName) throws RasterNotLoadException {
278
		if(fileName ==  null)
279
			return null;
280

  
281
		//Seleccionamos la vista de gvSIG
282
		AbstractViewPanel theView = null;
283
		try {
284
			IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
285
			if(viewName != null) {
286
				for (int i = 0; i < allViews.length; i++) {
287
					if (allViews[i] instanceof AbstractViewPanel
288
						&& (((AbstractViewPanel) allViews[i]).getDocument().getName().equals(viewName) ||
289
							PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName)))
290
						theView = (AbstractViewPanel) allViews[i];
291
				}
292
			} else {
293
				IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
294
				for (int i = 0; i < allViews.length; i++) {
295
					if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa
296
						theView = (AbstractViewPanel) allViews[i];
297
				}
298
				if(theView == null) {
299
					for (int i = 0; i < allViews.length; i++) {
300
						if (allViews[i] instanceof AbstractViewPanel) //En la primera vista
301
							theView = (AbstractViewPanel) allViews[i];
302
					}
303
				}
304
			}
305

  
306
			if (theView == null)
307
				throw new RasterNotLoadException("Imposible cargar la capa.");
308
		} catch (ClassCastException ex) {
309
			throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View.");
310
		}
311

  
312
		theView.getMapControl().getMapContext().beginAtomicEvent();
313

  
314
		DefaultFLyrRaster lyr = null;
315
		try {
316
			ProviderServices provServ = RasterLocator.getManager().getProviderServices();
317
			RasterDataParameters storeParameters = provServ.createNotTiledParameters(fileName);
318
			storeParameters.setSRS(theView.getProjection());
319
			
320
			MapContextManager mcm = MapContextLocator.getMapContextManager();
321
			DataManager dataManager = DALLocator.getDataManager();
322
			DataStore dataStore = null;
323
			try {
324
				dataStore = dataManager.createStore(storeParameters);
325
			} catch (ValidateDataParametersException e) {
326
				throw new RasterNotLoadException("Error al cargar la capa.");
327
			} catch (InitializeException e) {
328
				throw new RasterNotLoadException("Error al cargar la capa.");
329
			} catch (ProviderNotRegisteredException e) {
330
				throw new RasterNotLoadException("Error al cargar la capa.");
331
			}
332
			
333
			lyr = new DefaultFLyrRaster();
334
			
335
			if(layerName == null) {
336
				int endIndex = fileName.lastIndexOf(".");
337
				if (endIndex < 0)
338
					endIndex = fileName.length();
339
				
340
				layerName = fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex);
341
			}
342
			
343
			lyr = (DefaultFLyrRaster) mcm.createLayer(layerName, dataStore);
344

  
345
		} catch (LoadLayerException e) {
346
			throw new RasterNotLoadException("Error al cargar la capa.");
347
		} catch (InitializeException e) {
348
			throw new RasterNotLoadException("Error creating parameters.");
349
		} catch (ProviderNotRegisteredException e) {
350
			throw new RasterNotLoadException("Error creating parameters.");
351
		}
352
		theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
353
		theView.getMapControl().getMapContext().invalidate();
354
		theView.getMapControl().getMapContext().endAtomicEvent();
355
		return lyr;
356
	}
357
	
358
	/**
359
	 * Carga una capa raster en una vista de gvSIG.
360
	 * @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la
361
	 * primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n.
362
	 * @param fileName Nombre del fichero a cargar. No debe ser nulo nunca.
363
	 * @param layerName Nombre de la capa. Si es null se asignar? el nombre del
364
	 * fichero sin extensi?n.
365
	 * @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa
366
	 * por alg?n motivo.
367
	 */
368
	public static FLayer loadLayer(String viewName, FLayer lyr) throws RasterNotLoadException {
369
		if(lyr ==  null)
370
			return null;
371

  
372
		//Seleccionamos la vista de gvSIG
373
		AbstractViewPanel theView = null;
374
		try {
375
			IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
376
			if(viewName != null) {
377
				for (int i = 0; i < allViews.length; i++) {
378
					if (allViews[i] instanceof AbstractViewPanel
379
						&& PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName))
380
						theView = (AbstractViewPanel) allViews[i];
381
				}
382
			} else {
383
				IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
384
				for (int i = 0; i < allViews.length; i++) {
385
					if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa
386
						theView = (AbstractViewPanel) allViews[i];
387
				}
388
				if(theView == null) {
389
					for (int i = 0; i < allViews.length; i++) {
390
						if (allViews[i] instanceof AbstractViewPanel) //En la primera vista
391
							theView = (AbstractViewPanel) allViews[i];
392
					}
393
				}
394
			}
395

  
396
			if (theView == null)
397
				throw new RasterNotLoadException("Imposible cargar la capa.");
398
		} catch (ClassCastException ex) {
399
			throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View.");
400
		}
401

  
402
		theView.getMapControl().getMapContext().beginAtomicEvent();
403
		theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
404
		theView.getMapControl().getMapContext().invalidate();
405
		theView.getMapControl().getMapContext().endAtomicEvent();
406
		return lyr;
407
	}
408
	
409
	/**
410
	 * Calculo de las coordenadas de una ventana IWindow para que quede centrada sobre el 
411
	 * MainFrame. Estas coordenadas solo valen para un IWindow ya que andami mete las ventanas
412
	 * con coordenadas relativas a su ventanta principal.
413
	 * @param widthWindow Ancho de la ventana a a?adir
414
	 * @param heightWindow Alto de la ventana a a?adir
415
	 * @return Array con el ancho y el alto 
416
	 */
417
	public static Point iwindowPosition(int widthWindow, int heightWindow) {
418
		int posWindowX = 0;
419
		int posWindowY = 0;
420
		Dimension dim = null;
421
		Point pos = null;
422
		if(PluginServices.getMainFrame() instanceof Component) {
423
			dim = ((Component)PluginServices.getMainFrame()).getSize();
424
			pos = ((Component)PluginServices.getMainFrame()).getLocation();
425
			if(dim != null && pos != null) {
426
				posWindowX = ((dim.width >> 1) - (widthWindow >> 1));
427
				posWindowY = ((dim.height >> 1) - (heightWindow >> 1) - 70);
428
				return new Point(posWindowX, posWindowY);
429
			}
430
		}
431
		return null;
432
	}
433
}
0 434

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/StatisticsProcess.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.tools.app.basic.raster.process;
23

  
24
import javax.swing.SwingUtilities;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
31
import org.gvsig.raster.fmap.layers.FLyrRaster;
32

  
33

  
34
/**
35
 * Proceso para la generaci?n de estad?sticas.
36
 *
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class StatisticsProcess extends RasterProcess {
40
	private FLyrRaster            lyr   = null;
41
	private Statistics            stats = null;
42
	private boolean               force = false;
43
	private double                scale = 1;
44

  
45
	/**
46
	 * Lanzador del procesos de estad?sticas
47
	 * @param lyr Capa a calcular las estad?sticas
48
	 * @param actions Clase que recoge eventos del proceso
49
	 */
50
	public static void launcher(FLyrRaster lyr, IProcessActions actions) {
51
		RasterProcess process = new StatisticsProcess();
52
		process.addParam("layer", lyr);
53
		process.addParam("force", new Boolean(false));
54
		process.setActions(actions);
55
		process.start();	
56
	}
57
	
58
	public void init() {
59
		lyr = getLayerParam("layer");
60
		force = getBooleanParam("force");
61
		double s = getDoubleParam("scale");
62
		if(s > 0 && s < 1)
63
			scale = s;
64
	}
65

  
66
	/**
67
	 * M?todo donde se ejecutar? el Thread, aqu? se calcular?n las 
68
	 * estad?sticas.
69
	 * @throws ProcessException 
70
	 */
71
	public void process() throws ProcessInterruptedException, ProcessException {
72
		insertLineLog(PluginServices.getText(this, "statistics_generation"));
73
		if(lyr == null || lyr.getDataStore() == null)
74
			return;
75
		stats = lyr.getDataStore().getStatistics();
76
		lyr.setReadingData(Thread.currentThread().getId() + "");
77
		if (force)
78
			stats.forceToRecalc();
79
		try {
80
			stats.calculate(scale);
81
			SwingUtilities.invokeLater(new Runnable() {
82
				public void run() {
83
					if (externalActions != null)
84
						externalActions.end(lyr);
85
				}
86
			});
87
		} catch (FileNotOpenException e) {
88
			throw new ProcessException("No se ha podido escribir en el fichero rmf", e);
89
		} catch (RasterDriverException e) {
90
			throw new ProcessException("Error leyendo bloques de datos para calcular estad?sticas", e);
91
		} finally {
92
			lyr.setReadingData(null);
93
		}
94
	}
95

  
96
	public int getPercent() {
97
		return (stats != null) ? stats.getPercent() : 0;
98
	}
99

  
100
	public String getTitle() {
101
		return PluginServices.getText(this, "increase_statistics");
102
	}
103
}
0 104

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/UniqueProcessQueue.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.tools.app.basic.raster.process;
23

  
24
import org.gvsig.raster.util.Queue;
25
import org.slf4j.LoggerFactory;
26

  
27
/**
28
 * Cola de procesos de ejecuci?n exclusiva. Los procesos de esta lista se ir?n ejecutando
29
 * por orden de llegada impidiendo que se ejecuten dos al mismo tiempo.
30
 * 
31
 * 16/05/2008
32
 * @author Nacho Brodin nachobrodin@gmail.com
33
 */
34
public class UniqueProcessQueue implements IProcessActions {
35
	private static final int          LAPSE_TIME       = 1000;
36

  
37
	private Queue                     queue            = new Queue();
38
	private RasterProcess             executionProcess = null;
39
	static private UniqueProcessQueue singleton        = new UniqueProcessQueue();
40

  
41
	/**
42
	 * Dejamos el constructor privado para que nadie pueda referenciarlo
43
	 */
44
	private UniqueProcessQueue() {}
45
	
46
	/**
47
	 * Devuelve una instancia al unico objeto de UniqueProcessQueue que puede existir.
48
	 * @return
49
	 */
50
	static public UniqueProcessQueue getSingleton() {
51
		return singleton;
52
	}
53
	
54
	/**
55
	 * A?ade un proceso a la cola.
56
	 * @param id Identificador del proceso
57
	 * @param process Proceso
58
	 */
59
	public synchronized void add(RasterProcess process) {
60
		queue.put(process);
61
		process.setUniqueProcessActions(this);
62
		
63
		//Decisi?n de arranque
64
		if(queue.size() >= 1 && executionProcess != null)
65
			start();
66
	}
67
	
68
	/**
69
	 * Pone en marcha el primer proceso de la lista
70
	 */
71
	public void start() {
72
		nextProcess();
73
	}
74
	
75
	private void nextProcess() {
76
		executionProcess = ((RasterProcess) queue.get());
77
		if (executionProcess != null)
78
			executionProcess.start();
79
	}
80

  
81
	/**
82
	 * Evento de finalizaci?n de un proceso. Cuando un proceso acaba se 
83
	 * pone en marcha el siguiente de la lista si existe. Se asigna un tiempo de latencia para
84
	 * la ejecuci?n del siguiente marcado por LAPSE_TIME.  
85
	 */
86
	public void end(Object param) {
87
		try {
88
			Thread.sleep(LAPSE_TIME);
89
		} catch (InterruptedException e) {
90
			LoggerFactory.getLogger(UniqueProcessQueue.class).debug("sleep Exception", e);
91
		}
92
		nextProcess();
93
	}
94
	
95
	/**
96
	 * How many elements are there in this queue?
97
	 */
98
	public int size() {
99
		return queue.size();
100
	}
101

  
102
	/*
103
	 * (non-Javadoc)
104
	 * @see org.gvsig.raster.IProcessActions#interrupted()
105
	 */
106
	public void interrupted() {}	
107
}
0 108

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/HistogramProcess.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.tools.app.basic.raster.process;
23

  
24
import javax.swing.SwingUtilities;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
28
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
29
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
30
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
31

  
32
/**
33
* Process to calculate a Histogram using a Histogramable object. A Histogramable object
34
* has its own method to build an histogram an this process will call to this function. 
35
* 
36
* @author Nacho Brodin (nachobrodin@gmail.com)
37
*/
38
public class HistogramProcess extends RasterProcess {
39
	private BufferHistogram        lastHistogram  = null;
40
	private HistogramComputer      histogramable  = null;
41
	
42
	/*
43
	 * (non-Javadoc)
44
	 * @see org.gvsig.rastertools.RasterProcess#init()
45
	 */
46
	public void init() {
47
		histogramable = (HistogramComputer) getParam("histogramable");
48
	}
49

  
50
	/*
51
	 * (non-Javadoc)
52
	 * @see org.gvsig.rastertools.RasterProcess#process()
53
	 */
54
	public void process() throws ProcessInterruptedException, ProcessException {
55
		try {
56
			// Proceso duro de obtener un histograma. Puede durar bastante tiempo.
57
			lastHistogram = histogramable.getBufferHistogram();
58
			// Ya tenemos el histograma y lo representamos en la ventana
59
			SwingUtilities.invokeLater(new Runnable() {
60
				public void run() {
61
					if ((externalActions != null) && (lastHistogram != null))
62
						externalActions.end(lastHistogram);
63
				}
64
			});
65
			
66
		} catch (HistogramException e) {
67
			throw new ProcessException("Error calculando el histograma", e);
68
		} 
69
	}
70
	
71
	/*
72
	 * (non-Javadoc)
73
	 * @see org.gvsig.raster.RasterProcess#getResult()
74
	 */
75
	public Object getResult() {
76
		return lastHistogram;
77
	}
78

  
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.rastertools.RasterProcess#getLog()
82
	 */
83
	public String getLog() {
84
		return PluginServices.getText(this, "calculando_histograma") + "...\n";
85
	}
86

  
87
	/*
88
	 * (non-Javadoc)
89
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
90
	 */
91
	public int getPercent() {
92
		if (histogramable != null)
93
			return histogramable.getPercent();
94
		return 0;
95
	}
96

  
97
	/*
98
	 * (non-Javadoc)
99
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
100
	 */
101
	public String getTitle() {
102
		return PluginServices.getText(this, "calculando_histograma");
103
	}
104
	
105
	/*
106
	 * (non-Javadoc)
107
	 * @see java.lang.Object#finalize()
108
	 */
109
	protected void finalize() throws Throwable {
110
		lastHistogram           = null;
111
		histogramable           = null;
112
		super.finalize();
113
	}
114
}
0 115

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ProcessException.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.tools.app.basic.raster.process;
23
/**
24
 * This exception is thrown when a problem inside a raster process
25
 * is detected. 
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class ProcessException extends Exception {
30
	private static final long serialVersionUID = 666908550965442025L;
31

  
32
	public ProcessException(String msg, Throwable e) {
33
		super(msg, e);
34
	}
35
	
36
	public ProcessException(String msg){
37
		super(msg);
38
	}
39
}
0 40

  
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.13/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/RasterProcess.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.tools.app.basic.raster.process;
23

  
24
import java.util.Hashtable;
25

  
26
import org.gvsig.fmap.dal.coverage.RasterLocator;
27
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.process.CancelEvent;
30
import org.gvsig.fmap.dal.coverage.process.TaskEventManager;
31
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
32
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
33
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
34
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
35
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
36
import org.gvsig.raster.fmap.layers.FLyrRaster;
37
import org.gvsig.raster.swing.RasterSwingLibrary;
38
import org.gvsig.tools.dispose.Disposable;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41
/**
42
 * Clase base de todos los procesos raster. En ella se genstionan todas las
43
 * funciones comunes como incremento de la tarea, gesti?n de eventos a la tarea, 
44
 * par?metros de la tarea, etc ...
45
 * 
46
 * 18/12/2007
47
 * @author Nacho Brodin nachobrodin@gmail.com
48
 * @deprecated Use DataProcess in org.gvsig.raster.algorithm
49
 */
50
public abstract class RasterProcess implements IIncrementable, IncrementableListener, Runnable, Disposable {
51
	protected IncrementableTask incrementableTask = null;
52
	protected volatile Thread   blinker           = null;
53
	protected TaskEventManager  taskEventManager  = null;
54
	protected IProcessActions   externalActions   = null;
55
	protected Hashtable<String, Object>
56
	                            taskParams        = new Hashtable<String, Object>();
57

  
58
	private String              log               = "";
59
	private String              lastLine          = "";
60
	private long                time              = 0;
61
	private boolean             progressActive    = true;
62
	private IProcessActions     queueActions      = null;
63
	private Logger              logger            = LoggerFactory.getLogger(RasterProcess.class.toString());
64

  
65
	
66
	/**
67
	 * Crea la ventana de IncrementableTask
68
	 */
69
	public IncrementableTask getIncrementableTask() {
70
		if (incrementableTask == null) {
71
			incrementableTask = new IncrementableTask(this);
72
			incrementableTask.addIncrementableListener(this);
73
		}
74
		return incrementableTask;
75
	}
76
	
77
	/**
78
	 * Define si se puede cancelar el proceso. Por defecto es true.
79
	 * @param enabled
80
	 */
81
	public void setCancelable(boolean enabled) {
82
		getIncrementableTask().getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_CANCEL, enabled);
83
	}
84
	
85
	/**
86
	 * Muestra la ventana de IncrementableTask
87
	 */
88
	public void showIncrementableWindow() {
89
		if (progressActive) {
90
			getIncrementableTask().showWindow();
91
			getIncrementableTask().start();
92
		}
93
	}
94

  
95
	/**
96
	 * Arranca el proceso de recorte de un layer
97
	 */
98
	public void start() {
99
		showIncrementableWindow();
100
		if(blinker == null)
101
			blinker = new Thread(this);
102
		blinker.start();
103
	}
104
		
105
	/**
106
	 * Proceso de carga de par?metros. Puede no hacerse una carga de par?metros 
107
	 * explicita y obtenerlos directamente de la tabla Hash cuando vayan a usarse. 
108
	 * Esto queda a elecci?n del programador. En caso de hacerse una carga de par?metros
109
	 * explicita esta llamada deber?a hacerse justo despues del constructor de la clase
110
	 * que contendr? el proceso.
111
	 */
112
	public abstract void init();
113
	
114
	/**
115
	 * Proceso
116
	 * @throws InterruptedException
117
	 */
118
	public abstract void process() throws ProcessInterruptedException, ProcessException;
119
	
120
	/**
121
	 * Obtenci?n de un objeto de resultado. Este objeto deber? ser el mismo que el que se
122
	 * pasa por par?metro en el "end" de IProcessActions. Este m?todo es util cuando la tarea no se
123
	 * lanza en un Thread (ejecutamos process directamente) y queremos recoger el resultado
124
	 * sin registrarnos al evento de finalizaci?n de tarea.
125
	 * @return objeto resultado de la tarea
126
	 */
127
	public Object getResult() {
128
		return null;
129
	}
130
	
131
	/**
132
	 * Proceso
133
	 * @throws ProcessException 
134
	 */
135
	public void execute() throws ProcessInterruptedException, ProcessException {
136
		init();
137
		process();
138
	}
139
	
140
	/**
141
	 * M?todo donde se ejecutar? el Thread. Este har? las acciones globales para 
142
	 * cualquier tarea y llamar? al m?todo execute especifico de una tarea.
143
	 */
144
	public void run() {
145
		long t1 = new java.util.Date().getTime();
146

  
147
		try {
148
			taskEventManager = RasterLocator.getManager().createRasterTask(this);
149
			execute();
150
		} catch (ProcessInterruptedException e) {
151
			if (externalActions != null)
152
				externalActions.interrupted();
153
			Thread.currentThread().interrupt();
154
		} catch (ProcessException e) {
155
			if (progressActive) {
156
				if (incrementableTask != null) {
157
					getIncrementableTask().processFinalize();
158
					incrementableTask = null;
159
				}
160
			}
161
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
162
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
163
				RasterSwingLibrary.messageBoxError(e.getMessage(), this);
164
			else
165
				RasterSwingLibrary.messageBoxError("error_processing", this);
166
			queueActions = null;
167

  
168
		} catch (Exception e) {
169
			if (progressActive) {
170
				if (incrementableTask != null) {
171
					getIncrementableTask().processFinalize();
172
					incrementableTask = null;
173
				}
174
			}
175
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
176
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
177
				RasterSwingLibrary.messageBoxError(e.getMessage(), this);
178
			else
179
				RasterSwingLibrary.messageBoxError("error_processing", this);
180
			queueActions = null;
181
		} finally {
182
			taskEventManager.removeTask();
183
			if (progressActive) {
184
				if (incrementableTask != null)
185
					getIncrementableTask().processFinalize();
186
			}
187
			if (queueActions != null)
188
				queueActions.end(this);
189
			time = new java.util.Date().getTime() - t1;
190
			blinker = null;
191
		}
192
	}
193
	
194
	/**
195
	 * Activa o desactiva el interfaz de progreso en el lanzamiento de la tarea como un thread.
196
	 * @param active true para activarlo o false para desactivarlo
197
	 */
198
	public void setProgressActive(boolean active){
199
		this.progressActive = active;
200
	}
201
	
202
	/**
203
	 * Obtiene el tiempo que tard? en ejecutarse la tarea 
204
	 * la ?ltima vez que se proces?
205
	 */
206
	public long getTime() {
207
		return time;
208
	}
209
	
210
	/**
211
	 * Obtiene el objeto para ejecutar acciones externar.
212
	 * @param IProcessActions
213
	 */
214
	public IProcessActions getActions() {
215
		return externalActions;
216
	}
217

  
218
	/**
219
	 * Asigna el objeto para ejecutar acciones externar.
220
	 * @param IProcessActions
221
	 */
222
	public void setActions(IProcessActions actions) {
223
		this.externalActions = actions;
224
	}
225
	
226
	/**
227
	 * Obtiene el objeto para ejecutar acciones de la cola de procesos de ejecuci?n exclusiva.
228
	 * @param IProcessActions
229
	 */
230
	public IProcessActions getUniqueProcessActions() {
231
		return queueActions;
232
	}
233

  
234
	/**
235
	 * Asigna el objeto para ejecutar acciones externar.
236
	 * @param IProcessActions
237
	 */
238
	public void setUniqueProcessActions(IProcessActions actions) {
239
		this.queueActions = actions;
240
	}
241
	
242
	/**
243
	 * Inserta una nueva l?nea en el log del cuadro de incremento de tarea
244
	 * @param line
245
	 */
246
	protected void insertLineLog(String line) {
247
		lastLine = line;
248
		log = log + line + "\n";
249
	}
250
	
251
	/**
252
	 * Obtiene la ?ltima l?nea introducida en el log del cuadro de incremento.
253
	 */
254
	public String getLabel() {
255
		return lastLine;
256
	}
257
	
258
	/**
259
	 * Obtiene el texto de log del cuadro de incremento completo.
260
	 */
261
	public String getLog() {
262
		return log;
263
	}
264
	
265
	/**
266
	 * Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para
267
	 * ello se crear? un objeto CancelEvent y se asignar? a la tarea en ejecuci?n. Esta lo
268
	 * procesar? cuando pueda e interrumpir? el proceso.
269
	 */
270
	public void actionCanceled(IncrementableEvent e) {
271
		taskEventManager.setEvent(new CancelEvent(this));
272
	}
273
	
274
	/**
275
	 * A?ade un par?metro a la tarea
276
	 * @param name Clave del par?metro
277
	 * @param param Objeto pasado como par?metro
278
	 */
279
	public void addParam(String name, Object param) {
280
		if (param != null)
281
			taskParams.put(name, param);
282
		else
283
			taskParams.remove(name);
284
	}
285

  
286
	/**
287
	 * Elimina un par?metro de la tarea
288
	 * @param name Clave del par?metro a eliminar
289
	 */
290
	public void removeParam(String name) {
291
		taskParams.remove(name);
292
	}
293

  
294
	/**
295
	 * Obtiene un par?metro a partir de la clave
296
	 * @param name Par?metro
297
	 * @return Par?metro
298
	 */
299
	public Object getParam(String name) {
300
		return taskParams.get(name);
301
	}
302
	
303
	/**
304
	 * Obtiene un par?metro String a partir de la clave
305
	 * @param name Par?metro
306
	 * @return Par?metro
307
	 */
308
	public String getStringParam(String name) {
309
		Object value = taskParams.get(name);
310
		return (value != null && value instanceof String) ? (String)value : null;
311
	}
312
	
313
	/**
314
	 * Obtiene un par?metro byte a partir de la clave
315
	 * @param name Par?metro
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff