root / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / PropertiesWMSDialog.java @ 3465
History | View | Annotate | Download (21.6 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 PropertiesWMSDialog 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(PropertiesWMSDialog 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 PropertiesWMSDialog(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,"Anadir")); |
176 |
this.getBandSetup().getFileList().getJButtonRemove().setText(PluginServices.getText(this,"Eliminar")); |
177 |
this.getBandSetup().getFileList().lbandasVisibles.setText(PluginServices.getText(this,"bandas")); |
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("Bandas")) |
203 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"bandas")); |
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,"Aceptar")); |
209 |
this.getApplyButton().setText(PluginServices.getText(this,"Aplicar")); |
210 |
this.getCancelButton().setText(PluginServices.getText(this,"Cancelar")); |
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 PropertiesWMSDialog() {
|
225 |
initialize(); |
226 |
} |
227 |
|
228 |
/**
|
229 |
* Loads the info panel data.
|
230 |
*/
|
231 |
private void loadInfoData(){ |
232 |
Rectangle2D r = null; |
233 |
try{
|
234 |
r = fLayer.getFullExtent(); |
235 |
}catch(DriverException exc){
|
236 |
return;
|
237 |
} |
238 |
if(fLayer!=null){ |
239 |
props = new Object[nprops][2]; |
240 |
props[0][0] = new String(PluginServices.getText(this,"Fichero_")); |
241 |
props[0][1] = "http://"+fLayer.host.getHost()+fLayer.host.getFile(); |
242 |
props[1][0] = new String(PluginServices.getText(this,"num_bandas")); |
243 |
props[1][1] = new String(String.valueOf( grf.getBandCount())); |
244 |
props[2][0] = new String(PluginServices.getText(this,"ancho_alto")); |
245 |
props[2][1] = (int)(fLayer.getWidth())+" X "+(int)(fLayer.getHeight()); |
246 |
props[3][0] = new String(PluginServices.getText(this,"formato")); |
247 |
props[3][1] = fLayer.m_Format; |
248 |
props[4][0] = new String(PluginServices.getText(this,"tipo_dato")); |
249 |
String type = null; |
250 |
switch(grf.getDataType()){
|
251 |
case 0: type = new String("BYTE");break; |
252 |
case 1: type = new String("USHORT");break; |
253 |
case 2: type = new String("SHORT");break; |
254 |
case 3: type = new String("INT");break; |
255 |
case 4: type = new String("FLOAT");break; |
256 |
case 5: type = new String("DOUBLE");break; |
257 |
default: type = new String("UNDEFINED");break; |
258 |
} |
259 |
props[4][1] = type; |
260 |
props[5][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
261 |
props[6][0] = new String(PluginServices.getText(this,"xmin")); |
262 |
props[6][1] = String.valueOf(px.getExtent().minX()); |
263 |
props[7][0] = new String(PluginServices.getText(this,"ymin")); |
264 |
props[7][1] = String.valueOf(px.getExtent().minY()); |
265 |
props[8][0] = new String(PluginServices.getText(this,"xmax")); |
266 |
props[8][1] = String.valueOf(px.getExtent().maxX()); |
267 |
props[9][0] = new String(PluginServices.getText(this,"ymax")); |
268 |
props[9][1] = String.valueOf(px.getExtent().maxY()); |
269 |
|
270 |
}else{
|
271 |
props = new Object[1][2]; |
272 |
props[0][0] = new String("No props"); |
273 |
props[0][1] = new String("-"); |
274 |
} |
275 |
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* A?ade bandas al contador de bandas del FilterRasterDialogPanel
|
280 |
* @param numBands N?mero de bandas a a?adir
|
281 |
*/
|
282 |
public void addNumBands(int numBands){ |
283 |
nbands += numBands; |
284 |
if(this.getTransparencyPanel() != null && this.getTransparencyPanel().getTRojo().isEnabled()) |
285 |
this.getTransparencyPanel().setActiveTransparencyControl(true); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* Inits the jDialog
|
290 |
*/
|
291 |
private void initialize() { |
292 |
|
293 |
//this.setLayout(new FlowLayout());
|
294 |
|
295 |
setName("filterRaster");
|
296 |
|
297 |
this.loadInfoData();
|
298 |
super.init(props);
|
299 |
//this.add(getContentPane());
|
300 |
|
301 |
this.setSize(486, 318); |
302 |
|
303 |
//contentPane.getAcceptButton().setEnabled(false);
|
304 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
305 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
306 |
acceptButtonActionPerformed(evt); |
307 |
closeJDialog(); |
308 |
} |
309 |
}); |
310 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
311 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
312 |
cancelButtonActionPerformed(evt); |
313 |
closeJDialog(); |
314 |
} |
315 |
}); |
316 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
317 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
318 |
acceptButtonActionPerformed(evt); |
319 |
} |
320 |
}); |
321 |
this.getBandSetup().getFileList().getJButtonAdd().addActionListener(new java.awt.event.ActionListener() { |
322 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
323 |
addFileBand(evt); |
324 |
|
325 |
} |
326 |
}); |
327 |
this.getBandSetup().getFileList().getJButtonRemove().addActionListener(new java.awt.event.ActionListener() { |
328 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
329 |
delFileBand(evt); |
330 |
} |
331 |
}); |
332 |
|
333 |
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* Saves the initial state to restore it if cancel.
|
338 |
*/
|
339 |
public void readStat(){ |
340 |
status = new Status(((FilterRasterDialogPanel)this).getTransparencyPanel().getOpacityText().getText(), |
341 |
getAssignedBand(GeoRasterFile.RED_BAND), |
342 |
getAssignedBand(GeoRasterFile.GREEN_BAND), |
343 |
getAssignedBand(GeoRasterFile.BLUE_BAND) |
344 |
); |
345 |
} |
346 |
|
347 |
/**
|
348 |
* This method initializes jContentPane
|
349 |
*/
|
350 |
public Container getContentPane() { |
351 |
return this; |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Sets a projection.
|
356 |
*
|
357 |
* @param prj
|
358 |
*/
|
359 |
public void setProjection(IProjection prj) { |
360 |
this.currentProjection = prj;
|
361 |
} |
362 |
|
363 |
|
364 |
|
365 |
public void closeJDialog() { |
366 |
PluginServices.getMDIManager().closeView(PropertiesWMSDialog.this); |
367 |
} |
368 |
|
369 |
/**
|
370 |
* Sets the RasterFilterStackManager
|
371 |
* @param stackManager
|
372 |
*/
|
373 |
public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
374 |
this.stackManager = stackManager;
|
375 |
stackManager.resetTempFilters(); |
376 |
} |
377 |
|
378 |
/**
|
379 |
*
|
380 |
* @param flag
|
381 |
* @return
|
382 |
*/
|
383 |
public int getAssignedBand(int flag) { |
384 |
return this.getBandSetup().getAssignedBand(flag); |
385 |
} |
386 |
|
387 |
/**
|
388 |
* Pressing OK with the bands panel selected makes its values to be
|
389 |
* processed.
|
390 |
*
|
391 |
* @return true if the bands panel was selected and the action is processed, false it
|
392 |
* was not selected.
|
393 |
*/
|
394 |
public boolean processBandPanel(){ |
395 |
fLayer.setBandR(getAssignedBand(GeoRasterFile.RED_BAND)); |
396 |
fLayer.setBandG(getAssignedBand(GeoRasterFile.GREEN_BAND)); |
397 |
fLayer.setBandB(getAssignedBand(GeoRasterFile.BLUE_BAND)); |
398 |
rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
399 |
rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
400 |
rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
401 |
|
402 |
//Comprobamos si hay alguna banda que no est? asignada y aplicamos el filtro
|
403 |
StringBuffer sb = new StringBuffer(); |
404 |
if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
405 |
sb.append("R");
|
406 |
if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
407 |
sb.append("G");
|
408 |
if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
409 |
sb.append("B");
|
410 |
|
411 |
if(!sb.toString().equals("")) |
412 |
stackManager.addRemoveBands(sb.toString()); |
413 |
else
|
414 |
stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
415 |
|
416 |
fLayer.getFMap().invalidate(); |
417 |
return true; |
418 |
} |
419 |
|
420 |
/**
|
421 |
* Pressing OK with the transparency panel selected makes its values to be processed.
|
422 |
* @return true if the transparency panel was selected and the action is processed, false it
|
423 |
* was not selected.
|
424 |
*/
|
425 |
public boolean processTransparencyPanel(){ |
426 |
//OPACIDAD
|
427 |
String sOpac = this.getTransparencyPanel().getOpacityText().getText(); |
428 |
if(!sOpac.equals("") && this.getTransparencyPanel().getOpacityCheck().isSelected()){ |
429 |
int opac = Integer.parseInt(sOpac); |
430 |
opac = (int)((opac*255)/100); |
431 |
px.setTransparency(true);
|
432 |
//px.setTransparency(255-opac);
|
433 |
fLayer.setTransparency(255-opac);
|
434 |
rasterStatus.transparency = 255-opac;
|
435 |
}else{
|
436 |
px.setTransparency(false);
|
437 |
fLayer.setTransparency(0);
|
438 |
rasterStatus.transparency = 0;
|
439 |
} |
440 |
|
441 |
//TRANSPARENCIA
|
442 |
if( this.getTransparencyPanel().getTransparencyCheck().isSelected()){ |
443 |
this.checkTransparencyValues();
|
444 |
stackManager.addTransparencyFilter( this.getRangeRed(),
|
445 |
this.getRangeGreen(),
|
446 |
this.getRangeBlue(),
|
447 |
0x10, //Transparencia |
448 |
0xff, //Color Transparencia R |
449 |
0xff, //Color Transparencia G |
450 |
0xff); //Color Transparencia B |
451 |
}else
|
452 |
px.filterStack.removeFilter(stackManager.getTypeFilter("transparency"));
|
453 |
|
454 |
fLayer.getFMap().invalidate(); |
455 |
return true; |
456 |
} |
457 |
|
458 |
/**
|
459 |
* Pressing OK with the enhancement panel selected makes its values to be processed.
|
460 |
* @return true if the enhancement panel was selected and the action is processed, false it
|
461 |
* was not selected.
|
462 |
*/
|
463 |
public boolean processEnhancedPanel(){ |
464 |
//Filtro lineal seleccionado
|
465 |
if( this.getEnhancedPanel().getLinealDirectoRadioButton().isSelected()){ |
466 |
if( this.getEnhancedPanel().getRemoveCheck().isSelected() && |
467 |
!this.getEnhancedPanel().getTailCheck().isSelected())
|
468 |
stackManager.addEnhancedFilter(true);
|
469 |
else
|
470 |
stackManager.addEnhancedFilter(false);
|
471 |
|
472 |
//Recorte de colas seleccionado
|
473 |
if(this.getEnhancedPanel().getTailCheck().isSelected()){ |
474 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
475 |
double recorte = Double.parseDouble(this.getEnhancedPanel().getTailText().getText())/100; |
476 |
if(this.getEnhancedPanel().getRemoveCheck().isSelected()) |
477 |
stackManager.addTailFilter( recorte, 0D, true); |
478 |
else
|
479 |
stackManager.addTailFilter( recorte, 0D, false); |
480 |
}else{
|
481 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
482 |
stackManager.addComputeMinMaxFilter(); |
483 |
} |
484 |
} |
485 |
|
486 |
//Sin filtro lineal seleccionado
|
487 |
if(this.getEnhancedPanel().getSinRealceRadioButton().isSelected()){ |
488 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
489 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
490 |
stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
491 |
} |
492 |
fLayer.getFMap().invalidate(); |
493 |
|
494 |
return true; |
495 |
} |
496 |
|
497 |
/**
|
498 |
* Manages the action perfomed when Apply/OK is pressed or Apply at the raster
|
499 |
* properties control.
|
500 |
* @param e
|
501 |
*/
|
502 |
private void acceptButtonActionPerformed(ActionEvent e) { |
503 |
this.processBandPanel();
|
504 |
this.processTransparencyPanel();
|
505 |
this.processEnhancedPanel();
|
506 |
} |
507 |
|
508 |
/**
|
509 |
* Adds a band to the raster.
|
510 |
* @param e
|
511 |
*/
|
512 |
private void addFileBand(ActionEvent e){ |
513 |
String[] driverNames = null; |
514 |
String rasterDriver = null; |
515 |
|
516 |
//Creaci?n del dialogo para selecci?n de ficheros
|
517 |
|
518 |
fileChooser = new JFileChooser(lastPath); |
519 |
fileChooser.setMultiSelectionEnabled(true);
|
520 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
521 |
try {
|
522 |
driverNames = LayerFactory.getDM().getDriverNames(); |
523 |
FileFilter defaultFileFilter = null, auxF; |
524 |
for (int i = 0; i < driverNames.length; i++) { |
525 |
|
526 |
if (driverNames[i].endsWith("gvSIG Image Driver")){ |
527 |
rasterDriver = driverNames[i]; |
528 |
auxF = new DriverFileFilter(driverNames[i]);
|
529 |
fileChooser.addChoosableFileFilter(auxF); |
530 |
defaultFileFilter = auxF; |
531 |
} |
532 |
} |
533 |
} catch (DriverLoadException e1) {
|
534 |
NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
535 |
} |
536 |
int result = fileChooser.showOpenDialog(PropertiesWMSDialog.this);
|
537 |
|
538 |
if(result == JFileChooser.APPROVE_OPTION){ |
539 |
File[] files = fileChooser.getSelectedFiles(); |
540 |
FileFilter filter = fileChooser.getFileFilter();
|
541 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
542 |
lastPath = files[0].getPath();
|
543 |
|
544 |
//Lo a?adimos a la capa si no esta
|
545 |
|
546 |
Vector v = new Vector(); |
547 |
for(int i=0;i<files.length;i++){ |
548 |
boolean exist = false; |
549 |
for(int j=0;j<px.getFiles().length;j++){ |
550 |
if(px.getFiles()[j].getName().endsWith(files[i].getName()))
|
551 |
exist = true;
|
552 |
} |
553 |
if(!exist){
|
554 |
try{
|
555 |
Rectangle2D extentOrigin = fLayer.getFullExtent();
|
556 |
|
557 |
Extent extentNewFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()).getExtent(); |
558 |
|
559 |
//Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
560 |
//fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
561 |
|
562 |
double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
563 |
double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
564 |
|
565 |
if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
566 |
(widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
567 |
(heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
568 |
(heightNewFile-extentOrigin.getHeight()) < -1.0){
|
569 |
JOptionPane.showMessageDialog( null, |
570 |
PluginServices.getText(this, "extents_no_coincidentes"), |
571 |
"",
|
572 |
JOptionPane.ERROR_MESSAGE);
|
573 |
return;
|
574 |
} |
575 |
|
576 |
if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
577 |
(extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
578 |
JOptionPane.showMessageDialog(null, |
579 |
PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
580 |
return;
|
581 |
} |
582 |
|
583 |
}catch(Exception exc){ |
584 |
exc.printStackTrace(); |
585 |
} |
586 |
|
587 |
//Lo a?adimos a la capa
|
588 |
px.addFile(files[i].getAbsolutePath()); |
589 |
|
590 |
}else{
|
591 |
JOptionPane.showMessageDialog(null, |
592 |
PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
593 |
} |
594 |
} |
595 |
|
596 |
//A?adimos los georasterfile a la tabla del Panel
|
597 |
|
598 |
v = new Vector(); |
599 |
for(int i=0;i<px.getFiles().length;i++){ |
600 |
boolean exist = false; |
601 |
for(int j=0;j<bandSetup.getNBands();j++){ |
602 |
if(px.getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
603 |
exist = true;
|
604 |
} |
605 |
if(!exist)
|
606 |
v.add(px.getFiles()[i]); |
607 |
} |
608 |
|
609 |
GeoRasterFile[] grf = new GeoRasterFile[v.size()]; |
610 |
for(int i=0;i<grf.length;i++){ |
611 |
grf[i] = (GeoRasterFile)v.get(i); |
612 |
} |
613 |
bandSetup.addFiles(grf); |
614 |
} |
615 |
} |
616 |
|
617 |
/**
|
618 |
* Deletes a band from the raster. If there is only a file or no band is
|
619 |
* selected then it does nothing.
|
620 |
*
|
621 |
* @param e
|
622 |
*/
|
623 |
private void delFileBand(ActionEvent e){ |
624 |
BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
625 |
|
626 |
if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
627 |
bandSetup.getFileList().getNFiles() > 1){
|
628 |
String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
629 |
px.delFile(pathName); |
630 |
String file = pathName.substring(pathName.lastIndexOf("/")+1); |
631 |
file = file.substring(file.lastIndexOf("\\")+1); |
632 |
bandSetup.removeFile(file); |
633 |
|
634 |
} |
635 |
} |
636 |
|
637 |
/**
|
638 |
* The cancel button restores the previous state to the loading of this dialog
|
639 |
* @param e Evento
|
640 |
*/
|
641 |
private void cancelButtonActionPerformed(ActionEvent e) { |
642 |
this.status.restoreStatus(this); |
643 |
fLayer.getFMap().invalidate(); |
644 |
} |
645 |
|
646 |
/**
|
647 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
648 |
*/
|
649 |
public ViewInfo getViewInfo() {
|
650 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
651 |
m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
652 |
return m_viewinfo;
|
653 |
} |
654 |
|
655 |
|
656 |
} |