svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / Panels / PropertiesWCSDialog.java @ 2532
History | View | Annotate | Download (21.5 KB)
1 |
/*
|
---|---|
2 |
* Creado el 7-marzo-2005
|
3 |
*/
|
4 |
package com.iver.cit.gvsig.gui.Panels; |
5 |
|
6 |
import java.awt.Container; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.geom.Rectangle2D; |
9 |
import java.io.File; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Vector; |
12 |
|
13 |
import javax.swing.JFileChooser; |
14 |
import javax.swing.JOptionPane; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.filechooser.FileFilter; |
17 |
|
18 |
import org.cresques.cts.IProjection; |
19 |
import org.cresques.io.GeoRasterFile; |
20 |
import org.cresques.io.raster.RasterFilterStackManager; |
21 |
import org.cresques.px.Extent; |
22 |
import org.cresques.px.PxRaster; |
23 |
import org.cresques.ui.raster.BandSetupPanel; |
24 |
import org.cresques.ui.raster.EnhancedPanel; |
25 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
26 |
import org.cresques.ui.raster.RasterTransparencyPanel; |
27 |
|
28 |
import com.hardcode.driverManager.Driver; |
29 |
import com.hardcode.driverManager.DriverLoadException; |
30 |
import com.iver.andami.PluginServices; |
31 |
import com.iver.andami.messages.NotificationManager; |
32 |
import com.iver.andami.ui.mdiManager.View; |
33 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
34 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
36 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
37 |
|
38 |
/**
|
39 |
* <P>
|
40 |
* Dialog for the properties of a WCS layer. It manages the avants and aplies
|
41 |
* filters to the raster through the filter stack manager according to the user's
|
42 |
* selection. This dialog contains some panels.
|
43 |
* </P>
|
44 |
* <UL>
|
45 |
* <LI>Propierties</LI>
|
46 |
* <LI>Band selection</LI>
|
47 |
* <LI>Transparency</LI>
|
48 |
* <LI>Enhancement</LI>
|
49 |
* </UL>
|
50 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
51 |
*/
|
52 |
public class PropertiesWCSDialog extends FilterRasterDialogPanel implements View { |
53 |
|
54 |
private FilterRasterDialogPanel contentPane = null; |
55 |
private JPanel propPanel = null; |
56 |
private IProjection currentProjection = null; |
57 |
private FLyrWCS fLayer = null; |
58 |
private static final int nprops = 11; |
59 |
private Object[][] props = null; |
60 |
private RasterFilterStackManager stackManager = null; |
61 |
private Status status = null; |
62 |
private JFileChooser fileChooser = null; |
63 |
private String lastPath = new String("./"); |
64 |
private PxRaster px = null; |
65 |
private GeoRasterFile grf = null; |
66 |
|
67 |
/**
|
68 |
* Class that holds the dialog state and restores the initial state if it
|
69 |
* is cancelled.
|
70 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
71 |
*/
|
72 |
class Status{ |
73 |
public String inicAlpha; |
74 |
public int bandR; |
75 |
public int bandG; |
76 |
public int bandB; |
77 |
private ArrayList filters = new ArrayList(); |
78 |
|
79 |
public Status(String alpha, int bandR, int bandG, int bandB){ |
80 |
this.inicAlpha = alpha;
|
81 |
this.bandR = bandR;
|
82 |
this.bandG = bandG;
|
83 |
this.bandB = bandB;
|
84 |
filters = stackManager.getStringsFromStack(); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Restaura el Estado salvado
|
89 |
* @param status Estado
|
90 |
*/
|
91 |
public void restoreStatus(PropertiesWCSDialog props){ |
92 |
//Devolvemos la pila de filtros al estado inicial
|
93 |
/*if(stackManager != null)
|
94 |
stackManager.deleteTempFilters();*/
|
95 |
|
96 |
//Devolvemos el alpha al estado inicial
|
97 |
int opac = Integer.parseInt(status.inicAlpha); |
98 |
opac = (int)((opac*255)/100); |
99 |
fLayer.getWCSAdaptor().setTransparency(255-opac);
|
100 |
|
101 |
if (fLayer != null) { |
102 |
fLayer.getWCSAdaptor().setBandR(bandR); |
103 |
fLayer.getWCSAdaptor().setBandG(bandG); |
104 |
fLayer.getWCSAdaptor().setBandB(bandB); |
105 |
} |
106 |
|
107 |
//Restauramos los filtros
|
108 |
if(filters!=null) |
109 |
stackManager.createStackFromStrings(filters); |
110 |
|
111 |
fLayer.getFMap().invalidate(); |
112 |
|
113 |
} |
114 |
} |
115 |
|
116 |
public class DriverFileFilter extends FileFilter{ |
117 |
|
118 |
private Driver driver; |
119 |
|
120 |
public DriverFileFilter(String driverName) throws DriverLoadException{ |
121 |
driver = LayerFactory.getDM().getDriver(driverName); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
126 |
*/
|
127 |
public boolean accept(File f) { |
128 |
if (f.isDirectory()) return true; |
129 |
if (driver instanceof RasterDriver){ |
130 |
return ((RasterDriver) driver).fileAccepted(f);
|
131 |
}else{
|
132 |
throw new RuntimeException("Tipo no reconocido"); |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
138 |
*/
|
139 |
public String getDescription() { |
140 |
return ((Driver) driver).getName(); |
141 |
} |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Dialog window constructor.
|
146 |
*
|
147 |
* @param app
|
148 |
*/
|
149 |
public PropertiesWCSDialog(FLyrWCS layer, int[][] rangeR, int[][] rangeG, int[][] rangeB){ |
150 |
super();
|
151 |
fLayer = layer; |
152 |
this.px = layer.getWCSAdaptor().getPxRaster();
|
153 |
this.grf = layer.getWCSAdaptor().getGeoRasterFile();
|
154 |
initialize(); |
155 |
this.setRanges(rangeR, rangeG, rangeB);
|
156 |
FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
157 |
fr.getBandSetup().getFileList().getJButton2().setEnabled(false);
|
158 |
fr.getBandSetup().getFileList().getJButton3().setEnabled(false);
|
159 |
this.setTranslation();
|
160 |
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Asigna los textos a los paneles
|
165 |
*/
|
166 |
private void setTranslation(){ |
167 |
this.getBandSetup().getFileList().getJButton2().setText(PluginServices.getText(this,"Anadir")); |
168 |
this.getBandSetup().getFileList().getJButton3().setText(PluginServices.getText(this,"Eliminar")); |
169 |
this.getBandSetup().getFileList().bandasVisibles.setText(PluginServices.getText(this,"bandas")); |
170 |
|
171 |
RasterTransparencyPanel tpan = this.getTransparencyPanel();
|
172 |
|
173 |
tpan.greenValue.setText(PluginServices.getText(this,"Valor_verde")); |
174 |
tpan.redValue.setText(PluginServices.getText(this,"Valor_rojo")); |
175 |
tpan.blueValue.setText(PluginServices.getText(this,"Valor_azul")); |
176 |
tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
177 |
tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
178 |
tpan.range.setText(PluginServices.getText(this,"usar_rango")); |
179 |
tpan.jLabel4.setText(PluginServices.getText(this,"valor_pixel")+": 0 a 255"); |
180 |
|
181 |
EnhancedPanel ep = this.getEnhancedPanel();
|
182 |
ep.jLabel.setText(PluginServices.getText(this,"lineal_directo")); |
183 |
ep.jLabel1.setText(PluginServices.getText(this,"recorte_colas")); |
184 |
ep.jLabel2.setText(PluginServices.getText(this,"sin_realce")); |
185 |
ep.jLabel4.setText(PluginServices.getText(this,"recorte")); |
186 |
ep.jLabel5.setText(PluginServices.getText(this,"eliminar_extremos")); |
187 |
|
188 |
//Recorremos los Tab y traducimos el nombre
|
189 |
for(int i=0;i<this.getTab().getTabCount();i++){ |
190 |
if(this.getTab().getTitleAt(i).equals("Info")) |
191 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"info")); |
192 |
if(this.getTab().getTitleAt(i).equals("Transparencia")) |
193 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"Transparencia")); |
194 |
if(this.getTab().getTitleAt(i).equals("Bandas")) |
195 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"bandas")); |
196 |
if(this.getTab().getTitleAt(i).equals("Realce")) |
197 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"realce")); |
198 |
} |
199 |
|
200 |
this.getAcceptButton().setText(PluginServices.getText(this,"Aceptar")); |
201 |
this.getApplyButton().setText(PluginServices.getText(this,"Aplicar")); |
202 |
this.getCancelButton().setText(PluginServices.getText(this,"Cancelar")); |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Assigns a FLayerRaster
|
207 |
* @param layer capa a asignar
|
208 |
*/
|
209 |
public void setFLyrWCS(FLyrWCS layer){ |
210 |
fLayer = layer; |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Dialog window constructor.
|
215 |
*/
|
216 |
public PropertiesWCSDialog() {
|
217 |
initialize(); |
218 |
} |
219 |
|
220 |
/**
|
221 |
* Loads the info panel data.
|
222 |
*/
|
223 |
private void loadInfoData(){ |
224 |
Rectangle2D r = fLayer.getFullExtent();
|
225 |
if(fLayer.getWCSAdaptor()!=null){ |
226 |
props = new Object[nprops][2]; |
227 |
props[0][0] = new String(PluginServices.getText(this,"Fichero_")); |
228 |
props[0][1] = grf.getName(); |
229 |
props[1][0] = new String(PluginServices.getText(this,"num_bandas")); |
230 |
props[1][1] = new String(String.valueOf( grf.getBandCount())); |
231 |
props[2][0] = new String(PluginServices.getText(this,"ancho_alto")); |
232 |
props[2][1] = (int)(r.getWidth()/fLayer.getMaxResolution().getX())+" X "+(int)(r.getHeight()/fLayer.getMaxResolution().getY()); |
233 |
props[3][0] = new String(PluginServices.getText(this,"formato")); |
234 |
props[3][1] = grf.getName().substring( |
235 |
grf.getName().lastIndexOf('.')+1, |
236 |
grf.getName().length()); |
237 |
props[4][0] = new String(PluginServices.getText(this,"tipo_dato")); |
238 |
String type = null; |
239 |
switch(grf.getDataType()){
|
240 |
case 0: type = new String("BYTE");break; |
241 |
case 1: type = new String("USHORT");break; |
242 |
case 2: type = new String("SHORT");break; |
243 |
case 3: type = new String("INT");break; |
244 |
case 4: type = new String("FLOAT");break; |
245 |
case 5: type = new String("DOUBLE");break; |
246 |
default: type = new String("UNDEFINED");break; |
247 |
} |
248 |
props[4][1] = type; |
249 |
props[5][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
250 |
props[6][0] = new String(PluginServices.getText(this,"xmin")); |
251 |
props[6][1] = String.valueOf(px.getExtent().minX()); |
252 |
props[7][0] = new String(PluginServices.getText(this,"ymin")); |
253 |
props[7][1] = String.valueOf(px.getExtent().minY()); |
254 |
props[8][0] = new String(PluginServices.getText(this,"xmax")); |
255 |
props[8][1] = String.valueOf(px.getExtent().maxX()); |
256 |
props[9][0] = new String(PluginServices.getText(this,"ymax")); |
257 |
props[9][1] = String.valueOf(px.getExtent().maxY()); |
258 |
|
259 |
}else{
|
260 |
props = new Object[1][2]; |
261 |
props[0][0] = new String("No props"); |
262 |
props[0][1] = new String("-"); |
263 |
} |
264 |
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* A?ade bandas al contador de bandas del FilterRasterDialogPanel
|
269 |
* @param numBands N?mero de bandas a a?adir
|
270 |
*/
|
271 |
public void addNumBands(int numBands){ |
272 |
nbands += numBands; |
273 |
if(this.getTransparencyPanel() != null && this.getTransparencyPanel().getTRojo().isEnabled()) |
274 |
this.getTransparencyPanel().setActiveTransparencyControl(true); |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Inits the jDialog
|
279 |
*/
|
280 |
private void initialize() { |
281 |
|
282 |
//this.setLayout(new FlowLayout());
|
283 |
|
284 |
setName("filterRaster");
|
285 |
|
286 |
this.loadInfoData();
|
287 |
super.init(props);
|
288 |
//this.add(getContentPane());
|
289 |
|
290 |
this.setSize(486, 318); |
291 |
|
292 |
//contentPane.getAcceptButton().setEnabled(false);
|
293 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
294 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
295 |
acceptButtonActionPerformed(evt); |
296 |
closeJDialog(); |
297 |
} |
298 |
}); |
299 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
300 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
301 |
cancelButtonActionPerformed(evt); |
302 |
closeJDialog(); |
303 |
} |
304 |
}); |
305 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
306 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
307 |
acceptButtonActionPerformed(evt); |
308 |
} |
309 |
}); |
310 |
this.getBandSetup().getFileList().getJButton2().addActionListener(new java.awt.event.ActionListener() { |
311 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
312 |
addFileBand(evt); |
313 |
|
314 |
} |
315 |
}); |
316 |
this.getBandSetup().getFileList().getJButton3().addActionListener(new java.awt.event.ActionListener() { |
317 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
318 |
delFileBand(evt); |
319 |
} |
320 |
}); |
321 |
|
322 |
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Saves the initial state to restore it if cancel.
|
327 |
*/
|
328 |
public void readStat(){ |
329 |
status = new Status(((FilterRasterDialogPanel)this).getTransparencyPanel().getOpacityText().getText(), |
330 |
getAssignedBand(GeoRasterFile.RED_BAND), |
331 |
getAssignedBand(GeoRasterFile.GREEN_BAND), |
332 |
getAssignedBand(GeoRasterFile.BLUE_BAND) |
333 |
); |
334 |
} |
335 |
|
336 |
/**
|
337 |
* This method initializes jContentPane
|
338 |
*/
|
339 |
public Container getContentPane() { |
340 |
return this; |
341 |
} |
342 |
|
343 |
/**
|
344 |
* Sets a projection.
|
345 |
*
|
346 |
* @param prj
|
347 |
*/
|
348 |
public void setProjection(IProjection prj) { |
349 |
this.currentProjection = prj;
|
350 |
} |
351 |
|
352 |
|
353 |
|
354 |
public void closeJDialog() { |
355 |
PluginServices.getMDIManager().closeView(PropertiesWCSDialog.this); |
356 |
} |
357 |
|
358 |
/**
|
359 |
* Sets the RasterFilterStackManager
|
360 |
* @param stackManager
|
361 |
*/
|
362 |
public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
363 |
this.stackManager = stackManager;
|
364 |
stackManager.resetTempFilters(); |
365 |
} |
366 |
|
367 |
/**
|
368 |
*
|
369 |
* @param flag
|
370 |
* @return
|
371 |
*/
|
372 |
public int getAssignedBand(int flag) { |
373 |
return this.getBandSetup().getAssignedBand(flag); |
374 |
} |
375 |
|
376 |
/**
|
377 |
* Pressing OK with the bands panel selected makes its values to be
|
378 |
* processed.
|
379 |
*
|
380 |
* @return true if the bands panel was selected and the action is processed, false it
|
381 |
* was not selected.
|
382 |
*/
|
383 |
public boolean processBandPanel(){ |
384 |
if(this.getTab().getSelectedComponent() == this.getBandSetup()){ |
385 |
|
386 |
fLayer.getWCSAdaptor().setBandR(getAssignedBand(GeoRasterFile.RED_BAND)); |
387 |
fLayer.getWCSAdaptor().setBandG(getAssignedBand(GeoRasterFile.GREEN_BAND)); |
388 |
fLayer.getWCSAdaptor().setBandB(getAssignedBand(GeoRasterFile.BLUE_BAND)); |
389 |
|
390 |
//Comprobamos si hay alguna banda que no est? asignada y aplicamos el filtro
|
391 |
StringBuffer sb = new StringBuffer(); |
392 |
if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
393 |
sb.append("R");
|
394 |
if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
395 |
sb.append("G");
|
396 |
if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
397 |
sb.append("B");
|
398 |
|
399 |
if(!sb.toString().equals("")) |
400 |
stackManager.addRemoveBands(sb.toString()); |
401 |
else
|
402 |
stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
403 |
|
404 |
fLayer.getFMap().invalidate(); |
405 |
return true; |
406 |
} |
407 |
return false; |
408 |
} |
409 |
|
410 |
/**
|
411 |
* Pressing OK with the transparency panel selected makes its values to be processed.
|
412 |
* @return true if the transparency panel was selected and the action is processed, false it
|
413 |
* was not selected.
|
414 |
*/
|
415 |
public boolean processTransparencyPanel(){ |
416 |
|
417 |
if(this.getTab().getSelectedComponent() == this.getTransparencyPanel()){ |
418 |
|
419 |
//OPACIDAD
|
420 |
String sOpac = this.getTransparencyPanel().getOpacityText().getText(); |
421 |
if(!sOpac.equals("") && this.getTransparencyPanel().getOpacityCheck().isSelected()){ |
422 |
int opac = Integer.parseInt(sOpac); |
423 |
opac = (int)((opac*255)/100); |
424 |
px.setTransparency(true);
|
425 |
//px.setTransparency(255-opac);
|
426 |
fLayer.getWCSAdaptor().setTransparency(255-opac);
|
427 |
}else{
|
428 |
px.setTransparency(false);
|
429 |
fLayer.getWCSAdaptor().setTransparency(0);
|
430 |
} |
431 |
|
432 |
//TRANSPARENCIA
|
433 |
if( this.getTransparencyPanel().getTransparencyCheck().isSelected()){ |
434 |
this.checkTransparencyValues();
|
435 |
stackManager.addTransparencyFilter( this.getRangeRed(),
|
436 |
this.getRangeGreen(),
|
437 |
this.getRangeBlue(),
|
438 |
0x10, //Transparencia |
439 |
0xff, //Color Transparencia R |
440 |
0xff, //Color Transparencia G |
441 |
0xff); //Color Transparencia B |
442 |
}else
|
443 |
px.filterStack.removeFilter(stackManager.getTypeFilter("transparency"));
|
444 |
|
445 |
fLayer.getFMap().invalidate(); |
446 |
return true; |
447 |
} |
448 |
|
449 |
return false; |
450 |
} |
451 |
|
452 |
/**
|
453 |
* Pressing OK with the enhancement panel selected makes its values to be processed.
|
454 |
* @return true if the enhancement panel was selected and the action is processed, false it
|
455 |
* was not selected.
|
456 |
*/
|
457 |
public boolean processEnhancedPanel(){ |
458 |
if(this.getTab().getSelectedComponent() == this.getEnhancedPanel()){ |
459 |
|
460 |
//Filtro lineal seleccionado
|
461 |
if( this.getEnhancedPanel().getLinealDirectoRadioButton().isSelected()){ |
462 |
if( this.getEnhancedPanel().getRemoveCheck().isSelected() && |
463 |
!this.getEnhancedPanel().getTailCheck().isSelected())
|
464 |
stackManager.addEnhancedFilter(true);
|
465 |
else
|
466 |
stackManager.addEnhancedFilter(false);
|
467 |
|
468 |
|
469 |
//Recorte de colas seleccionado
|
470 |
if(this.getEnhancedPanel().getTailCheck().isSelected()){ |
471 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
472 |
double recorte = Double.parseDouble(this.getEnhancedPanel().getTailText().getText())/100; |
473 |
if(this.getEnhancedPanel().getRemoveCheck().isSelected()) |
474 |
stackManager.addTailFilter( recorte, 0D, true); |
475 |
else
|
476 |
stackManager.addTailFilter( recorte, 0D, false); |
477 |
}else{
|
478 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
479 |
stackManager.addComputeMinMaxFilter(); |
480 |
} |
481 |
} |
482 |
|
483 |
//Sin filtro lineal seleccionado
|
484 |
if(this.getEnhancedPanel().getSinRealceRadioButton().isSelected()){ |
485 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
486 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
487 |
stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
488 |
} |
489 |
fLayer.getFMap().invalidate(); |
490 |
|
491 |
return true; |
492 |
} |
493 |
return false; |
494 |
} |
495 |
|
496 |
/**
|
497 |
* Manages the action perfomed when Apply/OK is pressed or Apply at the raster
|
498 |
* properties control.
|
499 |
* @param e
|
500 |
*/
|
501 |
private void acceptButtonActionPerformed(ActionEvent e) { |
502 |
this.processBandPanel();
|
503 |
this.processTransparencyPanel();
|
504 |
this.processEnhancedPanel();
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* Adds a band to the raster.
|
509 |
* @param e
|
510 |
*/
|
511 |
private void addFileBand(ActionEvent e){ |
512 |
String[] driverNames = null; |
513 |
String rasterDriver = null; |
514 |
|
515 |
//Creaci?n del dialogo para selecci?n de ficheros
|
516 |
|
517 |
fileChooser = new JFileChooser(lastPath); |
518 |
fileChooser.setMultiSelectionEnabled(true);
|
519 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
520 |
try {
|
521 |
driverNames = LayerFactory.getDM().getDriverNames(); |
522 |
FileFilter defaultFileFilter = null, auxF; |
523 |
for (int i = 0; i < driverNames.length; i++) { |
524 |
|
525 |
if (driverNames[i].endsWith("gvSIG Image Driver")){ |
526 |
rasterDriver = driverNames[i]; |
527 |
auxF = new DriverFileFilter(driverNames[i]);
|
528 |
fileChooser.addChoosableFileFilter(auxF); |
529 |
defaultFileFilter = auxF; |
530 |
} |
531 |
} |
532 |
} catch (DriverLoadException e1) {
|
533 |
NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
534 |
} |
535 |
int result = fileChooser.showOpenDialog(PropertiesWCSDialog.this);
|
536 |
|
537 |
if(result == JFileChooser.APPROVE_OPTION){ |
538 |
File[] files = fileChooser.getSelectedFiles(); |
539 |
FileFilter filter = fileChooser.getFileFilter();
|
540 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
541 |
lastPath = files[0].getPath();
|
542 |
|
543 |
//Lo a?adimos a la capa si no esta
|
544 |
|
545 |
Vector v = new Vector(); |
546 |
for(int i=0;i<files.length;i++){ |
547 |
boolean exist = false; |
548 |
for(int j=0;j<px.getFiles().length;j++){ |
549 |
if(px.getFiles()[j].getName().endsWith(files[i].getName()))
|
550 |
exist = true;
|
551 |
} |
552 |
if(!exist){
|
553 |
try{
|
554 |
Rectangle2D extentOrigin = fLayer.getFullExtent();
|
555 |
|
556 |
Extent extentNewFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()).getExtent(); |
557 |
|
558 |
//Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
559 |
//fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
560 |
|
561 |
double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
562 |
double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
563 |
|
564 |
if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
565 |
(widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
566 |
(heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
567 |
(heightNewFile-extentOrigin.getHeight()) < -1.0){
|
568 |
JOptionPane.showMessageDialog( null, |
569 |
PluginServices.getText(this, "extents_no_coincidentes"), |
570 |
"",
|
571 |
JOptionPane.ERROR_MESSAGE);
|
572 |
return;
|
573 |
} |
574 |
|
575 |
if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
576 |
(extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
577 |
JOptionPane.showMessageDialog(null, |
578 |
PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
579 |
return;
|
580 |
} |
581 |
|
582 |
}catch(Exception exc){ |
583 |
exc.printStackTrace(); |
584 |
} |
585 |
|
586 |
//Lo a?adimos a la capa
|
587 |
px.addFile(files[i].getAbsolutePath()); |
588 |
|
589 |
}else{
|
590 |
JOptionPane.showMessageDialog(null, |
591 |
PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
592 |
} |
593 |
} |
594 |
|
595 |
//A?adimos los georasterfile a la tabla del Panel
|
596 |
|
597 |
v = new Vector(); |
598 |
for(int i=0;i<px.getFiles().length;i++){ |
599 |
boolean exist = false; |
600 |
for(int j=0;j<bandSetup.getNBands();j++){ |
601 |
if(px.getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
602 |
exist = true;
|
603 |
} |
604 |
if(!exist)
|
605 |
v.add(px.getFiles()[i]); |
606 |
} |
607 |
|
608 |
GeoRasterFile[] grf = new GeoRasterFile[v.size()]; |
609 |
for(int i=0;i<grf.length;i++){ |
610 |
grf[i] = (GeoRasterFile)v.get(i); |
611 |
} |
612 |
bandSetup.addFiles(grf); |
613 |
} |
614 |
} |
615 |
|
616 |
/**
|
617 |
* Deletes a band from the raster. If there is only a file or no band is
|
618 |
* selected then it does nothing.
|
619 |
*
|
620 |
* @param e
|
621 |
*/
|
622 |
private void delFileBand(ActionEvent e){ |
623 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
624 |
|
625 |
if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
626 |
bandSetup.getFileList().getNFiles() > 1){
|
627 |
String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
628 |
px.delFile(pathName); |
629 |
String file = pathName.substring(pathName.lastIndexOf("/")+1); |
630 |
file = file.substring(file.lastIndexOf("\\")+1); |
631 |
bandSetup.removeFile(file); |
632 |
|
633 |
} |
634 |
} |
635 |
|
636 |
/**
|
637 |
* The cancel button restores the previous state to the loading of this dialog
|
638 |
* @param e Evento
|
639 |
*/
|
640 |
private void cancelButtonActionPerformed(ActionEvent e) { |
641 |
this.status.restoreStatus(this); |
642 |
fLayer.getFMap().invalidate(); |
643 |
} |
644 |
|
645 |
/**
|
646 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
647 |
*/
|
648 |
public ViewInfo getViewInfo() {
|
649 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
650 |
m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
651 |
return m_viewinfo;
|
652 |
} |
653 |
|
654 |
|
655 |
} |