Revision 3890
trunk/extensions/extRasterTools/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>extRasterTools</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
</buildSpec> |
|
14 |
<natures> |
|
15 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
16 |
</natures> |
|
17 |
</projectDescription> |
|
0 | 18 |
trunk/extensions/extRasterTools/text_cs.properties | ||
---|---|---|
1 |
#text_cs.properties |
|
0 | 2 |
trunk/extensions/extRasterTools/config/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<depends plugin-name="com.iver.cit.gvsig"/> |
|
4 |
<libraries library-dir="."/> |
|
5 |
<resourceBundle name="text"/> |
|
6 |
<extensions> |
|
7 |
<extension class-name="com.iver.cit.gvsig.rasterTools.saveRaster.SaveRasterModule" |
|
8 |
description="M?dulo de Salvar a Raster." |
|
9 |
active="true" |
|
10 |
priority="1"> |
|
11 |
<tool-bar name="com.iver.cit.gvsig.Herramientas"> |
|
12 |
<selectable-tool |
|
13 |
icon="images/Rectangle.png" |
|
14 |
action-command="SAVERASTER" |
|
15 |
tooltip="salvar_raster"/> |
|
16 |
</tool-bar> |
|
17 |
</extension> |
|
18 |
</extensions> |
|
19 |
</plugin-config> |
|
0 | 20 |
trunk/extensions/extRasterTools/text_fr.properties | ||
---|---|---|
1 |
#text_fr.properties |
|
0 | 2 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/fmap/rasterTools/tools/SaveRasterListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.rasterTools.tools; |
|
42 |
|
|
43 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
44 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
45 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
|
46 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
|
47 |
|
|
48 |
import java.awt.Cursor; |
|
49 |
import java.awt.Image; |
|
50 |
import java.awt.Point; |
|
51 |
import java.awt.Toolkit; |
|
52 |
import java.awt.event.MouseEvent; |
|
53 |
import java.awt.geom.Rectangle2D; |
|
54 |
|
|
55 |
import javax.swing.ImageIcon; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* Implementaci?n de la interfaz RectangleListener como herramienta para |
|
60 |
* realizar un Salvado a Raster. |
|
61 |
* |
|
62 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
63 |
*/ |
|
64 |
public class SaveRasterListenerImpl implements RectangleListener { |
|
65 |
private final Image isaveraster = new ImageIcon(MapControl.class.getResource( |
|
66 |
"images/RectSelectCursor.gif")).getImage(); |
|
67 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(isaveraster, |
|
68 |
new Point(16, 16), ""); |
|
69 |
protected MapControl mapCtrl; |
|
70 |
|
|
71 |
protected Rectangle2D pixelRect = null; |
|
72 |
protected Rectangle2D rect = null; |
|
73 |
|
|
74 |
/** |
|
75 |
* Crea un nuevo RectangleListenerImpl. |
|
76 |
* |
|
77 |
* @param mapCtrl MapControl. |
|
78 |
*/ |
|
79 |
public SaveRasterListenerImpl(MapControl mapCtrl) { |
|
80 |
this.mapCtrl = mapCtrl; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent) |
|
85 |
*/ |
|
86 |
public void rectangle(RectangleEvent event) { |
|
87 |
rect = event.getWorldCoordRect(); |
|
88 |
pixelRect = event.getPixelCoordRect(); |
|
89 |
//Rectangle2D.Double r = new Rectangle2D.Double(); |
|
90 |
|
|
91 |
//ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
|
92 |
|
|
93 |
// mapCtrl.drawMap(false); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
98 |
*/ |
|
99 |
public Cursor getCursor() { |
|
100 |
return cur; |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
105 |
*/ |
|
106 |
public boolean cancelDrawing() { |
|
107 |
System.out.println("cancelDrawing del SaveRasterListenerImpl"); |
|
108 |
return true; |
|
109 |
} |
|
110 |
} |
|
0 | 111 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/fmap/rasterTools/RasterizerLayer.java | ||
---|---|---|
1 |
/* |
|
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 com.iver.cit.gvsig.fmap.rasterTools; |
|
48 |
|
|
49 |
import java.awt.Color; |
|
50 |
import java.awt.Dimension; |
|
51 |
import java.awt.Graphics2D; |
|
52 |
import java.awt.geom.Rectangle2D; |
|
53 |
import java.awt.image.BufferedImage; |
|
54 |
|
|
55 |
import javax.swing.JProgressBar; |
|
56 |
|
|
57 |
import org.cresques.io.Rasterizer; |
|
58 |
import org.cresques.io.raster.RasterBuf; |
|
59 |
import org.cresques.io.raster.RasterStats; |
|
60 |
|
|
61 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
62 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
63 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
64 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
66 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
|
67 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
|
68 |
|
|
69 |
/** |
|
70 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
71 |
* |
|
72 |
* Sirve datos solicitados por los drivers que salvan a raster. |
|
73 |
* Hereda de Rasterizer y reescribe el m?todo readData que es el que |
|
74 |
* ser? llamado desde el driver cada vez que vacie el buffer y |
|
75 |
* necesite m?s datos. |
|
76 |
*/ |
|
77 |
public class RasterizerLayer extends Rasterizer{ |
|
78 |
|
|
79 |
private ViewPort viewPort = null; |
|
80 |
private ViewPort viewPortBlock = null; |
|
81 |
private FLayers flayers = null; |
|
82 |
private Color backgroundColor = null; |
|
83 |
private JProgressBar progressBar = null; |
|
84 |
private double incrProgressBar = 0; |
|
85 |
private boolean firstRead = true; |
|
86 |
private int nBlocks = 0; |
|
87 |
private double percentMax = 100.0D; |
|
88 |
private double incrTemp = 0; |
|
89 |
|
|
90 |
/** |
|
91 |
* Calculo del viewPort |
|
92 |
* @param vp |
|
93 |
*/ |
|
94 |
private void calcViewPort(ViewPort vp){ |
|
95 |
Rectangle2D ext = null; |
|
96 |
|
|
97 |
if(viewPortBlock == null){ |
|
98 |
ext = new Rectangle2D.Double( vp.getExtent().getMinX(), |
|
99 |
vp.getExtent().getMaxY()-wcIntervalo, |
|
100 |
vp.getExtent().getWidth(), |
|
101 |
wcIntervalo |
|
102 |
); |
|
103 |
}else{ |
|
104 |
ext = new Rectangle2D.Double( vp.getExtent().getMinX(), |
|
105 |
vp.getExtent().getMinY()-wcIntervalo, |
|
106 |
vp.getExtent().getWidth(), |
|
107 |
wcIntervalo |
|
108 |
); |
|
109 |
} |
|
110 |
|
|
111 |
viewPortBlock = new ViewPort(vp.getProjection()); |
|
112 |
viewPortBlock.setExtent(ext); |
|
113 |
viewPortBlock.setImageSize(dimension); |
|
114 |
viewPortBlock.setScale(); |
|
115 |
//System.out.println("--->bloque="+contBlocks+" ImageHeight="+viewPortBlock.getImageHeight()+" ImageWidth="+viewPortBlock.getImageWidth()); |
|
116 |
//System.out.println("--->minX="+viewPortBlock.getExtent().getMinX()+" minY="+viewPortBlock.getExtent().getMinY()+" maxX="+viewPortBlock.getExtent().getMaxX()+" maxY="+viewPortBlock.getExtent().getMaxY()+" width="+viewPortBlock.getExtent().getWidth()+" height="+viewPortBlock.getExtent().getHeight()); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Constructor |
|
121 |
* @param flyrs capas |
|
122 |
* @param vp viewport |
|
123 |
* @param sizeBlock altura del bloque que se lee de una vez en la imagen de entrada |
|
124 |
* @param mapCtrl Mapcontrol |
|
125 |
*/ |
|
126 |
public RasterizerLayer(FLayers flyrs, ViewPort vp, int sizeBlock, MapControl mapCtrl){ |
|
127 |
super(sizeBlock); |
|
128 |
//System.out.println("===>VP="+vp.getExtent().getMinX()+" "+vp.getExtent().getMinY()+" "+vp.getExtent().getMaxX()+" "+vp.getExtent().getMaxY()); |
|
129 |
backgroundColor = vp.getBackColor(); |
|
130 |
viewPort = new ViewPort(vp.getProjection()); |
|
131 |
viewPort.setImageSize(vp.getImageSize()); |
|
132 |
viewPort.setExtent(vp.getExtent()); |
|
133 |
|
|
134 |
//Calculo del viewPort del primer bloque |
|
135 |
|
|
136 |
wcAlto = viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY(); |
|
137 |
wcIntervalo = (sizeBlock*wcAlto)/viewPort.getImageHeight(); |
|
138 |
dimension = new Dimension(viewPort.getImageWidth(), sizeBlock); |
|
139 |
|
|
140 |
nBlocks = (int)(vp.getImageHeight()/sizeBlock); |
|
141 |
|
|
142 |
incrProgressBar = percentMax/((double)nBlocks); |
|
143 |
//System.out.println("===>NBLOCKS="+nBlocks+" INCR="+incrProgressBar); |
|
144 |
|
|
145 |
//Tama?o de ?ltimo bloque en pixeles |
|
146 |
lastBlock = vp.getImageHeight()-(nBlocks*sizeBlock); |
|
147 |
|
|
148 |
//System.out.println("1--->SizeBlock="+sizeBlock+" ImageHeight="+viewPort.getImageHeight()+" ImageWidth="+viewPort.getImageWidth()); |
|
149 |
//System.out.println("2--->wcAlto="+wcAlto+" wcIntervalo="+wcIntervalo); |
|
150 |
//System.out.println("3--->nBlocks="+nBlocks+" lastBlock="+lastBlock); |
|
151 |
//System.out.println("4--->minX="+viewPort.getExtent().getMinX()+" minY="+viewPort.getExtent().getMinY()+" maxX="+viewPort.getExtent().getMaxX()+" maxY="+viewPort.getExtent().getMaxY()+" width="+viewPort.getExtent().getWidth()+" height="+viewPort.getExtent().getHeight()); |
|
152 |
|
|
153 |
calcViewPort(viewPort); |
|
154 |
|
|
155 |
this.flayers = flyrs; |
|
156 |
this.sizeBlock = sizeBlock; |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
/* (non-Javadoc) |
|
161 |
* @see org.cresques.io.IDataWriter#readData(int, int, int) |
|
162 |
*/ |
|
163 |
public int[] readData(int sX, int sY, int nBand){ |
|
164 |
if(nBand == 0){ //Con nBand==0 se devuelven las 3 bandas |
|
165 |
image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_RGB); |
|
166 |
g = (Graphics2D) image.getGraphics(); |
|
167 |
BufferedImage img = new BufferedImage( viewPortBlock.getImageWidth(), |
|
168 |
viewPortBlock.getImageHeight(), |
|
169 |
BufferedImage.TYPE_INT_ARGB); |
|
170 |
g.setColor(backgroundColor); |
|
171 |
g.fillRect(0, 0, viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight()); |
|
172 |
try{ |
|
173 |
//Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n |
|
174 |
//de realce si la imagen es de 16 bits. |
|
175 |
if(firstRead){ |
|
176 |
for(int i=0;i<flayers.getLayersCount();i++){ |
|
177 |
if(flayers.getLayer(i) instanceof FLyrRaster){ |
|
178 |
FLyrRaster raster = (FLyrRaster)flayers.getLayer(i); |
|
179 |
if( raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || |
|
180 |
raster.getSource().getDataType() == RasterBuf.TYPE_USHORT){ |
|
181 |
RasterStats stats = raster.getSource().getFilterStack().getStats(); |
|
182 |
stats.history.add(stats.new History(raster.getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
firstRead = false; |
|
187 |
} |
|
188 |
|
|
189 |
flayers.draw(image, g, viewPortBlock,new Cancellable() { |
|
190 |
public boolean isCanceled() { |
|
191 |
return false; |
|
192 |
} |
|
193 |
},flayers.getFMap().getScaleView()); |
|
194 |
|
|
195 |
//Si es el ?ltimo bloque vaciamos el historial de m?ximos y m?nimos |
|
196 |
if((contBlocks+1)==nBlocks){ |
|
197 |
for(int i=0;i<flayers.getLayersCount();i++){ |
|
198 |
if(flayers.getLayer(i) instanceof FLyrRaster){ |
|
199 |
FLyrRaster raster = (FLyrRaster)flayers.getLayer(i); |
|
200 |
if( raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || |
|
201 |
raster.getSource().getDataType() == RasterBuf.TYPE_USHORT){ |
|
202 |
raster.getSource().getFilterStack().getStats().history.clear(); |
|
203 |
RasterStats stats = raster.getSource().getFilterStack().getStats(); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
|
|
210 |
}catch (DriverException e) { |
|
211 |
e.printStackTrace(); |
|
212 |
} |
|
213 |
rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
|
214 |
|
|
215 |
//Calculamos el viewPort del sgte bloque |
|
216 |
|
|
217 |
if(((contBlocks+1)*sizeBlock)<=viewPort.getImageHeight()){ |
|
218 |
dimension = new Dimension(sX, sY); |
|
219 |
} |
|
220 |
else{ //Calculo de la altura del ?ltimo bloque |
|
221 |
dimension = new Dimension(sX, (int)(viewPort.getImageHeight()-(contBlocks*sizeBlock))); |
|
222 |
wcIntervalo = (lastBlock*wcAlto)/viewPort.getImageHeight(); |
|
223 |
} |
|
224 |
|
|
225 |
calcViewPort(viewPortBlock); |
|
226 |
|
|
227 |
if(progressBar != null){ |
|
228 |
this.incrTemp = (incrTemp - ((int)incrTemp)) + progressBar.getValue() + incrProgressBar; |
|
229 |
if(((int)incrTemp) != progressBar.getValue()) |
|
230 |
progressBar.setValue((int)incrTemp); |
|
231 |
//System.out.println("===>progressBar.getValue()="+incrProgressBar+" "+incrTemp+" "+Math.floor(incrTemp)+" "+progressBar.getValue()); |
|
232 |
} |
|
233 |
|
|
234 |
contBlocks++; |
|
235 |
return rasterData; |
|
236 |
} |
|
237 |
|
|
238 |
return null; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Asigna la barra de progreso |
|
243 |
* @param bar Barra de progreso |
|
244 |
*/ |
|
245 |
public void setProgressBar(JProgressBar bar, double percentMax){ |
|
246 |
this.progressBar = bar; |
|
247 |
if(percentMax != 0){ |
|
248 |
this.percentMax = percentMax; |
|
249 |
incrProgressBar = percentMax/((double)nBlocks); |
|
250 |
} |
|
251 |
//progressBar.setValue((int)Math.round(incrProgressBar)); |
|
252 |
} |
|
253 |
} |
|
0 | 254 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/SaveRasterModule.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.rasterTools.saveRaster; |
|
42 |
|
|
43 |
import com.iver.andami.PluginServices; |
|
44 |
import com.iver.andami.plugins.Extension; |
|
45 |
import com.iver.cit.gvsig.fmap.FMap; |
|
46 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
47 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
48 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
49 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
|
50 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
|
51 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
|
52 |
import com.iver.cit.gvsig.gui.View; |
|
53 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
|
54 |
import com.iver.cit.gvsig.project.ProjectView; |
|
55 |
import com.iver.cit.gvsig.rasterTools.saveRaster.gui.toolListeners.SaveRasterListener; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* |
|
60 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
61 |
*/ |
|
62 |
public class SaveRasterModule implements Extension { |
|
63 |
/* (non-Javadoc) |
|
64 |
* @see com.iver.andami.plugins.Extension#inicializar() |
|
65 |
*/ |
|
66 |
public void inicializar() { |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Carga el listener de salvar a raster en el MapControl. |
|
71 |
*/ |
|
72 |
private void loadListener(MapControl m_MapControl){ |
|
73 |
//Si no se ha cargado el listener a?n lo cargamos. |
|
74 |
if(m_MapControl.getNamesMapTools().get("saveRaster") == null){ |
|
75 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado |
|
76 |
StatusBarListener sbl = new StatusBarListener(m_MapControl); |
|
77 |
|
|
78 |
//Salvar a Raster |
|
79 |
SaveRasterListener srl = new SaveRasterListener(m_MapControl); |
|
80 |
m_MapControl.addMapTool("saveRaster", new Behavior[]{ |
|
81 |
new RectangleBehavior(srl), new MouseMovementBehavior(sbl)}); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
/** |
|
87 |
* Cargamos el listener y ejecutamos la herramienta de salvar a Raster. |
|
88 |
*/ |
|
89 |
public void execute(String actionCommand) { |
|
90 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
|
91 |
MapControl m_MapControl = theView.getMapControl(); |
|
92 |
loadListener(m_MapControl); |
|
93 |
m_MapControl.setTool("saveRaster"); |
|
94 |
} |
|
95 |
|
|
96 |
/* (non-Javadoc) |
|
97 |
* @see com.iver.andami.plugins.Extension#isEnabled() |
|
98 |
*/ |
|
99 |
public boolean isEnabled() { |
|
100 |
return true; |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* Mostramos el control si hay alguna capa cargada. |
|
105 |
*/ |
|
106 |
public boolean isVisible() { |
|
107 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
|
108 |
.getActiveView(); |
|
109 |
if (f == null) |
|
110 |
return false; |
|
111 |
|
|
112 |
if (f.getClass() == View.class) { |
|
113 |
View vista = (View) f; |
|
114 |
ProjectView model = vista.getModel(); |
|
115 |
FMap mapa = model.getMapContext(); |
|
116 |
if (mapa.getLayers().getLayersCount() > 0) |
|
117 |
return true; |
|
118 |
} |
|
119 |
|
|
120 |
return false; |
|
121 |
} |
|
122 |
} |
|
0 | 123 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/gui/SaveRasterDialog.java | ||
---|---|---|
1 |
/* |
|
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 com.iver.cit.gvsig.rasterTools.saveRaster.gui; |
|
48 |
|
|
49 |
import java.awt.Container; |
|
50 |
import java.awt.Dimension; |
|
51 |
import java.awt.event.ActionEvent; |
|
52 |
import java.awt.geom.Rectangle2D; |
|
53 |
|
|
54 |
import org.cresques.cts.IProjection; |
|
55 |
import org.cresques.io.EcwWriter; |
|
56 |
import org.cresques.io.GdalWriter; |
|
57 |
import org.cresques.io.GeoRasterWriter; |
|
58 |
import org.cresques.ui.raster.DataInputSaveRaster; |
|
59 |
import org.cresques.ui.raster.SaveRasterDialogPanel; |
|
60 |
import org.cresques.ui.raster.SaveSetupPanel; |
|
61 |
|
|
62 |
import com.iver.andami.PluginServices; |
|
63 |
import com.iver.andami.ui.mdiManager.View; |
|
64 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
65 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
66 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
67 |
|
|
68 |
/** |
|
69 |
* Dialogo para abrir fichero. |
|
70 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
71 |
*/ |
|
72 |
//public class SaveRasterDialog extends JDialog{ |
|
73 |
public class SaveRasterDialog extends SaveRasterDialogPanel implements View { |
|
74 |
|
|
75 |
//private SaveRasterDialogPanel contentPane = null; |
|
76 |
private GeoRasterWriter writer=null; |
|
77 |
private GeoRasterWriter writerProps=null; |
|
78 |
private IProjection currentProjection = null; |
|
79 |
private SaveRasterPropsDialog frameSaveRasterProps = null; |
|
80 |
private int compresion = 1; |
|
81 |
private int sizeBlock = 64; |
|
82 |
public DriverProperties driverProps = null; |
|
83 |
private FLayers layers = null; |
|
84 |
private MapControl mapCtrl = null; |
|
85 |
|
|
86 |
class DriverProperties{ |
|
87 |
|
|
88 |
private String[][] driversProps = null; |
|
89 |
private String[] driversExtension = null; |
|
90 |
|
|
91 |
DriverProperties(){ |
|
92 |
|
|
93 |
driversProps = new String[GeoRasterWriter.getNDrivers()][]; |
|
94 |
for(int i=0;i<GeoRasterWriter.getNDrivers();i++) |
|
95 |
driversProps[i] = null; |
|
96 |
driversExtension = GeoRasterWriter.getDriversExtensions(); |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Asigna un vector de propiedades de driver de escritura. |
|
102 |
* @param ext extensi?n del driver. |
|
103 |
* @param props propiedades. |
|
104 |
*/ |
|
105 |
public void setProperties(String ext, String[] props){ |
|
106 |
for(int i=0;i<driversExtension.length;i++){ |
|
107 |
if(ext.equals(driversExtension[i])){ |
|
108 |
driversProps[i] = props; |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Obtiene un vector de propiedades de driver de escritura. |
|
115 |
* @param ext extensi?n del driver. |
|
116 |
* @return propiedades. |
|
117 |
*/ |
|
118 |
public String[] getProperties(String ext){ |
|
119 |
for(int i=0;i<driversExtension.length;i++){ |
|
120 |
if(ext.equals(driversExtension[i])){ |
|
121 |
return driversProps[i]; |
|
122 |
} |
|
123 |
} |
|
124 |
return null; |
|
125 |
} |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Constructor de la ventana de dialogo. |
|
131 |
* |
|
132 |
*/ |
|
133 |
public SaveRasterDialog(FLayers layers, MapControl mapCtrl) { |
|
134 |
super(); |
|
135 |
//super.setModal(true); |
|
136 |
driverProps = new DriverProperties(); |
|
137 |
this.layers = layers; |
|
138 |
this.mapCtrl = mapCtrl; |
|
139 |
init(); |
|
140 |
this.setTranslation(); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Asigna los textos a los paneles |
|
145 |
*/ |
|
146 |
public void setTranslation(){ |
|
147 |
DataInputSaveRaster dInput = ((SaveSetupPanel)super.getContentPanel()).getSaveParameters(); |
|
148 |
dInput.lSupIzq.setText(PluginServices.getText(this,"lsup_izq")+":"); |
|
149 |
dInput.lInfDer.setText(PluginServices.getText(this,"linf_der")+":"); |
|
150 |
dInput.lFile.setText(PluginServices.getText(this,"Fichero")+":"); |
|
151 |
dInput.lResolucion.setText(PluginServices.getText(this,"resolucion")); |
|
152 |
dInput.lEscala.setText(PluginServices.getText(this,"escala")+" 1:"); |
|
153 |
dInput.lPpp.setText(PluginServices.getText(this,"lppp")); |
|
154 |
dInput.bSeleccion.setText(PluginServices.getText(this,"Seleccionar")); |
|
155 |
dInput.lAncho.setText(PluginServices.getText(this,"ancho")+"."); |
|
156 |
dInput.lAlto.setText(PluginServices.getText(this,"alto")+"."); |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Inicializa el jDialog |
|
162 |
* |
|
163 |
* @return javax.swing.JDialog |
|
164 |
*/ |
|
165 |
private void init() { |
|
166 |
setBounds(0, 0, 386, 268); |
|
167 |
setName("saveRaster"); |
|
168 |
|
|
169 |
this.getAcceptButton().setEnabled(false); |
|
170 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
|
171 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
172 |
acceptButtonActionPerformed(evt); |
|
173 |
closeJDialog(); |
|
174 |
} |
|
175 |
}); |
|
176 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
|
177 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
178 |
closeJDialog(); |
|
179 |
} |
|
180 |
}); |
|
181 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
|
182 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
183 |
acceptButtonActionPerformed(evt); |
|
184 |
} |
|
185 |
}); |
|
186 |
|
|
187 |
//Captura de eventos para el bot?n de propiedades |
|
188 |
|
|
189 |
((SaveSetupPanel)this.getContentPanel()).getSaveParameters().getBPropiedades().addActionListener(new java.awt.event.ActionListener() { |
|
190 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
191 |
propsButtonActionPerformed(evt); |
|
192 |
} |
|
193 |
}); |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
|
|
198 |
/** |
|
199 |
* This method initializes jContentPane |
|
200 |
* |
|
201 |
* @return javax.swing.JPanel |
|
202 |
*/ |
|
203 |
public Container getContentPane() { |
|
204 |
return this; |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* |
|
209 |
* @param prj |
|
210 |
*/ |
|
211 |
|
|
212 |
public void setProjection(IProjection prj) { |
|
213 |
this.currentProjection = prj; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Asigna el FLayers |
|
218 |
* @param layers |
|
219 |
*/ |
|
220 |
public void setLayerList(FLayers layers){ |
|
221 |
this.layers = layers; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
public void closeJDialog() { |
|
226 |
this.hide(); |
|
227 |
for(int i=0;i<layers.getLayersCount();i++){ |
|
228 |
layers.getLayer(i).getFMap().invalidate(); |
|
229 |
} |
|
230 |
PluginServices.getMDIManager().closeView(SaveRasterDialog.this); |
|
231 |
//dlg.dispose(); |
|
232 |
} |
|
233 |
|
|
234 |
private void propsButtonActionPerformed(ActionEvent e){ |
|
235 |
DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters(); |
|
236 |
if(dialog.getBPropiedades().getText().endsWith("Ecw")){ |
|
237 |
writerProps = new EcwWriter(); |
|
238 |
if(driverProps.getProperties("ecw")!=null){ |
|
239 |
writerProps.setProps(driverProps.getProperties("ecw")); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
if( dialog.getBPropiedades().getText().endsWith("GeoTiff") || |
|
244 |
dialog.getBPropiedades().getText().endsWith("Jpeg")){ |
|
245 |
writerProps = new GdalWriter("GTiff"); |
|
246 |
if(driverProps.getProperties("tif")!=null){ |
|
247 |
writerProps.setProps(driverProps.getProperties("tif")); |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
if(dialog.getBPropiedades().getText().endsWith("Jp2")){ |
|
252 |
writerProps = new EcwWriter(); |
|
253 |
if(driverProps.getProperties("jp2")!=null){ |
|
254 |
writerProps.setProps(driverProps.getProperties("jp2")); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
frameSaveRasterProps = new SaveRasterPropsDialog(writerProps); |
|
259 |
frameSaveRasterProps.setParentDialog(this); |
|
260 |
frameSaveRasterProps.show(); |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* |
|
265 |
* @param e |
|
266 |
*/ |
|
267 |
private void acceptButtonActionPerformed(ActionEvent e) { |
|
268 |
DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters(); |
|
269 |
|
|
270 |
String fName = ((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getFileName(); |
|
271 |
Dimension dimension = new Dimension(Integer.parseInt(dialog.getTancho().getText()), |
|
272 |
Integer.parseInt(dialog.getTalto().getText())); |
|
273 |
|
|
274 |
double lrX = Double.parseDouble(dialog.getTinf_derX().getText()); |
|
275 |
double lrY = Double.parseDouble(dialog.getTinf_derY().getText()); |
|
276 |
double ulX = Double.parseDouble(dialog.getTsup_izqX().getText()); |
|
277 |
double ulY = Double.parseDouble(dialog.getTsup_izqY().getText()); |
|
278 |
double width = 0; |
|
279 |
if(ulX>lrX)width = (double)(ulX-lrX); |
|
280 |
else width = (double)(lrX-ulX); |
|
281 |
double height = 0; |
|
282 |
if(ulY>lrY)height = (double)(ulY-lrY); |
|
283 |
else height = (double)(lrY-ulY); |
|
284 |
Rectangle2D ext = null; |
|
285 |
|
|
286 |
if(ulY<lrY) |
|
287 |
ext = new Rectangle2D.Double(ulX, ulY, width, height); |
|
288 |
else |
|
289 |
ext = new Rectangle2D.Double(ulX, lrY, width, height); |
|
290 |
|
|
291 |
ProgressSaveRasterDialog progressBar = new ProgressSaveRasterDialog(mapCtrl, |
|
292 |
this.layers, |
|
293 |
this.currentProjection, |
|
294 |
dimension, |
|
295 |
ext); |
|
296 |
|
|
297 |
progressBar.setProps(driverProps); |
|
298 |
progressBar.setWriter(writer); |
|
299 |
progressBar.setFName(fName); |
|
300 |
progressBar.setBlockSize(sizeBlock); |
|
301 |
progressBar.setCompresion(compresion); |
|
302 |
progressBar.showWindow(); |
|
303 |
|
|
304 |
/*ViewPort vp = new ViewPort(this.currentProjection); |
|
305 |
vp.setBackColor(mapCtrl.getViewPort().getBackColor()); |
|
306 |
vp.setImageSize(dimension); |
|
307 |
vp.setExtent(ext); |
|
308 |
|
|
309 |
if (fName.endsWith(".ecw")) { |
|
310 |
//System.out.println("Salvando vista a fichero "+fName+" a formato Ecw"); |
|
311 |
try{ |
|
312 |
|
|
313 |
RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl); |
|
314 |
Extent ex = new Extent(vp.getAdjustedExtent()); |
|
315 |
Dimension imgSz = vp.getImageSize(); |
|
316 |
ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz ); |
|
317 |
writer = new EcwWriter( ((IDataWriter)p), |
|
318 |
vpData, |
|
319 |
fName, |
|
320 |
sizeBlock, |
|
321 |
3, |
|
322 |
compresion); |
|
323 |
//Si han sido modificadas las propiedades se asignan los valores modificados |
|
324 |
String[] prp = driverProps.getProperties("ecw"); |
|
325 |
if(prp!=null) |
|
326 |
writer.setProps(prp); |
|
327 |
((EcwWriter)writer).dataWrite(); |
|
328 |
((EcwWriter)writer).writeClose(); |
|
329 |
|
|
330 |
|
|
331 |
}catch(IOException ev){ |
|
332 |
ev.printStackTrace(); |
|
333 |
}catch(es.gva.cit.jecwcompress.EcwException r){ |
|
334 |
r.printStackTrace(); |
|
335 |
} |
|
336 |
|
|
337 |
}else if (fName.endsWith(".tif")) { |
|
338 |
//System.out.println("Salvando fichero "+fName+" a formato Tif"); |
|
339 |
try{ |
|
340 |
|
|
341 |
RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl); |
|
342 |
Extent ex = new Extent(vp.getAdjustedExtent()); |
|
343 |
writer = new GdalWriter( ((IDataWriter)p), |
|
344 |
dimension.width, |
|
345 |
dimension.height, |
|
346 |
fName, |
|
347 |
ex.maxX(), |
|
348 |
ex.minX(), |
|
349 |
ex.maxY(), |
|
350 |
ex.minY(), |
|
351 |
3, |
|
352 |
sizeBlock, |
|
353 |
"GTiff"); |
|
354 |
//Si han sido modificadas las propiedades se asignan los valores modificados |
|
355 |
String[] prp = driverProps.getProperties("tif"); |
|
356 |
if(prp!=null) |
|
357 |
writer.setProps(prp); |
|
358 |
((GdalWriter)writer).dataWrite(); |
|
359 |
((GdalWriter)writer).writeClose(); |
|
360 |
}catch(IOException ev){ |
|
361 |
ev.printStackTrace(); |
|
362 |
}catch(es.gva.cit.jgdal.GdalException r){ |
|
363 |
r.printStackTrace(); |
|
364 |
} |
|
365 |
|
|
366 |
} else { |
|
367 |
System.err.println("Extensi?n del fichero " + fName + " no soportada."); |
|
368 |
}*/ |
|
369 |
|
|
370 |
for(int i=0;i<layers.getLayersCount();i++){ |
|
371 |
layers.getLayer(i).getFMap().invalidate(); |
|
372 |
} |
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo() |
|
377 |
*/ |
|
378 |
public ViewInfo getViewInfo() { |
|
379 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG); |
|
380 |
m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
|
381 |
return m_viewinfo; |
|
382 |
} |
|
383 |
|
|
384 |
} |
|
0 | 385 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/gui/SaveRasterPropsDialog.java | ||
---|---|---|
1 |
/* |
|
2 |
* Creado el 7-marzo-2005 |
|
3 |
*/ |
|
4 |
package com.iver.cit.gvsig.rasterTools.saveRaster.gui; |
|
5 |
|
|
6 |
import java.awt.Container; |
|
7 |
import java.awt.event.ActionEvent; |
|
8 |
|
|
9 |
import javax.swing.JDialog; |
|
10 |
|
|
11 |
import org.cresques.cts.IProjection; |
|
12 |
import org.cresques.io.CXMLParser; |
|
13 |
import org.cresques.io.GeoRasterWriter; |
|
14 |
import org.cresques.px.PxLayerList; |
|
15 |
import org.cresques.ui.raster.SavePropsSetupPanel; |
|
16 |
import org.cresques.ui.raster.SaveRasterPropsDialogPanel; |
|
17 |
|
|
18 |
|
|
19 |
/** |
|
20 |
* Dialogo para abrir fichero. |
|
21 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
22 |
*/ |
|
23 |
public class SaveRasterPropsDialog extends JDialog { |
|
24 |
|
|
25 |
private SaveRasterPropsDialogPanel contentPane = null; |
|
26 |
private GeoRasterWriter writer=null; |
|
27 |
private String formato = null; |
|
28 |
private IProjection currentProjection = null; |
|
29 |
private PxLayerList layerList = null; |
|
30 |
private int widthWindow=386; |
|
31 |
private int heightWindow=300; |
|
32 |
private String[] properties = null; |
|
33 |
private SaveRasterDialog parentDialog = null; |
|
34 |
|
|
35 |
/** |
|
36 |
* Constructor |
|
37 |
* @param writer |
|
38 |
*/ |
|
39 |
public SaveRasterPropsDialog(GeoRasterWriter writer) { |
|
40 |
super(); |
|
41 |
super.setModal(true); |
|
42 |
this.writer = writer; |
|
43 |
this.formato = writer.getIdent(); |
|
44 |
//Obtenemos el tama?o de la ventana del XML generado por el driver |
|
45 |
String xml = writer.getXMLPropertiesDialog(); |
|
46 |
if(xml!=null){ |
|
47 |
CXMLParser parser = new CXMLParser(xml); |
|
48 |
widthWindow = Integer.parseInt(parser.getAttr("window","sizex")); |
|
49 |
heightWindow = Integer.parseInt(parser.getAttr("window","sizey")); |
|
50 |
} |
|
51 |
initialize(); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Inicializaci?n del dialogo |
|
56 |
* |
|
57 |
* @return javax.swing.JDialog |
|
58 |
*/ |
|
59 |
private void initialize() { |
|
60 |
setBounds(0, 0, widthWindow, heightWindow); //Size Ventana |
|
61 |
setResizable(false); |
|
62 |
setName("saveRasterProps"); |
|
63 |
setTitle("Propiedades de "+formato); |
|
64 |
setContentPane(getContentPane()); |
|
65 |
//contentPane.getAcceptButton().setEnabled(false); |
|
66 |
contentPane.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
|
67 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
68 |
acceptButtonActionPerformed(evt); |
|
69 |
closeJDialog(); |
|
70 |
} |
|
71 |
}); |
|
72 |
contentPane.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
|
73 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
74 |
closeJDialog(); |
|
75 |
} |
|
76 |
}); |
|
77 |
contentPane.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
|
78 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
79 |
acceptButtonActionPerformed(evt); |
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Asigna el dialogo padre a una variable. |
|
86 |
* @param parentDialog Cuadro de dialogo padre. |
|
87 |
*/ |
|
88 |
public void setParentDialog(SaveRasterDialog parentDialog){ |
|
89 |
this.parentDialog = parentDialog; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Inicializa contenPane |
|
94 |
* @return Container |
|
95 |
*/ |
|
96 |
public Container getContentPane() { |
|
97 |
if (contentPane == null) { |
|
98 |
contentPane = new SaveRasterPropsDialogPanel(writer); |
|
99 |
//contentPane.addAncestorListener(this); |
|
100 |
} |
|
101 |
return contentPane; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Asigna la proyecci?n |
|
106 |
* @param prj Proyecci?n |
|
107 |
*/ |
|
108 |
|
|
109 |
public void setProjection(IProjection prj) { |
|
110 |
this.currentProjection = prj; |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* |
|
115 |
* @param layerList |
|
116 |
*/ |
|
117 |
|
|
118 |
public void setLayerList(PxLayerList layerList){ |
|
119 |
this.layerList = layerList; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
public void closeJDialog() { |
|
124 |
this.hide(); |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
/** |
|
129 |
* Cuando se acepta se obtienen las propiedades seleccionadas |
|
130 |
* @param e |
|
131 |
*/ |
|
132 |
private void acceptButtonActionPerformed(ActionEvent e) { |
|
133 |
if(((SavePropsSetupPanel)((SaveRasterPropsDialogPanel)this.getContentPane()).getContentPanel()).getProperties()!=null){ |
|
134 |
properties = ((SavePropsSetupPanel)((SaveRasterPropsDialogPanel)this.getContentPane()).getContentPanel()).getProperties(); |
|
135 |
parentDialog.driverProps.setProperties(writer.getDriverName(), properties); |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
0 | 139 |
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/gui/ProgressSaveRasterDialog.java | ||
---|---|---|
1 |
/* |
|
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 com.iver.cit.gvsig.rasterTools.saveRaster.gui; |
|
48 |
|
|
49 |
import java.awt.Dimension; |
|
50 |
import java.awt.geom.Rectangle2D; |
|
51 |
import java.io.File; |
|
52 |
import java.io.IOException; |
|
53 |
|
|
54 |
import org.cresques.cts.IProjection; |
|
55 |
import org.cresques.geo.ViewPortData; |
|
56 |
import org.cresques.io.EcwWriter; |
|
57 |
import org.cresques.io.GdalWriter; |
|
58 |
import org.cresques.io.GeoRasterWriter; |
|
59 |
import org.cresques.io.IDataWriter; |
|
60 |
import org.cresques.px.Extent; |
|
61 |
import org.cresques.ui.raster.ProgressSaveRasterPanel; |
|
62 |
|
|
63 |
import com.iver.andami.PluginServices; |
|
64 |
import com.iver.andami.ui.mdiManager.View; |
|
65 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
66 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
67 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
68 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
69 |
import com.iver.cit.gvsig.fmap.rasterTools.RasterizerLayer; |
|
70 |
import com.iver.cit.gvsig.rasterTools.saveRaster.gui.SaveRasterDialog.DriverProperties; |
|
71 |
|
|
72 |
import es.gva.cit.jgdal.Gdal; |
|
73 |
import es.gva.cit.jgdal.GdalDriver; |
|
74 |
import es.gva.cit.jgdal.GdalException; |
|
75 |
|
|
76 |
/** |
|
77 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
78 |
*/ |
|
79 |
public class ProgressSaveRasterDialog extends ProgressSaveRasterPanel implements View{ |
|
80 |
|
|
81 |
private FLayers layers = null; |
|
82 |
private IProjection currentProjection = null; |
|
83 |
private MapControl mapCtrl = null; |
|
84 |
private ViewPort vp = null; |
|
85 |
private DriverProperties driverProps = null; |
|
86 |
private GeoRasterWriter writer = null; |
|
87 |
private String fName = null; |
|
88 |
private int sizeBlock = 64; |
|
89 |
private int compresion = 1; |
|
90 |
private Dimension dimension = null; |
|
91 |
private Save threadSave = null; |
|
92 |
private double[] maxPercentBarList = new double[1]; |
|
93 |
|
|
94 |
/** |
|
95 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
96 |
*/ |
|
97 |
class Save extends Thread{ |
|
98 |
|
|
99 |
private ProgressSaveRasterDialog window = null; |
|
100 |
|
|
101 |
Save(ProgressSaveRasterDialog window){ |
|
102 |
this.window = window; |
|
103 |
} |
|
104 |
|
|
105 |
public void run(){ |
|
106 |
if (fName.endsWith(".ecw") || fName.endsWith(".jp2")) { |
|
107 |
//System.out.println("Salvando vista a fichero "+fName+" a formato Ecw"); |
|
108 |
try{ |
|
109 |
|
|
110 |
RasterizerLayer p = new RasterizerLayer(layers, vp, sizeBlock, mapCtrl); |
|
111 |
p.setProgressBar(window.getJProgressBar(), maxPercentBarList[0]); |
|
112 |
Extent ex = new Extent(vp.getAdjustedExtent()); |
|
113 |
Dimension imgSz = vp.getImageSize(); |
|
114 |
ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz ); |
|
115 |
writer = new EcwWriter( ((IDataWriter)p), |
|
116 |
vpData, |
|
117 |
fName, |
|
118 |
sizeBlock, |
|
119 |
3, |
|
120 |
compresion); |
|
121 |
//Si han sido modificadas las propiedades se asignan los valores modificados |
|
122 |
String[] prp = driverProps.getProperties("ecw"); |
|
123 |
if(prp!=null) |
|
124 |
writer.setProps(prp); |
|
125 |
((EcwWriter)writer).dataWrite(); |
|
126 |
((EcwWriter)writer).writeClose(); |
|
127 |
|
|
128 |
|
|
129 |
}catch(IOException ev){ |
|
130 |
ev.printStackTrace(); |
|
131 |
}catch(es.gva.cit.jecwcompress.EcwException r){ |
|
132 |
r.printStackTrace(); |
|
133 |
} |
|
134 |
|
|
135 |
}else if ( fName.endsWith(".tif") || fName.endsWith(".jpg") || fName.endsWith(".jpeg")) { |
|
136 |
//System.out.println("Salvando fichero "+fName+" a formato Tif"); |
|
137 |
try{ |
|
138 |
String drvName = null; |
|
139 |
String fJpegName = null; |
|
140 |
String drvJpegName = null; |
|
141 |
|
|
142 |
String end = fName.substring(fName.lastIndexOf("."), fName.length()); |
|
143 |
if(end.equals(".tif")) |
|
144 |
drvName = "GTiff"; |
|
145 |
|
|
146 |
if(end.equals(".jpg") || end.equals(".jpeg")){ |
|
147 |
drvName = "GTiff"; |
|
148 |
drvJpegName = "JPEG"; |
|
149 |
fJpegName = fName; |
|
150 |
fName = fName.substring(0, fName.lastIndexOf("."))+".tif"; |
|
151 |
maxPercentBarList = new double[2]; |
|
152 |
maxPercentBarList[0] = 75D; |
|
153 |
maxPercentBarList[1] = 25D; |
|
154 |
} |
|
155 |
|
|
156 |
RasterizerLayer p = new RasterizerLayer(layers, vp, sizeBlock, mapCtrl); |
|
157 |
p.setProgressBar(window.getJProgressBar(),maxPercentBarList[0]); |
|
158 |
Extent ex = new Extent(vp.getAdjustedExtent()); |
|
159 |
|
|
160 |
writer = new GdalWriter( ((IDataWriter)p), |
|
161 |
dimension.width, |
|
162 |
dimension.height, |
|
163 |
fName, |
|
164 |
ex.maxX(), |
|
165 |
ex.minX(), |
|
166 |
ex.maxY(), |
|
167 |
ex.minY(), |
|
168 |
3, |
|
169 |
sizeBlock, |
|
170 |
drvName); |
|
171 |
//Si han sido modificadas las propiedades se asignan los valores modificados |
|
172 |
String[] prp = driverProps.getProperties("tif"); |
|
173 |
|
|
174 |
if(prp!=null) |
|
175 |
writer.setProps(prp); |
|
176 |
|
|
177 |
|
|
178 |
((GdalWriter)writer).dataWrite(); |
|
179 |
((GdalWriter)writer).writeClose(); |
|
180 |
|
|
181 |
//Barra de progreso de comprimir a Jpeg |
|
182 |
if(end.equals(".jpg") || end.equals(".jpeg")){ |
|
183 |
|
|
184 |
CopyDataset copyDataset = new CopyDataset( fName, |
|
185 |
fName.substring(0, fName.lastIndexOf("."))+".jpg", |
|
186 |
vp, |
|
187 |
prp, |
|
188 |
"JPEG", |
|
189 |
"jpg", |
|
190 |
window); |
|
191 |
copyDataset.setMaxPercentBar(maxPercentBarList[1]); |
|
192 |
//copyDataset.setPriority(Thread.MAX_PRIORITY); |
|
193 |
copyDataset.start(); |
|
194 |
copyDataset.copy(); |
|
195 |
new File(fName).delete(); |
|
196 |
} |
|
197 |
|
|
198 |
}catch(IOException ev){ |
|
199 |
ev.printStackTrace(); |
|
200 |
}catch(es.gva.cit.jgdal.GdalException r){ |
|
201 |
r.printStackTrace(); |
|
202 |
} |
|
203 |
|
|
204 |
} else { |
|
205 |
System.err.println("Extensi?n del fichero " + fName + " no soportada."); |
|
206 |
} |
|
207 |
PluginServices.getMDIManager().closeView(this.window); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
|
|
212 |
/** |
|
213 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
214 |
* |
|
215 |
* Esta clase copia un dataset desde disco en un formato soportado por Gdal |
|
216 |
* a otro especificado. |
|
217 |
*/ |
|
218 |
class CopyDataset extends Thread{ |
|
219 |
|
|
220 |
private GdalDriver driver = null; |
|
221 |
private String fDstName = null; |
|
222 |
private String fSrcName = null; |
|
223 |
private ViewPort vp = null; |
|
224 |
private String[] driverProps = null; |
|
225 |
private String extension = null; |
|
226 |
private double maxPercentBar = 0D; |
|
227 |
private boolean runCopy = false; |
|
228 |
private ProgressSaveRasterDialog window = null; |
|
229 |
|
|
230 |
/** |
|
231 |
* Constructor |
|
232 |
* @param src Nombre del fichero fuente |
|
233 |
* @param dst Nombre del fichero destino |
|
234 |
* @param viewPort Viewport |
|
235 |
* @param dp DriverProperties |
|
236 |
* @param drvName Nombre del driver de Gdal |
|
237 |
* @param extens Extensi?n del fichero |
|
238 |
*/ |
|
239 |
CopyDataset(String src, |
|
240 |
String dst, |
|
241 |
ViewPort viewPort, |
|
242 |
String[] dp, |
|
243 |
String drvName, |
|
244 |
String extens, |
|
245 |
ProgressSaveRasterDialog window){ |
|
246 |
fSrcName = src; |
|
247 |
fDstName = dst; |
|
248 |
vp = viewPort; |
|
249 |
this.window = window; |
|
250 |
this.driverProps = dp; |
|
251 |
this.extension = extens; |
|
252 |
try{ |
|
253 |
driver = Gdal.getDriverByName(drvName); |
|
254 |
}catch(GdalException exc){ |
|
255 |
System.err.println("No se ha podido obtener el driver."); |
|
256 |
} |
|
257 |
runCopy = true; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Funci?n que realiza la copia del dataset |
|
262 |
*/ |
|
263 |
public void copy(){ |
|
264 |
try{ |
|
265 |
GdalWriter.createCopy( driver, |
|
266 |
fDstName, |
|
267 |
fSrcName, |
|
268 |
false, |
|
269 |
driverProps, |
|
270 |
vp.getProjection()); |
|
271 |
}catch(IOException ev){ |
|
272 |
ev.printStackTrace(); |
|
273 |
}catch(GdalException ev){ |
|
274 |
ev.printStackTrace(); |
|
275 |
} |
|
276 |
runCopy = false; |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* El thread maneja el incremento de la barra |
|
281 |
*/ |
|
282 |
public void run(){ |
|
283 |
File f = new File(fSrcName); |
|
284 |
long sizeSrc = f.length(); |
|
285 |
long sizeDst = 0; |
|
286 |
if(extension.equals("jpg")) |
|
287 |
sizeDst = (long)(sizeSrc * 0.085); |
|
288 |
double incrProgressBar = 0; |
|
289 |
int last = 0; |
|
290 |
|
|
291 |
String osname = System.getProperty("os.name").toLowerCase(); |
|
292 |
if(osname.indexOf("windows")>=0){ |
|
293 |
//Temporalmente hacemos esto en windows |
|
294 |
long l1 = System.currentTimeMillis(); |
|
295 |
long l2 = 0; |
|
296 |
while(runCopy){ |
|
297 |
if((l2 - l1) > 1000){ |
|
298 |
l1 = System.currentTimeMillis(); |
|
299 |
window.getJProgressBar().setValue(window.getJProgressBar().getValue() + 1); |
|
300 |
} |
|
301 |
l2 = System.currentTimeMillis(); |
|
302 |
try{ |
|
303 |
Thread.sleep(10); |
|
304 |
}catch(InterruptedException exc){} |
|
305 |
} |
|
306 |
}else{ |
|
307 |
while(runCopy){ |
|
308 |
File fdst = new File(fDstName); |
|
309 |
incrProgressBar = (fdst.length() * maxPercentBar) / sizeDst; |
|
310 |
if(fdst.exists() && incrProgressBar < maxPercentBar){ |
|
311 |
if(last != ((int)incrProgressBar)){ |
Also available in: Unified diff