svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / PropertiesRasterDialog.java @ 4377
History | View | Annotate | Download (29.3 KB)
1 | 2183 | fernando | /*
|
---|---|---|---|
2 | * Created on 17-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package com.iver.cit.gvsig.gui.Panels; |
||
48 | |||
49 | import java.awt.Container; |
||
50 | import java.awt.event.ActionEvent; |
||
51 | import java.awt.geom.Rectangle2D; |
||
52 | import java.io.File; |
||
53 | import java.util.ArrayList; |
||
54 | import java.util.Vector; |
||
55 | |||
56 | import javax.swing.JFileChooser; |
||
57 | import javax.swing.JOptionPane; |
||
58 | import javax.swing.JPanel; |
||
59 | import javax.swing.filechooser.FileFilter; |
||
60 | |||
61 | import org.cresques.cts.IProjection; |
||
62 | import org.cresques.io.GeoRasterFile; |
||
63 | 3581 | nacho | import org.cresques.io.raster.RasterFilter; |
64 | 2183 | fernando | import org.cresques.io.raster.RasterFilterStackManager; |
65 | import org.cresques.px.Extent; |
||
66 | import org.cresques.ui.raster.BandSetupPanel; |
||
67 | import org.cresques.ui.raster.EnhancedPanel; |
||
68 | import org.cresques.ui.raster.FilterRasterDialogPanel; |
||
69 | import org.cresques.ui.raster.RasterTransparencyPanel; |
||
70 | |||
71 | import com.hardcode.driverManager.Driver; |
||
72 | import com.hardcode.driverManager.DriverLoadException; |
||
73 | import com.iver.andami.PluginServices; |
||
74 | import com.iver.andami.messages.NotificationManager; |
||
75 | import com.iver.andami.ui.mdiManager.View; |
||
76 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
77 | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
||
78 | import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
||
79 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
80 | import com.iver.cit.gvsig.fmap.layers.StatusLayerRaster; |
||
81 | |||
82 | /**
|
||
83 | * <P>
|
||
84 | * Dialogo para las propiedades de un raster. Esta maneja los eventos y aplica
|
||
85 | * filtros sobre el raster a trav?s de l gestor de la pila de filtros seg?n la
|
||
86 | * selecci?n del usuario. Este dialogo contiene varios paneles:
|
||
87 | * </P>
|
||
88 | * <UL>
|
||
89 | * <LI>Propiedades</LI>
|
||
90 | * <LI>Selecci?n de bandas</LI>
|
||
91 | * <LI>Transparencia</LI>
|
||
92 | * <LI>Realce</LI>
|
||
93 | * </UL>
|
||
94 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
95 | */
|
||
96 | public class PropertiesRasterDialog extends FilterRasterDialogPanel implements View { |
||
97 | |||
98 | private JPanel propPanel = null; |
||
99 | private IProjection currentProjection = null; |
||
100 | private FLyrRaster fLayer = null; |
||
101 | private static final int nprops = 11; |
||
102 | private Object[][] props = null; |
||
103 | private RasterFilterStackManager stackManager = null; |
||
104 | private Status status = null; |
||
105 | private String filename = null; |
||
106 | private long filesize = 0; |
||
107 | private int width = 0; |
||
108 | private int height = 0; |
||
109 | private JFileChooser fileChooser = null; |
||
110 | private String lastPath = new String("./"); |
||
111 | private StatusLayerRaster rasterStatus = null; |
||
112 | private int sizeX = 486, sizeY = 318; |
||
113 | |||
114 | /**
|
||
115 | * Clase que guarda el estado del dialogo y gestiona la restauraci?n
|
||
116 | * del estado inicial en caso de cancelar.
|
||
117 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
118 | */
|
||
119 | class Status{ |
||
120 | public String inicAlpha; |
||
121 | public int bandR; |
||
122 | public int bandG; |
||
123 | public int bandB; |
||
124 | private ArrayList filesAdd = new ArrayList(); |
||
125 | private ArrayList filesRem = new ArrayList(); |
||
126 | private ArrayList filters = null; |
||
127 | |||
128 | |||
129 | public Status(String alpha, int bandR, int bandG, int bandB){ |
||
130 | this.inicAlpha = alpha;
|
||
131 | this.bandR = bandR;
|
||
132 | this.bandG = bandG;
|
||
133 | this.bandB = bandB;
|
||
134 | filters = stackManager.getStringsFromStack(); |
||
135 | } |
||
136 | |||
137 | /**
|
||
138 | * A?ade un fichero a la lista de a?adidos. Si estaba en la de eliminados
|
||
139 | * lo quitamos.
|
||
140 | * @param file Fichero a?adido
|
||
141 | */
|
||
142 | public void addFile(String file){ |
||
143 | filesAdd.add(file); |
||
144 | for(int j=0;j<filesRem.size();j++){ |
||
145 | if(file.equals((String)filesRem.get(j))) |
||
146 | filesRem.remove(j); |
||
147 | } |
||
148 | |||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * Elimina un fichero de la lista de a?adidos si ha sido a?adido. Si ya estaba
|
||
153 | * antes no estar? en la lista de a?adidos por lo que habr? que ponerlo en la
|
||
154 | * lista de eliminados.
|
||
155 | * @param file Fichero eliminado
|
||
156 | */
|
||
157 | public void removeFile(String file){ |
||
158 | boolean isAdd = false; |
||
159 | for(int i=0;i<filesAdd.size();i++){ |
||
160 | if(((String)filesAdd.get(i)).equals(file)){ |
||
161 | filesAdd.remove(i); |
||
162 | isAdd = true;
|
||
163 | } |
||
164 | } |
||
165 | if(!isAdd)
|
||
166 | filesRem.add(file); |
||
167 | |||
168 | } |
||
169 | |||
170 | /**
|
||
171 | * Restaura el Estado salvado
|
||
172 | * @param status Estado
|
||
173 | */
|
||
174 | public void restoreStatus(PropertiesRasterDialog props){ |
||
175 | //Devolvemos la pila de filtros al estado inicial
|
||
176 | //if(stackManager != null)
|
||
177 | // stackManager.deleteTempFilters();
|
||
178 | |||
179 | //Devolvemos el alpha al estado inicial
|
||
180 | int opac = Integer.parseInt(status.inicAlpha); |
||
181 | opac = (int)((opac*255)/100); |
||
182 | fLayer.getSource().setTransparency(true);
|
||
183 | fLayer.setTransparency(255-opac);
|
||
184 | rasterStatus.transparency = 255-opac;
|
||
185 | |||
186 | //Devolvemos el estado inicial de las bandas
|
||
187 | |||
188 | if (fLayer != null) { |
||
189 | fLayer.getSource().setBand(GeoRasterFile.RED_BAND, status.bandR); |
||
190 | fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, status.bandG); |
||
191 | fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, status.bandB); |
||
192 | rasterStatus.bandR = status.bandR; |
||
193 | rasterStatus.bandG = status.bandG; |
||
194 | rasterStatus.bandB = status.bandB; |
||
195 | } |
||
196 | |||
197 | BandSetupPanel bandSetup = ((FilterRasterDialogPanel)props.getContentPane()).getBandSetup(); |
||
198 | |||
199 | //Los que han sido a?adidos los quitamos
|
||
200 | for(int i=0;i<filesAdd.size();i++) |
||
201 | fLayer.delFile((String)this.filesAdd.get(i)); |
||
202 | |||
203 | //Los que fueron quitados los a?adimos
|
||
204 | for(int i=0;i<filesRem.size();i++) |
||
205 | fLayer.addFiles((String)this.filesRem.get(i)); |
||
206 | |||
207 | //Restauramos los filtros
|
||
208 | if(filters!=null) |
||
209 | 4236 | nacho | stackManager.createStackFromStrings(filters, ((FLyrRaster)fLayer).getSource().getFiles()); |
210 | 2183 | fernando | |
211 | fLayer.getFMap().invalidate(); |
||
212 | //this.show();
|
||
213 | } |
||
214 | |||
215 | public void show(){ |
||
216 | System.out.println("***Lista A?adidos***"); |
||
217 | for(int i=0;i<filesAdd.size();i++){ |
||
218 | System.out.println(filesAdd.get(i).toString());
|
||
219 | } |
||
220 | System.out.println("***Lista Eliminados***"); |
||
221 | for(int i=0;i<filesRem.size();i++){ |
||
222 | System.out.println(filesRem.get(i).toString());
|
||
223 | } |
||
224 | System.out.println("*********************"); |
||
225 | } |
||
226 | |||
227 | } |
||
228 | |||
229 | public class DriverFileFilter extends FileFilter{ |
||
230 | |||
231 | private Driver driver; |
||
232 | |||
233 | public DriverFileFilter(String driverName) throws DriverLoadException{ |
||
234 | driver = LayerFactory.getDM().getDriver(driverName); |
||
235 | } |
||
236 | |||
237 | /**
|
||
238 | * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||
239 | */
|
||
240 | public boolean accept(File f) { |
||
241 | if (f.isDirectory()) return true; |
||
242 | if (driver instanceof RasterDriver){ |
||
243 | return ((RasterDriver) driver).fileAccepted(f);
|
||
244 | }else{
|
||
245 | throw new RuntimeException("Tipo no reconocido"); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | /**
|
||
250 | * @see javax.swing.filechooser.FileFilter#getDescription()
|
||
251 | */
|
||
252 | public String getDescription() { |
||
253 | return ((Driver) driver).getName(); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * Constructor de la ventana de dialogo.
|
||
259 | * @param app
|
||
260 | */
|
||
261 | 4377 | nacho | public PropertiesRasterDialog(FLyrRaster layer, ArrayList ranges){ |
262 | 2183 | fernando | super();
|
263 | fLayer = layer; |
||
264 | if(fLayer.getStatus()==null){ |
||
265 | rasterStatus = new StatusLayerRaster();
|
||
266 | fLayer.setStatus(rasterStatus); |
||
267 | }else
|
||
268 | rasterStatus = (StatusLayerRaster)fLayer.getStatus(); |
||
269 | initialize(); |
||
270 | 4377 | nacho | this.setRanges(ranges);
|
271 | 2183 | fernando | setTranslation(); |
272 | } |
||
273 | |||
274 | /**
|
||
275 | * Asigna los textos a los paneles
|
||
276 | */
|
||
277 | private void setTranslation(){ |
||
278 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonAdd().setText(PluginServices.getText(this,"Anadir")); |
279 | this.getBandSetup().getFileList().getJButtonRemove().setText(PluginServices.getText(this,"Eliminar")); |
||
280 | this.getBandSetup().getFileList().lbandasVisibles.setText(PluginServices.getText(this,"bandas")); |
||
281 | 2183 | fernando | |
282 | RasterTransparencyPanel tpan = this.getTransparencyPanel();
|
||
283 | 2252 | igbrotru | |
284 | 4377 | nacho | |
285 | 2183 | fernando | tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
286 | tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
||
287 | 4377 | nacho | |
288 | 2183 | fernando | EnhancedPanel ep = this.getEnhancedPanel();
|
289 | 2706 | nacho | ep.lLineal.setText(PluginServices.getText(this,"lineal_directo")); |
290 | ep.lQueue.setText(PluginServices.getText(this,"recorte_colas")); |
||
291 | ep.lWithoutEnhanced.setText(PluginServices.getText(this,"sin_realce")); |
||
292 | ep.lCut.setText("% "+PluginServices.getText(this,"recorte")); |
||
293 | ep.lRemove.setText(PluginServices.getText(this,"eliminar_extremos")); |
||
294 | 2183 | fernando | |
295 | //Recorremos los Tab y traducimos el nombre
|
||
296 | for(int i=0;i<this.getTab().getTabCount();i++){ |
||
297 | if(this.getTab().getTitleAt(i).equals("Info")) |
||
298 | 2532 | nacho | this.getTab().setTitleAt(i,PluginServices.getText(this,"info")); |
299 | 2183 | fernando | if(this.getTab().getTitleAt(i).equals("Transparencia")) |
300 | this.getTab().setTitleAt(i,PluginServices.getText(this,"Transparencia")); |
||
301 | if(this.getTab().getTitleAt(i).equals("Bandas")) |
||
302 | 2532 | nacho | this.getTab().setTitleAt(i,PluginServices.getText(this,"bandas")); |
303 | 2183 | fernando | if(this.getTab().getTitleAt(i).equals("Realce")) |
304 | this.getTab().setTitleAt(i,PluginServices.getText(this,"realce")); |
||
305 | } |
||
306 | 2532 | nacho | |
307 | this.getAcceptButton().setText(PluginServices.getText(this,"Aceptar")); |
||
308 | this.getApplyButton().setText(PluginServices.getText(this,"Aplicar")); |
||
309 | this.getCancelButton().setText(PluginServices.getText(this,"Cancelar")); |
||
310 | 4236 | nacho | |
311 | this.getSharpeningPanel().getCbActiveSharpening().setText(PluginServices.getText(this,"onSharpening")); |
||
312 | this.getSharpeningPanel().getPSharpNorth().setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"selectBandaRefinado"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
313 | 2183 | fernando | } |
314 | |||
315 | /**
|
||
316 | * Asigna un FLayerRaster
|
||
317 | * @param layer capa a asignar
|
||
318 | */
|
||
319 | public void setFLyrRaster(FLyrRaster layer){ |
||
320 | fLayer = layer; |
||
321 | } |
||
322 | |||
323 | /**
|
||
324 | * Constructor de la ventana de dialogo.
|
||
325 | */
|
||
326 | public PropertiesRasterDialog() {
|
||
327 | initialize(); |
||
328 | } |
||
329 | |||
330 | /**
|
||
331 | * Carga los datos del panel info.
|
||
332 | */
|
||
333 | private void loadInfoData(){ |
||
334 | if(fLayer.getSource()!=null){ |
||
335 | props = new Object[nprops][2]; |
||
336 | 2233 | igbrotru | props[0][0] = new String(PluginServices.getText(this,"Fichero")+":"); |
337 | 2183 | fernando | props[0][1] = filename; |
338 | 2233 | igbrotru | props[1][0] = new String(PluginServices.getText(this,"num_bandas")+":"); |
339 | 2183 | fernando | props[1][1] = new String(String.valueOf(fLayer.getSource().getNumBands())); |
340 | 2233 | igbrotru | props[2][0] = new String(PluginServices.getText(this,"ancho_alto")+":"); |
341 | 2183 | fernando | props[2][1] = this.width+" X "+this.height; |
342 | 2233 | igbrotru | props[3][0] = new String(PluginServices.getText(this,"formato")+":"); |
343 | 2183 | fernando | props[3][1] = filename.substring( |
344 | filename.lastIndexOf('.')+1, |
||
345 | filename.length()); |
||
346 | 2233 | igbrotru | props[4][0] = new String(PluginServices.getText(this,"tipo_dato")+":"); |
347 | 2183 | fernando | String type = null; |
348 | switch(fLayer.getSource().getDataType()){
|
||
349 | case 0: type = new String("BYTE");break; |
||
350 | case 1: type = new String("USHORT");break; |
||
351 | case 2: type = new String("SHORT");break; |
||
352 | case 3: type = new String("INT");break; |
||
353 | case 4: type = new String("FLOAT");break; |
||
354 | case 5: type = new String("DOUBLE");break; |
||
355 | default: type = new String("UNDEFINED");break; |
||
356 | } |
||
357 | props[4][1] = type; |
||
358 | props[5][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
||
359 | 2233 | igbrotru | props[6][0] = new String(PluginServices.getText(this,"xmin")+":"); |
360 | 2183 | fernando | props[6][1] = String.valueOf(fLayer.getSource().getFullExtent().getMinX()); |
361 | 2233 | igbrotru | props[7][0] = new String(PluginServices.getText(this,"ymin")+":"); |
362 | 2183 | fernando | props[7][1] = String.valueOf(fLayer.getSource().getFullExtent().getMinY()); |
363 | 2233 | igbrotru | props[8][0] = new String(PluginServices.getText(this,"xmax")+":"); |
364 | 2183 | fernando | props[8][1] = String.valueOf(fLayer.getSource().getFullExtent().getMaxX()); |
365 | 2233 | igbrotru | props[9][0] = new String(PluginServices.getText(this,"ymax")+":"); |
366 | 2183 | fernando | props[9][1] = String.valueOf(fLayer.getSource().getFullExtent().getMaxY()); |
367 | |||
368 | }else{
|
||
369 | props = new Object[1][2]; |
||
370 | props[0][0] = new String("No props"); |
||
371 | props[0][1] = new String("-"); |
||
372 | } |
||
373 | |||
374 | } |
||
375 | |||
376 | 2233 | igbrotru | /**
|
377 | * A?ade bandas al contador de bandas del FilterRasterDialogPanel
|
||
378 | * @param numBands N?mero de bandas a a?adir
|
||
379 | */
|
||
380 | 2183 | fernando | public void addNumBands(int numBands){ |
381 | nbands += numBands; |
||
382 | 4377 | nacho | /*if(this.getTransparencyPanel() != null && this.getTransparencyPanel().getTRojo().isEnabled())
|
383 | this.getTransparencyPanel().setActiveTransparencyControl(true); */
|
||
384 | 2183 | fernando | } |
385 | |||
386 | /**
|
||
387 | * Inicializa el jDialog
|
||
388 | */
|
||
389 | private void initialize() { |
||
390 | |||
391 | //this.setLayout(new FlowLayout());
|
||
392 | |||
393 | setName("filterRaster");
|
||
394 | ArrayList attr = ((FLyrRaster)fLayer).getSource().getAttributes();
|
||
395 | for (int i=0; i<attr.size(); i++) { |
||
396 | Object[] a = (Object []) attr.get(i); |
||
397 | if(a[0].toString().equals("Filename")) |
||
398 | filename = a[1].toString();
|
||
399 | if(a[0].toString().equals("Filesize")) |
||
400 | filesize = ((Long)a[1]).intValue(); |
||
401 | if(a[0].toString().equals("Width")) |
||
402 | width = ((Integer)a[1]).intValue(); |
||
403 | if(a[0].toString().equals("Height")) |
||
404 | height = ((Integer)a[1]).intValue(); |
||
405 | } |
||
406 | |||
407 | this.loadInfoData();
|
||
408 | super.init(props);
|
||
409 | 2233 | igbrotru | |
410 | this.getInfoPanel().columnNames[0] = PluginServices.getText(this,"propiedad"); |
||
411 | this.getInfoPanel().columnNames[1] = PluginServices.getText(this,"Valor"); |
||
412 | this.getInfoPanel().resetTable();
|
||
413 | this.getInfoPanel().initialize();
|
||
414 | |||
415 | 2183 | fernando | //this.add(getContentPane());
|
416 | |||
417 | this.setSize(this.sizeX, this.sizeY); |
||
418 | |||
419 | //contentPane.getAcceptButton().setEnabled(false);
|
||
420 | this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
||
421 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
422 | acceptButtonActionPerformed(evt); |
||
423 | //Solo cuando le damos a aceptar guardamos la situaci?n actual de los
|
||
424 | //ficheros cargados en el StatusLayerRaster
|
||
425 | if(rasterStatus!=null){ |
||
426 | ArrayList rs = new ArrayList(); |
||
427 | for(int i=0;i<fLayer.getSource().getFiles().length;i++) |
||
428 | rs.add(fLayer.getSource().getFiles()[i].getName()); |
||
429 | rasterStatus.files = rs; |
||
430 | } |
||
431 | closeJDialog(); |
||
432 | } |
||
433 | }); |
||
434 | this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
||
435 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
436 | cancelButtonActionPerformed(evt); |
||
437 | closeJDialog(); |
||
438 | } |
||
439 | }); |
||
440 | this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
||
441 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
442 | acceptButtonActionPerformed(evt); |
||
443 | } |
||
444 | }); |
||
445 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonAdd().addActionListener(new java.awt.event.ActionListener() { |
446 | 2183 | fernando | public void actionPerformed(java.awt.event.ActionEvent evt){ |
447 | addFileBand(evt); |
||
448 | |||
449 | } |
||
450 | }); |
||
451 | 2706 | nacho | this.getBandSetup().getFileList().getJButtonRemove().addActionListener(new java.awt.event.ActionListener() { |
452 | 2183 | fernando | public void actionPerformed(java.awt.event.ActionEvent evt){ |
453 | delFileBand(evt); |
||
454 | } |
||
455 | }); |
||
456 | |||
457 | |||
458 | } |
||
459 | |||
460 | /**
|
||
461 | * Salva el estado inicial por si se cancela
|
||
462 | */
|
||
463 | public void readStat(){ |
||
464 | status = new Status(((FilterRasterDialogPanel)this).getTransparencyPanel().getOpacityText().getText(), |
||
465 | getAssignedBand(GeoRasterFile.RED_BAND), |
||
466 | getAssignedBand(GeoRasterFile.GREEN_BAND), |
||
467 | getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
468 | } |
||
469 | |||
470 | /**
|
||
471 | * This method initializes jContentPane
|
||
472 | */
|
||
473 | public Container getContentPane() { |
||
474 | return this; |
||
475 | } |
||
476 | |||
477 | /**
|
||
478 | * Asigna una proyecci?n
|
||
479 | * @param prj
|
||
480 | */
|
||
481 | public void setProjection(IProjection prj) { |
||
482 | this.currentProjection = prj;
|
||
483 | } |
||
484 | |||
485 | public void closeJDialog() { |
||
486 | PluginServices.getMDIManager().closeView(PropertiesRasterDialog.this); |
||
487 | } |
||
488 | |||
489 | /**
|
||
490 | * Asigna el RasterFilterStackManager
|
||
491 | * @param stackManager
|
||
492 | */
|
||
493 | public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
||
494 | this.stackManager = stackManager;
|
||
495 | stackManager.resetTempFilters(); |
||
496 | } |
||
497 | |||
498 | /**
|
||
499 | *
|
||
500 | * @param flag
|
||
501 | * @return
|
||
502 | */
|
||
503 | public int getAssignedBand(int flag) { |
||
504 | return this.getBandSetup().getAssignedBand(flag); |
||
505 | } |
||
506 | |||
507 | /**
|
||
508 | 2365 | igbrotru | * Obtiene las bandas que el usuario ha seleccionado que son visibles.
|
509 | * Devuelve una cadena: RGB, R, G, B, RG, RB, GB
|
||
510 | * @return Bandas visibles
|
||
511 | */
|
||
512 | public String getVisibleBands(){ |
||
513 | return this.getBandSetup().getFileList().getJComboBox().getSelectedItem().toString(); |
||
514 | } |
||
515 | |||
516 | /**
|
||
517 | 2183 | fernando | * Pulsar aceptar con el panel de bandas seleccionado hace que se procesen los valores
|
518 | * introducidos en este.
|
||
519 | * @return true si estaba seleccionado el panel de bandas y se ha procesado la
|
||
520 | * acci?n y false si no lo estaba.
|
||
521 | */
|
||
522 | 3581 | nacho | public void processBandPanel(){ |
523 | 2654 | nacho | //if(this.getTab().getSelectedComponent() == this.getBandSetup()){
|
524 | fLayer.getSource().setBand(GeoRasterFile.RED_BAND, |
||
525 | getAssignedBand(GeoRasterFile.RED_BAND)); |
||
526 | fLayer.getSource().setBand(GeoRasterFile.GREEN_BAND, |
||
527 | getAssignedBand(GeoRasterFile.GREEN_BAND)); |
||
528 | fLayer.getSource().setBand(GeoRasterFile.BLUE_BAND, |
||
529 | getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
530 | rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
||
531 | rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
||
532 | rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
||
533 | 2365 | igbrotru | |
534 | 2654 | nacho | //Comprobamos si hay alguna banda que no est? asignada y aplicamos el filtro
|
535 | StringBuffer sb = new StringBuffer(); |
||
536 | if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
||
537 | sb.append("R");
|
||
538 | if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
||
539 | sb.append("G");
|
||
540 | if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
||
541 | sb.append("B");
|
||
542 | 2365 | igbrotru | |
543 | 2654 | nacho | if(!sb.toString().equals("")) |
544 | stackManager.addRemoveBands(sb.toString()); |
||
545 | else
|
||
546 | stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
||
547 | 3581 | nacho | |
548 | //Al reasignar las bandas tenemos que tenerlo en cuenta en el sharpening
|
||
549 | RasterFilter sharp = stackManager.getFilter("sharpening");
|
||
550 | if(sharp != null){ |
||
551 | int[] order = {getAssignedBand(GeoRasterFile.RED_BAND),getAssignedBand(GeoRasterFile.GREEN_BAND),getAssignedBand(GeoRasterFile.BLUE_BAND)}; |
||
552 | sharp.removeParam("order");
|
||
553 | sharp.addParam("order", order);
|
||
554 | } |
||
555 | 2654 | nacho | fLayer.getFMap().invalidate(); |
556 | 2183 | fernando | } |
557 | |||
558 | /**
|
||
559 | * Pulsar aceptar con el panel de transparecias seleccionado hace que se procesen los valores
|
||
560 | * introducidos en este.
|
||
561 | * @return true si estaba seleccionado el panel de transparencias y se ha procesado la
|
||
562 | * acci?n y false si no lo estaba.
|
||
563 | */
|
||
564 | 3581 | nacho | public void processTransparencyPanel(){ |
565 | 2654 | nacho | //OPACIDAD
|
566 | String sOpac = this.getTransparencyPanel().getOpacityText().getText(); |
||
567 | if(!sOpac.equals("") && this.getTransparencyPanel().getOpacityCheck().isSelected()){ |
||
568 | int opac = Integer.parseInt(sOpac); |
||
569 | opac = (int)((opac*255)/100); |
||
570 | fLayer.getSource().setTransparency(true);
|
||
571 | fLayer.setTransparency(255-opac);
|
||
572 | rasterStatus.transparency = 255-opac;
|
||
573 | }else{
|
||
574 | fLayer.getSource().setTransparency(false);
|
||
575 | fLayer.setTransparency(0);
|
||
576 | rasterStatus.transparency = 0;
|
||
577 | 2183 | fernando | } |
578 | |||
579 | 2654 | nacho | //TRANSPARENCIA
|
580 | 4377 | nacho | if( this.getTransparencyPanel().getTransparencyCheck().isSelected()){ |
581 | stackManager.addTransparencyFilter( getTransparencyPanel().getPTranspByPixel().getEntries(), |
||
582 | 2654 | nacho | 0x10, //Transparencia |
583 | 0xff, //Color Transparencia R |
||
584 | 0xff, //Color Transparencia G |
||
585 | 0xff); //Color Transparencia B |
||
586 | }else{
|
||
587 | fLayer.getSource().getFilterStack().removeFilter(stackManager.getTypeFilter("transparency"));
|
||
588 | } |
||
589 | 3581 | nacho | |
590 | 2183 | fernando | } |
591 | |||
592 | /**
|
||
593 | * Pulsar aceptar con el panel de realce seleccionado hace que se procesen los valores
|
||
594 | * introducidos en este.
|
||
595 | * @return true si estaba seleccionado el panel de realce y se ha procesado la
|
||
596 | * acci?n y false si no lo estaba.
|
||
597 | */
|
||
598 | 3581 | nacho | public void processEnhancedPanel(){ |
599 | 2654 | nacho | //Filtro lineal seleccionado
|
600 | if( this.getEnhancedPanel().getLinealDirectoRadioButton().isSelected()){ |
||
601 | if( this.getEnhancedPanel().getRemoveCheck().isSelected() && |
||
602 | !this.getEnhancedPanel().getTailCheck().isSelected())
|
||
603 | stackManager.addEnhancedFilter(true, fLayer.getSource().getFiles()[0].getName()); |
||
604 | else
|
||
605 | stackManager.addEnhancedFilter(false, fLayer.getSource().getFiles()[0].getName()); |
||
606 | 2183 | fernando | |
607 | 2654 | nacho | //Recorte de colas seleccionado
|
608 | if(this.getEnhancedPanel().getTailCheck().isSelected()){ |
||
609 | 2183 | fernando | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
610 | 2654 | nacho | double recorte = Double.parseDouble(this.getEnhancedPanel().getTailText().getText())/100; |
611 | if(this.getEnhancedPanel().getRemoveCheck().isSelected()) |
||
612 | stackManager.addTailFilter( recorte, 0D, true); |
||
613 | else
|
||
614 | stackManager.addTailFilter( recorte, 0D, false); |
||
615 | }else{
|
||
616 | 2183 | fernando | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
617 | 2654 | nacho | stackManager.addComputeMinMaxFilter(); |
618 | } |
||
619 | } |
||
620 | 2183 | fernando | |
621 | 2654 | nacho | //Sin filtro lineal seleccionado
|
622 | if(this.getEnhancedPanel().getSinRealceRadioButton().isSelected()){ |
||
623 | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
||
624 | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
||
625 | stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
||
626 | 2183 | fernando | } |
627 | 2654 | nacho | fLayer.getFMap().invalidate(); |
628 | 3581 | nacho | } |
629 | |||
630 | /**
|
||
631 | * Pulsar aceptar hace que se procesen los valores introducidos en el panel de
|
||
632 | * sharpening.
|
||
633 | * @return true
|
||
634 | */
|
||
635 | public void processSharpeningPanel(){ |
||
636 | if(this.getSharpeningPanel().getCbActiveSharpening().isSelected()){ |
||
637 | String pancr = null; |
||
638 | 2654 | nacho | |
639 | 3581 | nacho | //Obtenemos el nombre de la banda seleccionada
|
640 | for(int i=0;i<(getSharpeningPanel().getRGBTable()).getRowCount();i++){ |
||
641 | if(((Boolean) (getSharpeningPanel().getRGBTable()).getValueAt(i, 0)).booleanValue()) |
||
642 | pancr = ((String) (getSharpeningPanel().getRGBTable()).getValueAt(i, 1)); |
||
643 | } |
||
644 | |||
645 | //Buscamos el GeoRasterFile que corresponde a la capa y a?adimos el filtro con el
|
||
646 | if(pancr!=null){ |
||
647 | pancr = pancr.substring(pancr.lastIndexOf("] ") + 2, pancr.length()); |
||
648 | for(int i=0; i<fLayer.getSource().getFiles().length;i++){ |
||
649 | 4236 | nacho | if(fLayer.getSource().getFiles()[i].getName().endsWith(File.separator+pancr)){ |
650 | 3581 | nacho | int[] order = {getAssignedBand(GeoRasterFile.RED_BAND),getAssignedBand(GeoRasterFile.GREEN_BAND),getAssignedBand(GeoRasterFile.BLUE_BAND)}; |
651 | |||
652 | int opac = Integer.parseInt(this.getTransparencyPanel().getOpacityText().getText()); |
||
653 | opac = (int)((opac*255)/100); |
||
654 | |||
655 | String method = "brovey"; |
||
656 | if(getSharpeningPanel().getRbHSL().isSelected())
|
||
657 | method = "hsl";
|
||
658 | |||
659 | double coef = 0D; |
||
660 | if(getSharpeningPanel().getRbHSL().isSelected())
|
||
661 | coef = Double.parseDouble(pSharp.getJTextField().getText());
|
||
662 | |||
663 | int coefBrovey = 0; |
||
664 | if(getSharpeningPanel().getRbBrovey().isSelected())
|
||
665 | coefBrovey = Integer.parseInt(pSharp.getJTextField1().getText());
|
||
666 | |||
667 | stackManager.addSharpeningFilter(fLayer.getSource().getFiles(), i, order, opac, method, coef, coefBrovey); |
||
668 | } |
||
669 | } |
||
670 | |||
671 | } |
||
672 | }else{
|
||
673 | stackManager.removeFilter(stackManager.getTypeFilter("sharpening"));
|
||
674 | } |
||
675 | fLayer.getFMap().invalidate(); |
||
676 | 2183 | fernando | } |
677 | |||
678 | /**
|
||
679 | * Gestiona la acci?n cuando se pulsa aplicar/aceptar o aplicar en el control
|
||
680 | * de propiedades de raster
|
||
681 | * @param e
|
||
682 | */
|
||
683 | private void acceptButtonActionPerformed(ActionEvent e) { |
||
684 | this.processBandPanel();
|
||
685 | this.processTransparencyPanel();
|
||
686 | 3581 | nacho | this.processEnhancedPanel();
|
687 | this.processSharpeningPanel();
|
||
688 | 2183 | fernando | } |
689 | |||
690 | /**
|
||
691 | * A?ade una banda al raster
|
||
692 | * @param e
|
||
693 | */
|
||
694 | private void addFileBand(ActionEvent e){ |
||
695 | String[] driverNames = null; |
||
696 | String rasterDriver = null; |
||
697 | |||
698 | //Creaci?n del dialogo para selecci?n de ficheros
|
||
699 | |||
700 | fileChooser = new JFileChooser(lastPath); |
||
701 | fileChooser.setMultiSelectionEnabled(true);
|
||
702 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
703 | try {
|
||
704 | driverNames = LayerFactory.getDM().getDriverNames(); |
||
705 | FileFilter defaultFileFilter = null, auxF; |
||
706 | for (int i = 0; i < driverNames.length; i++) { |
||
707 | |||
708 | if (driverNames[i].endsWith("gvSIG Image Driver")){ |
||
709 | rasterDriver = driverNames[i]; |
||
710 | auxF = new DriverFileFilter(driverNames[i]);
|
||
711 | fileChooser.addChoosableFileFilter(auxF); |
||
712 | defaultFileFilter = auxF; |
||
713 | } |
||
714 | } |
||
715 | } catch (DriverLoadException e1) {
|
||
716 | NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
||
717 | } |
||
718 | int result = fileChooser.showOpenDialog(PropertiesRasterDialog.this);
|
||
719 | |||
720 | if(result == JFileChooser.APPROVE_OPTION){ |
||
721 | File[] files = fileChooser.getSelectedFiles(); |
||
722 | FileFilter filter = fileChooser.getFileFilter();
|
||
723 | BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
||
724 | lastPath = files[0].getPath();
|
||
725 | |||
726 | //Lo a?adimos a la capa si no esta
|
||
727 | |||
728 | Vector v = new Vector(); |
||
729 | for(int i=0;i<files.length;i++){ |
||
730 | |||
731 | //Comprobamos que el fichero no est?
|
||
732 | boolean exist = false; |
||
733 | for(int j=0;j<fLayer.getSource().getFiles().length;j++){ |
||
734 | if(fLayer.getSource().getFiles()[j].getName().endsWith(files[i].getName()))
|
||
735 | exist = true;
|
||
736 | } |
||
737 | if(!exist){
|
||
738 | try{
|
||
739 | Rectangle2D extentOrigin = fLayer.getFullExtent();
|
||
740 | |||
741 | GeoRasterFile geoRasterFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()); |
||
742 | Extent extentNewFile = geoRasterFile.getExtent(); |
||
743 | nbands += geoRasterFile.getBandCount(); |
||
744 | |||
745 | //Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
||
746 | //fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
||
747 | |||
748 | double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
||
749 | double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
||
750 | |||
751 | if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
||
752 | (widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
||
753 | (heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
||
754 | (heightNewFile-extentOrigin.getHeight()) < -1.0){
|
||
755 | JOptionPane.showMessageDialog( null, |
||
756 | PluginServices.getText(this, "extents_no_coincidentes"), |
||
757 | "",
|
||
758 | JOptionPane.ERROR_MESSAGE);
|
||
759 | return;
|
||
760 | } |
||
761 | |||
762 | if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
||
763 | (extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
||
764 | JOptionPane.showMessageDialog(null, |
||
765 | PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
||
766 | return;
|
||
767 | } |
||
768 | |||
769 | }catch(Exception exc){ |
||
770 | exc.printStackTrace(); |
||
771 | } |
||
772 | |||
773 | //Lo a?adimos a la capa
|
||
774 | fLayer.addFiles(files[i].getAbsolutePath()); |
||
775 | //Mantiene la lista de ficheros a?adidos por si se cancela
|
||
776 | status.addFile(files[i].getAbsolutePath()); |
||
777 | |||
778 | |||
779 | }else{
|
||
780 | JOptionPane.showMessageDialog(null, |
||
781 | PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
||
782 | } |
||
783 | } |
||
784 | |||
785 | //A?adimos los georasterfile a la tabla del Panel
|
||
786 | |||
787 | v = new Vector(); |
||
788 | for(int i=0;i<fLayer.getSource().getFiles().length;i++){ |
||
789 | boolean exist = false; |
||
790 | for(int j=0;j<bandSetup.getNBands();j++){ |
||
791 | if(fLayer.getSource().getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
||
792 | exist = true;
|
||
793 | } |
||
794 | if(!exist)
|
||
795 | v.add(fLayer.getSource().getFiles()[i]); |
||
796 | } |
||
797 | |||
798 | 3581 | nacho | grf = new GeoRasterFile[v.size()];
|
799 | 2183 | fernando | for(int i=0;i<grf.length;i++){ |
800 | grf[i] = (GeoRasterFile)v.get(i); |
||
801 | } |
||
802 | 3581 | nacho | this.addFiles(grf);
|
803 | 2183 | fernando | } |
804 | } |
||
805 | |||
806 | /**
|
||
807 | 3581 | nacho | * Asigna la lista de GeoRasterFile
|
808 | * @return
|
||
809 | */
|
||
810 | public void setGeoRasterFile(GeoRasterFile[] grf){ |
||
811 | this.grf = grf;
|
||
812 | } |
||
813 | |||
814 | /**
|
||
815 | 2183 | fernando | * Elimina una banda del raster. Si queda solo un fichero o no se ha
|
816 | * seleccionado ninguna banda no hace nada.
|
||
817 | * @param e
|
||
818 | */
|
||
819 | private void delFileBand(ActionEvent e){ |
||
820 | BandSetupPanel bandSetup = ((FilterRasterDialogPanel)this.getContentPane()).getBandSetup();
|
||
821 | |||
822 | if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
||
823 | bandSetup.getFileList().getNFiles() > 1){
|
||
824 | String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
||
825 | GeoRasterFile geoRasterFile = GeoRasterFile.openFile(fLayer.getProjection(), pathName); |
||
826 | nbands -= geoRasterFile.getBandCount(); |
||
827 | fLayer.delFile(pathName); |
||
828 | String file = pathName.substring(pathName.lastIndexOf("/")+1); |
||
829 | file = file.substring(file.lastIndexOf("\\")+1); |
||
830 | 3581 | nacho | this.removeFile(file);
|
831 | 2183 | fernando | |
832 | //Mantiene la lista de ficheros eliminados por si se cancela
|
||
833 | status.removeFile(pathName); |
||
834 | } |
||
835 | } |
||
836 | |||
837 | /**
|
||
838 | * El bot?n de cancelar recupera el estado anterior a la apertura de
|
||
839 | * este dialogo.
|
||
840 | * @param e Evento
|
||
841 | */
|
||
842 | private void cancelButtonActionPerformed(ActionEvent e) { |
||
843 | this.status.restoreStatus(this); |
||
844 | fLayer.getFMap().invalidate(); |
||
845 | } |
||
846 | |||
847 | /**
|
||
848 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
849 | */
|
||
850 | public ViewInfo getViewInfo() {
|
||
851 | ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
852 | m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
||
853 | return m_viewinfo;
|
||
854 | } |
||
855 | } |