root / tags / Root_v061 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / PropertiesRasterDialog.java @ 4812
History | View | Annotate | Download (29.5 KB)
1 | 2183 | fernando | /*
|
---|---|---|---|
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.gui.Panels; |
||
48 | |||
49 | import java.awt.Container; |
||
50 | import java.awt.event.ActionEvent; |
||
51 | import java.awt.geom.Rectangle2D; |
||
52 | import java.io.File; |
||
53 | import java.util.ArrayList; |
||
54 | import java.util.Vector; |
||
55 | |||
56 | import javax.swing.JFileChooser; |
||
57 | import javax.swing.JOptionPane; |
||
58 | import javax.swing.JPanel; |
||
59 | import javax.swing.filechooser.FileFilter; |
||
60 | |||
61 | import org.cresques.cts.IProjection; |
||
62 | import org.cresques.io.GeoRasterFile; |
||
63 | 3791 | nacho | import org.cresques.io.raster.RasterFilter; |
64 | 2183 | fernando | import org.cresques.io.raster.RasterFilterStackManager; |
65 | import org.cresques.px.Extent; |
||
66 | import org.cresques.ui.raster.BandSetupPanel; |
||
67 | import org.cresques.ui.raster.EnhancedPanel; |
||
68 | import org.cresques.ui.raster.FilterRasterDialogPanel; |
||
69 | import org.cresques.ui.raster.RasterTransparencyPanel; |
||
70 | |||
71 | import com.hardcode.driverManager.Driver; |
||
72 | import com.hardcode.driverManager.DriverLoadException; |
||
73 | import com.iver.andami.PluginServices; |
||
74 | import com.iver.andami.messages.NotificationManager; |
||
75 | import com.iver.andami.ui.mdiManager.View; |
||
76 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
77 | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
||
78 | import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
||
79 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
80 | import com.iver.cit.gvsig.fmap.layers.StatusLayerRaster; |
||
81 | |||
82 | /**
|
||
83 | * <P>
|
||
84 | * Dialogo para las propiedades de un raster. Esta maneja los eventos y aplica
|
||
85 | * filtros sobre el raster a trav?s de l gestor de la pila de filtros seg?n la
|
||
86 | * selecci?n del usuario. Este dialogo contiene varios paneles:
|
||
87 | * </P>
|
||
88 | * <UL>
|
||
89 | * <LI>Propiedades</LI>
|
||
90 | * <LI>Selecci?n de bandas</LI>
|
||
91 | * <LI>Transparencia</LI>
|
||
92 | * <LI>Realce</LI>
|
||
93 | * </UL>
|
||
94 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
95 | */
|
||
96 | public class PropertiesRasterDialog extends FilterRasterDialogPanel implements View { |
||
97 | |||
98 | private JPanel propPanel = null; |
||
99 | private IProjection currentProjection = null; |
||
100 | private FLyrRaster fLayer = null; |
||
101 | private static final int nprops = 11; |
||
102 | private Object[][] props = null; |
||
103 | private RasterFilterStackManager stackManager = null; |
||
104 | private Status status = null; |
||
105 | private String filename = null; |
||
106 | private long filesize = 0; |
||
107 | private int width = 0; |
||
108 | private int height = 0; |
||
109 | private JFileChooser fileChooser = null; |
||
110 | private String lastPath = new String("./"); |
||
111 | private StatusLayerRaster rasterStatus = null; |
||
112 | private int sizeX = 486, sizeY = 318; |
||
113 | |||
114 | /**
|
||
115 | * Clase que guarda el estado del dialogo y gestiona la restauraci?n
|
||
116 | * del estado inicial en caso de cancelar.
|
||
117 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
118 | */
|
||
119 | class Status{ |
||
120 | public String inicAlpha; |
||
121 | public int bandR; |
||
122 | public int bandG; |
||
123 | public int bandB; |
||
124 | private ArrayList filesAdd = new ArrayList(); |
||
125 | private ArrayList filesRem = new ArrayList(); |
||
126 | private ArrayList filters = null; |
||
127 | |||
128 | |||
129 | public Status(String alpha, int bandR, int bandG, int bandB){ |
||
130 | this.inicAlpha = alpha;
|
||
131 | this.bandR = bandR;
|
||
132 | this.bandG = bandG;
|
||
133 | this.bandB = bandB;
|
||
134 | filters = stackManager.getStringsFromStack(); |
||
135 | } |
||
136 | |||
137 | /**
|
||
138 | * A?ade un fichero a la lista de a?adidos. Si estaba en la de eliminados
|
||
139 | * lo quitamos.
|
||
140 | * @param file Fichero a?adido
|
||
141 | */
|
||
142 | public void addFile(String file){ |
||
143 | filesAdd.add(file); |
||
144 | for(int j=0;j<filesRem.size();j++){ |
||
145 | if(file.equals((String)filesRem.get(j))) |
||
146 | filesRem.remove(j); |
||
147 | } |
||
148 | |||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * Elimina un fichero de la lista de a?adidos si ha sido a?adido. Si ya estaba
|
||
153 | * antes no estar? en la lista de a?adidos por lo que habr? que ponerlo en la
|
||
154 | * lista de eliminados.
|
||
155 | * @param file Fichero eliminado
|
||
156 | */
|
||
157 | public void removeFile(String file){ |
||
158 | boolean isAdd = false; |
||
159 | for(int i=0;i<filesAdd.size();i++){ |
||
160 | if(((String)filesAdd.get(i)).equals(file)){ |
||
161 | filesAdd.remove(i); |
||
162 | isAdd = true;
|
||
163 | } |
||
164 | } |
||
165 | if(!isAdd)
|
||
166 | filesRem.add(file); |
||
167 | |||
168 | } |
||
169 | |||
170 | /**
|
||
171 | * Restaura el Estado salvado
|
||
172 | * @param status Estado
|
||
173 | */
|
||
174 | public void restoreStatus(PropertiesRasterDialog props){ |
||
175 | //Devolvemos el alpha al estado inicial
|
||
176 | int opac = Integer.parseInt(status.inicAlpha); |
||
177 | opac = (int)((opac*255)/100); |
||
178 | fLayer.getSource().setTransparency(true);
|
||
179 | fLayer.setTransparency(255-opac);
|
||
180 | rasterStatus.transparency = 255-opac;
|
||
181 | |||
182 | //Devolvemos el estado inicial de las bandas
|
||
183 | |||
184 | if (fLayer != null) { |
||
185 | fLayer.getSource().setBand(GeoRasterFile.RED_BAND, status.bandR); |
||
186 | fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, status.bandG); |
||
187 | fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, status.bandB); |
||
188 | rasterStatus.bandR = status.bandR; |
||
189 | rasterStatus.bandG = status.bandG; |
||
190 | rasterStatus.bandB = status.bandB; |
||
191 | } |
||
192 | 4162 | nacho | |
193 | 2183 | fernando | //Los que han sido a?adidos los quitamos
|
194 | for(int i=0;i<filesAdd.size();i++) |
||
195 | fLayer.delFile((String)this.filesAdd.get(i)); |
||
196 | |||
197 | //Los que fueron quitados los a?adimos
|
||
198 | for(int i=0;i<filesRem.size();i++) |
||
199 | fLayer.addFiles((String)this.filesRem.get(i)); |
||
200 | |||
201 | //Restauramos los filtros
|
||
202 | if(filters!=null) |
||
203 | 4162 | nacho | stackManager.createStackFromStrings(filters, ((FLyrRaster)fLayer).getSource().getFiles()); |
204 | 2183 | fernando | |
205 | fLayer.getFMap().invalidate(); |
||
206 | } |
||
207 | |||
208 | public void show(){ |
||
209 | System.out.println("***Lista A?adidos***"); |
||
210 | for(int i=0;i<filesAdd.size();i++){ |
||
211 | System.out.println(filesAdd.get(i).toString());
|
||
212 | } |
||
213 | System.out.println("***Lista Eliminados***"); |
||
214 | for(int i=0;i<filesRem.size();i++){ |
||
215 | System.out.println(filesRem.get(i).toString());
|
||
216 | } |
||
217 | System.out.println("*********************"); |
||
218 | } |
||
219 | |||
220 | } |
||
221 | |||
222 | public class DriverFileFilter extends FileFilter{ |
||
223 | |||
224 | private Driver driver; |
||
225 | |||
226 | public DriverFileFilter(String driverName) throws DriverLoadException{ |
||
227 | driver = LayerFactory.getDM().getDriver(driverName); |
||
228 | } |
||
229 | |||
230 | /**
|
||
231 | * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||
232 | */
|
||
233 | public boolean accept(File f) { |
||
234 | if (f.isDirectory()) return true; |
||
235 | if (driver instanceof RasterDriver){ |
||
236 | return ((RasterDriver) driver).fileAccepted(f);
|
||
237 | }else{
|
||
238 | throw new RuntimeException("Tipo no reconocido"); |
||
239 | } |
||
240 | } |
||
241 | |||
242 | /**
|
||
243 | * @see javax.swing.filechooser.FileFilter#getDescription()
|
||
244 | */
|
||
245 | public String getDescription() { |
||
246 | return ((Driver) driver).getName(); |
||
247 | } |
||
248 | } |
||
249 | |||
250 | /**
|
||
251 | * Constructor de la ventana de dialogo.
|
||
252 | * @param app
|
||
253 | */
|
||
254 | public PropertiesRasterDialog(FLyrRaster layer, int[][] rangeR, int[][] rangeG, int[][] rangeB){ |
||
255 | super();
|
||
256 | fLayer = layer; |
||
257 | if(fLayer.getStatus()==null){ |
||
258 | rasterStatus = new StatusLayerRaster();
|
||
259 | fLayer.setStatus(rasterStatus); |
||
260 | }else
|
||
261 | rasterStatus = (StatusLayerRaster)fLayer.getStatus(); |
||
262 | initialize(); |
||
263 | this.setRanges(rangeR, rangeG, rangeB);
|
||
264 | setTranslation(); |
||
265 | } |
||
266 | |||
267 | /**
|
||
268 | * Asigna los textos a los paneles
|
||
269 | */
|
||
270 | private void setTranslation(){ |
||
271 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonAdd().setText(PluginServices.getText(this,"Anadir")); |
272 | this.getBandSetup().getFileList().getJButtonRemove().setText(PluginServices.getText(this,"Eliminar")); |
||
273 | this.getBandSetup().getFileList().lbandasVisibles.setText(PluginServices.getText(this,"bandas")); |
||
274 | 2183 | fernando | |
275 | RasterTransparencyPanel tpan = this.getTransparencyPanel();
|
||
276 | 2252 | igbrotru | |
277 | 2706 | nacho | tpan.lGreenValue.setText(PluginServices.getText(this,"Valor_verde")+":"); |
278 | tpan.lRedValue.setText(PluginServices.getText(this,"Valor_rojo")+":"); |
||
279 | tpan.lBlueValue.setText(PluginServices.getText(this,"Valor_azul")+":"); |
||
280 | 2183 | fernando | tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
281 | tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
||
282 | 2706 | nacho | tpan.lRange.setText(PluginServices.getText(this,"usar_rango")+": 1,3,5:8"); |
283 | tpan.lPixelValue.setText(PluginServices.getText(this,"valor_pixel")+": 0 a 255"); |
||
284 | 2183 | fernando | |
285 | EnhancedPanel ep = this.getEnhancedPanel();
|
||
286 | 2706 | nacho | ep.lLineal.setText(PluginServices.getText(this,"lineal_directo")); |
287 | ep.lQueue.setText(PluginServices.getText(this,"recorte_colas")); |
||
288 | ep.lWithoutEnhanced.setText(PluginServices.getText(this,"sin_realce")); |
||
289 | ep.lCut.setText("% "+PluginServices.getText(this,"recorte")); |
||
290 | ep.lRemove.setText(PluginServices.getText(this,"eliminar_extremos")); |
||
291 | 2183 | fernando | |
292 | //Recorremos los Tab y traducimos el nombre
|
||
293 | for(int i=0;i<this.getTab().getTabCount();i++){ |
||
294 | if(this.getTab().getTitleAt(i).equals("Info")) |
||
295 | 2532 | nacho | this.getTab().setTitleAt(i,PluginServices.getText(this,"info")); |
296 | 2183 | fernando | if(this.getTab().getTitleAt(i).equals("Transparencia")) |
297 | this.getTab().setTitleAt(i,PluginServices.getText(this,"Transparencia")); |
||
298 | if(this.getTab().getTitleAt(i).equals("Bandas")) |
||
299 | 2532 | nacho | this.getTab().setTitleAt(i,PluginServices.getText(this,"bandas")); |
300 | 2183 | fernando | if(this.getTab().getTitleAt(i).equals("Realce")) |
301 | this.getTab().setTitleAt(i,PluginServices.getText(this,"realce")); |
||
302 | } |
||
303 | 2532 | nacho | |
304 | this.getAcceptButton().setText(PluginServices.getText(this,"Aceptar")); |
||
305 | this.getApplyButton().setText(PluginServices.getText(this,"Aplicar")); |
||
306 | this.getCancelButton().setText(PluginServices.getText(this,"Cancelar")); |
||
307 | 3791 | nacho | |
308 | this.getSharpeningPanel().getCbActiveSharpening().setText(PluginServices.getText(this,"onSharpening")); |
||
309 | this.getSharpeningPanel().getPSharpNorth().setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"selectBandaRefinado"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
310 | 2183 | fernando | } |
311 | |||
312 | /**
|
||
313 | * Asigna un FLayerRaster
|
||
314 | * @param layer capa a asignar
|
||
315 | */
|
||
316 | public void setFLyrRaster(FLyrRaster layer){ |
||
317 | fLayer = layer; |
||
318 | } |
||
319 | |||
320 | /**
|
||
321 | * Constructor de la ventana de dialogo.
|
||
322 | */
|
||
323 | public PropertiesRasterDialog() {
|
||
324 | initialize(); |
||
325 | } |
||
326 | |||
327 | |||
328 | |||
329 | /**
|
||
330 | * Carga los datos del panel info.
|
||
331 | */
|
||
332 | private void loadInfoData(){ |
||
333 | if(fLayer.getSource()!=null){ |
||
334 | props = new Object[nprops][2]; |
||
335 | 2233 | igbrotru | props[0][0] = new String(PluginServices.getText(this,"Fichero")+":"); |
336 | 2183 | fernando | props[0][1] = filename; |
337 | 2233 | igbrotru | props[1][0] = new String(PluginServices.getText(this,"num_bandas")+":"); |
338 | 2183 | fernando | props[1][1] = new String(String.valueOf(fLayer.getSource().getNumBands())); |
339 | 2233 | igbrotru | props[2][0] = new String(PluginServices.getText(this,"ancho_alto")+":"); |
340 | 2183 | fernando | props[2][1] = this.width+" X "+this.height; |
341 | 2233 | igbrotru | props[3][0] = new String(PluginServices.getText(this,"formato")+":"); |
342 | 2183 | fernando | props[3][1] = filename.substring( |
343 | filename.lastIndexOf('.')+1, |
||
344 | filename.length()); |
||
345 | 2233 | igbrotru | props[4][0] = new String(PluginServices.getText(this,"tipo_dato")+":"); |
346 | 2183 | fernando | String type = null; |
347 | switch(fLayer.getSource().getDataType()){
|
||
348 | case 0: type = new String("BYTE");break; |
||
349 | case 1: type = new String("USHORT");break; |
||
350 | case 2: type = new String("SHORT");break; |
||
351 | case 3: type = new String("INT");break; |
||
352 | case 4: type = new String("FLOAT");break; |
||
353 | case 5: type = new String("DOUBLE");break; |
||
354 | default: type = new String("UNDEFINED");break; |
||
355 | } |
||
356 | props[4][1] = type; |
||
357 | props[5][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
||
358 | 2233 | igbrotru | props[6][0] = new String(PluginServices.getText(this,"xmin")+":"); |
359 | 2183 | fernando | props[6][1] = String.valueOf(fLayer.getSource().getFullExtent().getMinX()); |
360 | 2233 | igbrotru | props[7][0] = new String(PluginServices.getText(this,"ymin")+":"); |
361 | 2183 | fernando | props[7][1] = String.valueOf(fLayer.getSource().getFullExtent().getMinY()); |
362 | 2233 | igbrotru | props[8][0] = new String(PluginServices.getText(this,"xmax")+":"); |
363 | 2183 | fernando | props[8][1] = String.valueOf(fLayer.getSource().getFullExtent().getMaxX()); |
364 | 2233 | igbrotru | props[9][0] = new String(PluginServices.getText(this,"ymax")+":"); |
365 | 2183 | fernando | props[9][1] = String.valueOf(fLayer.getSource().getFullExtent().getMaxY()); |
366 | |||
367 | }else{
|
||
368 | props = new Object[1][2]; |
||
369 | props[0][0] = new String("No props"); |
||
370 | props[0][1] = new String("-"); |
||
371 | } |
||
372 | |||
373 | } |
||
374 | |||
375 | 2233 | igbrotru | /**
|
376 | * A?ade bandas al contador de bandas del FilterRasterDialogPanel
|
||
377 | * @param numBands N?mero de bandas a a?adir
|
||
378 | */
|
||
379 | 2183 | fernando | public void addNumBands(int numBands){ |
380 | nbands += numBands; |
||
381 | 2233 | igbrotru | if(this.getTransparencyPanel() != null && this.getTransparencyPanel().getTRojo().isEnabled()) |
382 | this.getTransparencyPanel().setActiveTransparencyControl(true); |
||
383 | 2183 | fernando | } |
384 | |||
385 | /**
|
||
386 | * Inicializa el jDialog
|
||
387 | */
|
||
388 | private void initialize() { |
||
389 | |||
390 | //this.setLayout(new FlowLayout());
|
||
391 | |||
392 | setName("filterRaster");
|
||
393 | ArrayList attr = ((FLyrRaster)fLayer).getSource().getAttributes();
|
||
394 | for (int i=0; i<attr.size(); i++) { |
||
395 | Object[] a = (Object []) attr.get(i); |
||
396 | if(a[0].toString().equals("Filename")) |
||
397 | filename = a[1].toString();
|
||
398 | if(a[0].toString().equals("Filesize")) |
||
399 | filesize = ((Long)a[1]).intValue(); |
||
400 | if(a[0].toString().equals("Width")) |
||
401 | width = ((Integer)a[1]).intValue(); |
||
402 | if(a[0].toString().equals("Height")) |
||
403 | height = ((Integer)a[1]).intValue(); |
||
404 | } |
||
405 | |||
406 | this.loadInfoData();
|
||
407 | super.init(props);
|
||
408 | 2233 | igbrotru | |
409 | this.getInfoPanel().columnNames[0] = PluginServices.getText(this,"propiedad"); |
||
410 | this.getInfoPanel().columnNames[1] = PluginServices.getText(this,"Valor"); |
||
411 | this.getInfoPanel().resetTable();
|
||
412 | this.getInfoPanel().initialize();
|
||
413 | |||
414 | 2183 | fernando | //this.add(getContentPane());
|
415 | |||
416 | this.setSize(this.sizeX, this.sizeY); |
||
417 | |||
418 | //contentPane.getAcceptButton().setEnabled(false);
|
||
419 | this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
||
420 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
421 | acceptButtonActionPerformed(evt); |
||
422 | //Solo cuando le damos a aceptar guardamos la situaci?n actual de los
|
||
423 | //ficheros cargados en el StatusLayerRaster
|
||
424 | if(rasterStatus!=null){ |
||
425 | ArrayList rs = new ArrayList(); |
||
426 | for(int i=0;i<fLayer.getSource().getFiles().length;i++) |
||
427 | rs.add(fLayer.getSource().getFiles()[i].getName()); |
||
428 | rasterStatus.files = rs; |
||
429 | } |
||
430 | closeJDialog(); |
||
431 | } |
||
432 | }); |
||
433 | this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
||
434 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
435 | cancelButtonActionPerformed(evt); |
||
436 | closeJDialog(); |
||
437 | } |
||
438 | }); |
||
439 | this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
||
440 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
441 | acceptButtonActionPerformed(evt); |
||
442 | } |
||
443 | }); |
||
444 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonAdd().addActionListener(new java.awt.event.ActionListener() { |
445 | 2183 | fernando | public void actionPerformed(java.awt.event.ActionEvent evt){ |
446 | addFileBand(evt); |
||
447 | |||
448 | } |
||
449 | }); |
||
450 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonRemove().addActionListener(new java.awt.event.ActionListener() { |
451 | 2183 | fernando | public void actionPerformed(java.awt.event.ActionEvent evt){ |
452 | delFileBand(evt); |
||
453 | } |
||
454 | }); |
||
455 | |||
456 | |||
457 | } |
||
458 | |||
459 | /**
|
||
460 | * Salva el estado inicial por si se cancela
|
||
461 | */
|
||
462 | public void readStat(){ |
||
463 | status = new Status(((FilterRasterDialogPanel)this).getTransparencyPanel().getOpacityText().getText(), |
||
464 | getAssignedBand(GeoRasterFile.RED_BAND), |
||
465 | getAssignedBand(GeoRasterFile.GREEN_BAND), |
||
466 | getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
467 | } |
||
468 | |||
469 | /**
|
||
470 | * This method initializes jContentPane
|
||
471 | */
|
||
472 | public Container getContentPane() { |
||
473 | return this; |
||
474 | } |
||
475 | |||
476 | /**
|
||
477 | * Asigna una proyecci?n
|
||
478 | * @param prj
|
||
479 | */
|
||
480 | public void setProjection(IProjection prj) { |
||
481 | this.currentProjection = prj;
|
||
482 | } |
||
483 | |||
484 | |||
485 | |||
486 | public void closeJDialog() { |
||
487 | PluginServices.getMDIManager().closeView(PropertiesRasterDialog.this); |
||
488 | } |
||
489 | |||
490 | /**
|
||
491 | * Asigna el RasterFilterStackManager
|
||
492 | * @param stackManager
|
||
493 | */
|
||
494 | public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
||
495 | this.stackManager = stackManager;
|
||
496 | stackManager.resetTempFilters(); |
||
497 | } |
||
498 | |||
499 | /**
|
||
500 | *
|
||
501 | * @param flag
|
||
502 | * @return
|
||
503 | */
|
||
504 | public int getAssignedBand(int flag) { |
||
505 | return this.getBandSetup().getAssignedBand(flag); |
||
506 | } |
||
507 | |||
508 | /**
|
||
509 | 2365 | igbrotru | * Obtiene las bandas que el usuario ha seleccionado que son visibles.
|
510 | * Devuelve una cadena: RGB, R, G, B, RG, RB, GB
|
||
511 | * @return Bandas visibles
|
||
512 | */
|
||
513 | public String getVisibleBands(){ |
||
514 | return this.getBandSetup().getFileList().getJComboBox().getSelectedItem().toString(); |
||
515 | } |
||
516 | |||
517 | /**
|
||
518 | 2183 | fernando | * Pulsar aceptar con el panel de bandas seleccionado hace que se procesen los valores
|
519 | * introducidos en este.
|
||
520 | * @return true si estaba seleccionado el panel de bandas y se ha procesado la
|
||
521 | * acci?n y false si no lo estaba.
|
||
522 | */
|
||
523 | 3791 | nacho | public void processBandPanel(){ |
524 | 2654 | nacho | //if(this.getTab().getSelectedComponent() == this.getBandSetup()){
|
525 | fLayer.getSource().setBand(GeoRasterFile.RED_BAND, |
||
526 | getAssignedBand(GeoRasterFile.RED_BAND)); |
||
527 | fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, |
||
528 | getAssignedBand(GeoRasterFile.GREEN_BAND)); |
||
529 | fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, |
||
530 | getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
531 | rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
||
532 | rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
||
533 | rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
||
534 | 2365 | igbrotru | |
535 | 2654 | nacho | //Comprobamos si hay alguna banda que no est? asignada y aplicamos el filtro
|
536 | StringBuffer sb = new StringBuffer(); |
||
537 | if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
||
538 | sb.append("R");
|
||
539 | if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
||
540 | sb.append("G");
|
||
541 | if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
||
542 | sb.append("B");
|
||
543 | 2365 | igbrotru | |
544 | 2654 | nacho | if(!sb.toString().equals("")) |
545 | stackManager.addRemoveBands(sb.toString()); |
||
546 | else
|
||
547 | stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
||
548 | 3791 | nacho | |
549 | //Al reasignar las bandas tenemos que tenerlo en cuenta en el sharpening
|
||
550 | RasterFilter sharp = stackManager.getFilter("sharpening");
|
||
551 | if(sharp != null){ |
||
552 | int[] order = {getAssignedBand(GeoRasterFile.RED_BAND),getAssignedBand(GeoRasterFile.GREEN_BAND),getAssignedBand(GeoRasterFile.BLUE_BAND)}; |
||
553 | sharp.removeParam("order");
|
||
554 | sharp.addParam("order", order);
|
||
555 | } |
||
556 | 2183 | fernando | } |
557 | |||
558 | /**
|
||
559 | * Pulsar aceptar con el panel de transparecias seleccionado hace que se procesen los valores
|
||
560 | * introducidos en este.
|
||
561 | * @return true si estaba seleccionado el panel de transparencias y se ha procesado la
|
||
562 | * acci?n y false si no lo estaba.
|
||
563 | */
|
||
564 | 3791 | nacho | public void processTransparencyPanel(){ |
565 | 2654 | nacho | //OPACIDAD
|
566 | String sOpac = this.getTransparencyPanel().getOpacityText().getText(); |
||
567 | if(!sOpac.equals("") && this.getTransparencyPanel().getOpacityCheck().isSelected()){ |
||
568 | int opac = Integer.parseInt(sOpac); |
||
569 | opac = (int)((opac*255)/100); |
||
570 | fLayer.getSource().setTransparency(true);
|
||
571 | fLayer.setTransparency(255-opac);
|
||
572 | rasterStatus.transparency = 255-opac;
|
||
573 | }else{
|
||
574 | fLayer.getSource().setTransparency(false);
|
||
575 | fLayer.setTransparency(0);
|
||
576 | rasterStatus.transparency = 0;
|
||
577 | 2183 | fernando | } |
578 | |||
579 | 2654 | nacho | //TRANSPARENCIA
|
580 | if( this.getTransparencyPanel().getTransparencyCheck().isSelected()){ |
||
581 | this.checkTransparencyValues();
|
||
582 | stackManager.addTransparencyFilter( this.getRangeRed(),
|
||
583 | this.getRangeGreen(),
|
||
584 | this.getRangeBlue(),
|
||
585 | 0x10, //Transparencia |
||
586 | 0xff, //Color Transparencia R |
||
587 | 0xff, //Color Transparencia G |
||
588 | 0xff); //Color Transparencia B |
||
589 | }else{
|
||
590 | fLayer.getSource().getFilterStack().removeFilter(stackManager.getTypeFilter("transparency"));
|
||
591 | } |
||
592 | 3791 | nacho | |
593 | 2183 | fernando | } |
594 | |||
595 | /**
|
||
596 | * Pulsar aceptar con el panel de realce seleccionado hace que se procesen los valores
|
||
597 | * introducidos en este.
|
||
598 | * @return true si estaba seleccionado el panel de realce y se ha procesado la
|
||
599 | * acci?n y false si no lo estaba.
|
||
600 | */
|
||
601 | 3791 | nacho | public void processEnhancedPanel(){ |
602 | 2654 | nacho | //Filtro lineal seleccionado
|
603 | if( this.getEnhancedPanel().getLinealDirectoRadioButton().isSelected()){ |
||
604 | if( this.getEnhancedPanel().getRemoveCheck().isSelected() && |
||
605 | !this.getEnhancedPanel().getTailCheck().isSelected())
|
||
606 | stackManager.addEnhancedFilter(true, fLayer.getSource().getFiles()[0].getName()); |
||
607 | else
|
||
608 | stackManager.addEnhancedFilter(false, fLayer.getSource().getFiles()[0].getName()); |
||
609 | 2183 | fernando | |
610 | 2654 | nacho | //Recorte de colas seleccionado
|
611 | if(this.getEnhancedPanel().getTailCheck().isSelected()){ |
||
612 | 2183 | fernando | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
613 | 2654 | nacho | double recorte = Double.parseDouble(this.getEnhancedPanel().getTailText().getText())/100; |
614 | if(this.getEnhancedPanel().getRemoveCheck().isSelected()) |
||
615 | stackManager.addTailFilter( recorte, 0D, true); |
||
616 | else
|
||
617 | stackManager.addTailFilter( recorte, 0D, false); |
||
618 | }else{
|
||
619 | 2183 | fernando | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
620 | 2654 | nacho | stackManager.addComputeMinMaxFilter(); |
621 | } |
||
622 | } |
||
623 | 2183 | fernando | |
624 | 2654 | nacho | //Sin filtro lineal seleccionado
|
625 | if(this.getEnhancedPanel().getSinRealceRadioButton().isSelected()){ |
||
626 | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
||
627 | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
||
628 | stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
||
629 | 2183 | fernando | } |
630 | 3791 | nacho | } |
631 | |||
632 | /**
|
||
633 | * Pulsar aceptar hace que se procesen los valores introducidos en el panel de
|
||
634 | * sharpening.
|
||
635 | * @return true
|
||
636 | */
|
||
637 | public void processSharpeningPanel(){ |
||
638 | if(this.getSharpeningPanel().getCbActiveSharpening().isSelected()){ |
||
639 | String pancr = null; |
||
640 | 2654 | nacho | |
641 | 3791 | nacho | //Obtenemos el nombre de la banda seleccionada
|
642 | for(int i=0;i<(getSharpeningPanel().getRGBTable()).getRowCount();i++){ |
||
643 | if(((Boolean) (getSharpeningPanel().getRGBTable()).getValueAt(i, 0)).booleanValue()) |
||
644 | pancr = ((String) (getSharpeningPanel().getRGBTable()).getValueAt(i, 1)); |
||
645 | } |
||
646 | 4066 | nacho | |
647 | 3791 | nacho | //Buscamos el GeoRasterFile que corresponde a la capa y a?adimos el filtro con el
|
648 | if(pancr!=null){ |
||
649 | pancr = pancr.substring(pancr.lastIndexOf("] ") + 2, pancr.length()); |
||
650 | for(int i=0; i<fLayer.getSource().getFiles().length;i++){ |
||
651 | 4066 | nacho | if(fLayer.getSource().getFiles()[i].getName().endsWith(File.separator+pancr)){ |
652 | 3791 | nacho | int[] order = {getAssignedBand(GeoRasterFile.RED_BAND),getAssignedBand(GeoRasterFile.GREEN_BAND),getAssignedBand(GeoRasterFile.BLUE_BAND)}; |
653 | |||
654 | int opac = Integer.parseInt(this.getTransparencyPanel().getOpacityText().getText()); |
||
655 | opac = (int)((opac*255)/100); |
||
656 | |||
657 | String method = "brovey"; |
||
658 | if(getSharpeningPanel().getRbHSL().isSelected())
|
||
659 | method = "hsl";
|
||
660 | |||
661 | double coef = 0D; |
||
662 | if(getSharpeningPanel().getRbHSL().isSelected())
|
||
663 | coef = Double.parseDouble(pSharp.getJTextField().getText());
|
||
664 | |||
665 | int coefBrovey = 0; |
||
666 | if(getSharpeningPanel().getRbBrovey().isSelected())
|
||
667 | coefBrovey = Integer.parseInt(pSharp.getJTextField1().getText());
|
||
668 | 4066 | nacho | |
669 | 3791 | nacho | stackManager.addSharpeningFilter(fLayer.getSource().getFiles(), i, order, opac, method, coef, coefBrovey); |
670 | } |
||
671 | } |
||
672 | |||
673 | } |
||
674 | }else{
|
||
675 | stackManager.removeFilter(stackManager.getTypeFilter("sharpening"));
|
||
676 | } |
||
677 | 2183 | fernando | } |
678 | |||
679 | /**
|
||
680 | * Gestiona la acci?n cuando se pulsa aplicar/aceptar o aplicar en el control
|
||
681 | * de propiedades de raster
|
||
682 | * @param e
|
||
683 | */
|
||
684 | private void acceptButtonActionPerformed(ActionEvent e) { |
||
685 | this.processBandPanel();
|
||
686 | this.processTransparencyPanel();
|
||
687 | 3791 | nacho | this.processEnhancedPanel();
|
688 | this.processSharpeningPanel();
|
||
689 | 4330 | nacho | fLayer.getFMap().invalidate(); |
690 | 2183 | fernando | } |
691 | |||
692 | /**
|
||
693 | * A?ade una banda al raster
|
||
694 | * @param e
|
||
695 | */
|
||
696 | private void addFileBand(ActionEvent e){ |
||
697 | String[] driverNames = null; |
||
698 | String rasterDriver = null; |
||
699 | |||
700 | //Creaci?n del dialogo para selecci?n de ficheros
|
||
701 | |||
702 | fileChooser = new JFileChooser(lastPath); |
||
703 | fileChooser.setMultiSelectionEnabled(true);
|
||
704 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
705 | try {
|
||
706 | driverNames = LayerFactory.getDM().getDriverNames(); |
||
707 | FileFilter defaultFileFilter = null, auxF; |
||
708 | for (int i = 0; i < driverNames.length; i++) { |
||
709 | |||
710 | if (driverNames[i].endsWith("gvSIG Image Driver")){ |
||
711 | rasterDriver = driverNames[i]; |
||
712 | auxF = new DriverFileFilter(driverNames[i]);
|
||
713 | fileChooser.addChoosableFileFilter(auxF); |
||
714 | defaultFileFilter = auxF; |
||
715 | } |
||
716 | } |
||
717 | } catch (DriverLoadException e1) {
|
||
718 | NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
||
719 | } |
||
720 | int result = fileChooser.showOpenDialog(PropertiesRasterDialog.this);
|
||
721 | |||
722 | if(result == JFileChooser.APPROVE_OPTION){ |
||
723 | File[] files = fileChooser.getSelectedFiles(); |
||
724 | FileFilter filter = fileChooser.getFileFilter();
|
||
725 | BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
||
726 | lastPath = files[0].getPath();
|
||
727 | |||
728 | //Lo a?adimos a la capa si no esta
|
||
729 | |||
730 | Vector v = new Vector(); |
||
731 | for(int i=0;i<files.length;i++){ |
||
732 | |||
733 | //Comprobamos que el fichero no est?
|
||
734 | boolean exist = false; |
||
735 | for(int j=0;j<fLayer.getSource().getFiles().length;j++){ |
||
736 | if(fLayer.getSource().getFiles()[j].getName().endsWith(files[i].getName()))
|
||
737 | exist = true;
|
||
738 | } |
||
739 | if(!exist){
|
||
740 | try{
|
||
741 | Rectangle2D extentOrigin = fLayer.getFullExtent();
|
||
742 | |||
743 | GeoRasterFile geoRasterFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()); |
||
744 | Extent extentNewFile = geoRasterFile.getExtent(); |
||
745 | nbands += geoRasterFile.getBandCount(); |
||
746 | |||
747 | //Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
||
748 | //fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
||
749 | |||
750 | double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
||
751 | double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
||
752 | |||
753 | if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
||
754 | (widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
||
755 | (heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
||
756 | (heightNewFile-extentOrigin.getHeight()) < -1.0){
|
||
757 | JOptionPane.showMessageDialog( null, |
||
758 | PluginServices.getText(this, "extents_no_coincidentes"), |
||
759 | "",
|
||
760 | JOptionPane.ERROR_MESSAGE);
|
||
761 | return;
|
||
762 | } |
||
763 | |||
764 | if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
||
765 | (extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
||
766 | JOptionPane.showMessageDialog(null, |
||
767 | PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
||
768 | return;
|
||
769 | } |
||
770 | |||
771 | }catch(Exception exc){ |
||
772 | exc.printStackTrace(); |
||
773 | } |
||
774 | |||
775 | //Lo a?adimos a la capa
|
||
776 | fLayer.addFiles(files[i].getAbsolutePath()); |
||
777 | //Mantiene la lista de ficheros a?adidos por si se cancela
|
||
778 | status.addFile(files[i].getAbsolutePath()); |
||
779 | |||
780 | |||
781 | }else{
|
||
782 | JOptionPane.showMessageDialog(null, |
||
783 | PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
||
784 | } |
||
785 | } |
||
786 | |||
787 | //A?adimos los georasterfile a la tabla del Panel
|
||
788 | |||
789 | v = new Vector(); |
||
790 | for(int i=0;i<fLayer.getSource().getFiles().length;i++){ |
||
791 | boolean exist = false; |
||
792 | for(int j=0;j<bandSetup.getNBands();j++){ |
||
793 | if(fLayer.getSource().getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
||
794 | exist = true;
|
||
795 | } |
||
796 | if(!exist)
|
||
797 | v.add(fLayer.getSource().getFiles()[i]); |
||
798 | } |
||
799 | |||
800 | 3791 | nacho | grf = new GeoRasterFile[v.size()];
|
801 | 2183 | fernando | for(int i=0;i<grf.length;i++){ |
802 | grf[i] = (GeoRasterFile)v.get(i); |
||
803 | } |
||
804 | 3791 | nacho | this.addFiles(grf);
|
805 | 2183 | fernando | } |
806 | } |
||
807 | |||
808 | /**
|
||
809 | 3791 | nacho | * Asigna la lista de GeoRasterFile
|
810 | * @return
|
||
811 | */
|
||
812 | public void setGeoRasterFile(GeoRasterFile[] grf){ |
||
813 | this.grf = grf;
|
||
814 | } |
||
815 | |||
816 | /**
|
||
817 | 2183 | fernando | * Elimina una banda del raster. Si queda solo un fichero o no se ha
|
818 | * seleccionado ninguna banda no hace nada.
|
||
819 | * @param e
|
||
820 | */
|
||
821 | private void delFileBand(ActionEvent e){ |
||
822 | BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
||
823 | |||
824 | if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
||
825 | bandSetup.getFileList().getNFiles() > 1){
|
||
826 | String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
||
827 | GeoRasterFile geoRasterFile = GeoRasterFile.openFile(fLayer.getProjection(), pathName); |
||
828 | nbands -= geoRasterFile.getBandCount(); |
||
829 | fLayer.delFile(pathName); |
||
830 | String file = pathName.substring(pathName.lastIndexOf("/")+1); |
||
831 | file = file.substring(file.lastIndexOf("\\")+1); |
||
832 | 3791 | nacho | this.removeFile(file);
|
833 | 2183 | fernando | |
834 | //Mantiene la lista de ficheros eliminados por si se cancela
|
||
835 | status.removeFile(pathName); |
||
836 | } |
||
837 | } |
||
838 | |||
839 | /**
|
||
840 | * El bot?n de cancelar recupera el estado anterior a la apertura de
|
||
841 | * este dialogo.
|
||
842 | * @param e Evento
|
||
843 | */
|
||
844 | private void cancelButtonActionPerformed(ActionEvent e) { |
||
845 | this.status.restoreStatus(this); |
||
846 | fLayer.getFMap().invalidate(); |
||
847 | } |
||
848 | |||
849 | |||
850 | /**
|
||
851 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
852 | */
|
||
853 | public ViewInfo getViewInfo() {
|
||
854 | ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
855 | m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
||
856 | return m_viewinfo;
|
||
857 | } |
||
858 | |||
859 | |||
860 | } |