Revision 141

View differences:

branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutUtilities.java
313 313
        double wcm,
314 314
        double wpixels) {
315 315
        
316
        double dpi = wpixels / wcm * 2.54;
316
        double dpi = (2.54*wpixels) / wcm;
317 317
        IProjection proj = viewPort.getProjection();
318 318

  
319 319
        if (viewPort.getAdjustedEnvelope() == null) {
branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/DefaultLayoutControl.java
239 239
    public void setLayoutContext(LayoutContext lc) {
240 240
        layoutContext = lc;
241 241
        layoutContext.addObserver(this);
242
        fullRect();
242 243
    }
243 244

  
244 245
    /**
......
273 274
            Graphics gimgRuler = imgRuler.getGraphics();
274 275
            clipVisibleRect((Graphics2D) gimag);
275 276

  
276
            if (initial) {
277
                fullRect();
278
                initial = false;
279
            }
277
            // moved to initialize()
278
//            if (initial) {
279
//                fullRect();
280
//                initial = false;
281
//            }
280 282

  
281 283
            try {
282 284
                layoutDraw.drawLayout((Graphics2D) gimag, img);
branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
88 88
    private static final String TYPESCALE_FIELD = "typeScale";
89 89
    private static final String EXTENSION_FIELD = "extension";
90 90
    private static final String QUALITY_FIELD = "quality";
91
    private static final String VIEWING_FIELD = "viewing";
92 91
    private static final String BLINKED_FIELD = "bLinked";
93 92
    private static final String MAPUNITS_FIELD = "mapUnits";
94 93
    private static final String SCALE_FIELD = "scale";
......
108 107
    protected int typeScale = AUTOMATICO;
109 108
    protected int extension = 0;
110 109
    protected int quality = PRESENTATION;
111
    protected int viewing = 0;
112 110
    protected boolean linked = true;
113 111
    protected ViewDocument viewDocument = null;
114 112
    protected MapContext mapContext = null;
......
167 165
        refresh = true;
168 166
        mapScale =
169 167
            FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
170
                getBoundBox().width, getBoundingBox(null).width
171
                    / getBoundBox().width);
168
                getBoundBox().width, getBoundingBox(null).width);
169
        updateScaleCtrl();
172 170
    }
171
    
172
    /**
173
     * Calculates the resolution (measured on dots per inch, DPI) to be
174
     * considered to draw the FFrameView on screen. It is calculated by
175
     * dividing the width (in pixels) of the FFrame divided by the width
176
     * in inches of the paper.
177
     */
178
    protected double getDrawPaperDPI() {
179
    	return (2.54*getBoundingBox(null).width)/getBoundBox().width;	
180
    }
173 181

  
174 182
    /**
175 183
     * Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
......
201 209
    }
202 210

  
203 211
    /**
204
     * Devuelve un entero que representa la forma en que se actualiza la vista.
205
     * 
206
     * @return forma que se actualiza la vista.
207
     */
208
    public int getViewing() {
209
        return viewing;
210
    }
211

  
212
    /**
213
     * Rellena la forma de actualizar la vista(cuando activo o siempre). De
214
     * momento esta opci?n esta deshabilitada.
215
     * 
216
     * @param v
217
     *            entero que representa la forma de actualizar la vista.
218
     */
219
    public void setViewing(int v) {
220
        viewing = v;
221
    }
222

  
223
    /**
224 212
     * Inserta el ProjectView de donde obtener las propiedades de la vista a
225 213
     * mostrar.
226 214
     * 
......
378 366
    }
379 367

  
380 368
    /**
381
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
382
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
383
     * de dibujar.
369
     * Draws the FFrameView on the provided Graphics, according to the
370
     * provided affine transform and the visible rectangle.
384 371
     * 
385
     * @param g
386
     *            Graphics2D
387
     * @param at
388
     *            Transformada af?n.
389
     * @param rectangleView
390
     *            rect?ngulo sobre el que hacer un clip.
391
     * @param imgBase
392
     *            Imagen para acelerar el dibujado.
372
     * @param g Graphics2D
373
     * @param at Affine transform to translate sheet coordinates (in cm)
374
     * 				to screen coordinates (in pixels)
375
     * @param visibleLayoutDocRect visible rectangle
376
     * @param imgBase Image used to speed up the drawing process
393 377
     */
394
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rectangleView, BufferedImage imgBase) {
395
        Rectangle2D.Double rectangleLayout = getBoundingBox(at);  
396
        Rectangle originalClip = preDraw(g, rectangleLayout);    
397
        if (intersects(rectangleView, rectangleLayout)) {
378
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase) {
379
        Rectangle2D.Double fframeViewRect = getBoundingBox(at);  
380
        Rectangle originalClip = preDraw(g, fframeViewRect);    
381
        if (intersects(visibleLayoutDocRect, fframeViewRect)) {
398 382
            if (getMapContext() == null) {
399 383
                drawEmpty(g);
400 384
            } else {
......
409 393
                } else {
410 394
                    if (getQuality() == PRESENTATION) {
411 395
                        try {
412
                            drawPresentation(g, at, rectangleLayout, rectangleView, imgBase);
396
                            drawPresentation(g, at, fframeViewRect, visibleLayoutDocRect, imgBase);
413 397
                        } catch (Exception exc) {
414 398
                            drawMessage(g, FLayoutFunctions.getLastMessage(exc));
415 399
                        }
......
420 404
                }
421 405
            }
422 406
        }
423
        postDraw(g, rectangleLayout, rectangleView, imgBase, originalClip, at); 
407
        postDraw(g, fframeViewRect, visibleLayoutDocRect, imgBase, originalClip, at); 
424 408
        if (showGrid && grid != null) {           
425
            grid.draw(g, at, rectangleView, imgBase);
409
            grid.draw(g, at, visibleLayoutDocRect, imgBase);
426 410
        }    
427 411
    }
428 412
    
......
449 433
    protected void drawPresentation(
450 434
        Graphics2D g,
451 435
        AffineTransform affineTransform,
452
        Rectangle2D.Double rectangleLayout,
453
        Rectangle2D rectangleView,
436
        Rectangle2D.Double fframeViewRect,
437
        Rectangle2D visibleLayoutDocRect,
454 438
        BufferedImage imgBase) throws Exception {
455 439
        
456
        Point mapOrigin = new Point((int)rectangleView.getMinX(), (int)rectangleView.getMaxY());
440
        Point mapOrigin = new Point((int)visibleLayoutDocRect.getMinX(), (int)visibleLayoutDocRect.getMaxY());
457 441

  
458 442
        ViewPort viewPort = this.getMapContext().getViewPort();
459 443
        Color theBackColor = viewPort.getBackColor();
444
    	int drawWidth = (int)fframeViewRect.width;
445
    	int drawHeight = (int)fframeViewRect.height;
460 446

  
461 447
        //If the image has to be created...
462 448
        if (!(origin != null
......
464 450
            && affineTransform.getScaleX() == scaleAnt
465 451
            && m_image != null
466 452
            && !refresh
467
            && !(rectangleLayout.getWidth() > rectangleView.getWidth() || rectangleLayout.getHeight() > rectangleView.getHeight()))) {
453
            && !(fframeViewRect.getWidth() > visibleLayoutDocRect.getWidth() || fframeViewRect.getHeight() > visibleLayoutDocRect.getHeight()))) {
468 454

  
469
            double scale1_1 = viewPort.getDPI() / 2.54;
470
            /*
471
             * This is the ratio between the size assumed by the
472
             * mapcontext drawer and the true size on screen
473
             */
474
            double visible_factor = affineTransform.getScaleX() / scale1_1;
475
            int draw_w = (int) (1d * rectangleLayout.width / visible_factor);
476
            int draw_h = (int) (1d * rectangleLayout.height / visible_factor);
477

  
478
            viewPort.setImageSize(new Dimension(draw_w, draw_h));
479
            viewPort.refreshExtent();
480

  
481
            /*
482
            viewPort.setOffset(new Point2D.Double(rectangleLayout.x, rectangleLayout.y));
483
            */
484

  
455
        	viewPort.setImageSize(new Dimension(drawWidth, drawHeight));
456
        	viewPort.refreshExtent(); // comprobar si es necesario; el setImageSize ya calcula la nueva AT, pero no lanza el evento extentChanged
457
            viewPort.setDPI(getDrawPaperDPI());
485 458
            m_image =
486
                new BufferedImage(
487
                    draw_w, //(int) rectangleLayout.getWidth(),
488
                    draw_h, //(int) rectangleLayout.getHeight(),
489
                    BufferedImage.TYPE_INT_ARGB);
459
                    new BufferedImage(
460
                    		drawWidth,
461
                    		drawHeight,
462
                    		BufferedImage.TYPE_INT_ARGB);
490 463

  
491
            Graphics2D gimg = (Graphics2D) m_image.createGraphics();
492
            
493
            /*
494
            gimg.translate(-((int) rectangleLayout.getX()),
495
                -((int) rectangleLayout.getY()));
496
            */
464
                Graphics2D gimg = (Graphics2D) m_image.createGraphics();
465
                
497 466

  
498
            getMapContext().draw(m_image, gimg, getScale());
499
            gimg.dispose();
500
            /*
501
            gimg.translate(((int) rectangleLayout.getX()),
502
                ((int) rectangleLayout.getY()));
503
                */
467
                getMapContext().draw(m_image, gimg, getScale());
468
                gimg.dispose();
504 469
            refresh = false;    
505 470
        } 
506 471

  
507 472
        //Draw the created image
508 473
        if (theBackColor != null) {
509 474
            g.setColor(theBackColor);
510
            g.fillRect((int) rectangleLayout.x, (int) rectangleLayout.y,
511
                viewPort.getImageWidth(),
512
                viewPort.getImageHeight());
475
            g.fillRect((int) fframeViewRect.x, (int) fframeViewRect.y,
476
            		(int)fframeViewRect.width,
477
            		(int)fframeViewRect.height);
513 478
        }
479
        g.drawImage(m_image, 
480
        		(int) fframeViewRect.x,
481
        		(int) fframeViewRect.y,
482
        		null);
514 483
        
515
        m_image = copyForcingImageSize(
516
            m_image,
517
            (int) rectangleLayout.getWidth(),
518
            (int) rectangleLayout.getHeight());
519

  
520
        g.drawImage(m_image,
521
            (int) rectangleLayout.getX(),
522
            (int) rectangleLayout.getY(), null);
523
        
524 484
        scaleAnt = affineTransform.getScaleX();
525 485
        origin = mapOrigin;             
526 486
    }
527
    
528
    /**
529
     * @param m_image2
530
     * @param width
531
     * @param height
532
     * @return
533
     */
534
    protected BufferedImage copyForcingImageSize(
535
        BufferedImage disp_img, int w, int h) {
536
        
537
        Graphics rg = null;
538
        
539
        try {
540
            if (disp_img == null || w < 1 || h < 1) {
541
                return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
542
            }
543
            int from_w = disp_img.getWidth(null);
544
            int from_h = disp_img.getHeight(null);
545
            if (from_w < 1 || from_h < 1) {
546
                return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
547
            }
548
            
549
            BufferedImage resp =
550
                new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
551
            rg = resp.createGraphics();
552
            
553
            double rat_w = (1d*w) / (1d*from_w);
554
            double rat_h = (1d*h) / (1d*from_h);
555
            int offset_w = 0;
556
            int offset_h = 0;
557
            Image aux = null;
558 487

  
559
            if (rat_w <= rat_h) {
560
                // apply resize of width
561
                int target_h = Math.max(1, (int) (from_h * rat_w));
562
                // w, target_h
563
                offset_w = 0;
564
                offset_h = (h - target_h) / 2;
565
                aux = disp_img.getScaledInstance(w, target_h, Image.SCALE_FAST);
566
                rg.drawImage(aux, offset_w, offset_h, null);
567

  
568
            } else {
569
                // apply resize from height
570
                int target_w = Math.max(1, (int) (from_w * rat_h));
571
                // target_w, h
572
                offset_w = (w - target_w) / 2;
573
                offset_h = 0;
574
                aux = disp_img.getScaledInstance(target_w, h, Image.SCALE_FAST);
575
                rg.drawImage(aux, offset_w, offset_h, null);
576
            }
577
            
578
            aux = null;
579
            resp.flush();
580
            rg.dispose();
581
            return resp;
582
        } catch (Throwable th) {
583
            logger.info("While resizing image.", th);
584
            if (rg != null) {
585
                rg.dispose();
586
            }
587
            return null;
588
        }
589
        
590
    }
591

  
592
    protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout){
488
    protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect){
593 489
        Rectangle originalClip = null;
594 490
        if (g.getClipBounds() != null) {
595 491
            originalClip = (Rectangle) g.getClipBounds().clone();
596 492
        }
597 493
        if (getRotation() != 0) {
598
            g.rotate(Math.toRadians(getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY()
599
                + (rectangleLayout.height / 2));
494
            g.rotate(Math.toRadians(getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY()
495
                + (fframeViewRect.height / 2));
600 496
        }       
601
        g.clipRect((int) rectangleLayout.getMinX(), (int) rectangleLayout.getMinY(),
602
            (int) rectangleLayout.getWidth(), (int) rectangleLayout.getHeight());
497
        g.clipRect((int) fframeViewRect.getMinX(), (int) fframeViewRect.getMinY(),
498
            (int) fframeViewRect.getWidth(), (int) fframeViewRect.getHeight());
603 499
        return originalClip;
604 500
    }
605 501
    
606
    protected void postDraw(Graphics2D g, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase, 
502
    protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase, 
607 503
        Rectangle originalClip, AffineTransform at){
608 504
        if (getRotation() != 0) {
609
            g.rotate(Math.toRadians(-getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY());
505
            g.rotate(Math.toRadians(-getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY());
610 506
        }
611 507
        if (getMapContext() != null) {
612 508
            setATMap(getMapContext().getViewPort().getAffineTransform());
......
854 750
        if (linked){
855 751
            if (getTypeScale() == AUTOMATICO) {
856 752
                mapContext.getViewPort().setEnvelope(e.getNewExtent());
753
//                observers.notifyObservers(this, 
754
//                    new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));      
857 755
                observers.notifyObservers(this, 
858
                    new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));      
756
                        new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH));
859 757
            } else
860 758
                if (getTypeScale() == MANUAL) {
861 759
                    Envelope oldExtent = mapContext.getViewPort().getEnvelope();
......
878 776
                }
879 777
            refresh = true;
880 778
        }
779
        updateScaleCtrl();
881 780
    }
882 781

  
883 782
    /**
......
994 893
    	statusbar.setMessage("units",
995 894
    			PluginServices.getText(this, mapContext.getDistanceName()));
996 895
    	statusbar.setControlValue("layout-view-change-scale",
997
    			String.valueOf(mapContext.getScaleView()));
896
    			String.valueOf(getScale()));
998 897
    	IProjection proj = mapContext.getViewPort().getProjection();
999 898
    	if (proj != null) {
1000 899
    		statusbar.setMessage("projection", proj.getAbrev());
......
1149 1048
            definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(true);
1150 1049
            definition.addDynFieldInt(EXTENSION_FIELD).setMandatory(true);
1151 1050
            definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);
1152
            definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);
1153 1051
            definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(true);
1154 1052
            definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true);
1155 1053
            definition.addDynFieldDouble(SCALE_FIELD).setMandatory(true);
......
1173 1071
        typeScale = state.getInt(TYPESCALE_FIELD);
1174 1072
        extension = state.getInt(EXTENSION_FIELD);
1175 1073
        quality = state.getInt(QUALITY_FIELD);
1176
        viewing = state.getInt(VIEWING_FIELD);
1177 1074
        linked = state.getBoolean(BLINKED_FIELD);
1178 1075
        mapUnits = state.getInt(MAPUNITS_FIELD);
1179 1076
        mapScale = state.getDouble(SCALE_FIELD);
......
1196 1093
        state.set(TYPESCALE_FIELD, typeScale);
1197 1094
        state.set(EXTENSION_FIELD, extension);
1198 1095
        state.set(QUALITY_FIELD, quality);
1199
        state.set(VIEWING_FIELD, viewing);
1200 1096
        state.set(BLINKED_FIELD, linked);
1201 1097
        state.set(MAPUNITS_FIELD, mapUnits);
1202 1098
        state.set(SCALE_FIELD, mapScale);
branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/dialogs/FFrameViewDialog.java
145 145
            jContentPane.add(getTEscalaNumerica(), null);
146 146
            jContentPane.add(getLExtension(), null);
147 147
            jContentPane.add(getCbExtension(), null);
148
            jContentPane.add(getLVisualizacion(), null);
149
            jContentPane.add(getCbVisualizacion(), null);
150 148
            jContentPane.add(getLCalidad(), null);
151 149
            jContentPane.add(getCbCalidad(), null);
152 150
            jContentPane.add(getbAceptar(), null);
......
452 450
    }
453 451

  
454 452
    /**
455
     * This method initializes jLabel4
456
     * 
457
     * @return javax.swing.JLabel
458
     */
459
    private javax.swing.JLabel getLVisualizacion() {
460
        if (lVisualizacion == null) {
461
            lVisualizacion = new javax.swing.JLabel();
462
            lVisualizacion.setSize(86, 16);
463
            lVisualizacion.setText(PluginServices
464
                .getText(this, "visualizacion"));
465
            lVisualizacion.setLocation(10, 180);
466
            lVisualizacion.setVisible(false);
467
        }
468

  
469
        return lVisualizacion;
470
    }
471

  
472
    /**
473
     * This method initializes cbVisualizacion
474
     * 
475
     * @return javax.swing.JComboBox
476
     */
477
    private javax.swing.JComboBox getCbVisualizacion() {
478
        if (cbVisualizacion == null) {
479
            // String[] s={"Cuando activo","Siempre"};
480
            cbVisualizacion = new javax.swing.JComboBox();
481
            cbVisualizacion.setSize(220, 20);
482
            cbVisualizacion.addItem(PluginServices.getText(this,
483
                "cuando_activo"));
484
            cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
485
            cbVisualizacion.setSelectedIndex(fframeview.getViewing());
486
            cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
487
            cbVisualizacion.setLocation(100, 180);
488
            cbVisualizacion.setEnabled(false);
489
            cbVisualizacion.setVisible(false);
490
        }
491

  
492
        return cbVisualizacion;
493
    }
494

  
495
    /**
496 453
     * This method initializes jButton
497 454
     * 
498 455
     * @return javax.swing.JButton
......
525 482
                            // fframeview.setFMap(m_projectView.getMapContext());
526 483
                            newFFrameView.setExtension(getCbExtension()
527 484
                                .getSelectedIndex());
528
                            newFFrameView.setViewing(getCbVisualizacion()
529
                                .getSelectedIndex());
530 485
                            newFFrameView.setQuality(getCbCalidad()
531 486
                                .getSelectedIndex());
532 487
                            if (fframeview.getGrid() != null) {                             
branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrame.java
484 484
        BufferedImage imgBase);
485 485

  
486 486
    /**
487
     * Devuelve el boundingBox del fframe en funci�n de la transformada af�n
488
     * que se pasa como par�metro. Si se pasa como par�metro null, devuelve
489
     * el
490
     * �ltimo boundingbox que se calcul�.
487
     * Returns the bounding box (in pixels) of this FFrame, based on the provided
488
     * AffineTransform. If the AffineTransform is null, it returns the last
489
     * calculated bounding box.
491 490
     * 
492
     * @param at
493
     *            Transformada af�n
494
     * 
495
     * @return Rect�ngulo que representa el BoundingBox del fframe.
491
     * @param at Affine transform to apply to the sheet coordinates to get the
492
     *  		bounding box in pixels.
493
     * @return Rectangle representing the bounding box (in pixels) of this
494
     * FFrame
496 495
     */
497 496
    public Rectangle2D.Double getBoundingBox(AffineTransform at) {
498 497
        if (at != null) {
......
520 519
    }
521 520

  
522 521
    /**
523
     * Devuelve el rect�ngulo que representa el fframe en cent�metros.
522
     * Returns the bounding box in centimeters of this FFrame
523
     * Returns the rectangle that represents the FFrame in centimeters.
524 524
     * 
525
     * @return Rect�ngulo en centimetros.
525
     * @return The bounding box of this FFrame, measured in centimeters.
526 526
     */
527 527
    public Rectangle2D.Double getBoundBox() {
528 528
        return m_BoundBox;
......
580 580
    }
581 581

  
582 582
    /**
583
     * Dibuja sobre el graphics el rect�ngulo del fframe pero vacio, mostrando
584
     * el nombre del fframe y vacio.
583
     * Draws the FFrame rectangle on the provided Graphics2D, only showing the
584
     * FFrame name on an empty rectangle.
585 585
     * 
586
     * @param g
587
     *            Graphics sobre el que dibujar.
586
     * @param g The graphics to draw on
588 587
     */
589 588
    public void drawEmpty(Graphics2D g) {
590 589
        Rectangle2D r = getBoundingBox(null);

Also available in: Unified diff