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