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