Revision 228 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java

View differences:

FFrameView.java
29 29
import java.awt.Point;
30 30
import java.awt.Rectangle;
31 31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.Area;
33
import java.awt.geom.NoninvertibleTransformException;
32 34
import java.awt.geom.Point2D;
33 35
import java.awt.geom.Rectangle2D;
34 36
import java.awt.image.BufferedImage;
......
160 162
	 */
161 163
	private boolean b_frameInitialized = true;
162 164

  
163
	protected AffineTransform originalGraphicsAt = null;
165
	protected AffineTransform originalGraphicsAT = null;
164 166
	protected Rectangle originalClip = null;
167
	private AffineTransform rotationAT = null;
165 168

  
166 169

  
167 170
    /**
......
346 349
     * @param imgBase Image used to speed up the drawing process
347 350
     */
348 351
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase) {
349
        Rectangle2D.Double fframeViewRect = getBoundingBox(at);  
350
        preDraw(g, fframeViewRect);    
351
        if (intersects(visibleLayoutDocRect, fframeViewRect)) {
352
            if (getMapContext() == null) {
353
                drawEmpty(g);
354
            } else {
355
                if (FLayoutUtilities.hasEditingLayers(getView())) {
356
                    
357
                    /*
358
                     * We are not drawing if any layer is in editing mode
359
                     */
360
                    drawMessage(g, Messages.getText(
361
                        "_Cannot_draw_view_if_layers_in_editing_mode"));
362
                    
363
                } else {
364
                    if (getQuality() == PRESENTATION) {
365
                        try {
366
                            drawPresentation(g, at, fframeViewRect, visibleLayoutDocRect, imgBase);
367
                        } catch (Exception exc) {
368
                            drawMessage(g, FLayoutFunctions.getLastMessage(exc));
369
                        }
370
                        
371
                    } else {
372
                        drawDraft(g);
373
                    }               
374
                }
375
                updateScaleCtrl(); // we need to update the scale whenever the window gets activated
376
            }
352
        Rectangle2D.Double fframeViewRect = getBoundingBox(at);
353
        Rectangle2D.Double visibleArea = (Rectangle2D.Double) getVisibleRect(visibleLayoutDocRect, fframeViewRect);
354
        if (visibleArea==null) {
355
        	return;
377 356
        }
378
        postDraw(g, fframeViewRect, visibleLayoutDocRect, imgBase, at); 
357
        preDraw(g, fframeViewRect, visibleArea);
358
        if (getMapContext() == null) {
359
        	drawEmpty(g);
360
        } else {
361
        	if (FLayoutUtilities.hasEditingLayers(getView())) {
362

  
363
        		/*
364
        		 * We are not drawing if any layer is in editing mode
365
        		 */
366
        		drawMessage(g, Messages.getText(
367
        				"_Cannot_draw_view_if_layers_in_editing_mode"));
368

  
369
        	} else {
370
        		if (getQuality() == PRESENTATION) {
371
        			try {
372
        				drawPresentation(g, at, fframeViewRect, visibleArea, imgBase);
373
        			} catch (Exception exc) {
374
        				drawMessage(g, FLayoutFunctions.getLastMessage(exc));
375
        			}
376

  
377
        		} else {
378
        			drawDraft(g);
379
        		}               
380
        	}
381
        	updateScaleCtrl(); // we need to update the scale whenever the window gets activated
382
        }
383
        postDraw(g, fframeViewRect, at); 
379 384
        if (showGrid && grid != null) {           
380 385
            grid.draw(g, at, visibleLayoutDocRect, imgBase);
381 386
        }    
......
401 406
            (int) (r.getCenterY()));        
402 407
    }
403 408

  
409
    /**
410
     * Gets the visible envelope, in map coordinates
411
     * 
412
     * @param fframeViewRect Rectangle defining the bounding box of the
413
     * FFrameView, in screen coordinates
414
     * @param visiblefframeViewRect Rectangle defining the bounding box
415
     * of the visible area of the fframeView, in screen coordinates
416
     * @return
417
     */
404 418
    protected Envelope getVisibleEnvelope(Rectangle2D.Double fframeViewRect,
405 419
            Rectangle2D.Double visiblefframeViewRect) {
406 420
    	Envelope oldEnv = getMapContext().getViewPort().getAdjustedEnvelope();
......
434 448
        Graphics2D g,
435 449
        AffineTransform affineTransform,
436 450
        Rectangle2D.Double fframeViewRect,
437
        Rectangle2D visibleLayoutDocRect,
451
        Rectangle2D.Double visibleRect,
438 452
        BufferedImage imgBase) throws Exception {
439
        
453
    	
440 454
    	b_drawing = true;
441
    	Rectangle2D.Double visiblefframeViewRect = new Rectangle2D.Double();
442
    	Rectangle2D.Double.intersect(fframeViewRect, visibleLayoutDocRect, visiblefframeViewRect);
443
        if (visiblefframeViewRect.width<=0 || visiblefframeViewRect.height<=0) {
444
        	b_drawing = false;
445
        	return;
446
        }
447
    	int drawWidth = (int)visiblefframeViewRect.width;
448
    	int drawHeight = (int)visiblefframeViewRect.height;
455
    	int drawWidth = (int)visibleRect.width;
456
    	int drawHeight = (int)visibleRect.height;
449 457

  
450 458
        Envelope oldEnvelope = getMapContext().getViewPort().getEnvelope();
451
        if (!visiblefframeViewRect.equals(fframeViewRect)) {
459
        if (!fframeViewRect.equals(visibleRect)) {
452 460
        	// if visible area is smaller than the fframe, we will only draw this area,
453 461
        	// so we need to tell the ViewPort the image size and extent for drawing,
454 462
        	// and restore the real extent after drawing
455
        	Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visiblefframeViewRect);
463
        	Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visibleRect);
456 464
        	// image size must be set before the envelope, as it has influence on the adjustedExtent
457 465
        	getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight));
458 466
        	getMapContext().getViewPort().setEnvelope(newEnvelope);
......
465 473
        createImage(affineTransform, drawWidth, drawHeight, mapOrigin);
466 474

  
467 475
        //Draw the created image
468
        drawImage(g, m_image, visiblefframeViewRect);
476
        drawImage(g, m_image, visibleRect);
469 477
        
470
        if (!visiblefframeViewRect.equals(fframeViewRect)) {
478
        if (!visibleRect.equals(fframeViewRect)) {
471 479
        	// restore real envelope and image size
472 480
        	getMapContext().getViewPort().setImageSize(new Dimension((int)fframeViewRect.width, (int) fframeViewRect.height));
473 481
        	getMapContext().getViewPort().setEnvelope(oldEnvelope);
......
522 530
        		null);    	
523 531
    }
524 532

  
525
    protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect){
526
    	originalGraphicsAt = (AffineTransform) g.getTransform().clone();
533
    protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D.Double visibleRect){
534
    	originalGraphicsAT = (AffineTransform) g.getTransform().clone();
535
    	
527 536
        if (g.getClipBounds() != null) {
528 537
            originalClip = (Rectangle) g.getClipBounds().clone();
529 538
        }
530 539
        if (getRotation() != 0) {
531
            g.rotate(Math.toRadians(getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY());
540
        	rotationAT = new AffineTransform();
541
        	rotationAT.rotate(Math.toRadians(getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY());
542
        	g.transform(rotationAT);
532 543
        }
533
        g.clipRect((int) fframeViewRect.getMinX(), (int) fframeViewRect.getMinY(),
534
            (int) fframeViewRect.getWidth(), (int) fframeViewRect.getHeight());
544
        g.setClip((int) visibleRect.getMinX(), (int) visibleRect.getMinY(),
545
            (int) visibleRect.getWidth(), (int) visibleRect.getHeight());
535 546
    }
536 547
    
537
    protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase, 
538
        AffineTransform at){
539
    	g.setTransform(originalGraphicsAt);
548
    protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, AffineTransform at){
549
    	g.setTransform(originalGraphicsAT);
550
    	rotationAT = null;
540 551
        if (getMapContext() != null) {
541 552
            setATMap(getMapContext().getViewPort().getAffineTransform());
542 553
        }
543
        if (originalGraphicsAt != null) {
554
        if (originalClip != null) {
544 555
            g.setClip(originalClip.x, originalClip.y, originalClip.width, originalClip.height);
545 556
        }            
546 557
    }
......
549 560
        PrintAttributes printAttributes) {
550 561
        Rectangle2D.Double rectangleLayout = getBoundingBox(at);  
551 562
        
552
        preDraw(g, rectangleLayout);
563
        preDraw(g, rectangleLayout, rectangleLayout);
553 564
        print(g, at, printAttributes);
554
        postDraw(g, rectangleLayout, null, null, at);
565
        postDraw(g, rectangleLayout, at);
555 566
        if (showGrid && grid != null) {
556 567
            grid.print(g, at, geom, printAttributes);
557 568
        }    

Also available in: Unified diff