root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / dialog / WCSRasterPropsDialog.java @ 6877
History | View | Annotate | Download (29 KB)
1 | 4505 | jaume | /*
|
---|---|---|---|
2 | * Creado el 7-marzo-2005
|
||
3 | */
|
||
4 | package com.iver.cit.gvsig.gui.dialog; |
||
5 | |||
6 | import java.awt.Container; |
||
7 | import java.awt.event.ActionEvent; |
||
8 | 5769 | maquerol | import java.awt.event.ActionListener; |
9 | 5534 | nacho | import java.awt.event.KeyEvent; |
10 | import java.awt.event.KeyListener; |
||
11 | import java.awt.event.MouseEvent; |
||
12 | import java.awt.event.MouseListener; |
||
13 | 4505 | jaume | import java.awt.geom.Rectangle2D; |
14 | import java.io.File; |
||
15 | import java.util.ArrayList; |
||
16 | import java.util.Vector; |
||
17 | |||
18 | import javax.swing.JFileChooser; |
||
19 | import javax.swing.JOptionPane; |
||
20 | import javax.swing.JPanel; |
||
21 | import javax.swing.filechooser.FileFilter; |
||
22 | |||
23 | import org.cresques.cts.IProjection; |
||
24 | 5980 | nacho | import org.cresques.filter.RasterFilterStackManager; |
25 | import org.cresques.filter.BrightnessContrast.BrightnessContrastStackManager; |
||
26 | 4505 | jaume | import org.cresques.io.GeoRasterFile; |
27 | import org.cresques.px.Extent; |
||
28 | import org.cresques.px.PxRaster; |
||
29 | 5534 | nacho | import org.cresques.ui.BrightnessContrast.EnhancedBrightnessContrastPanel; |
30 | 4505 | jaume | import org.cresques.ui.raster.BandSetupPanel; |
31 | import org.cresques.ui.raster.FilterRasterDialogPanel; |
||
32 | 6208 | maquerol | import org.cresques.ui.raster.InfoPanel; |
33 | 4505 | jaume | import org.cresques.ui.raster.RasterTransparencyPanel; |
34 | |||
35 | import com.hardcode.driverManager.Driver; |
||
36 | import com.hardcode.driverManager.DriverLoadException; |
||
37 | import com.iver.andami.PluginServices; |
||
38 | import com.iver.andami.messages.NotificationManager; |
||
39 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
40 | 4505 | jaume | import com.iver.andami.ui.mdiManager.ViewInfo; |
41 | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
||
42 | import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
||
43 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
44 | import com.iver.cit.gvsig.fmap.layers.StatusLayerRaster; |
||
45 | |||
46 | /**
|
||
47 | * <P>
|
||
48 | * Dialog for the properties of a WCS layer. It manages the avants and aplies
|
||
49 | * filters to the raster through the filter stack manager according to the user's
|
||
50 | * selection. This dialog contains some panels.
|
||
51 | * </P>
|
||
52 | * <UL>
|
||
53 | * <LI>Propierties</LI>
|
||
54 | * <LI>Band selection</LI>
|
||
55 | * <LI>Transparency</LI>
|
||
56 | * <LI>Enhancement</LI>
|
||
57 | * </UL>
|
||
58 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
59 | */
|
||
60 | 6877 | cesar | public class WCSRasterPropsDialog extends FilterRasterDialogPanel implements IWindow, MouseListener, KeyListener, ActionListener{ |
61 | 4505 | jaume | |
62 | private FilterRasterDialogPanel contentPane = null; |
||
63 | private JPanel propPanel = null; |
||
64 | private IProjection currentProjection = null; |
||
65 | private FLyrWCS fLayer = null; |
||
66 | 6208 | maquerol | private static final int nprops = 13; |
67 | 4505 | jaume | private Object[][] props = null; |
68 | private RasterFilterStackManager stackManager = null; |
||
69 | private Status status = null; |
||
70 | private StatusLayerRaster rasterStatus = null; |
||
71 | private JFileChooser fileChooser = null; |
||
72 | private String lastPath = new String("./"); |
||
73 | private PxRaster px = null; |
||
74 | private GeoRasterFile grf = null; |
||
75 | |||
76 | /**
|
||
77 | * Class that holds the dialog state and restores the initial state if it
|
||
78 | * is cancelled.
|
||
79 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
80 | */
|
||
81 | class Status{ |
||
82 | public String inicAlpha; |
||
83 | public int bandR; |
||
84 | public int bandG; |
||
85 | public int bandB; |
||
86 | private ArrayList filters = new ArrayList(); |
||
87 | |||
88 | public Status(String alpha, int bandR, int bandG, int bandB){ |
||
89 | this.inicAlpha = alpha;
|
||
90 | this.bandR = bandR;
|
||
91 | this.bandG = bandG;
|
||
92 | this.bandB = bandB;
|
||
93 | filters = stackManager.getStringsFromStack(); |
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * Restaura el Estado salvado
|
||
98 | * @param status Estado
|
||
99 | */
|
||
100 | public void restoreStatus(WCSRasterPropsDialog props){ |
||
101 | //Devolvemos la pila de filtros al estado inicial
|
||
102 | /*if(stackManager != null)
|
||
103 | stackManager.deleteTempFilters();*/
|
||
104 | |||
105 | //Devolvemos el alpha al estado inicial
|
||
106 | int opac = Integer.parseInt(status.inicAlpha); |
||
107 | opac = (int)((opac*255)/100); |
||
108 | fLayer.setTransparency(255-opac);
|
||
109 | |||
110 | if (fLayer != null) { |
||
111 | fLayer.setBandR(bandR); |
||
112 | fLayer.setBandG(bandG); |
||
113 | fLayer.setBandB(bandB); |
||
114 | } |
||
115 | |||
116 | //Restauramos los filtros
|
||
117 | if(filters!=null) |
||
118 | stackManager.createStackFromStrings(filters); |
||
119 | |||
120 | fLayer.getFMap().invalidate(); |
||
121 | |||
122 | } |
||
123 | } |
||
124 | |||
125 | public class DriverFileFilter extends FileFilter{ |
||
126 | |||
127 | private Driver driver; |
||
128 | |||
129 | public DriverFileFilter(String driverName) throws DriverLoadException{ |
||
130 | driver = LayerFactory.getDM().getDriver(driverName); |
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||
135 | */
|
||
136 | public boolean accept(File f) { |
||
137 | if (f.isDirectory()) return true; |
||
138 | if (driver instanceof RasterDriver){ |
||
139 | return ((RasterDriver) driver).fileAccepted(f);
|
||
140 | }else{
|
||
141 | throw new RuntimeException("Tipo no reconocido"); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * @see javax.swing.filechooser.FileFilter#getDescription()
|
||
147 | */
|
||
148 | public String getDescription() { |
||
149 | return ((Driver) driver).getName(); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * Dialog window constructor.
|
||
155 | *
|
||
156 | * @param app
|
||
157 | */
|
||
158 | public WCSRasterPropsDialog(FLyrWCS layer, ArrayList ranges){ |
||
159 | super();
|
||
160 | fLayer = layer; |
||
161 | this.px = layer.getPxRaster();
|
||
162 | this.grf = layer.getGeoRasterFile();
|
||
163 | if(fLayer.getStatus()==null){ |
||
164 | rasterStatus = new StatusLayerRaster();
|
||
165 | fLayer.setStatus(rasterStatus); |
||
166 | }else
|
||
167 | rasterStatus = (StatusLayerRaster)fLayer.getStatus(); |
||
168 | init(); |
||
169 | this.setRanges(ranges);
|
||
170 | FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
||
171 | 4578 | nacho | BandSetupPanel bandSetup = (BandSetupPanel)fr.getPanelByClassName("BandSetupPanel");
|
172 | bandSetup.getFileList().getJButtonAdd().setEnabled(false);
|
||
173 | bandSetup.getFileList().getJButtonRemove().setEnabled(false);
|
||
174 | 4505 | jaume | this.setTranslation();
|
175 | |||
176 | 5534 | nacho | EnhancedBrightnessContrastPanel ep = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
177 | ep.lstBrightness.getJSlider().addMouseListener(this);
|
||
178 | ep.lstContrast.getJSlider().addMouseListener(this);
|
||
179 | ep.getCheckSliderText().getJTextField().addKeyListener(this);
|
||
180 | 5769 | maquerol | ep.getLabelSliderText().getJTextField().addActionListener(this);
|
181 | ep.getLabelSliderText1().getJTextField().addActionListener(this);
|
||
182 | 4505 | jaume | } |
183 | |||
184 | /**
|
||
185 | * Asigna los textos a los paneles
|
||
186 | */
|
||
187 | private void setTranslation(){ |
||
188 | 4578 | nacho | FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
189 | BandSetupPanel bandSetup = (BandSetupPanel)fr.getPanelByClassName("BandSetupPanel");
|
||
190 | bandSetup.getFileList().getJButtonAdd().setText(PluginServices.getText(this,"Anadir")); |
||
191 | bandSetup.getFileList().getJButtonRemove().setText(PluginServices.getText(this,"Eliminar")); |
||
192 | bandSetup.getFileList().lbandasVisibles.setText(PluginServices.getText(this,"bandas")); |
||
193 | 4505 | jaume | |
194 | 4578 | nacho | RasterTransparencyPanel tpan = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
195 | |||
196 | 4505 | jaume | tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
197 | tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
||
198 | 5534 | nacho | |
199 | EnhancedBrightnessContrastPanel ep = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
200 | 4505 | jaume | |
201 | 5534 | nacho | ep.lLineal.setText(PluginServices.getText(this, "lineal_directo")); |
202 | ep.lRemove.setText(PluginServices.getText(this, "eliminar_extremos")); |
||
203 | ep.cstEnhanced.setName(PluginServices.getText(this, "recorte_colas")+" ( % )"); |
||
204 | ep.lBrightC.setText(PluginServices.getText(this, "brillo_y_contraste")); |
||
205 | ep.lstBrightness.setName(PluginServices.getText(this, "brillo")); |
||
206 | ep.lstContrast.setName(PluginServices.getText(this, "contraste")); |
||
207 | ep.lpreview.setText(PluginServices.getText(this, "previsualizacion")); |
||
208 | ep.getPBrightCont().setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1), (PluginServices.getText(this, "brillo_y_contraste")), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black)); |
||
209 | ep.getPEnhanced().setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1), (PluginServices.getText(this, "realce")), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black)); |
||
210 | |||
211 | 6208 | maquerol | InfoPanel ip = (InfoPanel)super.getPanelByClassName("InfoPanel"); |
212 | 5534 | nacho | |
213 | 6208 | maquerol | ip.cabInfo = new String(PluginServices.getText(this, "Informacion")); |
214 | ip.cabCoord = new String(PluginServices.getText(this, "coor_geograficas")); |
||
215 | ip.cabProy = new String(PluginServices.getText(this, "Proyecciones")); |
||
216 | ip.cabOrig = new String(PluginServices.getText(this, "origen_de_datos")); |
||
217 | 6249 | maquerol | ip.cabMeta = new String(PluginServices.getText(this, "metadatos")); |
218 | 6208 | maquerol | ip.refresh(); |
219 | |||
220 | |||
221 | |||
222 | 4505 | jaume | //Recorremos los Tab y traducimos el nombre
|
223 | for(int i=0;i<this.getTab().getTabCount();i++){ |
||
224 | if(this.getTab().getTitleAt(i).equals("Info")) |
||
225 | this.getTab().setTitleAt(i,PluginServices.getText(this,"info")); |
||
226 | if(this.getTab().getTitleAt(i).equals("Transparencia")) |
||
227 | 5499 | jaume | this.getTab().setTitleAt(i,PluginServices.getText(this,"transparencia")); |
228 | 4505 | jaume | if(this.getTab().getTitleAt(i).equals("Bandas")) |
229 | this.getTab().setTitleAt(i,PluginServices.getText(this,"bandas")); |
||
230 | if(this.getTab().getTitleAt(i).equals("Realce")) |
||
231 | this.getTab().setTitleAt(i,PluginServices.getText(this,"realce")); |
||
232 | } |
||
233 | |||
234 | this.getAcceptButton().setText(PluginServices.getText(this,"Aceptar")); |
||
235 | this.getApplyButton().setText(PluginServices.getText(this,"Aplicar")); |
||
236 | this.getCancelButton().setText(PluginServices.getText(this,"Cancelar")); |
||
237 | } |
||
238 | |||
239 | /**
|
||
240 | * Assigns a FLayerRaster
|
||
241 | * @param layer capa a asignar
|
||
242 | */
|
||
243 | public void setFLyrWCS(FLyrWCS layer){ |
||
244 | fLayer = layer; |
||
245 | } |
||
246 | |||
247 | /**
|
||
248 | * Dialog window constructor.
|
||
249 | */
|
||
250 | public WCSRasterPropsDialog() {
|
||
251 | init(); |
||
252 | } |
||
253 | |||
254 | /**
|
||
255 | * Loads the info panel data.
|
||
256 | */
|
||
257 | private void loadInfoData(){ |
||
258 | Rectangle2D r = fLayer.getFullExtent();
|
||
259 | 6208 | maquerol | if(fLayer != null){ |
260 | 4505 | jaume | props = new Object[nprops][2]; |
261 | 6208 | maquerol | props[0][0] = new String(PluginServices.getText(this,"Fichero")+":"); |
262 | 4505 | jaume | props[0][1] = fLayer.getHost(); |
263 | 6208 | maquerol | props[1][0] = new String(PluginServices.getText(this,"tamano")+":"); |
264 | props[1][1] = ""; |
||
265 | props[2][0] = new String(PluginServices.getText(this,"ancho_alto")+":"); |
||
266 | props[2][1] = fLayer.getWidth()+" , "+fLayer.getHeight(); |
||
267 | props[3][0] = new String(PluginServices.getText(this,"formato")+":"); |
||
268 | props[3][1] = "WCS"; |
||
269 | props[4][0] = new String(PluginServices.getText(this,"tipo_dato")+":"); |
||
270 | 4505 | jaume | String type = null; |
271 | switch(grf.getDataType()){
|
||
272 | case 0: type = new String("BYTE");break; |
||
273 | case 1: type = new String("USHORT");break; |
||
274 | case 2: type = new String("SHORT");break; |
||
275 | case 3: type = new String("INT");break; |
||
276 | case 4: type = new String("FLOAT");break; |
||
277 | case 5: type = new String("DOUBLE");break; |
||
278 | default: type = new String("UNDEFINED");break; |
||
279 | } |
||
280 | props[4][1] = type; |
||
281 | 6208 | maquerol | props[4][0] = new String(PluginServices.getText(this, "georeferenciado")+":"); |
282 | props[4][1] = new String(PluginServices.getText(this, "si")); |
||
283 | props[5][0] = new String(PluginServices.getText(this,"num_bandas")+":"); |
||
284 | props[5][1] = new String(String.valueOf(grf.getBandCount())); |
||
285 | props[6][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
||
286 | props[7][0] = new String(PluginServices.getText(this,"xmin")+":"); |
||
287 | props[7][1] = String.valueOf(fLayer.getMinX()); |
||
288 | props[8][0] = new String(PluginServices.getText(this,"ymin")+":"); |
||
289 | props[8][1] = String.valueOf(fLayer.getMinY()); |
||
290 | props[9][0] = new String(PluginServices.getText(this,"xmax")+":"); |
||
291 | props[9][1] = String.valueOf(fLayer.getMaxX()); |
||
292 | props[10][0] = new String(PluginServices.getText(this,"ymax")+":"); |
||
293 | props[10][1] = String.valueOf(fLayer.getMaxY()); |
||
294 | 4505 | jaume | |
295 | 6208 | maquerol | double tamRealX = fLayer.getMaxX()-fLayer.getMinX();
|
296 | double tamRealY = fLayer.getMaxY()-fLayer.getMinY();
|
||
297 | double tamX = Math.round((tamRealX/fLayer.getWidth())*10000000); |
||
298 | double tamY = Math.round((tamRealY/fLayer.getHeight())*10000000); |
||
299 | |||
300 | String tamPixX = String.valueOf(tamX/10000000); |
||
301 | String tamPixY = String.valueOf(tamY/10000000); |
||
302 | |||
303 | props[11][0] = new String(PluginServices.getText(this, "tamPixX")); |
||
304 | props[11][1] = tamPixX + " " + new String(PluginServices.getText(this, "m/pixel")); |
||
305 | props[12][0] = new String(PluginServices.getText(this, "tamPixY")); |
||
306 | props[12][1] = tamPixY + " " + new String(PluginServices.getText(this, "m/pixel")); |
||
307 | |||
308 | }else{
|
||
309 | props = new Object[1][2]; |
||
310 | props[0][0] = new String("No props"); |
||
311 | props[0][1] = new String("-"); |
||
312 | } |
||
313 | 4505 | jaume | |
314 | } |
||
315 | |||
316 | /**
|
||
317 | 5769 | maquerol | * A�ade bandas al contador de bandas del FilterRasterDialogPanel
|
318 | * @param numBands N�mero de bandas a a�adir
|
||
319 | 4505 | jaume | */
|
320 | public void addNumBands(int numBands){ |
||
321 | nbands += numBands; |
||
322 | 4578 | nacho | FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
323 | RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
||
324 | if(rasterTrans != null && rasterTrans.getPTranspByPixel().isControlEnabled()) |
||
325 | rasterTrans.setActiveTransparencyControl(true);
|
||
326 | 4505 | jaume | } |
327 | |||
328 | /**
|
||
329 | * Inits the jDialog
|
||
330 | */
|
||
331 | public void init() { |
||
332 | |||
333 | //this.setLayout(new FlowLayout());
|
||
334 | |||
335 | setName("filterRaster");
|
||
336 | |||
337 | this.loadInfoData();
|
||
338 | super.init(props);
|
||
339 | this.setTabVisible("Pansharpening", false); |
||
340 | |||
341 | //this.add(getContentPane());
|
||
342 | |||
343 | 6836 | maquerol | this.setSize(486, 352); |
344 | 4505 | jaume | |
345 | //contentPane.getAcceptButton().setEnabled(false);
|
||
346 | this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
||
347 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
348 | acceptButtonActionPerformed(evt); |
||
349 | closeJDialog(); |
||
350 | } |
||
351 | }); |
||
352 | this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
||
353 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
354 | cancelButtonActionPerformed(evt); |
||
355 | closeJDialog(); |
||
356 | } |
||
357 | }); |
||
358 | this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
||
359 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
360 | acceptButtonActionPerformed(evt); |
||
361 | } |
||
362 | }); |
||
363 | 4578 | nacho | BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
364 | bandSetup.getFileList().getJButtonAdd().addActionListener(new java.awt.event.ActionListener() {
|
||
365 | 4505 | jaume | public void actionPerformed(java.awt.event.ActionEvent evt){ |
366 | addFileBand(evt); |
||
367 | |||
368 | } |
||
369 | }); |
||
370 | 4578 | nacho | bandSetup.getFileList().getJButtonRemove().addActionListener(new java.awt.event.ActionListener() {
|
371 | 4505 | jaume | public void actionPerformed(java.awt.event.ActionEvent evt){ |
372 | delFileBand(evt); |
||
373 | } |
||
374 | }); |
||
375 | |||
376 | |||
377 | } |
||
378 | |||
379 | /**
|
||
380 | * Saves the initial state to restore it if cancel.
|
||
381 | */
|
||
382 | public void readStat(){ |
||
383 | 4578 | nacho | FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
384 | RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
||
385 | status = new Status(rasterTrans.getOpacityText().getText(),
|
||
386 | 4505 | jaume | getAssignedBand(GeoRasterFile.RED_BAND), |
387 | getAssignedBand(GeoRasterFile.GREEN_BAND), |
||
388 | getAssignedBand(GeoRasterFile.BLUE_BAND) |
||
389 | ); |
||
390 | } |
||
391 | |||
392 | /**
|
||
393 | * This method initializes jContentPane
|
||
394 | */
|
||
395 | public Container getContentPane() { |
||
396 | return this; |
||
397 | } |
||
398 | |||
399 | /**
|
||
400 | * Sets a projection.
|
||
401 | *
|
||
402 | * @param prj
|
||
403 | */
|
||
404 | public void setProjection(IProjection prj) { |
||
405 | this.currentProjection = prj;
|
||
406 | } |
||
407 | |||
408 | |||
409 | |||
410 | public void closeJDialog() { |
||
411 | PluginServices.getMDIManager().closeView(WCSRasterPropsDialog.this); |
||
412 | } |
||
413 | |||
414 | /**
|
||
415 | * Sets the RasterFilterStackManager
|
||
416 | * @param stackManager
|
||
417 | */
|
||
418 | public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
||
419 | this.stackManager = stackManager;
|
||
420 | stackManager.resetTempFilters(); |
||
421 | } |
||
422 | |||
423 | /**
|
||
424 | *
|
||
425 | * @param flag
|
||
426 | * @return
|
||
427 | */
|
||
428 | public int getAssignedBand(int flag) { |
||
429 | 4578 | nacho | BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
430 | return bandSetup.getAssignedBand(flag);
|
||
431 | 4505 | jaume | } |
432 | |||
433 | /**
|
||
434 | * Pressing OK with the bands panel selected makes its values to be
|
||
435 | * processed.
|
||
436 | *
|
||
437 | * @return true if the bands panel was selected and the action is processed, false it
|
||
438 | * was not selected.
|
||
439 | */
|
||
440 | public boolean processBandPanel(){ |
||
441 | fLayer.setBandR(getAssignedBand(GeoRasterFile.RED_BAND)); |
||
442 | fLayer.setBandG(getAssignedBand(GeoRasterFile.GREEN_BAND)); |
||
443 | fLayer.setBandB(getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
444 | rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
||
445 | rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
||
446 | rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
||
447 | |||
448 | 5769 | maquerol | //Comprobamos si hay alguna banda que no est� asignada y aplicamos el filtro
|
449 | 4505 | jaume | StringBuffer sb = new StringBuffer(); |
450 | if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
||
451 | sb.append("R");
|
||
452 | if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
||
453 | sb.append("G");
|
||
454 | if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
||
455 | sb.append("B");
|
||
456 | |||
457 | if(!sb.toString().equals("")) |
||
458 | stackManager.addRemoveBands(sb.toString()); |
||
459 | else
|
||
460 | stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
||
461 | |||
462 | fLayer.getFMap().invalidate(); |
||
463 | 6223 | maquerol | |
464 | InfoPanel pInfo = (InfoPanel)super.getPanelByClassName("InfoPanel"); |
||
465 | pInfo.setBands(getAssignedBand(GeoRasterFile.RED_BAND),getAssignedBand(GeoRasterFile.GREEN_BAND),getAssignedBand(GeoRasterFile.BLUE_BAND)); |
||
466 | |||
467 | 4505 | jaume | return true; |
468 | } |
||
469 | |||
470 | /**
|
||
471 | * Pressing OK with the transparency panel selected makes its values to be processed.
|
||
472 | * @return true if the transparency panel was selected and the action is processed, false it
|
||
473 | * was not selected.
|
||
474 | */
|
||
475 | public boolean processTransparencyPanel(){ |
||
476 | //OPACIDAD
|
||
477 | 4578 | nacho | RasterTransparencyPanel tpan = (RasterTransparencyPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("RasterTransparencyPanel"); |
478 | String sOpac = tpan.getOpacityText().getText();
|
||
479 | if(!sOpac.equals("") && tpan.getOpacityCheck().isSelected()){ |
||
480 | 4505 | jaume | int opac = Integer.parseInt(sOpac); |
481 | opac = (int)((opac*255)/100); |
||
482 | px.setTransparency(true);
|
||
483 | //px.setTransparency(255-opac);
|
||
484 | fLayer.setTransparency(255-opac);
|
||
485 | rasterStatus.transparency = 255-opac;
|
||
486 | }else{
|
||
487 | px.setTransparency(false);
|
||
488 | fLayer.setTransparency(0);
|
||
489 | rasterStatus.transparency = 0;
|
||
490 | } |
||
491 | |||
492 | //TRANSPARENCIA
|
||
493 | 4578 | nacho | if( tpan.getTransparencyCheck().isSelected()){
|
494 | stackManager.addTransparencyFilter( tpan.getPTranspByPixel().getEntries(), |
||
495 | 4505 | jaume | 0x10, //Transparencia |
496 | 0xff, //Color Transparencia R |
||
497 | 0xff, //Color Transparencia G |
||
498 | 0xff); //Color Transparencia B |
||
499 | |||
500 | }else
|
||
501 | px.filterStack.removeFilter(stackManager.getTypeFilter("transparency"));
|
||
502 | |||
503 | fLayer.getFMap().invalidate(); |
||
504 | return true; |
||
505 | } |
||
506 | |||
507 | /**
|
||
508 | 5534 | nacho | * Pressing OK with the BrightnessContrastPanel selected makes its values to be processed.
|
509 | * @return true if the BrightnessContrastPanel was selected and the action is processed, false it
|
||
510 | 4505 | jaume | * was not selected.
|
511 | */
|
||
512 | 5534 | nacho | private void processBrightnessContrastPanel(){ |
513 | EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
514 | 5769 | maquerol | // Si est� activo el panel de brillo y contraste tomamos los valores y cargamos un filtro de
|
515 | 5534 | nacho | // brillo y contraste
|
516 | |||
517 | BrightnessContrastStackManager bcStackManager = (BrightnessContrastStackManager)stackManager.getManagerByClass(BrightnessContrastStackManager.class); |
||
518 | if(ebcPanel.getCBrightC().isSelected()){
|
||
519 | int incrBrillo = (int)Math.round(Double.valueOf(ebcPanel.lstBrightness.getTextValue()).doubleValue()); |
||
520 | int incrContraste = (int)Math.round(Double.valueOf(ebcPanel.lstContrast.getTextValue()).doubleValue()); |
||
521 | bcStackManager.addBrightnessFilter(incrBrillo); |
||
522 | bcStackManager.addContrastFilter(incrContraste); |
||
523 | }else{
|
||
524 | stackManager.removeFilter(bcStackManager.brightness); |
||
525 | stackManager.removeFilter(bcStackManager.contrast); |
||
526 | } |
||
527 | fLayer.getFMap().invalidate(); |
||
528 | } |
||
529 | |||
530 | /**
|
||
531 | * Pulsar aceptar con el panel de realce seleccionado hace que se procesen los valores
|
||
532 | * introducidos en este.
|
||
533 | * @return true si estaba seleccionado el panel de realce y se ha procesado la
|
||
534 | 5769 | maquerol | * acci�n y false si no lo estaba.
|
535 | 5534 | nacho | */
|
536 | public void processEnhancedPanel(){ |
||
537 | EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
538 | |||
539 | //Filtro de realce lineal seleccionado
|
||
540 | if(ebcPanel.getCEnhanced().isSelected()){
|
||
541 | if((ebcPanel.getJCheckBox().isSelected()) && (!ebcPanel.getCheckSliderText().getJCheckBox().isSelected()))
|
||
542 | 4505 | jaume | stackManager.addEnhancedFilter(true);
|
543 | else
|
||
544 | stackManager.addEnhancedFilter(false);
|
||
545 | 5534 | nacho | |
546 | 4505 | jaume | //Recorte de colas seleccionado
|
547 | 5534 | nacho | if(ebcPanel.getCheckSliderText().getJCheckBox().isSelected()){
|
548 | 4505 | jaume | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
549 | 5534 | nacho | double recorte = Double.parseDouble(ebcPanel.getCheckSliderText().getTextValue())/100; |
550 | if(ebcPanel.getJCheckBox().isSelected())
|
||
551 | stackManager.addTailFilter(recorte, 0D, true); |
||
552 | 4505 | jaume | else
|
553 | 5534 | nacho | stackManager.addTailFilter(recorte, 0D, false); |
554 | 4505 | jaume | }else{
|
555 | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
||
556 | stackManager.addComputeMinMaxFilter(); |
||
557 | 5534 | nacho | } |
558 | |||
559 | 4505 | jaume | } |
560 | 5534 | nacho | // Sin filtro lineal seleccionado
|
561 | if(!ebcPanel.getCEnhanced().isSelected()){
|
||
562 | 4505 | jaume | stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
563 | stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
||
564 | stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
||
565 | } |
||
566 | fLayer.getFMap().invalidate(); |
||
567 | } |
||
568 | |||
569 | /**
|
||
570 | * Manages the action perfomed when Apply/OK is pressed or Apply at the raster
|
||
571 | * properties control.
|
||
572 | * @param e
|
||
573 | */
|
||
574 | private void acceptButtonActionPerformed(ActionEvent e) { |
||
575 | 5534 | nacho | processBandPanel(); |
576 | processTransparencyPanel(); |
||
577 | processEnhancedPanel(); |
||
578 | processBrightnessContrastPanel(); |
||
579 | 4505 | jaume | } |
580 | |||
581 | /**
|
||
582 | * Adds a band to the raster.
|
||
583 | * @param e
|
||
584 | */
|
||
585 | private void addFileBand(ActionEvent e){ |
||
586 | String[] driverNames = null; |
||
587 | String rasterDriver = null; |
||
588 | |||
589 | 5769 | maquerol | //Creaci�n del dialogo para selecci�n de ficheros
|
590 | 4505 | jaume | |
591 | fileChooser = new JFileChooser(lastPath); |
||
592 | fileChooser.setMultiSelectionEnabled(true);
|
||
593 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
594 | try {
|
||
595 | driverNames = LayerFactory.getDM().getDriverNames(); |
||
596 | FileFilter defaultFileFilter = null, auxF; |
||
597 | for (int i = 0; i < driverNames.length; i++) { |
||
598 | |||
599 | if (driverNames[i].endsWith("gvSIG Image Driver")){ |
||
600 | rasterDriver = driverNames[i]; |
||
601 | auxF = new DriverFileFilter(driverNames[i]);
|
||
602 | fileChooser.addChoosableFileFilter(auxF); |
||
603 | defaultFileFilter = auxF; |
||
604 | } |
||
605 | } |
||
606 | } catch (DriverLoadException e1) {
|
||
607 | NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
||
608 | } |
||
609 | int result = fileChooser.showOpenDialog(WCSRasterPropsDialog.this);
|
||
610 | |||
611 | if(result == JFileChooser.APPROVE_OPTION){ |
||
612 | File[] files = fileChooser.getSelectedFiles(); |
||
613 | FileFilter filter = fileChooser.getFileFilter();
|
||
614 | 4578 | nacho | BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
615 | 4505 | jaume | lastPath = files[0].getPath();
|
616 | |||
617 | 5769 | maquerol | //Lo a�adimos a la capa si no esta
|
618 | 4505 | jaume | |
619 | Vector v = new Vector(); |
||
620 | for(int i=0;i<files.length;i++){ |
||
621 | boolean exist = false; |
||
622 | for(int j=0;j<px.getFiles().length;j++){ |
||
623 | if(px.getFiles()[j].getName().endsWith(files[i].getName()))
|
||
624 | exist = true;
|
||
625 | } |
||
626 | if(!exist){
|
||
627 | try{
|
||
628 | Rectangle2D extentOrigin = fLayer.getFullExtent();
|
||
629 | |||
630 | Extent extentNewFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()).getExtent(); |
||
631 | |||
632 | 5769 | maquerol | //Comprobamos que el extent y tama�o del fichero a�adido sea igual al
|
633 | //fichero original. Si no es as� no abrimos la capa y mostramos un aviso
|
||
634 | 4505 | jaume | |
635 | double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
||
636 | double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
||
637 | |||
638 | if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
||
639 | (widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
||
640 | (heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
||
641 | (heightNewFile-extentOrigin.getHeight()) < -1.0){
|
||
642 | JOptionPane.showMessageDialog( null, |
||
643 | PluginServices.getText(this, "extents_no_coincidentes"), |
||
644 | "",
|
||
645 | JOptionPane.ERROR_MESSAGE);
|
||
646 | return;
|
||
647 | } |
||
648 | |||
649 | if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
||
650 | (extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
||
651 | JOptionPane.showMessageDialog(null, |
||
652 | PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
||
653 | return;
|
||
654 | } |
||
655 | |||
656 | }catch(Exception exc){ |
||
657 | exc.printStackTrace(); |
||
658 | } |
||
659 | |||
660 | 5769 | maquerol | //Lo a�adimos a la capa
|
661 | 4505 | jaume | px.addFile(files[i].getAbsolutePath()); |
662 | |||
663 | }else{
|
||
664 | JOptionPane.showMessageDialog(null, |
||
665 | PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
||
666 | } |
||
667 | } |
||
668 | |||
669 | 5769 | maquerol | //A�adimos los georasterfile a la tabla del Panel
|
670 | 4505 | jaume | |
671 | v = new Vector(); |
||
672 | 6223 | maquerol | Vector vInfo = new Vector(); |
673 | 4505 | jaume | for(int i=0;i<px.getFiles().length;i++){ |
674 | boolean exist = false; |
||
675 | for(int j=0;j<bandSetup.getNBands();j++){ |
||
676 | if(px.getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
||
677 | exist = true;
|
||
678 | } |
||
679 | 6223 | maquerol | if(!exist){
|
680 | 4505 | jaume | v.add(px.getFiles()[i]); |
681 | 6223 | maquerol | vInfo.add(px.getFiles()[i]); |
682 | } |
||
683 | 4505 | jaume | } |
684 | |||
685 | GeoRasterFile[] grf = new GeoRasterFile[v.size()]; |
||
686 | for(int i=0;i<grf.length;i++){ |
||
687 | grf[i] = (GeoRasterFile)v.get(i); |
||
688 | } |
||
689 | 6223 | maquerol | GeoRasterFile[] infoGrf = new GeoRasterFile[vInfo.size()]; |
690 | for(int i = 0; i<infoGrf.length ; i++){ |
||
691 | infoGrf[i] = (GeoRasterFile)vInfo.get(i); |
||
692 | } |
||
693 | 4505 | jaume | bandSetup.addFiles(grf); |
694 | 6223 | maquerol | this.addInfoFiles(infoGrf);
|
695 | 4505 | jaume | } |
696 | } |
||
697 | |||
698 | /**
|
||
699 | * Deletes a band from the raster. If there is only a file or no band is
|
||
700 | * selected then it does nothing.
|
||
701 | *
|
||
702 | * @param e
|
||
703 | */
|
||
704 | private void delFileBand(ActionEvent e){ |
||
705 | 4578 | nacho | BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
706 | 4505 | jaume | |
707 | if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
||
708 | bandSetup.getFileList().getNFiles() > 1){
|
||
709 | String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
||
710 | px.delFile(pathName); |
||
711 | String file = pathName.substring(pathName.lastIndexOf("/")+1); |
||
712 | file = file.substring(file.lastIndexOf("\\")+1); |
||
713 | bandSetup.removeFile(file); |
||
714 | |||
715 | 6223 | maquerol | } |
716 | |||
717 | Vector vInfo = new Vector(); |
||
718 | for(int i=0;i<px.getFiles().length;i++){ |
||
719 | vInfo.add(px.getFiles()[i]); |
||
720 | } |
||
721 | |||
722 | GeoRasterFile[] infoGrf = new GeoRasterFile[vInfo.size()]; |
||
723 | for(int i = 0; i<infoGrf.length ; i++){ |
||
724 | infoGrf[i] = (GeoRasterFile)vInfo.get(i); |
||
725 | } |
||
726 | |||
727 | this.addInfoFiles(infoGrf);
|
||
728 | |||
729 | 4505 | jaume | } |
730 | |||
731 | /**
|
||
732 | * The cancel button restores the previous state to the loading of this dialog
|
||
733 | * @param e Evento
|
||
734 | */
|
||
735 | private void cancelButtonActionPerformed(ActionEvent e) { |
||
736 | this.status.restoreStatus(this); |
||
737 | fLayer.getFMap().invalidate(); |
||
738 | } |
||
739 | |||
740 | /**
|
||
741 | 6877 | cesar | * @see com.iver.mdiApp.ui.MDIManager.IWindow#getViewInfo()
|
742 | 4505 | jaume | */
|
743 | public ViewInfo getViewInfo() {
|
||
744 | 6836 | maquerol | ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG | ViewInfo.RESIZABLE);
|
745 | 4505 | jaume | m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
746 | return m_viewinfo;
|
||
747 | } |
||
748 | |||
749 | 5534 | nacho | //********************************************************************
|
750 | 5769 | maquerol | //***********************EVENTOS DE RAT�N*****************************
|
751 | 4505 | jaume | |
752 | 5534 | nacho | public void mouseClicked(MouseEvent e) { |
753 | // TODO Auto-generated method stub
|
||
754 | |||
755 | } |
||
756 | |||
757 | public void mouseEntered(MouseEvent e) { |
||
758 | // TODO Auto-generated method stub
|
||
759 | |||
760 | } |
||
761 | |||
762 | public void mouseExited(MouseEvent e) { |
||
763 | // TODO Auto-generated method stub
|
||
764 | |||
765 | } |
||
766 | |||
767 | public void mousePressed(MouseEvent e) { |
||
768 | // TODO Auto-generated method stub
|
||
769 | |||
770 | } |
||
771 | |||
772 | public void mouseReleased(MouseEvent e) { |
||
773 | EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
774 | if (((e.getSource() == ebcPanel.lstBrightness.getJSlider()) || (e.getSource() == ebcPanel.lstContrast.getJSlider())) &&
|
||
775 | (ebcPanel.getJCheckBox1().isSelected() == true))
|
||
776 | processBrightnessContrastPanel(); |
||
777 | } |
||
778 | |||
779 | public void keyPressed(KeyEvent e) { |
||
780 | EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
781 | if(e.getSource() == ebcPanel.getCheckSliderText().getJTextField()){
|
||
782 | ebcPanel.getCheckSliderText().getJSlider().setValue((int) Math.round(Double.valueOf(ebcPanel.getCheckSliderText().getTextValue()).doubleValue())); |
||
783 | } |
||
784 | |||
785 | } |
||
786 | |||
787 | public void keyReleased(KeyEvent e) { |
||
788 | // TODO Auto-generated method stub
|
||
789 | |||
790 | } |
||
791 | |||
792 | public void keyTyped(KeyEvent e) { |
||
793 | // TODO Auto-generated method stub
|
||
794 | |||
795 | } |
||
796 | 5769 | maquerol | |
797 | public void actionPerformed(ActionEvent e){ |
||
798 | EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
||
799 | if((e.getSource() == ebcPanel.getLabelSliderText().getJTextField()) ||
|
||
800 | (e.getSource() == ebcPanel.getLabelSliderText1().getJTextField())){ |
||
801 | |||
802 | if(ebcPanel.getJCheckBox1().isSelected()){
|
||
803 | processBrightnessContrastPanel(); |
||
804 | } |
||
805 | |||
806 | } |
||
807 | } |
||
808 | |||
809 | 4505 | jaume | } |