svn-gvsig-desktop / tags / v1_0_2_Build_902 / extensions / extRasterTools / src / org / gvsig / rasterTools / saveRaster / operations / SaveRasterThread.java @ 10681
History | View | Annotate | Download (5.98 KB)
1 | 4547 | nacho | /*
|
---|---|---|---|
2 | * Created on 17-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package org.gvsig.rasterTools.saveRaster.operations; |
||
48 | |||
49 | import java.awt.Dimension; |
||
50 | import java.io.File; |
||
51 | import java.io.IOException; |
||
52 | |||
53 | import org.cresques.geo.ViewPortData; |
||
54 | import org.cresques.io.GeoRasterWriter; |
||
55 | import org.cresques.io.IDataWriter; |
||
56 | 10624 | nacho | import org.cresques.io.data.RasterBuf; |
57 | 4547 | nacho | import org.cresques.px.Extent; |
58 | import org.gvsig.rasterTools.saveRaster.ui.info.EndInfoDialog; |
||
59 | import org.gvsig.rasterTools.saveRaster.ui.properties.ProgressSaveRasterDialog; |
||
60 | import org.gvsig.rasterTools.saveRaster.util.DriverProperties; |
||
61 | |||
62 | import com.iver.andami.PluginServices; |
||
63 | import com.iver.cit.gvsig.fmap.MapControl; |
||
64 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
65 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
66 | |||
67 | /**
|
||
68 | * Thread que se encarga de llamar a los writer para realizar la tarea
|
||
69 | * de salvado y/p compresi?n
|
||
70 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
71 | */
|
||
72 | public class SaveRasterThread extends Thread{ |
||
73 | |||
74 | private GeoRasterWriter writer = null; |
||
75 | |||
76 | private ProgressSaveRasterDialog window = null; |
||
77 | private FLayers layers = null; |
||
78 | private ViewPort vp = null; |
||
79 | private MapControl mapCtrl = null; |
||
80 | private Dimension dimension = null; |
||
81 | |||
82 | private String fName = ""; |
||
83 | 6004 | nacho | private int sizeBlock = GeoRasterWriter.blockSizeDefault; |
84 | 4547 | nacho | private double[] maxPercentBarList = new double[1];; |
85 | 10489 | nacho | private int compresion = 10; |
86 | 4547 | nacho | private DriverProperties driverProps = null; |
87 | |||
88 | |||
89 | public SaveRasterThread(MapControl mapCtrl,
|
||
90 | FLayers layers, |
||
91 | Dimension dimension,
|
||
92 | ViewPort vp, |
||
93 | ProgressSaveRasterDialog window){ |
||
94 | this.window = window;
|
||
95 | this.layers = layers;
|
||
96 | this.mapCtrl = mapCtrl;
|
||
97 | this.dimension = dimension;
|
||
98 | this.vp = vp;
|
||
99 | } |
||
100 | |||
101 | public void run(){ |
||
102 | long t2;
|
||
103 | long t1 = new java.util.Date().getTime(); |
||
104 | |||
105 | //Creamos el servidor de datos de la vista
|
||
106 | 6004 | nacho | RasterizerLayer p = new RasterizerLayer(layers, vp, sizeBlock, mapCtrl, this); |
107 | 4547 | nacho | |
108 | //Asignamos la barra de progreso
|
||
109 | p.setProgressBar(window, maxPercentBarList[0]);
|
||
110 | |||
111 | //Creamos el driver
|
||
112 | Extent ex = new Extent(vp.getAdjustedExtent());
|
||
113 | Dimension imgSz = vp.getImageSize();
|
||
114 | ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
|
||
115 | writer = GeoRasterWriter.getWriter((IDataWriter)p, fName, sizeBlock, |
||
116 | 10624 | nacho | 3, vpData, compresion, dimension.width,
|
117 | dimension.height, RasterBuf.TYPE_IMAGE); |
||
118 | 4547 | nacho | |
119 | //Si han sido modificadas las propiedades se asignan los valores modificados
|
||
120 | String[] prp = driverProps.getProperties(fName.toLowerCase().substring(fName.lastIndexOf(".") + 1)); |
||
121 | 10489 | nacho | if(prp != null) |
122 | 4547 | nacho | writer.setProps(prp); |
123 | |||
124 | //Ejecutamos el driver con los datos pasados
|
||
125 | try{
|
||
126 | writer.dataWrite(); |
||
127 | writer.writeClose(); |
||
128 | }catch(IOException ev){ |
||
129 | return;
|
||
130 | } |
||
131 | |||
132 | t2 = new java.util.Date().getTime();
|
||
133 | |||
134 | try{
|
||
135 | this.setEndInfo(fName, (t2 - t1));
|
||
136 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(this.window);
|
137 | 4547 | nacho | }catch(ArrayIndexOutOfBoundsException exc){ |
138 | //Si la ventana se ha cerrado ya es porque ha sido cancelada por lo que
|
||
139 | //producir? esta excepci?n. En este caso no se lanza la ventana de informaci?n
|
||
140 | //de finalizaci?n.
|
||
141 | } |
||
142 | } |
||
143 | |||
144 | private void setEndInfo(String fName, long milis){ |
||
145 | EndInfoDialog info = new EndInfoDialog();
|
||
146 | info.setFileName(" "+fName);
|
||
147 | File f = new File(fName); |
||
148 | info.setSize(f.length()); |
||
149 | info.setTime(milis); |
||
150 | 5249 | nacho | if( fName.endsWith("ecw") || |
151 | fName.endsWith("jp2") ||
|
||
152 | fName.endsWith("jpg") ||
|
||
153 | fName.endsWith("jpeg"))
|
||
154 | 4547 | nacho | info.setCompression(true);
|
155 | else
|
||
156 | info.setCompression(false);
|
||
157 | 6880 | cesar | PluginServices.getMDIManager().addWindow(info); |
158 | 4547 | nacho | } |
159 | |||
160 | /**
|
||
161 | *Detiene la compresi?n
|
||
162 | */
|
||
163 | synchronized public void stopThread(){ |
||
164 | writer.writeCancel(); |
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | * Asigna el objeto que contiene las propiedades
|
||
169 | * @param driverProps
|
||
170 | */
|
||
171 | public void setProps(DriverProperties driverProps){ |
||
172 | this.driverProps = driverProps;
|
||
173 | } |
||
174 | |||
175 | /**
|
||
176 | * Asigna el nombre del fichero
|
||
177 | * @param fName Nombre del fichero
|
||
178 | */
|
||
179 | public void setFName(String fName){ |
||
180 | this.fName = fName;
|
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * Asigna el GeoRasterWriter que se usar? para salvar
|
||
185 | * @param writer
|
||
186 | */
|
||
187 | public void setWriter(GeoRasterWriter writer){ |
||
188 | this.writer = writer;
|
||
189 | } |
||
190 | |||
191 | /**
|
||
192 | * Asigna el tama?o de bloque que se lee de una sola vez desde el origen
|
||
193 | * Esto influye en la velocidad de escritura y depende de la memoria que
|
||
194 | * tengamos disponible. Si disponemos de poca corremos el riesgo de que al
|
||
195 | * asignar un bloque muy grande nos de un error
|
||
196 | * @param sizeBlock Tama?o de bloque
|
||
197 | */
|
||
198 | public void setBlockSize(int sizeBlock){ |
||
199 | this.sizeBlock = sizeBlock;
|
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * Asigna la compresi?n si el formato dispone de este par?metro
|
||
204 | * @param compresion Nivel de compresi?n
|
||
205 | */
|
||
206 | public void setCompresion(int compresion){ |
||
207 | this.compresion = compresion;
|
||
208 | } |
||
209 | } |
||
210 | |||
211 | |||
212 | |||
213 |