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