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