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