svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSRasterPropsDialog.java @ 6209
History | View | Annotate | Download (29.5 KB)
1 |
/*
|
---|---|
2 |
* Creado el 7-marzo-2005
|
3 |
*/
|
4 |
package com.iver.cit.gvsig.gui.dialogs; |
5 |
|
6 |
import java.awt.Container; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.KeyEvent; |
10 |
import java.awt.event.KeyListener; |
11 |
import java.awt.event.MouseEvent; |
12 |
import java.awt.event.MouseListener; |
13 |
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 |
import org.cresques.filter.RasterFilterStackManager; |
25 |
import org.cresques.filter.BrightnessContrast.BrightnessContrastStackManager; |
26 |
import org.cresques.io.GeoRasterFile; |
27 |
import org.cresques.px.Extent; |
28 |
import org.cresques.px.PxRaster; |
29 |
import org.cresques.ui.BrightnessContrast.EnhancedBrightnessContrastPanel; |
30 |
import org.cresques.ui.raster.BandSetupPanel; |
31 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
32 |
import org.cresques.ui.raster.InfoPanel; |
33 |
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 |
import com.iver.andami.ui.mdiManager.View; |
40 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
41 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
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 WMS 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 |
public class WMSRasterPropsDialog extends FilterRasterDialogPanel implements View, MouseListener, KeyListener, ActionListener{ |
61 |
|
62 |
private FilterRasterDialogPanel contentPane = null; |
63 |
private JPanel propPanel = null; |
64 |
private IProjection currentProjection = null; |
65 |
private FLyrWMS fLayer = null; |
66 |
private static final int nprops = 13; |
67 |
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(WMSRasterPropsDialog 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 WMSRasterPropsDialog(FLyrWMS 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 |
BandSetupPanel bandSetup = (BandSetupPanel)fr.getPanelByClassName("BandSetupPanel");
|
172 |
bandSetup.getFileList().getJButtonAdd().setEnabled(false);
|
173 |
bandSetup.getFileList().getJButtonRemove().setEnabled(false);
|
174 |
this.setTranslation();
|
175 |
|
176 |
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 |
ep.getLabelSliderText().getJTextField().addActionListener(this);
|
181 |
ep.getLabelSliderText1().getJTextField().addActionListener(this);
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Asigna los textos a los paneles
|
186 |
*/
|
187 |
private void setTranslation(){ |
188 |
FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
189 |
BandSetupPanel bandSetup = (BandSetupPanel)fr.getPanelByClassName("BandSetupPanel");
|
190 |
bandSetup.getFileList().getJButtonAdd().setText(PluginServices.getText(this,"add")); |
191 |
bandSetup.getFileList().getJButtonRemove().setText(PluginServices.getText(this,"remove")); |
192 |
bandSetup.getFileList().lbandasVisibles.setText(PluginServices.getText(this,"bands")); |
193 |
|
194 |
RasterTransparencyPanel tpan = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
195 |
|
196 |
tpan.getTransparencyCheck().setText(PluginServices.getText(this,"transparencia")); |
197 |
tpan.getOpacityCheck().setText(PluginServices.getText(this,"opacidad")); |
198 |
|
199 |
EnhancedBrightnessContrastPanel ep = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
200 |
|
201 |
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 |
|
212 |
InfoPanel ip = (InfoPanel)super.getPanelByClassName("InfoPanel"); |
213 |
|
214 |
ip.cabInfo = new String(PluginServices.getText(this, "Informacion")); |
215 |
ip.cabCoord = new String(PluginServices.getText(this, "coor_geograficas")); |
216 |
ip.cabProy = new String(PluginServices.getText(this, "Proyecciones")); |
217 |
ip.cabOrig = new String(PluginServices.getText(this, "origen_de_datos")); |
218 |
ip.refresh(); |
219 |
|
220 |
|
221 |
//Recorremos los Tab y traducimos el nombre
|
222 |
for(int i=0;i<this.getTab().getTabCount();i++){ |
223 |
if(this.getTab().getTitleAt(i).equals("Info")) |
224 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"info")); |
225 |
if(this.getTab().getTitleAt(i).equals("Transparencia")) |
226 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"transparencia")); |
227 |
if(this.getTab().getTitleAt(i).equals("Bands")) |
228 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"bands")); |
229 |
if(this.getTab().getTitleAt(i).equals("Realce")) |
230 |
this.getTab().setTitleAt(i,PluginServices.getText(this,"realce")); |
231 |
} |
232 |
|
233 |
this.getAcceptButton().setText(PluginServices.getText(this,"ok")); |
234 |
this.getApplyButton().setText(PluginServices.getText(this,"apply")); |
235 |
this.getCancelButton().setText(PluginServices.getText(this,"cancel")); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* Assigns a FLayerRaster
|
240 |
* @param layer capa a asignar
|
241 |
*/
|
242 |
public void setFLyrWMS(FLyrWMS layer){ |
243 |
fLayer = layer; |
244 |
} |
245 |
|
246 |
/**
|
247 |
* Dialog window constructor.
|
248 |
*/
|
249 |
public WMSRasterPropsDialog() {
|
250 |
init(); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Loads the info panel data.
|
255 |
*/
|
256 |
private void loadInfoData(){ |
257 |
Rectangle2D r = fLayer.getFullExtent();
|
258 |
if(fLayer != null){ |
259 |
props = new Object[nprops][2]; |
260 |
props[0][0] = new String(PluginServices.getText(this,"Fichero")+":"); |
261 |
props[0][1] = fLayer.getHost(); |
262 |
props[1][0] = new String(PluginServices.getText(this,"tamano")+":"); |
263 |
props[1][1] = ""; |
264 |
props[2][0] = new String(PluginServices.getText(this,"ancho_alto")+":"); |
265 |
props[2][1] = fLayer.getWidth()+" , "+fLayer.getHeight(); |
266 |
props[3][0] = new String(PluginServices.getText(this,"formato")+":"); |
267 |
props[3][1] = "WMS"; |
268 |
props[4][0] = new String(PluginServices.getText(this,"tipo_dato")+":"); |
269 |
String type = null; |
270 |
switch(grf.getDataType()){
|
271 |
case 0: type = new String("BYTE");break; |
272 |
case 1: type = new String("USHORT");break; |
273 |
case 2: type = new String("SHORT");break; |
274 |
case 3: type = new String("INT");break; |
275 |
case 4: type = new String("FLOAT");break; |
276 |
case 5: type = new String("DOUBLE");break; |
277 |
default: type = new String("UNDEFINED");break; |
278 |
} |
279 |
props[4][1] = type; |
280 |
props[4][0] = new String(PluginServices.getText(this, "georeferenciado")+":"); |
281 |
props[4][1] = new String(PluginServices.getText(this, "si")); |
282 |
props[5][0] = new String(PluginServices.getText(this,"num_bandas")+":"); |
283 |
props[5][1] = new String(String.valueOf(grf.getBandCount())); |
284 |
props[6][0] = new String(PluginServices.getText(this,"coor_geograficas")); |
285 |
props[7][0] = new String(PluginServices.getText(this,"xmin")+":"); |
286 |
props[7][1] = String.valueOf(fLayer.getMinX()); |
287 |
props[8][0] = new String(PluginServices.getText(this,"ymin")+":"); |
288 |
props[8][1] = String.valueOf(fLayer.getMinY()); |
289 |
props[9][0] = new String(PluginServices.getText(this,"xmax")+":"); |
290 |
props[9][1] = String.valueOf(fLayer.getMaxX()); |
291 |
props[10][0] = new String(PluginServices.getText(this,"ymax")+":"); |
292 |
props[10][1] = String.valueOf(fLayer.getMaxY()); |
293 |
|
294 |
double tamRealX = fLayer.getMaxX()-fLayer.getMinX();
|
295 |
double tamRealY = fLayer.getMaxY()-fLayer.getMinY();
|
296 |
double tamX = Math.round((tamRealX/fLayer.getWidth())*10000000); |
297 |
double tamY = Math.round((tamRealY/fLayer.getHeight())*10000000); |
298 |
|
299 |
String tamPixX = String.valueOf(tamX/10000000); |
300 |
String tamPixY = String.valueOf(tamY/10000000); |
301 |
|
302 |
props[11][0] = new String(PluginServices.getText(this, "tamPixX")); |
303 |
props[11][1] = tamPixX + " " + new String(PluginServices.getText(this, "m/pixel")); |
304 |
props[12][0] = new String(PluginServices.getText(this, "tamPixY")); |
305 |
props[12][1] = tamPixY + " " + new String(PluginServices.getText(this, "m/pixel")); |
306 |
|
307 |
}else{
|
308 |
props = new Object[1][2]; |
309 |
props[0][0] = new String("No props"); |
310 |
props[0][1] = new String("-"); |
311 |
} |
312 |
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* A?ade bandas al contador de bandas del FilterRasterDialogPanel
|
317 |
* @param numBands N?mero de bandas a a?adir
|
318 |
*/
|
319 |
public void addNumBands(int numBands){ |
320 |
nbands += numBands; |
321 |
FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
322 |
RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
323 |
if(rasterTrans != null && rasterTrans.getPTranspByPixel().isControlEnabled()) |
324 |
rasterTrans.setActiveTransparencyControl(true);
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Inits the jDialog
|
329 |
*/
|
330 |
public void init() { |
331 |
|
332 |
//this.setLayout(new FlowLayout());
|
333 |
|
334 |
setName("filterRaster");
|
335 |
|
336 |
this.loadInfoData();
|
337 |
super.init(props);
|
338 |
this.setTabVisible("Pansharpening", false); |
339 |
|
340 |
//this.add(getContentPane());
|
341 |
|
342 |
this.setSize(486, 338); |
343 |
|
344 |
//contentPane.getAcceptButton().setEnabled(false);
|
345 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
346 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
347 |
acceptButtonActionPerformed(evt); |
348 |
closeJDialog(); |
349 |
} |
350 |
}); |
351 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
352 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
353 |
cancelButtonActionPerformed(evt); |
354 |
closeJDialog(); |
355 |
} |
356 |
}); |
357 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
358 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
359 |
acceptButtonActionPerformed(evt); |
360 |
} |
361 |
}); |
362 |
BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
363 |
bandSetup.getFileList().getJButtonAdd().addActionListener(new java.awt.event.ActionListener() {
|
364 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
365 |
addFileBand(evt); |
366 |
|
367 |
} |
368 |
}); |
369 |
bandSetup.getFileList().getJButtonRemove().addActionListener(new java.awt.event.ActionListener() {
|
370 |
public void actionPerformed(java.awt.event.ActionEvent evt){ |
371 |
delFileBand(evt); |
372 |
} |
373 |
}); |
374 |
|
375 |
|
376 |
} |
377 |
|
378 |
/**
|
379 |
* Saves the initial state to restore it if cancel.
|
380 |
*/
|
381 |
public void readStat(){ |
382 |
FilterRasterDialogPanel fr = ((FilterRasterDialogPanel)this.getContentPane());
|
383 |
RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)fr.getPanelByClassName("RasterTransparencyPanel");
|
384 |
status = new Status(rasterTrans.getOpacityText().getText(),
|
385 |
getAssignedBand(GeoRasterFile.RED_BAND), |
386 |
getAssignedBand(GeoRasterFile.GREEN_BAND), |
387 |
getAssignedBand(GeoRasterFile.BLUE_BAND) |
388 |
); |
389 |
} |
390 |
|
391 |
/**
|
392 |
* This method initializes jContentPane
|
393 |
*/
|
394 |
public Container getContentPane() { |
395 |
return this; |
396 |
} |
397 |
|
398 |
/**
|
399 |
* Sets a projection.
|
400 |
*
|
401 |
* @param prj
|
402 |
*/
|
403 |
public void setProjection(IProjection prj) { |
404 |
this.currentProjection = prj;
|
405 |
} |
406 |
|
407 |
|
408 |
|
409 |
public void closeJDialog() { |
410 |
PluginServices.getMDIManager().closeView(WMSRasterPropsDialog.this); |
411 |
} |
412 |
|
413 |
/**
|
414 |
* Sets the RasterFilterStackManager
|
415 |
* @param stackManager
|
416 |
*/
|
417 |
public void setRasterFilterStackManager(RasterFilterStackManager stackManager){ |
418 |
this.stackManager = stackManager;
|
419 |
stackManager.resetTempFilters(); |
420 |
} |
421 |
|
422 |
/**
|
423 |
*
|
424 |
* @param flag
|
425 |
* @return
|
426 |
*/
|
427 |
public int getAssignedBand(int flag) { |
428 |
BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
429 |
return bandSetup.getAssignedBand(flag);
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* Pressing OK with the bands panel selected makes its values to be
|
434 |
* processed.
|
435 |
*
|
436 |
* @return true if the bands panel was selected and the action is processed, false it
|
437 |
* was not selected.
|
438 |
*/
|
439 |
public boolean processBandPanel(){ |
440 |
fLayer.setBandR(getAssignedBand(GeoRasterFile.RED_BAND)); |
441 |
fLayer.setBandG(getAssignedBand(GeoRasterFile.GREEN_BAND)); |
442 |
fLayer.setBandB(getAssignedBand(GeoRasterFile.BLUE_BAND)); |
443 |
rasterStatus.bandR = getAssignedBand(GeoRasterFile.RED_BAND); |
444 |
rasterStatus.bandG = getAssignedBand(GeoRasterFile.GREEN_BAND); |
445 |
rasterStatus.bandB = getAssignedBand(GeoRasterFile.BLUE_BAND); |
446 |
|
447 |
//Comprobamos si hay alguna banda que no est? asignada y aplicamos el filtro
|
448 |
StringBuffer sb = new StringBuffer(); |
449 |
if(getAssignedBand(GeoRasterFile.RED_BAND) == -1) |
450 |
sb.append("R");
|
451 |
if(getAssignedBand(GeoRasterFile.GREEN_BAND) == -1) |
452 |
sb.append("G");
|
453 |
if(getAssignedBand(GeoRasterFile.BLUE_BAND) == -1) |
454 |
sb.append("B");
|
455 |
|
456 |
if(!sb.toString().equals("")) |
457 |
stackManager.addRemoveBands(sb.toString()); |
458 |
else
|
459 |
stackManager.removeFilter(stackManager.getTypeFilter("removebands"));
|
460 |
|
461 |
fLayer.getFMap().invalidate(); |
462 |
return true; |
463 |
} |
464 |
|
465 |
/**
|
466 |
* Pressing OK with the transparency panel selected makes its values to be processed.
|
467 |
* @return true if the transparency panel was selected and the action is processed, false it
|
468 |
* was not selected.
|
469 |
*/
|
470 |
public boolean processTransparencyPanel(){ |
471 |
//OPACIDAD
|
472 |
RasterTransparencyPanel tpan = (RasterTransparencyPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("RasterTransparencyPanel"); |
473 |
String sOpac = tpan.getOpacityText().getText();
|
474 |
if(!sOpac.equals("") && tpan.getOpacityCheck().isSelected()){ |
475 |
int opac = Integer.parseInt(sOpac); |
476 |
opac = (int)((opac*255)/100); |
477 |
px.setTransparency(true);
|
478 |
//px.setTransparency(255-opac);
|
479 |
fLayer.setTransparency(255-opac);
|
480 |
rasterStatus.transparency = 255-opac;
|
481 |
}else{
|
482 |
px.setTransparency(false);
|
483 |
fLayer.setTransparency(0);
|
484 |
rasterStatus.transparency = 0;
|
485 |
} |
486 |
|
487 |
//TRANSPARENCIA
|
488 |
if( tpan.getTransparencyCheck().isSelected()){
|
489 |
|
490 |
stackManager.addTransparencyFilter( tpan.getPTranspByPixel().getEntries(), |
491 |
0x10, //Transparencia |
492 |
0xff, //Color Transparencia R |
493 |
0xff, //Color Transparencia G |
494 |
0xff); //Color Transparencia B |
495 |
|
496 |
}else
|
497 |
px.filterStack.removeFilter(stackManager.getTypeFilter("transparency"));
|
498 |
|
499 |
fLayer.getFMap().invalidate(); |
500 |
return true; |
501 |
} |
502 |
|
503 |
/**
|
504 |
* Pressing OK with the BrightnessContrastPanel selected makes its values to be processed.
|
505 |
* @return true if the BrightnessContrastPanel was selected and the action is processed, false it
|
506 |
* was not selected.
|
507 |
*/
|
508 |
private void processBrightnessContrastPanel(){ |
509 |
EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
510 |
// Si est? activo el panel de brillo y contraste tomamos los valores y cargamos un filtro de
|
511 |
// brillo y contraste
|
512 |
|
513 |
BrightnessContrastStackManager bcStackManager = (BrightnessContrastStackManager)stackManager.getManagerByClass(BrightnessContrastStackManager.class); |
514 |
if(ebcPanel.getCBrightC().isSelected()){
|
515 |
int incrBrillo = (int)Math.round(Double.valueOf(ebcPanel.lstBrightness.getTextValue()).doubleValue()); |
516 |
int incrContraste = (int)Math.round(Double.valueOf(ebcPanel.lstContrast.getTextValue()).doubleValue()); |
517 |
bcStackManager.addBrightnessFilter(incrBrillo); |
518 |
bcStackManager.addContrastFilter(incrContraste); |
519 |
}else{
|
520 |
stackManager.removeFilter(bcStackManager.brightness); |
521 |
stackManager.removeFilter(bcStackManager.contrast); |
522 |
} |
523 |
fLayer.getFMap().invalidate(); |
524 |
} |
525 |
|
526 |
/**
|
527 |
* Pulsar aceptar con el panel de realce seleccionado hace que se procesen los valores
|
528 |
* introducidos en este.
|
529 |
* @return true si estaba seleccionado el panel de realce y se ha procesado la
|
530 |
* acci?n y false si no lo estaba.
|
531 |
*/
|
532 |
public void processEnhancedPanel(){ |
533 |
EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
534 |
|
535 |
//Filtro de realce lineal seleccionado
|
536 |
if(ebcPanel.getCEnhanced().isSelected()){
|
537 |
if((ebcPanel.getJCheckBox().isSelected()) && (!ebcPanel.getCheckSliderText().getJCheckBox().isSelected()))
|
538 |
stackManager.addEnhancedFilter(true);
|
539 |
else
|
540 |
stackManager.addEnhancedFilter(false);
|
541 |
|
542 |
//Recorte de colas seleccionado
|
543 |
if(ebcPanel.getCheckSliderText().getJCheckBox().isSelected()){
|
544 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
545 |
double recorte = Double.parseDouble(ebcPanel.getCheckSliderText().getTextValue())/100; |
546 |
if(ebcPanel.getJCheckBox().isSelected())
|
547 |
stackManager.addTailFilter(recorte, 0D, true); |
548 |
else
|
549 |
stackManager.addTailFilter(recorte, 0D, false); |
550 |
}else{
|
551 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
552 |
stackManager.addComputeMinMaxFilter(); |
553 |
} |
554 |
|
555 |
} |
556 |
// Sin filtro lineal seleccionado
|
557 |
if(!ebcPanel.getCEnhanced().isSelected()){
|
558 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
559 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
560 |
stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
561 |
} |
562 |
fLayer.getFMap().invalidate(); |
563 |
} |
564 |
|
565 |
/**
|
566 |
* Pressing OK with the enhancement panel selected makes its values to be processed.
|
567 |
* @return true if the enhancement panel was selected and the action is processed, false it
|
568 |
* was not selected.
|
569 |
*/
|
570 |
/*public boolean processEnhancedPanel(){
|
571 |
//Filtro lineal seleccionado
|
572 |
EnhancedPanel ep = (EnhancedPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("EnhancedPanel");
|
573 |
if( ep.getLinealDirectoRadioButton().isSelected()){
|
574 |
if( ep.getRemoveCheck().isSelected() &&
|
575 |
!ep.getTailCheck().isSelected())
|
576 |
stackManager.addEnhancedFilter(true);
|
577 |
else
|
578 |
stackManager.addEnhancedFilter(false);
|
579 |
|
580 |
//Recorte de colas seleccionado
|
581 |
if(ep.getTailCheck().isSelected()){
|
582 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
583 |
double recorte = Double.parseDouble(ep.getTailText().getText())/100;
|
584 |
if(ep.getRemoveCheck().isSelected())
|
585 |
stackManager.addTailFilter( recorte, 0D, true);
|
586 |
else
|
587 |
stackManager.addTailFilter( recorte, 0D, false);
|
588 |
}else{
|
589 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
590 |
stackManager.addComputeMinMaxFilter();
|
591 |
}
|
592 |
}
|
593 |
|
594 |
//Sin filtro lineal seleccionado
|
595 |
if(ep.getSinRealceRadioButton().isSelected()){
|
596 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
597 |
stackManager.removeFilter(stackManager.getTypeFilter("tail"));
|
598 |
stackManager.removeFilter(stackManager.getTypeFilter("enhanced"));
|
599 |
}
|
600 |
fLayer.getFMap().invalidate();
|
601 |
|
602 |
return true;
|
603 |
}*/
|
604 |
|
605 |
/**
|
606 |
* Manages the action perfomed when Apply/OK is pressed or Apply at the raster
|
607 |
* properties control.
|
608 |
* @param e
|
609 |
*/
|
610 |
private void acceptButtonActionPerformed(ActionEvent e) { |
611 |
processBandPanel(); |
612 |
processTransparencyPanel(); |
613 |
processEnhancedPanel(); |
614 |
processBrightnessContrastPanel(); |
615 |
} |
616 |
|
617 |
/**
|
618 |
* Adds a band to the raster.
|
619 |
* @param e
|
620 |
*/
|
621 |
private void addFileBand(ActionEvent e){ |
622 |
String[] driverNames = null; |
623 |
String rasterDriver = null; |
624 |
|
625 |
//Creaci?n del dialogo para selecci?n de ficheros
|
626 |
|
627 |
fileChooser = new JFileChooser(lastPath); |
628 |
fileChooser.setMultiSelectionEnabled(true);
|
629 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
630 |
try {
|
631 |
driverNames = LayerFactory.getDM().getDriverNames(); |
632 |
FileFilter defaultFileFilter = null, auxF; |
633 |
for (int i = 0; i < driverNames.length; i++) { |
634 |
|
635 |
if (driverNames[i].endsWith("gvSIG Image Driver")){ |
636 |
rasterDriver = driverNames[i]; |
637 |
auxF = new DriverFileFilter(driverNames[i]);
|
638 |
fileChooser.addChoosableFileFilter(auxF); |
639 |
defaultFileFilter = auxF; |
640 |
} |
641 |
} |
642 |
} catch (DriverLoadException e1) {
|
643 |
NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
644 |
} |
645 |
int result = fileChooser.showOpenDialog(WMSRasterPropsDialog.this);
|
646 |
|
647 |
if(result == JFileChooser.APPROVE_OPTION){ |
648 |
File[] files = fileChooser.getSelectedFiles(); |
649 |
FileFilter filter = fileChooser.getFileFilter();
|
650 |
BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
651 |
lastPath = files[0].getPath();
|
652 |
|
653 |
//Lo a?adimos a la capa si no esta
|
654 |
|
655 |
Vector v = new Vector(); |
656 |
for(int i=0;i<files.length;i++){ |
657 |
boolean exist = false; |
658 |
for(int j=0;j<px.getFiles().length;j++){ |
659 |
if(px.getFiles()[j].getName().endsWith(files[i].getName()))
|
660 |
exist = true;
|
661 |
} |
662 |
if(!exist){
|
663 |
try{
|
664 |
Rectangle2D extentOrigin = fLayer.getFullExtent();
|
665 |
|
666 |
Extent extentNewFile = GeoRasterFile.openFile(fLayer.getProjection(), files[i].getAbsolutePath()).getExtent(); |
667 |
|
668 |
//Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
669 |
//fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
670 |
|
671 |
double widthNewFile = (extentNewFile.getMax().getX()-extentNewFile.getMin().getX());
|
672 |
double heightNewFile = (extentNewFile.getMax().getY()-extentNewFile.getMin().getY());
|
673 |
|
674 |
if( (widthNewFile-extentOrigin.getWidth()) > 1.0 || |
675 |
(widthNewFile-extentOrigin.getWidth()) < -1.0 ||
|
676 |
(heightNewFile-extentOrigin.getHeight()) > 1.0 ||
|
677 |
(heightNewFile-extentOrigin.getHeight()) < -1.0){
|
678 |
JOptionPane.showMessageDialog( null, |
679 |
PluginServices.getText(this, "extents_no_coincidentes"), |
680 |
"",
|
681 |
JOptionPane.ERROR_MESSAGE);
|
682 |
return;
|
683 |
} |
684 |
|
685 |
if( (extentNewFile.getMax().getX()-extentNewFile.getMin().getX())!=extentOrigin.getWidth() ||
|
686 |
(extentNewFile.getMax().getY()-extentNewFile.getMin().getY())!=extentOrigin.getHeight() ){ |
687 |
JOptionPane.showMessageDialog(null, |
688 |
PluginServices.getText(this, "extents_no_coincidentes"), "", JOptionPane.ERROR_MESSAGE); |
689 |
return;
|
690 |
} |
691 |
|
692 |
}catch(Exception exc){ |
693 |
exc.printStackTrace(); |
694 |
} |
695 |
|
696 |
//Lo a?adimos a la capa
|
697 |
px.addFile(files[i].getAbsolutePath()); |
698 |
|
699 |
}else{
|
700 |
JOptionPane.showMessageDialog(null, |
701 |
PluginServices.getText(this, "fichero_existe")+" "+files[i].getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE); |
702 |
} |
703 |
} |
704 |
|
705 |
//A?adimos los georasterfile a la tabla del Panel
|
706 |
|
707 |
v = new Vector(); |
708 |
for(int i=0;i<px.getFiles().length;i++){ |
709 |
boolean exist = false; |
710 |
for(int j=0;j<bandSetup.getNBands();j++){ |
711 |
if(px.getFiles()[i].getName().endsWith(bandSetup.getBandName(j)))
|
712 |
exist = true;
|
713 |
} |
714 |
if(!exist)
|
715 |
v.add(px.getFiles()[i]); |
716 |
} |
717 |
|
718 |
GeoRasterFile[] grf = new GeoRasterFile[v.size()]; |
719 |
for(int i=0;i<grf.length;i++){ |
720 |
grf[i] = (GeoRasterFile)v.get(i); |
721 |
} |
722 |
bandSetup.addFiles(grf); |
723 |
} |
724 |
} |
725 |
|
726 |
/**
|
727 |
* Deletes a band from the raster. If there is only a file or no band is
|
728 |
* selected then it does nothing.
|
729 |
*
|
730 |
* @param e
|
731 |
*/
|
732 |
private void delFileBand(ActionEvent e){ |
733 |
BandSetupPanel bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)this.getContentPane()).getPanelByClassName("BandSetupPanel"); |
734 |
|
735 |
if( bandSetup.getFileList().getJList().getSelectedValue()!=null && |
736 |
bandSetup.getFileList().getNFiles() > 1){
|
737 |
String pathName = bandSetup.getFileList().getJList().getSelectedValue().toString();
|
738 |
px.delFile(pathName); |
739 |
String file = pathName.substring(pathName.lastIndexOf("/")+1); |
740 |
file = file.substring(file.lastIndexOf("\\")+1); |
741 |
bandSetup.removeFile(file); |
742 |
|
743 |
} |
744 |
} |
745 |
|
746 |
/**
|
747 |
* The cancel button restores the previous state to the loading of this dialog
|
748 |
* @param e Evento
|
749 |
*/
|
750 |
private void cancelButtonActionPerformed(ActionEvent e) { |
751 |
this.status.restoreStatus(this); |
752 |
fLayer.getFMap().invalidate(); |
753 |
} |
754 |
|
755 |
/**
|
756 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
757 |
*/
|
758 |
public ViewInfo getViewInfo() {
|
759 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
760 |
m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_raster")); |
761 |
return m_viewinfo;
|
762 |
} |
763 |
|
764 |
//********************************************************************
|
765 |
//***********************EVENTOS DE RAT?N*****************************
|
766 |
|
767 |
public void mouseClicked(MouseEvent e) { |
768 |
// TODO Auto-generated method stub
|
769 |
|
770 |
} |
771 |
|
772 |
public void mouseEntered(MouseEvent e) { |
773 |
// TODO Auto-generated method stub
|
774 |
|
775 |
} |
776 |
|
777 |
public void mouseExited(MouseEvent e) { |
778 |
// TODO Auto-generated method stub
|
779 |
|
780 |
} |
781 |
|
782 |
public void mousePressed(MouseEvent e) { |
783 |
// TODO Auto-generated method stub
|
784 |
|
785 |
} |
786 |
|
787 |
public void mouseReleased(MouseEvent e) { |
788 |
EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
789 |
if (((e.getSource() == ebcPanel.lstBrightness.getJSlider()) || (e.getSource() == ebcPanel.lstContrast.getJSlider())) &&
|
790 |
(ebcPanel.getJCheckBox1().isSelected() == true))
|
791 |
processBrightnessContrastPanel(); |
792 |
} |
793 |
|
794 |
public void keyPressed(KeyEvent e) { |
795 |
EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
796 |
if(e.getSource() == ebcPanel.getCheckSliderText().getJTextField()){
|
797 |
ebcPanel.getCheckSliderText().getJSlider().setValue((int) Math.round(Double.valueOf(ebcPanel.getCheckSliderText().getTextValue()).doubleValue())); |
798 |
} |
799 |
|
800 |
} |
801 |
|
802 |
public void keyReleased(KeyEvent e) { |
803 |
// TODO Auto-generated method stub
|
804 |
|
805 |
} |
806 |
|
807 |
public void keyTyped(KeyEvent e) { |
808 |
// TODO Auto-generated method stub
|
809 |
|
810 |
} |
811 |
|
812 |
public void actionPerformed(ActionEvent e){ |
813 |
EnhancedBrightnessContrastPanel ebcPanel = (EnhancedBrightnessContrastPanel)super.getPanelByClassName("EnhancedBrightnessContrastPanel"); |
814 |
if((e.getSource() == ebcPanel.getLabelSliderText().getJTextField()) ||
|
815 |
(e.getSource() == ebcPanel.getLabelSliderText1().getJTextField())){ |
816 |
|
817 |
if(ebcPanel.getJCheckBox1().isSelected()){
|
818 |
processBrightnessContrastPanel(); |
819 |
} |
820 |
|
821 |
} |
822 |
} |
823 |
|
824 |
} |