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 @ 1757

History | View | Annotate | Download (24 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.image.BufferedImage;
35
import java.awt.image.MemoryImageSource;
36
import java.util.HashMap;
37
import javax.swing.JComponent;
38
import org.gvsig.andami.PluginsLocator;
39
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
40
import org.gvsig.app.project.documents.layout.fframes.IFFrameEditableVertex;
41
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
42
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter;
43
import org.gvsig.app.project.documents.layout.geometryadapters.PolyLineAdapter;
44
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
45
import org.gvsig.app.project.documents.layout.tools.LayoutAddBoxListenerImpl;
46
import org.gvsig.app.project.documents.layout.tools.LayoutAddCircleListenerImpl;
47
import org.gvsig.app.project.documents.layout.tools.LayoutAddLegendListenerImpl;
48
import org.gvsig.app.project.documents.layout.tools.LayoutAddLineListenerImpl;
49
import org.gvsig.app.project.documents.layout.tools.LayoutAddNorthListenerImpl;
50
import org.gvsig.app.project.documents.layout.tools.LayoutAddOverViewListenerImpl;
51
import org.gvsig.app.project.documents.layout.tools.LayoutAddPictureListenerImpl;
52
import org.gvsig.app.project.documents.layout.tools.LayoutAddPointListenerImpl;
53
import org.gvsig.app.project.documents.layout.tools.LayoutAddPolygonListenerImpl;
54
import org.gvsig.app.project.documents.layout.tools.LayoutAddPolylineListenerImpl;
55
import org.gvsig.app.project.documents.layout.tools.LayoutAddRectangleListenerImpl;
56
import org.gvsig.app.project.documents.layout.tools.LayoutAddScaleListenerImpl;
57
import org.gvsig.app.project.documents.layout.tools.LayoutAddTextListenerImpl;
58
import org.gvsig.app.project.documents.layout.tools.LayoutAddViewListenerImpl;
59
import org.gvsig.app.project.documents.layout.tools.LayoutEditGraphicsListenerImpl;
60
import org.gvsig.app.project.documents.layout.tools.LayoutPanListenerImpl;
61
import org.gvsig.app.project.documents.layout.tools.LayoutSelectListenerImpl;
62
import org.gvsig.app.project.documents.layout.tools.LayoutViewPanListenerImpl;
63
import org.gvsig.app.project.documents.layout.tools.LayoutViewZoomInListenerImpl;
64
import org.gvsig.app.project.documents.layout.tools.LayoutViewZoomOutListenerImpl;
65
import org.gvsig.app.project.documents.layout.tools.LayoutZoomInListenerImpl;
66
import org.gvsig.app.project.documents.layout.tools.LayoutZoomOutListenerImpl;
67
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutBehavior;
68
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutEditBehavior;
69
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutMoveBehavior;
70
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutPointBehavior;
71
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutRectangleByTwoPointsBehavior;
72
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutSelectBehavior;
73
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewMoveBehavior;
74
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutViewZoomBehavior;
75
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutZoomBehavior;
76
import org.gvsig.app.project.documents.layout.tools.listener.ILayoutGraphicListener;
77
import org.gvsig.fmap.dal.exception.ReadException;
78
import org.gvsig.tools.observer.Observable;
79
import org.slf4j.Logger;
80
import org.slf4j.LoggerFactory;
81

    
82
/**
83
 * Control of Layout.
84
 * 
85
 * @author Vicente Caballero Navarro
86
 */
87
public class DefaultLayoutControl extends JComponent implements LayoutControl {
88
    
89
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLayoutControl.class);
90

    
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 final Point origin = new Point(50, 50);
104
    private final 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 final 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 final 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 final 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 final Rectangle reSel = null;
130
    private boolean isReSel = true;
131
    private FLayoutZooms layoutZooms;
132
//        private LayoutPanel layoutPanel;
133

    
134
    private static final 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 LayoutRectangleByTwoPointsBehavior(lavl));
171

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

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

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

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

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

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

    
195
        LayoutAddBoxListenerImpl labl = new LayoutAddBoxListenerImpl(layoutPanel);
196
        addLayoutTool("layoutaddbox", new LayoutRectangleByTwoPointsBehavior(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

    
244
    @Override
245
    public String getCurrentTool() {
246
        return currentTool;
247
    }
248

    
249
    @Override
250
    public void addLayoutTool(String name, LayoutBehavior tool) {
251
        namesLayoutTools.put(name, tool);
252
        tool.setLayoutControl(this);
253
    }
254

    
255
    @Override
256
    public LayoutBehavior getLayoutTool(String name) {
257
        return (LayoutBehavior) namesLayoutTools.get(name);
258
    }
259
    
260
    @Override
261
    public void setLayoutContext(LayoutContext lc) {
262
        layoutContext = lc;
263
        layoutContext.addObserver(this);
264
        fullRect();
265
    }
266

    
267
    /**
268
     * paintComponent of Layout.
269
     * 
270
     * @param g
271
     *            Graphics of Layout.
272
     */
273
    @Override
274
    protected void paintComponent(Graphics g) {
275
        clipVisibleRect((Graphics2D) g);
276

    
277
        Rectangle rClip = g.getClipBounds();
278

    
279
        if (rClip == null) {
280
            LOGGER.debug("clip = null");
281
        }
282

    
283
        switch (status) {
284
        case DESACTUALIZADO:
285
            if (getWidth() == 0) {
286
                return;
287
            }
288

    
289
            img =
290
                new BufferedImage(getWidth(), getHeight(),
291
                    BufferedImage.TYPE_INT_ARGB);
292
            imgRuler =
293
                new BufferedImage(getWidth(), getHeight(),
294
                    BufferedImage.TYPE_INT_ARGB);
295

    
296
            Graphics gimag = img.getGraphics();
297
            Graphics gimgRuler = imgRuler.getGraphics();
298
            clipVisibleRect((Graphics2D) gimag);
299

    
300
            layoutDraw.drawLayout((Graphics2D) gimag, img);
301

    
302
            g.setClip(rClip);
303
            layoutDraw.drawRectangle((Graphics2D) g);
304

    
305
            g.drawImage(img, 0, 0, this);
306
            g.setClip(rClip);
307

    
308
            layoutDraw.drawGrid((Graphics2D) gimgRuler);
309
            layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
310
            setStatus(ACTUALIZADO);
311
            repaint();
312

    
313
            break;
314

    
315
        case ACTUALIZADO:
316
            layoutDraw.drawRectangle((Graphics2D) g);
317

    
318
            if (currentLayoutTool != null) {
319
                currentLayoutTool.paintComponent(g);
320
            } else {
321
                g.drawImage(img, 0, 0, this);
322
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
323
            }
324

    
325
            g.setClip(rClip);
326
            drawCursor(g);
327
        }
328
    }
329

    
330
    private void setStatus(int s) {
331
        status = s;
332
    }
333

    
334
    /**
335
     * Clip on visible rectangle.
336
     * 
337
     * @param g2d
338
     *            Graphics.
339
     */
340
    private void clipVisibleRect(Graphics2D g2d) {
341
        rectVisible = this.getVisibleRect();
342
        g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
343
            (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
344
    }
345

    
346
    @Override
347
    public BufferedImage getImgRuler() {
348
        return imgRuler;
349
    }
350

    
351
    @Override
352
    public void fullRect() {
353
        Rectangle2D r = new Rectangle2D.Double(origin.x, origin.y, getWidth(),
354
            getHeight());
355

    
356
        if (layoutContext.getAttributes().isLandscape()) {
357
            r =
358
                layoutContext.getAttributes().getRectangleLandscape(r,
359
                    getWidth(), getHeight());
360
        } else {
361
            r =
362
                layoutContext.getAttributes().getRectanglePortrait(r,
363
                    getWidth(), getHeight());
364
        }
365
        setRect(r);
366
        refresh();
367
    }
368

    
369
    @Override
370
    public Rectangle2D.Double getRect() {
371
            return (Rectangle2D.Double) rect.clone();
372
    }
373

    
374
    @Override
375
    public void setRect(Rectangle2D r) {
376
        rect.setRect(r);
377
        Rectangle2D bounds = getBounds();
378
        if (rect.getWidth()>0 && bounds.getWidth()>0) { // only when the component has been laid out and rect properly initialized
379
                // ensure the AT is properly initialized
380
                layoutDraw.initializeAffineTransform();
381
                AffineTransform at = layoutContext.getAT();
382
                if (at!=null) {
383
                        Rectangle2D.Double newVp = new Rectangle2D.Double(0d, 0d, bounds.getWidth(), bounds.getHeight());
384
                        viewPort.setRect(FLayoutUtilities.toSheetRect(newVp, at));
385
                }
386
        }
387
    }
388

    
389
    @Override
390
    public BufferedImage getImage() {
391
        return img;
392
    }
393

    
394
    /**
395
     * Draw the cursor on the Graphics.
396
     * 
397
     * @param g
398
     *            Graphics.
399
     */
400
    private void drawCursor(Graphics g) {
401
        if ((imageCursor != null) && (position != null)) {
402
            Point pAdjusted = position;
403
            g.drawImage(imageCursor, (int) pAdjusted.getX() - 16,
404
                (int) pAdjusted.getY() - 16, this);
405
        }
406
    }
407

    
408
    @Override
409
    public void setMapCursor(Image image) {
410
        imageCursor = image;
411
    }
412

    
413
    @Override
414
    public void setTool(String toolName) {
415
        LayoutBehavior layoutTool =
416
            (LayoutBehavior) namesLayoutTools.get(toolName);
417
        currentLayoutTool = layoutTool;
418
        currentLayoutTool.setLayoutControl(this);
419
        currentTool = toolName;
420
        this.setMapCursor(layoutTool.getImageCursor());
421

    
422
        if (getCurrentLayoutTool().getListener() instanceof ILayoutGraphicListener) {
423
            geometryAdapter =
424
                ((ILayoutGraphicListener) getCurrentLayoutTool().getListener())
425
                    .createGeometryAdapter();
426
        }
427

    
428
        if (getCurrentTool().equals("layoutedit")) {
429
            startEdit();
430
        } else {
431
            stopEdit();
432
        }
433
    }
434

    
435
    @Override
436
        public void setDefaultTool() {
437
        PluginsLocator.getMainFrame().setSelectedTool("selection-select-by-rectangle-layout");
438
        setTool("layoutselect");
439
        }
440

    
441
    @Override
442
    public void startEdit() {
443
        IFFrame[] fframes = layoutContext.getFFrames();
444

    
445
        for (IFFrame frame : fframes) {
446
            if (frame instanceof IFFrameEditableVertex) {
447
                if (frame.getSelected() != IFFrame.NOSELECT) {
448
                    ((IFFrameEditableVertex) frame).startEditing();
449
                } else {
450
                    ((IFFrameEditableVertex) frame).stopEditing();
451
                }
452
            }
453
        }
454

    
455
        refresh();
456
    }
457

    
458
    @Override
459
    public void stopEdit() {
460
        boolean refresh = false;
461
        IFFrame[] fframes = layoutContext.getFFrames();
462

    
463
        for (IFFrame frame : fframes) {
464
            if (frame instanceof IFFrameEditableVertex) {
465
                if (((IFFrameEditableVertex) frame).isEditing()) {
466
                    ((IFFrameEditableVertex) frame).stopEditing();
467
                    refresh = true;
468
                }
469
            }
470
        }
471

    
472
        if (refresh) {
473
            refresh();
474
        }
475
    }
476

    
477
    @Override
478
    public Point getRectOrigin() {
479
        return rectOrigin;
480
    }
481

    
482
    @Override
483
    public FLayoutDraw getLayoutDraw() {
484
        return layoutDraw;
485
    }
486

    
487
    @Override
488
    public LayoutBehavior getCurrentLayoutTool() {
489
        return currentLayoutTool;
490
    }
491

    
492
    @Override
493
    public Point getFirstPoint() {
494
        return m_FirstPoint;
495
    }
496

    
497
    @Override
498
    public Point getPointAnt() {
499
        return m_PointAnt;
500
    }
501

    
502
    @Override
503
    public Point getLastPoint() {
504
        return m_LastPoint;
505
    }
506

    
507
    @Override
508
    public void setFirstPoint() {
509
        m_FirstPoint = position;
510
    }
511

    
512
    @Override
513
    public void setPointAnt() {
514
        m_PointAnt = position;
515
    }
516

    
517
    @Override
518
    public void setLastPoint() {
519
        m_LastPoint = position;
520
    }
521

    
522
    @Override
523
    public void setPosition(Point point2) {
524
        if (layoutContext.isAdjustingToGrid()
525
            && getCurrentLayoutTool().isAdjustable()) {
526
            position =
527
                FLayoutUtilities.getPointGrid(point2, layoutContext
528
                    .getAttributes().getHGridGapCm(), layoutContext
529
                    .getAttributes().getVGridGapCm(), layoutContext.getAT());
530
        } else {
531
            position = point2;
532
        }
533
    }
534

    
535
    @Override
536
    public Point getPosition() {
537
        return position;
538
    }
539

    
540
    @Override
541
    public AffineTransform getAT() {
542
        return layoutContext.getAT();
543
    }
544

    
545
    @Override
546
    public GeometryAdapter getGeometryAdapter() {
547
        return geometryAdapter;
548
    }
549

    
550
    @Override
551
    public void delLastPoint() {
552
        getGeometryAdapter().delLastPoint();
553
    }
554

    
555
    @Override
556
    public int addGeometryAdapterPoint() {
557
        return getGeometryAdapter().addPoint(
558
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
559
    }
560

    
561
    @Override
562
    public void setGeometryAdapterPoinPosition() {
563
        getGeometryAdapter().pointPosition(
564
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
565
    }
566

    
567
    @Override
568
    public void clearMouseImage() {
569
        setCursor(transparentCursor);
570
    }
571

    
572
    @Override
573
    public void refresh() {
574
            AffineTransform at = calculateTransformFromViewport();
575
            if (at!=null) {
576
                // update rect according to the viewport rectangle
577
                    Size s = getLayoutContext().getAttributes().getPaperSize();
578
                    Rectangle2D paperRect = new Rectangle2D.Double(0, 0, s.getWidth(), s.getHeight());
579
                    Rectangle2D newRect = FLayoutUtilities.fromSheetRect(paperRect, at);
580
                    setRect(newRect);
581
            }
582
            // repaint
583
        setStatus(DESACTUALIZADO);
584
        invalidate();
585
        repaint();
586
    }
587
    
588
    /**
589
     * Calculates the affine transform using the viewport and the control size,
590
     * instead of calculating it from {@link #rect}. as usual. This is required when
591
     * the component size changes, as {@link #rect}. has to be recalculated using
592
     * the viewport, and thus we can't calculate the affine transform using
593
     * {@link #rect}.
594
     * 
595
     * @return An matrix to transform from paper coordinates to screen coordinates
596
     */
597
    protected AffineTransform calculateTransformFromViewport() {
598
            Rectangle2D bounds = getBounds();
599
            if (bounds.getWidth()>0 && viewPort.getHeight()>0) {
600
                    AffineTransform at = new AffineTransform();
601
                    // paper (paper units) to screen (pixels) scale
602
                double scale, scale1, scale2;
603
                scale1 = bounds.getHeight() / viewPort.getHeight() * 1;
604
                scale2 = bounds.getWidth() / viewPort.getWidth() * 1;
605
                scale = (scale1+scale2)/2d; // average scale
606
                    AffineTransform scaleAt = new AffineTransform();
607
                    AffineTransform translationAt = new AffineTransform();
608
                    translationAt.setToTranslation(-viewPort.getMinX(), -viewPort.getMinY());
609
                    scaleAt.setToScale(scale, scale);
610
                    at.concatenate(scaleAt);
611
                    at.concatenate(translationAt);
612
                    return at;
613
            }
614
            return null;
615
    }
616

    
617
    @Override
618
    public synchronized boolean isDrawingCancelled() {
619
        return m_bCancelDrawing;
620
    }
621

    
622
    @Override
623
    public synchronized void setCancelDrawing(boolean b) {
624
        m_bCancelDrawing = b;
625

    
626
        for (int i = 0; i < layoutContext.getFFrames().length; i++) {
627
            IFFrame fframe = layoutContext.getFFrame(i);
628

    
629
            if (fframe instanceof IFFrameUseFMap
630
                && (((IFFrameUseFMap) fframe).getMapContext() != null)) {
631
                // //TODO((FFrameView)
632
                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
633
            }
634
        }
635
    }
636

    
637
    @Override
638
    public Rectangle getReSel() {
639
        return reSel;
640
    }
641

    
642
    @Override
643
    public boolean isReSel() {
644
        return isReSel;
645
    }
646

    
647
    @Override
648
    public void setIsReSel(boolean b) {
649
        isReSel = b;
650
    }
651

    
652
    @Override
653
    public void viewFull() throws ReadException {
654
        IFFrame[] fframes = layoutContext.getSelectedFFrames();
655

    
656
        for (IFFrame fframe1 : fframes) {
657
            if (fframe1 instanceof IFFrameUseFMap) {
658
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframe1;
659
                if (fframe.getMapContext() != null) {
660
                    fframe.fullExtent();
661
                }
662
                fframe.refresh();
663
            }
664
        }
665

    
666
        refresh();
667
    }
668

    
669
    @Override
670
    public FLayoutZooms getLayoutZooms() {
671
        return layoutZooms;
672
    }
673

    
674
    @Override
675
    public FLayoutFunctions getLayoutFunctions() {
676
        return layoutFunctions;
677
    }
678

    
679
    @Override
680
    public LayoutContext getLayoutContext() {
681
        return layoutContext;
682
    }
683

    
684
    @Override
685
    public void setGeometryAdapter(GeometryAdapter adapter) {
686
        geometryAdapter = adapter;
687
    }
688

    
689
    @Override
690
    public JComponent getComponent() {
691
        return this;
692
    }
693

    
694
    @Override
695
    public void update(Observable observable, Object notification) {
696
       if ((notification != null) && (notification instanceof LayoutNotification)){
697
               LayoutNotification layoutNotification = (LayoutNotification)notification;
698
           if (null != layoutNotification.getType())switch (layoutNotification.getType()) {
699
               case LayoutNotification.LAYOUT_VALIDATED:
700
                   status = ACTUALIZADO;
701
                   break;
702
               case LayoutNotification.LAYOUT_INVALIDATED:
703
                   status = DESACTUALIZADO;
704
                   break;
705
               case LayoutNotification.LAYOUT_REFRESH:
706
                   refresh();
707
                   break;
708
               default:
709
                   break;
710
           }
711
       }
712
    }
713
}