Revision 4840 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/dialogs/GeoreferencingDialog.java

View differences:

GeoreferencingDialog.java
7 7
import java.awt.event.ActionListener;
8 8
import java.awt.event.ComponentEvent;
9 9
import java.awt.event.ComponentListener;
10
import java.awt.geom.Point2D;
11
import java.awt.geom.Rectangle2D;
10 12
import java.beans.PropertyVetoException;
11 13
import java.io.File;
12 14

  
......
25 27
import com.iver.cit.gvsig.GeoOperations;
26 28
import com.iver.cit.gvsig.fmap.DriverException;
27 29
import com.iver.cit.gvsig.fmap.MapControl;
30
import com.iver.cit.gvsig.fmap.ViewPort;
28 31
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
29 32
import com.iver.cit.gvsig.fmap.layers.FLayers;
30 33
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
......
285 288
		}catch(ClassCastException exc){
286 289
			return;
287 290
		}
288
		
289
		//ACEPTAR 
290
		if(e.getSource() == bAceptar){
291
			if(getLyrPoints() == null)
292
				return;
293
						
294
			if(lyrGeoRaster != null){
295
				getLyrPoints().setVisible(false);
296
				lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length()));
297
				lyrGeoRaster.setActive(false);
298
				theView.getMapControl().getMapContext().invalidate();
291

  
292
		try{
293
			//ACEPTAR 
294
			if(e.getSource() == bAceptar){
295
				accept(theView);	
299 296
			}
300 297
			
301
			try{
302
				frame.setClosed(true);
303
			}catch(PropertyVetoException exc){}
298
			//CANCELAR
299
			if(e.getSource() == bCancelar){
300
				cancel(theView);
301
			}
302
		}catch(Exception exc){
303
			return; 
304 304
		}
305 305
		
306
		//CANCELAR
307
		if(e.getSource() == bCancelar){
308
			if(getLyrPoints() == null)
309
				return;
310
						
311
			//Cerramos la ventana 
312
			//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
313
			try{
314
				frame.setClosed(true);
315
			}catch(PropertyVetoException exc){}
316
		}
317
		
318 306
		//CARGAR PUNTOS
319 307
		if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBLoad()){
320 308
			JFileChooser chooser = new JFileChooser(lastPathLoad);
......
402 390
		//PROCESAR
403 391
		if(e.getSource() == this.getBProcesar()){
404 392
			if(this.getLyrPoints().getCountPoints() > 0){
405
				GeoOperations go = new GeoOperations(getLyrPoints(), 
406
													(int)getLyrGeoRaster().getWidth(), 
407
													(int)getLyrGeoRaster().getHeight(),
408
													getLyrGeoRaster().getSource().getFiles()[0].getName());
409
				try{
410
					frame.setClosed(true);
411
				}catch(PropertyVetoException exc){
412 393
					
413
				}
414
				//View view = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView();
415
				//FLayers lyrs = view.getMapControl().getMapContext().getLayers();
394
				//Creamos el fichero de georreferenciaci?n
395
				GeoOperations go = new GeoOperations(getLyrPoints());
396
				go.createWorldFile( (int)getLyrGeoRaster().getWidth(), 
397
									(int)getLyrGeoRaster().getHeight(),
398
									getLyrGeoRaster().getSource().getFiles()[0].getName());
399
				
416 400
				FLayers lyrs = this.getLyrGeoRaster().getParentLayer(); 
417 401
				for(int i = 0; i < lyrs.getLayersCount();i++){
418 402
					if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
403
						
404
						//Eliminamos la capa
419 405
						lyrs.removeLayer(i);
420 406
						File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
421 407
						try{
408
							//Creamos la nueva capa GeoRaster y la a?adimos al TOC. 
422 409
							FLyrGeoRaster lyrGeoRaster = 
423
								FLyrGeoRaster.createLayer(getLyrGeoRaster().getName(), 
410
								FLyrGeoRaster.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()), 
424 411
														(RasterDriver)getLyrGeoRaster().getSource().getDriver(), 
425 412
														fich,
426 413
														getLyrGeoRaster().getProjection(),
427 414
														getLyrGeoRaster().getImageWidth(),
428 415
														getLyrGeoRaster().getImageHeight());
416
							getLyrPoints().setVisible(false);
417
							this.getLyrPoints().setLyrGeoRaster(lyrGeoRaster);
418
							lyrGeoRaster.setFLyrPoints(this.getLyrPoints());
419
							lyrGeoRaster.setGeoDialog(this);
420
							this.lyrGeoRaster = lyrGeoRaster;
421
							calcNewMiniExtent(theView);
429 422
							lyrs.addLayer(lyrGeoRaster);
423
														
424
							lyrGeoRaster.setActive(false);
425
							theView.getMapControl().getMapContext().invalidate();
426
														
427
							try{
428
								frame.setClosed(true);
429
							}catch(PropertyVetoException exc){}
430
																					
430 431
						}catch(DriverException exc){
431 432
							
432 433
						}
......
439 440
	}
440 441
	
441 442
	/**
443
	 * Funci?n que se ejecuta al pulsar el bot?n aceptar
444
	 * @param theView
445
	 */
446
	private void accept(View theView)throws Exception{
447
		if(getLyrPoints() == null)
448
			throw new Exception("LyrPoints not loaded.");
449
					
450
		if(lyrGeoRaster != null){
451
			getLyrPoints().setVisible(false);
452
			lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length()));
453
			lyrGeoRaster.setActive(false);
454
			theView.getMapControl().getMapContext().invalidate();
455
		}
456
		
457
		try{
458
			frame.setClosed(true);
459
		}catch(PropertyVetoException exc){}
460
	}
461
	
462
	/**
463
	 * Funci?n que se ejecuta al pulsar el bot?n cancelar
464
	 * @param theView
465
	 */
466
	private void cancel(View theView)throws Exception{
467
		if(getLyrPoints() == null)
468
			throw new Exception("LyrPoints not loaded.");
469
					
470
		//Cerramos la ventana 
471
		//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
472
		try{
473
			frame.setClosed(true);
474
			theView.getMapControl().getMapContext().invalidate();
475
		}catch(PropertyVetoException exc){}
476
	}
477
	
478
	
479
	/**
480
	 * Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas
481
	 * pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre
482
	 * el nuevo centro y el viejo desplaza el extent completo de la mini-imagen.
483
	 * @param theView
484
	 */
485
	private void calcNewMiniExtent(View theView){
486

  
487
		ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
488
		for(int j = 0; j < getLyrPoints().getCountPoints(); j++){
489
			//Calculamos el nuevo centro
490
			Point2D oldCenter = getLyrPoints().getPoint(j).leftCenterPoint;
491
			Point2D newCenter = new Point2D.Double();
492
			newCenter.setLocation(	lyrGeoRaster.img2World(getLyrPoints().getPoint(j).pixelPoint));
493
			
494
			double diffX = oldCenter.getX() - newCenter.getX();
495
			double diffY = oldCenter.getY() - newCenter.getY();
496
			
497
			getLyrPoints().getPoint(j).leftCenterPoint = newCenter;	
498
						
499
			ViewPort vpOld = getLyrPoints().getPoint(j).leftViewPort;			
500
			Rectangle2D newExtent = new Rectangle2D.Double(	vpOld.getExtent().getMinX() - diffX, 
501
															vpOld.getExtent().getMinY() - diffY, 
502
															vpOld.getExtent().getWidth(), 
503
															vpOld.getExtent().getHeight() );
504
			ViewPort vpNew = new ViewPort(vpOld.getProjection());
505
			vpNew.setExtent(newExtent);
506
			vpNew.setImageSize(vpOld.getImageSize());
507
			vpNew.setScale();
508
			getLyrPoints().getPoint(j).leftViewPort = vpNew;
509
		}
510
	}
511
	
512
	/**
442 513
	 * This method initializes bProcesar	
443 514
	 * 	
444 515
	 * @return javax.swing.JButton	
......
449 520
			bProcesar.setText(PluginServices.getText(this,"procesar"));
450 521
			bProcesar.setEnabled(true);
451 522
			bProcesar.addActionListener(this);
452
			
453
			/*new java.awt.event.ActionListener() { 
454
				public void actionPerformed(java.awt.event.ActionEvent e) {
455
					GeoOperations go = new GeoOperations(this.);
456
                    if (PluginServices.getMainFrame() == null) {
457
                        ((JDialog) (getParent().getParent().getParent()
458
                                .getParent())).dispose();
459
                    } else {
460
                        PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this);
461
                    }
462
				}
463
			});*/
464 523
		}
465 524
		return bProcesar;
466 525
	}

Also available in: Unified diff