303 |
303 |
if(e.getSource() == bCancelar){
|
304 |
304 |
cancel(theView);
|
305 |
305 |
}
|
306 |
|
}catch(Exception exc){
|
307 |
|
return;
|
308 |
|
}
|
309 |
|
|
310 |
|
//CARGAR PUNTOS
|
311 |
|
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBLoad()){
|
312 |
|
JFileChooser chooser = new JFileChooser(lastPathLoad);
|
313 |
|
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
314 |
|
FileFilter f = null;
|
315 |
|
for(int i=0; i<this.fileFilters.length;i++){
|
316 |
|
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
317 |
|
chooser.addChoosableFileFilter(f);
|
318 |
|
}
|
319 |
|
int returnVal = chooser.showOpenDialog(this);
|
320 |
|
if(returnVal == JFileChooser.APPROVE_OPTION){
|
321 |
|
String fName = chooser.getSelectedFile().toString();
|
322 |
|
FileFilter filter = chooser.getFileFilter();
|
323 |
|
lastPathLoad = chooser.getCurrentDirectory().getAbsolutePath();
|
324 |
306 |
|
325 |
|
if(getLyrPoints() == null)
|
326 |
|
return;
|
327 |
|
|
328 |
|
lyrGeoRaster.getFLyrPoints().saveState();
|
329 |
|
getLyrPoints().XML2PointList(fName);
|
|
307 |
//CARGAR PUNTOS
|
|
308 |
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBLoad()){
|
|
309 |
loadPoints(theView);
|
330 |
310 |
}
|
331 |
|
}
|
332 |
|
|
333 |
|
//SALVAR PUNTOS
|
334 |
|
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBSave()){
|
335 |
|
JFileChooser chooser = new JFileChooser(lastPathSave);
|
336 |
|
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
337 |
311 |
|
338 |
|
FileFilter f = null;
|
339 |
|
for(int i=0; i<this.fileFilters.length;i++){
|
340 |
|
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
341 |
|
chooser.addChoosableFileFilter(f);
|
|
312 |
//SALVAR PUNTOS
|
|
313 |
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBSave()){
|
|
314 |
savePoints(theView);
|
342 |
315 |
}
|
343 |
|
int returnVal = chooser.showOpenDialog(this);
|
344 |
|
if(returnVal == JFileChooser.APPROVE_OPTION){
|
345 |
|
String fName = chooser.getSelectedFile().toString();
|
346 |
|
lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
|
347 |
|
if(!fName.endsWith(".grf"))
|
348 |
|
fName = fName + ".grf";
|
349 |
|
if(this.checkFileExists(fName)){
|
350 |
|
if(getLyrPoints() != null)
|
351 |
|
getLyrPoints().PointList2XML(fName);
|
352 |
|
}
|
353 |
|
}
|
354 |
316 |
|
355 |
|
}
|
356 |
|
|
357 |
|
//EXPORTAR A ASCII
|
358 |
|
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBExportToAscii()){
|
359 |
|
JFileChooser chooser = new JFileChooser(lastPathSave);
|
360 |
|
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
361 |
|
|
362 |
|
FileFilter f = null;
|
363 |
|
for(int i=0; i<this.fileFilters.length;i++){
|
364 |
|
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
365 |
|
chooser.addChoosableFileFilter(f);
|
|
317 |
//EXPORTAR A ASCII
|
|
318 |
if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBExportToAscii()){
|
|
319 |
exportToASCII(theView);
|
366 |
320 |
}
|
367 |
|
int returnVal = chooser.showOpenDialog(this);
|
368 |
|
if(returnVal == JFileChooser.APPROVE_OPTION){
|
369 |
|
String fName = chooser.getSelectedFile().toString();
|
370 |
|
lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
|
371 |
|
if(this.checkFileExists(fName)){
|
372 |
|
if(getLyrPoints() != null)
|
373 |
|
getLyrPoints().PointList2Ascii(fName);
|
374 |
|
}
|
375 |
|
}
|
376 |
321 |
|
377 |
|
}
|
378 |
|
|
379 |
|
//DESACTIVAR PANELES
|
380 |
|
JCheckBox cb = this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive();
|
381 |
|
if(e.getSource() == cb){
|
382 |
|
if(cb.isSelected()){
|
383 |
|
this.setEnabled(true);
|
384 |
|
getLyrPoints().setPointActive(getSelectedPoint(), true);
|
385 |
|
}else{
|
386 |
|
this.setEnabled(false);
|
387 |
|
getLyrPoints().setPointActive(getSelectedPoint(), false);
|
388 |
|
}
|
389 |
|
theView.getMapControl().getMapContext().invalidate();
|
390 |
|
getZoomControlLeft().draw();
|
391 |
|
getZoomControlRight().draw();
|
392 |
|
}
|
393 |
|
|
394 |
|
//PROCESAR
|
395 |
|
if(e.getSource() == this.getBProcesar()){
|
396 |
|
if(this.getLyrPoints().getCountPoints() > 0){
|
397 |
|
|
398 |
|
//Creamos el fichero de georreferenciaci?n
|
399 |
|
GeoOperations go = new GeoOperations(getLyrPoints());
|
400 |
|
go.createWorldFile( (int)getLyrGeoRaster().getWidth(),
|
401 |
|
(int)getLyrGeoRaster().getHeight(),
|
402 |
|
getLyrGeoRaster().getSource().getFiles()[0].getName());
|
403 |
|
|
404 |
|
FLayers lyrs = this.getLyrGeoRaster().getParentLayer();
|
405 |
|
for(int i = 0; i < lyrs.getLayersCount();i++){
|
406 |
|
if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
|
407 |
|
|
408 |
|
//Eliminamos la capa
|
409 |
|
lyrs.removeLayer(i);
|
410 |
|
File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
|
411 |
|
try{
|
412 |
|
//Creamos la nueva capa GeoRaster y la a?adimos al TOC.
|
413 |
|
FLyrGeoRaster lyrGeoRaster =
|
414 |
|
FLyrGeoRaster.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()),
|
415 |
|
(RasterDriver)getLyrGeoRaster().getSource().getDriver(),
|
416 |
|
fich,
|
417 |
|
getLyrGeoRaster().getProjection(),
|
418 |
|
getLyrGeoRaster().getImageWidth(),
|
419 |
|
getLyrGeoRaster().getImageHeight());
|
420 |
|
getLyrPoints().setVisible(false);
|
421 |
|
this.getLyrPoints().setLyrGeoRaster(lyrGeoRaster);
|
422 |
|
lyrGeoRaster.setFLyrPoints(this.getLyrPoints());
|
423 |
|
lyrGeoRaster.setGeoDialog(this);
|
424 |
|
this.lyrGeoRaster = lyrGeoRaster;
|
425 |
|
calcNewMiniExtent(theView);
|
426 |
|
lyrs.addLayer(lyrGeoRaster);
|
427 |
|
|
428 |
|
lyrGeoRaster.setActive(false);
|
429 |
|
theView.getMapControl().getMapContext().invalidate();
|
430 |
|
|
431 |
|
try{
|
432 |
|
frame.setClosed(true);
|
433 |
|
}catch(PropertyVetoException exc){}
|
434 |
|
|
435 |
|
}catch(DriverException exc){
|
436 |
|
|
437 |
|
}
|
438 |
|
break;
|
439 |
|
}
|
440 |
|
}
|
|
322 |
//DESACTIVAR PANELES
|
|
323 |
JCheckBox cb = this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive();
|
|
324 |
if(e.getSource() == cb){
|
|
325 |
deactivatePanel(theView, cb);
|
|
326 |
}
|
441 |
327 |
|
|
328 |
//PROCESAR
|
|
329 |
if(e.getSource() == this.getBProcesar()){
|
|
330 |
process(theView);
|
442 |
331 |
}
|
|
332 |
}catch(Exception exc){
|
|
333 |
return;
|
443 |
334 |
}
|
444 |
335 |
}
|
445 |
336 |
|
... | ... | |
479 |
370 |
}catch(PropertyVetoException exc){}
|
480 |
371 |
}
|
481 |
372 |
|
|
373 |
/**
|
|
374 |
* Funci?n que se ejecuta al pulsar el bot?n de cargar puntos
|
|
375 |
* @param theView
|
|
376 |
*/
|
|
377 |
private void loadPoints(View theView)throws Exception{
|
|
378 |
JFileChooser chooser = new JFileChooser(lastPathLoad);
|
|
379 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
|
380 |
FileFilter f = null;
|
|
381 |
for(int i=0; i<this.fileFilters.length;i++){
|
|
382 |
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
|
383 |
chooser.addChoosableFileFilter(f);
|
|
384 |
}
|
|
385 |
int returnVal = chooser.showOpenDialog(this);
|
|
386 |
if(returnVal == JFileChooser.APPROVE_OPTION){
|
|
387 |
String fName = chooser.getSelectedFile().toString();
|
|
388 |
FileFilter filter = chooser.getFileFilter();
|
|
389 |
lastPathLoad = chooser.getCurrentDirectory().getAbsolutePath();
|
|
390 |
|
|
391 |
if(getLyrPoints() == null)
|
|
392 |
throw new Exception("LyrPoints not loaded.");
|
|
393 |
|
|
394 |
lyrGeoRaster.getFLyrPoints().saveState();
|
|
395 |
getLyrPoints().XML2PointList(fName);
|
|
396 |
}
|
|
397 |
}
|
482 |
398 |
|
483 |
399 |
/**
|
|
400 |
* Funci?n que se ejecuta al pulsar el bot?n salvar puntos
|
|
401 |
* @param theView
|
|
402 |
*/
|
|
403 |
private void savePoints(View theView)throws Exception{
|
|
404 |
if(getLyrPoints() == null)
|
|
405 |
throw new Exception("LyrPoints not loaded.");
|
|
406 |
|
|
407 |
JFileChooser chooser = new JFileChooser(lastPathSave);
|
|
408 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
|
409 |
|
|
410 |
FileFilter f = null;
|
|
411 |
for(int i=0; i<this.fileFilters.length;i++){
|
|
412 |
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
|
413 |
chooser.addChoosableFileFilter(f);
|
|
414 |
}
|
|
415 |
int returnVal = chooser.showOpenDialog(this);
|
|
416 |
if(returnVal == JFileChooser.APPROVE_OPTION){
|
|
417 |
String fName = chooser.getSelectedFile().toString();
|
|
418 |
lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
|
|
419 |
if(!fName.endsWith(".grf"))
|
|
420 |
fName = fName + ".grf";
|
|
421 |
if(this.checkFileExists(fName)){
|
|
422 |
if(getLyrPoints() != null)
|
|
423 |
getLyrPoints().PointList2XML(fName);
|
|
424 |
}
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
/**
|
|
429 |
* Funci?n que se ejecuta al pulsar el bot?n de export a ascii
|
|
430 |
* @param theView
|
|
431 |
*/
|
|
432 |
private void exportToASCII(View theView)throws Exception{
|
|
433 |
if(getLyrPoints() == null)
|
|
434 |
throw new Exception("LyrPoints not loaded.");
|
|
435 |
|
|
436 |
JFileChooser chooser = new JFileChooser(lastPathSave);
|
|
437 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
|
|
438 |
|
|
439 |
FileFilter f = null;
|
|
440 |
for(int i=0; i<this.fileFilters.length;i++){
|
|
441 |
f = new SelectFileFilter(chooser, this.fileFilters[i]);
|
|
442 |
chooser.addChoosableFileFilter(f);
|
|
443 |
}
|
|
444 |
int returnVal = chooser.showOpenDialog(this);
|
|
445 |
if(returnVal == JFileChooser.APPROVE_OPTION){
|
|
446 |
String fName = chooser.getSelectedFile().toString();
|
|
447 |
lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
|
|
448 |
if(this.checkFileExists(fName)){
|
|
449 |
if(getLyrPoints() != null)
|
|
450 |
getLyrPoints().PointList2Ascii(fName);
|
|
451 |
}
|
|
452 |
}
|
|
453 |
}
|
|
454 |
|
|
455 |
/**
|
|
456 |
* Funci?n que se ejecuta al pulsar el bot?n desactivar panel
|
|
457 |
* @param theView
|
|
458 |
*/
|
|
459 |
private void deactivatePanel(View theView, JCheckBox cb)throws Exception{
|
|
460 |
if(getLyrPoints() == null)
|
|
461 |
throw new Exception("LyrPoints not loaded.");
|
|
462 |
if(cb.isSelected()){
|
|
463 |
this.setEnabled(true);
|
|
464 |
getLyrPoints().setPointActive(getSelectedPoint(), true);
|
|
465 |
}else{
|
|
466 |
this.setEnabled(false);
|
|
467 |
getLyrPoints().setPointActive(getSelectedPoint(), false);
|
|
468 |
}
|
|
469 |
theView.getMapControl().getMapContext().invalidate();
|
|
470 |
getZoomControlLeft().draw();
|
|
471 |
getZoomControlRight().draw();
|
|
472 |
}
|
|
473 |
|
|
474 |
/**
|
|
475 |
* Funci?n que se ejecuta al pulsar el bot?n procesar
|
|
476 |
* @param theView
|
|
477 |
*/
|
|
478 |
private void process(View theView)throws Exception{
|
|
479 |
if(getLyrPoints() == null)
|
|
480 |
throw new Exception("LyrPoints not loaded.");
|
|
481 |
if(this.getLyrPoints().getCountPoints() > 0){
|
|
482 |
|
|
483 |
//Creamos el fichero de georreferenciaci?n
|
|
484 |
GeoOperations go = new GeoOperations(getLyrPoints());
|
|
485 |
go.createWorldFile( (int)getLyrGeoRaster().getWidth(),
|
|
486 |
(int)getLyrGeoRaster().getHeight(),
|
|
487 |
getLyrGeoRaster().getSource().getFiles()[0].getName());
|
|
488 |
|
|
489 |
FLayers lyrs = this.getLyrGeoRaster().getParentLayer();
|
|
490 |
for(int i = 0; i < lyrs.getLayersCount();i++){
|
|
491 |
if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
|
|
492 |
|
|
493 |
//Eliminamos la capa
|
|
494 |
lyrs.removeLayer(i);
|
|
495 |
File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
|
|
496 |
try{
|
|
497 |
//Creamos la nueva capa GeoRaster y la a?adimos al TOC.
|
|
498 |
FLyrGeoRaster lyrGeoRaster =
|
|
499 |
FLyrGeoRaster.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()),
|
|
500 |
(RasterDriver)getLyrGeoRaster().getSource().getDriver(),
|
|
501 |
fich,
|
|
502 |
getLyrGeoRaster().getProjection(),
|
|
503 |
getLyrGeoRaster().getImageWidth(),
|
|
504 |
getLyrGeoRaster().getImageHeight());
|
|
505 |
getLyrPoints().setVisible(false);
|
|
506 |
this.getLyrPoints().setLyrGeoRaster(lyrGeoRaster);
|
|
507 |
lyrGeoRaster.setFLyrPoints(this.getLyrPoints());
|
|
508 |
lyrGeoRaster.setGeoDialog(this);
|
|
509 |
this.lyrGeoRaster = lyrGeoRaster;
|
|
510 |
calcNewMiniExtent(theView);
|
|
511 |
lyrs.addLayer(lyrGeoRaster);
|
|
512 |
|
|
513 |
lyrGeoRaster.setActive(false);
|
|
514 |
theView.getMapControl().getMapContext().invalidate();
|
|
515 |
|
|
516 |
try{
|
|
517 |
frame.setClosed(true);
|
|
518 |
}catch(PropertyVetoException exc){}
|
|
519 |
|
|
520 |
}catch(DriverException exc){
|
|
521 |
|
|
522 |
}
|
|
523 |
break;
|
|
524 |
}
|
|
525 |
}
|
|
526 |
|
|
527 |
}
|
|
528 |
}
|
|
529 |
|
|
530 |
/**
|
484 |
531 |
* Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas
|
485 |
532 |
* pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre
|
486 |
533 |
* el nuevo centro y el viejo desplaza el extent completo de la mini-imagen.
|