Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / DefaultLayoutControl.java @ 364

History | View | Annotate | Download (23.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout;
23

    
24
import java.awt.Color;
25
import java.awt.Cursor;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.Image;
29
import java.awt.Point;
30
import java.awt.Rectangle;
31
import java.awt.Toolkit;
32
import java.awt.geom.AffineTransform;
33
import java.awt.geom.Rectangle2D;
34
import java.awt.geom.Rectangle2D.Double;
35
import java.awt.image.BufferedImage;
36
import java.awt.image.MemoryImageSource;
37
import java.util.HashMap;
38

    
39
import javax.swing.JComponent;
40

    
41
import org.gvsig.andami.PluginsLocator;
42
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
43
import org.gvsig.app.project.documents.layout.fframes.IFFrameEditableVertex;
44
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
45
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter;
46
import org.gvsig.app.project.documents.layout.geometryadapters.PolyLineAdapter;
47
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
48
import org.gvsig.app.project.documents.layout.tools.LayoutAddBoxListenerImpl;
49
import org.gvsig.app.project.documents.layout.tools.LayoutAddCircleListenerImpl;
50
import org.gvsig.app.project.documents.layout.tools.LayoutAddLegendListenerImpl;
51
import org.gvsig.app.project.documents.layout.tools.LayoutAddLineListenerImpl;
52
import org.gvsig.app.project.documents.layout.tools.LayoutAddNorthListenerImpl;
53
import org.gvsig.app.project.documents.layout.tools.LayoutAddOverViewListenerImpl;
54
import org.gvsig.app.project.documents.layout.tools.LayoutAddPictureListenerImpl;
55
import org.gvsig.app.project.documents.layout.tools.LayoutAddPointListenerImpl;
56
import org.gvsig.app.project.documents.layout.tools.LayoutAddPolygonListenerImpl;
57
import org.gvsig.app.project.documents.layout.tools.LayoutAddPolylineListenerImpl;
58
import org.gvsig.app.project.documents.layout.tools.LayoutAddRectangleListenerImpl;
59
import org.gvsig.app.project.documents.layout.tools.LayoutAddScaleListenerImpl;
60
import org.gvsig.app.project.documents.layout.tools.LayoutAddTextListenerImpl;
61
import org.gvsig.app.project.documents.layout.tools.LayoutAddViewListenerImpl;
62
import org.gvsig.app.project.documents.layout.tools.LayoutEditGraphicsListenerImpl;
63
import org.gvsig.app.project.documents.layout.tools.LayoutPanListenerImpl;
64
import org.gvsig.app.project.documents.layout.tools.LayoutSelectListenerImpl;
65
import org.gvsig.app.project.documents.layout.tools.LayoutViewPanListenerImpl;
66
import org.gvsig.app.project.documents.layout.tools.LayoutViewZoomInListenerImpl;
67
import org.gvsig.app.project.documents.layout.tools.LayoutViewZoomOutListenerImpl;
68
import org.gvsig.app.project.documents.layout.tools.LayoutZoomInListenerImpl;
69
import org.gvsig.app.project.documents.layout.tools.LayoutZoomOutListenerImpl;
70
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutBehavior;
71
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutEditBehavior;
72
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutMoveBehavior;
73
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutPointBehavior;
74
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleBehavior;
75
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutSelectBehavior;
76
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewMoveBehavior;
77
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewZoomBehavior;
78
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutZoomBehavior;
79
import org.gvsig.app.project.documents.layout.tools.listener.ILayoutGraphicListener;
80
import org.gvsig.fmap.dal.exception.ReadException;
81
import org.gvsig.tools.observer.Observable;
82
import org.slf4j.Logger;
83
import org.slf4j.LoggerFactory;
84

    
85
/**
86
 * Control of Layout.
87
 * 
88
 * @author Vicente Caballero Navarro
89
 */
90
public class DefaultLayoutControl extends JComponent implements LayoutControl {
91
    private static final int DESACTUALIZADO = 4;
92
    private static final int ACTUALIZADO = 5;
93
    
94
    private static final long serialVersionUID = -8290006366669291510L;
95

    
96
    public static final String PERSISTENCE_DEFINITION_NAME = "LayoutControl";
97

    
98
    private int status = DESACTUALIZADO;
99
    private Rectangle2D rectVisible;
100
    private BufferedImage img = null;
101
    private BufferedImage imgRuler = null;
102
    private LayoutContext layoutContext;
103
    private Point origin = new Point(50, 50);
104
    private Point rectOrigin = new Point(origin);
105
    /**
106
     * Size and position of the layout sheet within visible area of
107
     * the layout component, measured in screen coordinates (pixels).
108
     */
109
    private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
110
        rectOrigin.y, 400, 300);
111
    /**
112
     * Visible area of the layout document, measured on paper coordinates.
113
     */
114
    private Rectangle2D.Double viewPort = new Rectangle2D.Double();
115
    private FLayoutDraw layoutDraw = null;
116
    private FLayoutFunctions layoutFunctions = null;
117
    private LayoutBehavior currentLayoutTool = null;
118
    private Image imageCursor = null;
119
    private HashMap namesLayoutTools = new HashMap();
120
    private Point m_FirstPoint = new Point(0, 0);
121
    private Point m_PointAnt = new Point(0, 0);
122
    private Point m_LastPoint = new Point(0, 0);
123
    private LayoutEvents layoutEvents;
124
    private Point position;
125
    private GeometryAdapter geometryAdapter = new PolyLineAdapter();
126

    
127
    private String currentTool;
128
    private boolean m_bCancelDrawing = false;
129
    private Rectangle reSel = null;
130
    private boolean isReSel = true;
131
    private FLayoutZooms layoutZooms;
132
        private LayoutPanel layoutPanel;
133

    
134
    private static Cursor transparentCursor = Toolkit.getDefaultToolkit()
135
        .createCustomCursor(
136
            Toolkit.getDefaultToolkit().createImage(
137
                new MemoryImageSource(16, 16, new int[16 * 16], 0, 16)),
138
            new Point(0, 0), "invisiblecursor");
139

    
140
    /**
141
     * Create a new object of LayoutControl.
142
     * 
143
     * @param layout
144
     */
145
    public DefaultLayoutControl() {  
146
               
147
    }
148
    
149
    public void initialize(LayoutPanel layoutPanel){
150
            setFocusable(true);
151
            this.layoutPanel = layoutPanel;
152
        layoutDraw = new FLayoutDraw(layoutPanel);
153
        layoutEvents = new LayoutEvents(layoutPanel);
154
        layoutZooms = new FLayoutZooms(layoutPanel);
155
        layoutFunctions = new FLayoutFunctions(layoutPanel);
156
        addComponentListener(layoutEvents);
157
        addMouseMotionListener(layoutEvents);
158
        addMouseListener(layoutEvents);
159

    
160
        LayoutPanListenerImpl lpl = new LayoutPanListenerImpl(layoutPanel);
161
        addLayoutTool("layoutpan", new LayoutMoveBehavior(lpl));
162

    
163
        LayoutZoomInListenerImpl lzil = new LayoutZoomInListenerImpl(layoutPanel);
164
        addLayoutTool("layoutzoomin", new LayoutZoomBehavior(lzil));
165

    
166
        LayoutZoomOutListenerImpl lzol = new LayoutZoomOutListenerImpl(layoutPanel);
167
        addLayoutTool("layoutzoomout", new LayoutZoomBehavior(lzol));
168

    
169
        LayoutAddViewListenerImpl lavl = new LayoutAddViewListenerImpl(layoutPanel);
170
        addLayoutTool("layoutaddview", new LayoutRectangleBehavior(lavl));
171

    
172
        LayoutAddOverViewListenerImpl laovl =
173
            new LayoutAddOverViewListenerImpl(layoutPanel);
174
        addLayoutTool("layoutaddoverview", new LayoutRectangleBehavior(laovl));
175

    
176
        LayoutAddPictureListenerImpl lapl =
177
            new LayoutAddPictureListenerImpl(layoutPanel);
178
        addLayoutTool("layoutaddpicture", new LayoutRectangleBehavior(lapl));
179

    
180
        LayoutAddNorthListenerImpl lanorthl =
181
            new LayoutAddNorthListenerImpl(layoutPanel);
182
        addLayoutTool("layoutaddnorth", new LayoutRectangleBehavior(lanorthl));
183

    
184
        LayoutAddScaleListenerImpl lasl =
185
            new LayoutAddScaleListenerImpl(layoutPanel);
186
        addLayoutTool("layoutaddscale", new LayoutRectangleBehavior(lasl));
187

    
188
        LayoutAddLegendListenerImpl lall =
189
            new LayoutAddLegendListenerImpl(layoutPanel);
190
        addLayoutTool("layoutaddlegend", new LayoutRectangleBehavior(lall));
191

    
192
        LayoutAddTextListenerImpl latl = new LayoutAddTextListenerImpl(layoutPanel);
193
        addLayoutTool("layoutaddtext", new LayoutRectangleBehavior(latl));
194

    
195
        LayoutAddBoxListenerImpl labl = new LayoutAddBoxListenerImpl(layoutPanel);
196
        addLayoutTool("layoutaddbox", new LayoutRectangleBehavior(labl));
197

    
198
        LayoutAddPointListenerImpl lapointl =
199
            new LayoutAddPointListenerImpl(layoutPanel);
200
        addLayoutTool("layoutaddpoint", new LayoutPointBehavior(lapointl));
201

    
202
        LayoutAddLineListenerImpl lalinel =
203
            new LayoutAddLineListenerImpl(layoutPanel);
204
        addLayoutTool("layoutaddline", new LayoutPointBehavior(lalinel));
205

    
206
        LayoutAddPolygonListenerImpl lapolygonl =
207
            new LayoutAddPolygonListenerImpl(layoutPanel);
208
        addLayoutTool("layoutaddpolygon", new LayoutPointBehavior(lapolygonl));
209

    
210
        LayoutAddPolylineListenerImpl lapolylinel =
211
            new LayoutAddPolylineListenerImpl(layoutPanel);
212
        addLayoutTool("layoutaddpolyline", new LayoutPointBehavior(lapolylinel));
213

    
214
        LayoutAddCircleListenerImpl lacirclel =
215
            new LayoutAddCircleListenerImpl(layoutPanel);
216
        addLayoutTool("layoutaddcircle", new LayoutPointBehavior(lacirclel));
217

    
218
        LayoutAddRectangleListenerImpl larectanglel =
219
            new LayoutAddRectangleListenerImpl(layoutPanel);
220
        addLayoutTool("layoutaddrectangle", new LayoutPointBehavior(
221
            larectanglel));
222

    
223
        LayoutViewPanListenerImpl lvpl = new LayoutViewPanListenerImpl(layoutPanel);
224
        addLayoutTool("layoutviewpan", new LayoutViewMoveBehavior(lvpl));
225

    
226
        LayoutViewZoomInListenerImpl lvzil =
227
            new LayoutViewZoomInListenerImpl(layoutPanel);
228
        addLayoutTool("layoutviewzoomin", new LayoutViewZoomBehavior(lvzil));
229

    
230
        LayoutViewZoomOutListenerImpl lvzol =
231
            new LayoutViewZoomOutListenerImpl(layoutPanel);
232
        addLayoutTool("layoutviewzoomout", new LayoutViewZoomBehavior(lvzol));
233

    
234
        LayoutSelectListenerImpl lselectl =
235
            new LayoutSelectListenerImpl(layoutPanel);
236
        addLayoutTool("layoutselect", new LayoutSelectBehavior(lselectl));
237

    
238
        LayoutEditGraphicsListenerImpl leditl =
239
            new LayoutEditGraphicsListenerImpl(layoutPanel);
240
        addLayoutTool("layoutedit", new LayoutEditBehavior(leditl));
241
    }
242

    
243
    public String getCurrentTool() {
244
        return currentTool;
245
    }
246

    
247
    public void addLayoutTool(String name, LayoutBehavior tool) {
248
        namesLayoutTools.put(name, tool);
249
        tool.setLayoutControl(this);
250
    }
251

    
252
    public void setLayoutContext(LayoutContext lc) {
253
        layoutContext = lc;
254
        layoutContext.addObserver(this);
255
        fullRect();
256
    }
257

    
258
    /**
259
     * paintComponent of Layout.
260
     * 
261
     * @param g
262
     *            Graphics of Layout.
263
     */
264
    protected void paintComponent(Graphics g) {
265
        clipVisibleRect((Graphics2D) g);
266

    
267
        Rectangle rClip = g.getClipBounds();
268

    
269
        if (rClip == null) {
270
            System.err.println("clip = null");
271
        }
272

    
273
        switch (status) {
274
        case DESACTUALIZADO:
275
            if (getWidth() == 0) {
276
                return;
277
            }
278

    
279
            img =
280
                new BufferedImage(getWidth(), getHeight(),
281
                    BufferedImage.TYPE_INT_ARGB);
282
            imgRuler =
283
                new BufferedImage(getWidth(), getHeight(),
284
                    BufferedImage.TYPE_INT_ARGB);
285

    
286
            Graphics gimag = img.getGraphics();
287
            Graphics gimgRuler = imgRuler.getGraphics();
288
            clipVisibleRect((Graphics2D) gimag);
289

    
290
            try {
291
                layoutDraw.drawLayout((Graphics2D) gimag, img);
292
            } catch (ReadException e) {
293
                e.printStackTrace();
294
            }
295

    
296
            g.setClip(rClip);
297
            layoutDraw.drawRectangle((Graphics2D) g);
298

    
299
            g.drawImage(img, 0, 0, this);
300
            g.setClip(rClip);
301

    
302
            layoutDraw.drawGrid((Graphics2D) gimgRuler);
303
            layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
304
            setStatus(ACTUALIZADO);
305
            repaint();
306

    
307
            break;
308

    
309
        case ACTUALIZADO:
310
            layoutDraw.drawRectangle((Graphics2D) g);
311

    
312
            if (currentLayoutTool != null) {
313
                currentLayoutTool.paintComponent(g);
314
            } else {
315
                g.drawImage(img, 0, 0, this);
316
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
317
            }
318

    
319
            g.setClip(rClip);
320
            drawCursor(g);
321
        }
322
    }
323

    
324
    private void setStatus(int s) {
325
        status = s;
326
    }
327

    
328
    /**
329
     * Clip on visible rectangle.
330
     * 
331
     * @param g2d
332
     *            Graphics.
333
     */
334
    private void clipVisibleRect(Graphics2D g2d) {
335
        rectVisible = this.getVisibleRect();
336
        g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
337
            (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
338
    }
339

    
340
    public BufferedImage getImgRuler() {
341
        return imgRuler;
342
    }
343

    
344
    public void fullRect() {
345
        Rectangle2D r = new Rectangle2D.Double(origin.x, origin.y, getWidth(),
346
            getHeight());
347

    
348
        if (layoutContext.getAttributes().isLandscape()) {
349
            r =
350
                layoutContext.getAttributes().getRectangleLandscape(r,
351
                    getWidth(), getHeight());
352
        } else {
353
            r =
354
                layoutContext.getAttributes().getRectanglePortrait(r,
355
                    getWidth(), getHeight());
356
        }
357
        setRect(r);
358
        refresh();
359
    }
360

    
361
    public Rectangle2D.Double getRect() {
362
            return (Rectangle2D.Double) rect.clone();
363
    }
364

    
365
    public void setRect(Rectangle2D r) {
366
        rect.setRect(r);
367
        Rectangle2D bounds = getBounds();
368
        if (rect.getWidth()>0 && bounds.getWidth()>0) { // only when the component has been laid out and rect properly initialized
369
                // ensure the AT is properly initialized
370
                layoutDraw.initializeAffineTransform();
371
                AffineTransform at = layoutContext.getAT();
372
                if (at!=null) {
373
                        Rectangle2D.Double newVp = new Rectangle2D.Double(0d, 0d, bounds.getWidth(), bounds.getHeight());
374
                        viewPort.setRect(FLayoutUtilities.toSheetRect(newVp, at));
375
                }
376
        }
377
    }
378

    
379
    public BufferedImage getImage() {
380
        return img;
381
    }
382

    
383
    /**
384
     * Draw the cursor on the Graphics.
385
     * 
386
     * @param g
387
     *            Graphics.
388
     */
389
    private void drawCursor(Graphics g) {
390
        if ((imageCursor != null) && (position != null)) {
391
            Point pAdjusted = position;
392
            g.drawImage(imageCursor, (int) pAdjusted.getX() - 16,
393
                (int) pAdjusted.getY() - 16, this);
394
        }
395
    }
396

    
397
    public void setMapCursor(Image image) {
398
        imageCursor = image;
399
    }
400

    
401
    public void setTool(String toolName) {
402
        LayoutBehavior layoutTool =
403
            (LayoutBehavior) namesLayoutTools.get(toolName);
404
        currentLayoutTool = layoutTool;
405
        currentLayoutTool.setLayoutControl(this);
406
        currentTool = toolName;
407
        this.setMapCursor(layoutTool.getImageCursor());
408

    
409
        if (getCurrentLayoutTool().getListener() instanceof ILayoutGraphicListener) {
410
            geometryAdapter =
411
                ((ILayoutGraphicListener) getCurrentLayoutTool().getListener())
412
                    .createGeometryAdapter();
413
        }
414

    
415
        if (getCurrentTool().equals("layoutedit")) {
416
            startEdit();
417
        } else {
418
            stopEdit();
419
        }
420
    }
421

    
422
        public void setDefaultTool() {
423
        PluginsLocator.getMainFrame().setSelectedTool("selection-select-by-rectangle-layout");
424
        setTool("layoutselect");
425
        }
426

    
427
    public void startEdit() {
428
        IFFrame[] fframes = layoutContext.getFFrames();
429

    
430
        for (int i = 0; i < fframes.length; i++) {
431
            IFFrame frame = fframes[i];
432

    
433
            if (frame instanceof IFFrameEditableVertex) {
434
                if (frame.getSelected() != IFFrame.NOSELECT) {
435
                    ((IFFrameEditableVertex) frame).startEditing();
436
                } else {
437
                    ((IFFrameEditableVertex) frame).stopEditing();
438
                }
439
            }
440
        }
441

    
442
        refresh();
443
    }
444

    
445
    public void stopEdit() {
446
        boolean refresh = false;
447
        IFFrame[] fframes = layoutContext.getFFrames();
448

    
449
        for (int i = 0; i < fframes.length; i++) {
450
            IFFrame frame = fframes[i];
451

    
452
            if (frame instanceof IFFrameEditableVertex) {
453
                if (((IFFrameEditableVertex) frame).isEditing()) {
454
                    ((IFFrameEditableVertex) fframes[i]).stopEditing();
455
                    refresh = true;
456
                }
457
            }
458
        }
459

    
460
        if (refresh) {
461
            refresh();
462
        }
463
    }
464

    
465
    public Point getRectOrigin() {
466
        return rectOrigin;
467
    }
468

    
469
    public FLayoutDraw getLayoutDraw() {
470
        return layoutDraw;
471
    }
472

    
473
    public LayoutBehavior getCurrentLayoutTool() {
474
        return currentLayoutTool;
475
    }
476

    
477
    public Point getFirstPoint() {
478
        return m_FirstPoint;
479
    }
480

    
481
    public Point getPointAnt() {
482
        return m_PointAnt;
483
    }
484

    
485
    public Point getLastPoint() {
486
        return m_LastPoint;
487
    }
488

    
489
    public void setFirstPoint() {
490
        m_FirstPoint = position;
491
    }
492

    
493
    public void setPointAnt() {
494
        m_PointAnt = position;
495
    }
496

    
497
    public void setLastPoint() {
498
        m_LastPoint = position;
499
    }
500

    
501
    public void setPosition(Point point2) {
502
        if (layoutContext.isAdjustingToGrid()
503
            && getCurrentLayoutTool().isAdjustable()) {
504
            position =
505
                FLayoutUtilities.getPointGrid(point2, layoutContext
506
                    .getAttributes().getHGridGapCm(), layoutContext
507
                    .getAttributes().getVGridGapCm(), layoutContext.getAT());
508
        } else {
509
            position = point2;
510
        }
511
    }
512

    
513
    public Point getPosition() {
514
        return position;
515
    }
516

    
517
    public AffineTransform getAT() {
518
        return layoutContext.getAT();
519
    }
520

    
521
    public GeometryAdapter getGeometryAdapter() {
522
        return geometryAdapter;
523
    }
524

    
525
    public void delLastPoint() {
526
        getGeometryAdapter().delLastPoint();
527
    }
528

    
529
    public int addGeometryAdapterPoint() {
530
        return getGeometryAdapter().addPoint(
531
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
532
    }
533

    
534
    public void setGeometryAdapterPoinPosition() {
535
        getGeometryAdapter().pointPosition(
536
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
537
    }
538

    
539
    public void clearMouseImage() {
540
        setCursor(transparentCursor);
541
    }
542

    
543
    public void refresh() {
544
            AffineTransform at = calculateTransformFromViewport();
545
            if (at!=null) {
546
                // update rect according to the viewport rectangle
547
                    Size s = getLayoutContext().getAttributes().getPaperSize();
548
                    Rectangle2D paperRect = new Rectangle2D.Double(0, 0, s.getWidth(), s.getHeight());
549
                    Rectangle2D newRect = FLayoutUtilities.fromSheetRect(paperRect, at);
550
                    setRect(newRect);
551
            }
552
            // repaint
553
        setStatus(DESACTUALIZADO);
554
        invalidate();
555
        repaint();
556
    }
557
    
558
    /**
559
     * Calculates the affine transform using the viewport and the control size,
560
     * instead of calculating it from {@link #rect}. as usual. This is required when
561
     * the component size changes, as {@link #rect}. has to be recalculated using
562
     * the viewport, and thus we can't calculate the affine transform using
563
     * {@link #rect}.
564
     * 
565
     * @return An matrix to transform from paper coordinates to screen coordinates
566
     */
567
    protected AffineTransform calculateTransformFromViewport() {
568
            Rectangle2D bounds = getBounds();
569
            if (bounds.getWidth()>0 && viewPort.getHeight()>0) {
570
                    AffineTransform at = new AffineTransform();
571
                    // paper (paper units) to screen (pixels) scale
572
                double scale, scale1, scale2;
573
                scale1 = bounds.getHeight() / viewPort.getHeight() * 1;
574
                scale2 = bounds.getWidth() / viewPort.getWidth() * 1;
575
                scale = (scale1+scale2)/2d; // average scale
576
                    AffineTransform scaleAt = new AffineTransform();
577
                    AffineTransform translationAt = new AffineTransform();
578
                    translationAt.setToTranslation(-viewPort.getMinX(), -viewPort.getMinY());
579
                    scaleAt.setToScale(scale, scale);
580
                    at.concatenate(scaleAt);
581
                    at.concatenate(translationAt);
582
                    return at;
583
            }
584
            return null;
585
    }
586

    
587
    public synchronized boolean isDrawingCancelled() {
588
        return m_bCancelDrawing;
589
    }
590

    
591
    public synchronized void setCancelDrawing(boolean b) {
592
        m_bCancelDrawing = b;
593

    
594
        for (int i = 0; i < layoutContext.getFFrames().length; i++) {
595
            IFFrame fframe = layoutContext.getFFrame(i);
596

    
597
            if (fframe instanceof IFFrameUseFMap
598
                && (((IFFrameUseFMap) fframe).getMapContext() != null)) {
599
                // //TODO((FFrameView)
600
                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
601
            }
602
        }
603
    }
604

    
605
    public Rectangle getReSel() {
606
        return reSel;
607
    }
608

    
609
    public boolean isReSel() {
610
        return isReSel;
611
    }
612

    
613
    public void setIsReSel(boolean b) {
614
        isReSel = b;
615
    }
616

    
617
    public void viewFull() throws ReadException {
618
        IFFrame[] fframes = layoutContext.getSelectedFFrames();
619

    
620
        for (int i = 0; i < fframes.length; i++) {
621
            if (fframes[i] instanceof IFFrameUseFMap) {
622
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
623

    
624
                if (fframe.getMapContext() != null) {
625
                    fframe.fullExtent();
626
                }
627

    
628
                fframe.refresh();
629
            }
630
        }
631

    
632
        refresh();
633
    }
634

    
635
    public FLayoutZooms getLayoutZooms() {
636
        return layoutZooms;
637
    }
638

    
639
    public FLayoutFunctions getLayoutFunctions() {
640
        return layoutFunctions;
641
    }
642

    
643
    public LayoutContext getLayoutContext() {
644
        return layoutContext;
645
    }
646

    
647
    public void setGeometryAdapter(GeometryAdapter adapter) {
648
        geometryAdapter = adapter;
649
    }
650

    
651
    public JComponent getComponent() {
652
        return this;
653
    }
654

    
655
    public void update(Observable observable, Object notification) {
656
       if ((notification != null) && (notification instanceof LayoutNotification)){
657
               LayoutNotification layoutNotification = (LayoutNotification)notification;
658
           if (LayoutNotification.LAYOUT_VALIDATED.equals(layoutNotification.getType())){
659
               status = ACTUALIZADO;
660
           }else if (LayoutNotification.LAYOUT_INVALIDATED.equals(layoutNotification.getType())){
661
               status = DESACTUALIZADO;
662
           }else if (LayoutNotification.LAYOUT_REFRESH.equals(layoutNotification.getType())){
663
               refresh();
664
           }
665
       }
666
    }
667
}