svn-gvsig-desktop / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / PropertiesRasterDialog.java @ 2170
History | View | Annotate | Download (25.5 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 int nbands = 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 la pila de filtros al estado inicial
|
176 |
//if(stackManager != null)
|
177 |
// stackManager.deleteTempFilters();
|
178 |
|
179 |
//Devolvemos el alpha al estado inicial
|
180 |
int opac = Integer.parseInt(status.inicAlpha); |
181 |
opac = (int)((opac*255)/100); |
182 |
fLayer.getSource().setTransparency(true);
|
183 |
fLayer.setTransparency(255-opac);
|
184 |
rasterStatus.transparency = 255-opac;
|
185 |
|
186 |
//Devolvemos el estado inicial de las bandas
|
187 |
|
188 |
if (fLayer != null) { |
189 |
fLayer.getSource().setBand(GeoRasterFile.RED_BAND, status.bandR); |
190 |
fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, status.bandG); |
191 |
fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, status.bandB); |
192 |
rasterStatus.bandR = status.bandR; |
193 |
rasterStatus.bandG = status.bandG; |
194 |
rasterStatus.bandB = status.bandB; |
195 |
} |
196 |
|
197 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)props.getContentPane()).getBandSetup(); |
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) |
209 |
stackManager.createStackFromStrings(filters); |
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 |
* Constructor de la ventana de dialogo.
|
259 |
* @param app
|
260 |
*/
|
261 |
public PropertiesRasterDialog(FLyrRaster layer, int[][] rangeR, int[][] rangeG, int[][] rangeB){ |
262 |
super();
|
263 |
fLayer = layer; |
264 |
if(fLayer.getStatus()==null){ |
265 |
rasterStatus = new StatusLayerRaster();
|
266 |
fLayer.setStatus(rasterStatus); |
267 |
}else
|
268 |
rasterStatus = (StatusLayerRaster)fLayer.getStatus(); |
269 |
initialize(); |
270 |
this.setRanges(rangeR, rangeG, rangeB);
|
271 |
setTranslation(); |
272 |
} |
273 |
|
274 |
/**
|
275 |
* Asigna los textos a los paneles
|
276 |
*/
|
277 |
private void setTranslation(){ |
278 |
this.getBandSetup().getFileList().getJButton2().setText(PluginServices.getText(this,"Anadir")); |
279 |
this.getBandSetup().getFileList().getJButton3().setText(PluginServices.getText(this,"Eliminar")); |
280 |
|
281 |
RasterTransparencyPanel tpan = this.getTransparencyPanel();
|
282 |
if(tpan.nBands==1) |
283 |
tpan.jLabel1.setText(PluginServices.getText(this,"Valor_banda")); |
284 |
else
|
285 |
tpan.jLabel1.setText(PluginServices.getText(this,"Valor_verde")); |
286 |
tpan.jLabel.setText(PluginServices.getText(this,"Valor_rojo")); |
287 |
tpan.jLabel2.setText(PluginServices.getText(this,"Valor_azul")); |
288 |
tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
289 |
tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
290 |
tpan.jLabel3.setText(PluginServices.getText(this,"usar_rango")); |
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 |
/**
|
376 |
* Inicializa el jDialog
|
377 |
*/
|
378 |
private void initialize() { |
379 |
|
380 |
//this.setLayout(new FlowLayout());
|
381 |
|
382 |
setName("filterRaster");
|
383 |
ArrayList attr = ((FLyrRaster)fLayer).getSource().getAttributes();
|
384 |
for (int i=0; i<attr.size(); i++) { |
385 |
Object[] a = (Object []) attr.get(i); |
386 |
if(a[0].toString().equals("Filename")) |
387 |
filename = a[1].toString();
|
388 |
if(a[0].toString().equals("Filesize")) |
389 |
filesize = ((Long)a[1]).intValue(); |
390 |
if(a[0].toString().equals("Width")) |
391 |
width = ((Integer)a[1]).intValue(); |
392 |
if(a[0].toString().equals("Height")) |
393 |
height = ((Integer)a[1]).intValue(); |
394 |
if(a[0].toString().equals("Bands")) |
395 |
nbands = ((Integer)a[1]).intValue(); |
396 |
|
397 |
} |
398 |
|
399 |
this.loadInfoData();
|
400 |
super.init(props);
|
401 |
//this.add(getContentPane());
|
402 |
|
403 |
this.setSize(this.sizeX, this.sizeY); |
404 |
|
405 |
//contentPane.getAcceptButton().setEnabled(false);
|
406 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
407 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
408 |
acceptButtonActionPerformed(evt); |
409 |
//Solo cuando le damos a aceptar guardamos la situaci?n actual de los
|
410 |
//ficheros cargados en el StatusLayerRaster
|
411 |
if(rasterStatus!=null){ |
412 |
ArrayList rs = new ArrayList(); |
413 |
for(int i=0;i<fLayer.getSource().getFiles().length;i++) |
414 |
rs.add(fLayer.getSource().getFiles()[i].getName()); |
415 |
rasterStatus.files = rs; |
416 |
} |
417 |
closeJDialog(); |
418 |
} |
419 |
}); |
420 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
421 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
422 |
cancelButtonActionPerformed(evt); |
423 |
closeJDialog(); |
424 |
} |
425 |
}); |
426 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
427 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
428 |
acceptButtonActionPerformed(evt); |
429 |
} |
430 |
}); |
431 |
this.getBandSetup().getFileList().getJButton2().addActionListener(new java.awt.event.ActionListener() { |
432 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
433 |
addFileBand(evt); |
434 |
|
435 |
} |
436 |
}); |
437 |
this.getBandSetup().getFileList().getJButton3().addActionListener(new java.awt.event.ActionListener() { |
438 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
439 |
delFileBand(evt); |
440 |
} |
441 |
}); |
442 |
|
443 |
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* Salva el estado inicial por si se cancela
|
448 |
*/
|
449 |
public void readStat(){ |
450 |
status = new Status(((FilterRasterDialogPanel)this).getTransparencyPanel().getOpacityText().getText(), |
451 |
getAssignedBand(GeoRasterFile.RED_BAND), |
452 |
getAssignedBand(GeoRasterFile.GREEN_BAND), |
453 |
getAssignedBand(GeoRasterFile.BLUE_BAND)); |
454 |
} |
455 |
|
456 |
/**
|
457 |
* This method initializes jContentPane
|
458 |
*/
|
459 |
public Container getContentPane() { |
460 |
return this; |
461 |
} |
462 |
|
463 |
/**
|
464 |
* Asigna una proyecci?n
|
465 |
* @param prj
|
466 |
*/
|
467 |
public void setProjection(IProjection prj) { |
468 |
this.currentProjection = prj;
|
469 |
} |
470 |
|
471 |
|
472 |
|
473 |
public void closeJDialog() { |
474 |
PluginServices.getMDIManager().closeView(PropertiesRasterDialog.this); |
475 |
} |
476 |
|
477 |
/**
|
478 |
* Asigna el RasterFilterStackManager
|
479 |
* @param stackManager
|
480 |
*/
|
481 |
public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
482 |
this.stackManager = stackManager;
|
483 |
stackManager.resetTempFilters(); |
484 |
} |
485 |
|
486 |
/**
|
487 |
*
|
488 |
* @param flag
|
489 |
* @return
|
490 |
*/
|
491 |
public int getAssignedBand(int flag) { |
492 |
return this.getBandSetup().getAssignedBand(flag); |
493 |
} |
494 |
|
495 |
/**
|
496 |
* Pulsar aceptar con el panel de bandas seleccionado hace que se procesen los valores
|
497 |
* introducidos en este.
|
498 |
* @return true si estaba seleccionado el panel de bandas y se ha procesado la
|
499 |
* acci?n y false si no lo estaba.
|
500 |
*/
|
501 |
public boolean processBandPanel(){ |
502 |
if(this.getTab().getSelectedComponent() == this.getBandSetup()){ |
503 |
fLayer.getSource().setBand(GeoRasterFile.RED_BAND, |
504 |
getAssignedBand(GeoRasterFile.RED_BAND)); |
505 |
fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, |
506 |
getAssignedBand(GeoRasterFile.GREEN_BAND)); |
507 |
fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, |
508 |
getAssignedBand(GeoRasterFile.BLUE_BAND)); |
509 |
|
510 |
rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
511 |
rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
512 |
rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
513 |
fLayer.getFMap().invalidate(); |
514 |
return true; |
515 |
} |
516 |
return false; |
517 |
} |
518 |
|
519 |
/**
|
520 |
* Pulsar aceptar con el panel de transparecias seleccionado hace que se procesen los valores
|
521 |
* introducidos en este.
|
522 |
* @return true si estaba seleccionado el panel de transparencias y se ha procesado la
|
523 |
* acci?n y false si no lo estaba.
|
524 |
*/
|
525 |
public boolean processTransparencyPanel(){ |
526 |
|
527 |
if(this.getTab().getSelectedComponent() == this.getTransparencyPanel()){ |
528 |
|
529 |
//OPACIDAD
|
530 |
String sOpac = this.getTransparencyPanel().getOpacityText().getText(); |
531 |
if(!sOpac.equals("") && this.getTransparencyPanel().getOpacityCheck().isSelected()){ |
532 |
int opac = Integer.parseInt(sOpac); |
533 |
opac = (int)((opac*255)/100); |
534 |
fLayer.getSource().setTransparency(true);
|
535 |
fLayer.setTransparency(255-opac);
|
536 |
rasterStatus.transparency = 255-opac;
|
537 |
}else{
|
538 |
fLayer.getSource().setTransparency(false);
|
539 |
fLayer.setTransparency(0);
|
540 |
rasterStatus.transparency = 0;
|
541 |
} |
542 |
|
543 |
//TRANSPARENCIA
|
544 |
if( this.getTransparencyPanel().getTransparencyCheck().isSelected()){ |
545 |
this.checkTransparencyValues();
|
546 |
stackManager.addTransparencyFilter( this.getRangeRed(),
|
547 |
this.getRangeGreen(),
|
548 |
this.getRangeBlue(),
|
549 |
0x10, //Transparencia |
550 |
0xff, //Color Transparencia R |
551 |
0xff, //Color Transparencia G |
552 |
0xff); //Color Transparencia B |
553 |
}else{
|
554 |
fLayer.getSource().getFilterStack().removeFilter(stackManager.getTypeFilter("transparency"));
|
555 |
} |
556 |
|
557 |
return true; |
558 |
} |
559 |
|
560 |
return false; |
561 |
} |
562 |
|
563 |
/**
|
564 |
* Pulsar aceptar con el panel de realce seleccionado hace que se procesen los valores
|
565 |
* introducidos en este.
|
566 |
* @return true si estaba seleccionado el panel de realce y se ha procesado la
|
567 |
* acci?n y false si no lo estaba.
|
568 |
*/
|
569 |
public boolean processEnhancedPanel(){ |
570 |
if(this.getTab().getSelectedComponent() == this.getEnhancedPanel()){ |
571 |
|
572 |
//Filtro lineal seleccionado
|
573 |
if( this.getEnhancedPanel().getLinealDirectoRadioButton().isSelected()){ |
574 |
if( this.getEnhancedPanel().getRemoveCheck().isSelected() && |
575 |
!this.getEnhancedPanel().getTailCheck().isSelected())
|
576 |
stackManager.addEnhancedFilter(true, fLayer.getSource().getFiles()[0].getName()); |
577 |
else
|
578 |
stackManager.addEnhancedFilter(false, fLayer.getSource().getFiles()[0].getName()); |
579 |
|
580 |
//Recorte de colas seleccionado
|
581 |
if(this.getEnhancedPanel().getTailCheck().isSelected()){ |
582 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
583 |
double recorte = Double.parseDouble(this.getEnhancedPanel().getTailText().getText())/100; |
584 |
if(this.getEnhancedPanel().getRemoveCheck().isSelected()) |
585 |
stackManager.addTailFilter( recorte, 0D, true); |
586 |
else
|
587 |
stackManager.addTailFilter( recorte, 0D, false); |
588 |
}else{
|
589 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
590 |
stackManager.addComputeMinMaxFilter(); |
591 |
} |
592 |
} |
593 |
|
594 |
//Sin filtro lineal seleccionado
|
595 |
if(this.getEnhancedPanel().getSinRealceRadioButton().isSelected()){ |
596 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
597 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
598 |
stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
599 |
} |
600 |
fLayer.getFMap().invalidate(); |
601 |
|
602 |
return true; |
603 |
} |
604 |
return false; |
605 |
} |
606 |
|
607 |
/**
|
608 |
* Gestiona la acci?n cuando se pulsa aplicar/aceptar o aplicar en el control
|
609 |
* de propiedades de raster
|
610 |
* @param e
|
611 |
*/
|
612 |
private void acceptButtonActionPerformed(ActionEvent e) { |
613 |
this.processBandPanel();
|
614 |
this.processTransparencyPanel();
|
615 |
this.processEnhancedPanel();
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* A?ade una banda al raster
|
620 |
* @param e
|
621 |
*/
|
622 |
private void addFileBand(ActionEvent e){ |
623 |
String[] driverNames = null; |
624 |
String rasterDriver = null; |
625 |
|
626 |
//Creaci?n del dialogo para selecci?n de ficheros
|
627 |
|
628 |
fileChooser = new JFileChooser(lastPath); |
629 |
fileChooser.setMultiSelectionEnabled(true);
|
630 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
631 |
try {
|
632 |
driverNames = LayerFactory.getDM().getDriverNames(); |
633 |
FileFilter defaultFileFilter = null, auxF; |
634 |
for (int i = 0; i < driverNames.length; i++) { |
635 |
|
636 |
if (driverNames[i].endsWith("gvSIG Image Driver")){ |
637 |
rasterDriver = driverNames[i]; |
638 |
auxF = new DriverFileFilter(driverNames[i]);
|
639 |
fileChooser.addChoosableFileFilter(auxF); |
640 |
defaultFileFilter = auxF; |
641 |
} |
642 |
} |
643 |
} catch (DriverLoadException e1) {
|
644 |
NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
645 |
} |
646 |
int result = fileChooser.showOpenDialog(PropertiesRasterDialog.this);
|
647 |
|
648 |
if(result == JFileChooser.APPROVE_OPTION){ |
649 |
File[] files = fileChooser.getSelectedFiles(); |
650 |
FileFilter filter = fileChooser.getFileFilter();
|
651 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
652 |
lastPath = files[0].getPath();
|
653 |
|
654 |
//Lo a?adimos a la capa si no esta
|
655 |
|
656 |
Vector v = new Vector(); |
657 |
for(int i=0;i<files.length;i++){ |
658 |
|
659 |
//Comprobamos que el fichero no est?
|
660 |
boolean exist = false; |
661 |
for(int j=0;j<fLayer.getSource().getFiles().length;j++){ |
662 |
if(fLayer.getSource().getFiles()[j].getName().endsWith(files[i].getName()))
|
663 |
exist = true;
|
664 |
} |
665 |
if(!exist){
|
666 |
try{
|
667 |
Rectangle2D extentOrigin = fLayer.getFullExtent();
|
668 |
|
669 |
Extent extentNewFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()).getExtent(); |
670 |
|
671 |
//Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
672 |
//fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
673 |
|
674 |
double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
675 |
double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
676 |
|
677 |
if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
678 |
(widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
679 |
(heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
680 |
(heightNewFile-extentOrigin.getHeight()) < -1.0){
|
681 |
JOptionPane.showMessageDialog( null, |
682 |
PluginServices.getText(this, "extents_no_coincidentes"), |
683 |
"",
|
684 |
JOptionPane.ERROR_MESSAGE);
|
685 |
return;
|
686 |
} |
687 |
|
688 |
if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
689 |
(extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
690 |
JOptionPane.showMessageDialog(null, |
691 |
PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
692 |
return;
|
693 |
} |
694 |
|
695 |
}catch(Exception exc){ |
696 |
exc.printStackTrace(); |
697 |
} |
698 |
|
699 |
//Lo a?adimos a la capa
|
700 |
fLayer.addFiles(files[i].getAbsolutePath()); |
701 |
//Mantiene la lista de ficheros a?adidos por si se cancela
|
702 |
status.addFile(files[i].getAbsolutePath()); |
703 |
}else{
|
704 |
JOptionPane.showMessageDialog(null, |
705 |
PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
706 |
} |
707 |
} |
708 |
|
709 |
//A?adimos los georasterfile a la tabla del Panel
|
710 |
|
711 |
v = new Vector(); |
712 |
for(int i=0;i<fLayer.getSource().getFiles().length;i++){ |
713 |
boolean exist = false; |
714 |
for(int j=0;j<bandSetup.getNBands();j++){ |
715 |
if(fLayer.getSource().getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
716 |
exist = true;
|
717 |
} |
718 |
if(!exist)
|
719 |
v.add(fLayer.getSource().getFiles()[i]); |
720 |
} |
721 |
|
722 |
GeoRasterFile[] grf = new GeoRasterFile[v.size()]; |
723 |
for(int i=0;i<grf.length;i++){ |
724 |
grf[i] = (GeoRasterFile)v.get(i); |
725 |
} |
726 |
bandSetup.addFiles(grf); |
727 |
} |
728 |
} |
729 |
|
730 |
/**
|
731 |
* Elimina una banda del raster. Si queda solo un fichero o no se ha
|
732 |
* seleccionado ninguna banda no hace nada.
|
733 |
* @param e
|
734 |
*/
|
735 |
private void delFileBand(ActionEvent e){ |
736 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
737 |
|
738 |
if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
739 |
bandSetup.getFileList().getNFiles() > 1){
|
740 |
String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
741 |
fLayer.delFile(pathName); |
742 |
String file = pathName.substring(pathName.lastIndexOf("/")+1); |
743 |
file = file.substring(file.lastIndexOf("\\")+1); |
744 |
bandSetup.removeFile(file); |
745 |
|
746 |
//Mantiene la lista de ficheros eliminados por si se cancela
|
747 |
status.removeFile(pathName); |
748 |
} |
749 |
} |
750 |
|
751 |
/**
|
752 |
* El bot?n de cancelar recupera el estado anterior a la apertura de
|
753 |
* este dialogo.
|
754 |
* @param e Evento
|
755 |
*/
|
756 |
private void cancelButtonActionPerformed(ActionEvent e) { |
757 |
this.status.restoreStatus(this); |
758 |
fLayer.getFMap().invalidate(); |
759 |
} |
760 |
|
761 |
|
762 |
/**
|
763 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
764 |
*/
|
765 |
public ViewInfo getViewInfo() {
|
766 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
767 |
m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
768 |
return m_viewinfo;
|
769 |
} |
770 |
|
771 |
|
772 |
} |