Revision 4203 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameView.java

View differences:

FFrameView.java
101 101
    private double m_Scale = 0;
102 102
    private int m_mapUnits = 1; //Metros.
103 103

  
104
    //private int num = 0;
105 104
    private BufferedImage m_image = null;
106 105
    private AffineTransform at = null;
107 106
    private Project project = null;
108 107
    private Layout layout;
109 108
	private double scaleAnt;
110 109
	private boolean refresh=false;
111
	private FFrameView fframeAux;
112
	
110
	private boolean hasViewPort=false;
111
	private Point2D antpoint;
113 112
    /**
114 113
     * Creates a new FFrameView object.
115 114
     */
......
209 208

  
210 209
        ViewPort vp = v.getMapContext().getViewPort().cloneViewPort();
211 210

  
212
        vp.setImageSize(new Dimension((int) getBoundingBox(null).width,
211
        vp.setImageSize(new Dimension((int) getBoundingBox(getATMap()).width,
213 212
                (int) getBoundingBox(null).height));
214 213

  
215 214
        if (m_bLinked) {
......
266 265
                    e1);
267 266
            }
268 267
        }
269

  
270
        /*
271
           m_fmap = v.getMapContext();
272
        
273
           v.getMapContext().getViewPort();
274
           ViewPort vp = new ViewPort();
275
           vp.setExtent(v.getMapContext().getViewPort().getExtent());
276
           m_fmap = m_fmap.createNewFMap(vp);
277
           view = v;
278
         */
279 268
    }
280 269

  
281 270
    /**
......
300 289
        double wview = getBoundBox().getWidth();
301 290
        double hextent = (scale * hview) / 100.0;
302 291
        double wextent = (scale * wview) / 100.0;
303

  
304
        // double dif = hextent / m_fmap.getViewPort().getExtent().getHeight();
305 292
        double newx = m_fmap.getViewPort().getExtent().getCenterX() -
306 293
            (wextent / 2.0);
307 294
        double newy = m_fmap.getViewPort().getExtent().getCenterY() -
......
317 304
     *
318 305
     * @param g Graphics2D
319 306
     * @param at Transformada af?n.
320
     * @param rv rect?ngulo sobre el que hacer un clip.
307
     * @param rv rect?ngulo sobre el que hacer un clip. (el rect?ngulo visible)
321 308
     * @param imgBase Imagen para acelerar el dibujado.
322 309
     *
323 310
     * @throws com.iver.cit.gvsig.fmap.DriverException
324 311
     */
325 312
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
326 313
        BufferedImage imgBase) throws com.iver.cit.gvsig.fmap.DriverException {
314
    	System.out.println("Tama?o del imgBase= "+ imgBase.getWidth()+","+imgBase.getHeight());
315
    	Point2D point =null;
316
    	if (getATMap()!=null){
317
    	point =functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap());
318
    	}
319
    	/**
320
    	 * this FFrame's BoundingBox
321
    	 */
327 322
    	Rectangle2D.Double r = getBoundingBox(at);
328
    	if (layout.getAT().getScaleX()==scaleAnt && m_image!=null && !refresh){
329
        	g.translate((int)r.getX(),(int)r.getY());
330
        	g.drawImage(m_image,0,0,layout);
331
        	g.translate(-(int)r.getX(),-(int)r.getY());
332
        	scaleAnt=layout.getAT().getScaleX();
333
        	return;
323
    	if (rv!=null && layout.getAT().getScaleX()==scaleAnt && m_image!=null && !refresh){
324
        	if (point.equals(antpoint)) {
325
				g.translate((int) r.getX(), (int) r.getY());
326
				g.drawImage(m_image, 0, 0, layout);
327
				g.translate(-(int) r.getX(), -(int) r.getY());
328
				scaleAnt = layout.getAT().getScaleX();
329
				return;
330
			}
334 331
        }
332

  
335 333
    	if (getRotation()!=0)
336 334
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
337 335
            r.y + (r.height / 2));
......
347 345
                        (int) r.getWidth(), (int) r.getHeight());
348 346

  
349 347
                    if (getQuality() == PRESENTACION) {
350
                        if (rv.intersects(r)) {
351
                        	
352
                         
348
                    	if (rv.intersects(r)) {
349
                    		ViewPort viewPort = this.getFMap().getViewPort();
350
                    		Color theBackColor = viewPort.getBackColor();
353 351

  
354
                                ViewPort viewPort = this.getFMap().getViewPort();
355
                                Color theBackColor = viewPort.getBackColor();
352
                    		if (theBackColor != null) {
353
                    			g.setColor(theBackColor);
354
                    			g.fillRect((int) r.x, (int) r.y,
355
                    					viewPort.getImageWidth(),
356
                    					viewPort.getImageHeight());
357
                    		}
358
                    		System.err.println("r : "+r);
359
                    		if (r.getWidth()>layout.getWidth() || r.getHeight()>layout.getHeight()){
360
                    			getFMap().getViewPort().setOffset(new Point2D.Double(0,0));
361
                    			if (antpoint!=null && !refresh){
362
                    			Rectangle2D extent=getFMap().getViewPort().getExtent();
363
                    			extent.setRect(extent.getX()+(antpoint.getX()-point.getX()),extent.getY()+(antpoint.getY()-point.getY()),extent.getWidth(),extent.getHeight());
364
                    			setNewExtent(extent);
365
                    			}
366
                    			//if (antViewPort==null)
367
                    			//antViewPort=getFMap().getViewPort().cloneViewPort();
368
                    			getFMap().getViewPort().setImageSize(new Dimension((int) layout.getWidth(), (int)layout.getHeight()));
369
                    			getFMap().draw(imgBase, g, getScale());
370
                    			setATMap((AffineTransform) getFMap()
371
                    				        .getViewPort()
372
                    				        .getAffineTransform()
373
                    				        .clone());
374
                    			//getFMap().setViewPort(antViewPort.cloneViewPort());
375
                    			antpoint=functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap());
376
                    		}else{
377
                    			if (!hasViewPort){
378
                    				saveAntViewPort();
379
                    				hasViewPort=true;
380
                    			}else{
381
                    				getFMap().setViewPort(antViewPort.cloneViewPort());
382
                    			}
383
                    			getFMap().getViewPort().setOffset(new Point2D.Double(
384
                    					r.x, r.y));
385
                    			getFMap().getViewPort().setImageSize(new Dimension(
386
                    					(int) r.width, (int) r.height));
387
                    			m_image=new BufferedImage((int)r.getWidth(),
388
                    					(int) r.getHeight(),
389
                    					BufferedImage.TYPE_INT_ARGB);
390
                    			Graphics2D gimg=(Graphics2D) m_image.getGraphics();
391
                    			gimg.translate(-((int)r.getX()),-((int)r.getY()));
392
                    			getFMap().draw(m_image,gimg, getScale());
393
                    			gimg.translate(((int)r.getX()),((int)r.getY()));
394
                    			g.drawImage(m_image,(int)r.getX(),(int)r.getY(),layout);
395
                    			setATMap((AffineTransform) getFMap()
396
                    				        .getViewPort()
397
                    				        .getAffineTransform()
398
                    				        .clone());
399
                    			 antpoint=null;
400
                    		}
401
                    		scaleAnt=layout.getAT().getScaleX();
402
                    		refresh=false;
356 403

  
357
                                if (theBackColor != null) {
358
                                    g.setColor(theBackColor);
359
                                    g.fillRect((int) r.x, (int) r.y,
360
                                        viewPort.getImageWidth(),
361
                                        viewPort.getImageHeight());
362
                                }
363
                                System.err.println("r : "+r);
364
                                if (r.getWidth()>layout.getWidth() || r.getHeight()>layout.getHeight()){
365
                                /*	TODO Este c?digo todavia no funciona bien, lo hace en el primer zoom que se realiza, pero en el siguiente se hace mal.
366
                                	getFMap().getViewPort().setClipRect(cliprectMap);
367
                                	Rectangle2D cliprectLayoutpixels=FLayoutUtilities.fromSheetRect(cliprectLayout,layout.getAT());
368
                                	this.getFMap().getViewPort().setOffset(new Point2D.Double(
369
                                            r.getX(), r.getY()));
370
                                	getFMap().getViewPort().setImageSize(new Dimension(
371
                                            (int) r.getWidth(), (int) r.getHeight()));
372
                                	
373
                                	BufferedImage image=new BufferedImage((int)cliprectLayoutpixels.getWidth(),
374
                                            (int) cliprectLayoutpixels.getHeight(),
375
                                            BufferedImage.TYPE_INT_ARGB);
376
                                    
377
                                	Graphics2D gimg=(Graphics2D) image.getGraphics();
378
                                	gimg.translate(-r.getX(),-r.getY());
379
                                	getFMap().draw(image,gimg,getScale());
380
                                	getFMap().getViewPort().setClipRect(null);
381
                                	g.drawImage(image,(int)(0),(int)(0),layout);
382
                                	m_image=null;
383
                                */
384
                                	getFMap().getViewPort().setOffset(new Point2D.Double(
385
                                            r.getX(), r.getY()));
386
                                	getFMap().getViewPort().setImageSize(new Dimension(
387
                                            (int) r.getWidth(), (int) r.getHeight()));
388
                                	getFMap().draw(imgBase,g,getScale());
389
                                }else{
390
                                	getFMap().getViewPort().setOffset(new Point2D.Double(
391
                                            r.x, r.y));
392
                                	getFMap().getViewPort().setImageSize(new Dimension(
393
                                              (int) r.width, (int) r.height));
394
                                	m_image=new BufferedImage((int)r.getWidth(),
395
                                        (int) r.getHeight(),
396
                                        BufferedImage.TYPE_INT_ARGB);
397
                                	Graphics2D gimg=(Graphics2D) m_image.getGraphics();
398
                                	gimg.translate(-((int)r.getX()),-((int)r.getY()));
399
                                	getFMap().draw(m_image,gimg, getScale());
400
                                	gimg.translate(((int)r.getX()),((int)r.getY()));
401
                                	g.drawImage(m_image,(int)r.getX(),(int)r.getY(),layout);
402
                                }
403
                                scaleAnt=layout.getAT().getScaleX();
404
                                refresh=false;
405
                        }
406
                        if (rclip != null) {
407
                            g.setClip(rclip.x, rclip.y, rclip.width,
408
                                rclip.height);
409
                        }
404
                    	}
405
                    	if (rclip != null) {
406
                    		g.setClip(rclip.x, rclip.y, rclip.width,
407
                    				rclip.height);
408
                    	}
410 409
                    } else {
411
                        drawDraft(g);
410
                    	drawDraft(g);
412 411
                    }
413 412
                } else {
414
                    printX(g, at);
413
                	printX(g, at);
414
                	setATMap((AffineTransform) getFMap()
415
    				        .getViewPort()
416
    				        .getAffineTransform()
417
    				        .clone());
415 418
                }
416 419
            }
417 420
        }
421

  
418 422
        if (getRotation()!=0)
419 423
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
420 424
            r.y + (r.height / 2));
421
        
422
        setATMap((AffineTransform) getFMap()
423
        .getViewPort()
424
        .getAffineTransform()
425
        .clone());
426 425
    }
427 426

  
428 427
    /**
......
642 641
    }
643 642

  
644 643
    /**
645
     * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
644
     * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView para poder cambiar
645
     * un punto en pixels a coordenadas del mundo real.
646 646
     *
647 647
     * @return MAtriz de transformaci?n.
648 648
     */
......
691 691
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
692 692
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
693 693

  
694
        //ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
695 694
        this.m_Scale = xml.getDoubleProperty("m_Scale");
696 695

  
697 696
        int indice = xml.getIntProperty("indice");
......
742 741

  
743 742
            if (layout != null) {
744 743
                layout.setStatus(Layout.DESACTUALIZADO);
745

  
746
                //setBufferedImage(null);
747 744
            }
748 745
        }
749 746
    }
......
755 752
        if (getLinked()) {
756 753
            m_fmap.getViewPort().setBackColor(e.getNewColor());
757 754
            layout.setStatus(Layout.DESACTUALIZADO);
758

  
759
            //setBufferedImage(null);
760 755
        }
761 756
    }
762 757

  
......
777 772
    public void legendChanged(LegendChangedEvent e) {
778 773
        if (getLinked()) {
779 774
            layout.setStatus(Layout.DESACTUALIZADO);
780

  
781
            //setBufferedImage(null);
782 775
        }
783 776
    }
784 777

  
......
807 800
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
808 801
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
809 802
        setRotation(xml.getDoubleProperty("m_rotation"));
810

  
811
        //ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
812 803
        this.m_Scale = xml.getDoubleProperty("m_Scale");
813 804

  
814 805
        int indice = xml.getIntProperty("indice");
......
909 900
	public void refresh() {
910 901
		refresh=true;
911 902
	}
912
	private Rectangle2D cliprectMap;
913
	private Rectangle2D cliprectLayout;
914 903
	private FLayoutFunctions functions=new FLayoutFunctions(layout);
915
	public Rectangle2D getRectView(Point2D p1,Point2D p2){
916
		//if (cliprect==null){
917
		
918
		cliprectLayout=FLayoutUtilities.toSheetRect(new Rectangle2D.Double(p1.getX(),p1.getY(),p2.getX()-p1.getX(),p2.getY()-p1.getY()),layout.getAT());
919
		//setZoomIn(layout.getFirstPoint(),layout.getLastPoint());
920
		Point2D point1=functions.toMapPoint(new Point2D.Double(p1.getX(),p1.getY()),getATMap());
921
		Point2D point2=functions.toMapPoint(new Point2D.Double(p2.getX(),p2.getY()),getATMap());
922
		cliprectMap= new Rectangle2D.Double(point1.getX(),point1.getY()-Math.abs(point2.getY()-point1.getY()),Math.abs(point2.getX()-point1.getX()),Math.abs(point2.getY()-point1.getY()));
923
		//}
924
		return cliprectMap;
925
	}
926
	/*
927
	public void setZoomIn(Point p1, Point p2) {
928
		if (p1.getX()>p2.getX()){
929
			int aux=p2.x;
930
			p2.x=p1.x;
931
			p1.x=aux;
932
		}
933
		if (p1.getY()>p2.getY()){
934
			int aux=p2.y;
935
			p2.y=p1.y;
936
			p1.y=aux;
937
		}
938
		Point2D.Double pSheet1 = FLayoutUtilities.toSheetPoint(new Point2D.Double(
939
					p1.getX(), p1.getY()), layout.getAT());
940
		Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double(
941
					p2.getX(), p2.getY()), layout.getAT());
904
	private ViewPort antViewPort;
942 905

  
943
		double xmin;
944
		double xmax;
945
		double ymin;
946
		double ymax = 0;
906
	public void saveAntViewPort() {
907
		antViewPort=getFMap().getViewPort().cloneViewPort();
947 908

  
948
		if (pSheet1.x > pSheet2.x) {
949
			xmin = pSheet2.x;
950
			xmax = pSheet1.x;
951
		} else {
952
			xmin = pSheet1.x;
953
			xmax = pSheet2.x;
954
		}
909
	}
955 910

  
956
		if (pSheet1.y > pSheet2.y) {
957
			ymin = pSheet2.y;
958
			ymax = pSheet1.y;
959
		} else {
960
			ymin = pSheet1.y;
961
			ymax = pSheet2.y;
962
		}
963

  
964
		Rectangle2D.Double rScreen = new Rectangle2D.Double();
965
		Rectangle2D.Double rSheet = new Rectangle2D.Double();
966
		double x = cliprectLayout.getX();
967
		double y = cliprectLayout.getY();
968
		double w = cliprectLayout.getWidth();
969
		double h = cliprectLayout.getHeight();
970

  
971
		if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) {
972
			double difw = 2;
973

  
974
			rSheet.x = (-pSheet2.getX() * difw) - x +
975
				FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
976
					layout.getAT());
977
			rSheet.y = (-pSheet2.getY() * difw) - y +
978
				FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
979
					layout.getAT());
980

  
981
			rSheet.width = w * difw;
982
			rSheet.height = h * difw;
983

  
984
			rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet,
985
					layout.getAT()));
986
		} else {
987
			double wv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
988
															   .getWidth(),
989
					layout.getAT());
990
			double hv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
991
															   .getHeight(),
992
					layout.getAT());
993
			double mw = xmax - xmin;
994
			double mh = ymax - ymin;
995
			double difw = wv / mw;
996
			double difh = hv / mh;
997

  
998
			if (difw < difh) {
999
				rSheet.x = (-xmin * difw) - x +
1000
					((wv - ((pSheet2.getX() - pSheet1.getX()) * difw)) / 2);
1001
				rSheet.y = (-ymin * difw) - y +
1002
					((hv - ((pSheet2.getY() - pSheet1.getY()) * difw)) / 2);
1003

  
1004
				rSheet.width = w * difw;
1005
				rSheet.height = h * difw;
1006
			} else {
1007
				rSheet.x = (-xmin * difh) - x +
1008
					((wv - ((pSheet2.getX() - pSheet1.getX()) * difh)) / 2);
1009
				rSheet.y = (-ymin * difh) - y +
1010
					((hv - ((pSheet2.getY() - pSheet1.getY()) * difh)) / 2);
1011

  
1012
				rSheet.width = w * difh;
1013
				rSheet.height = h * difh;
1014
			}
1015

  
1016
			rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet,
1017
					layout.getAT()));
1018
		}
1019
		cliprectLayoutpixels=rScreen;
1020
		
1021
	}*/
911
	public void initialize() {
912
		setView(view);
913
	}
1022 914
}

Also available in: Unified diff