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