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

History | View | Annotate | Download (23.9 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.layout.mapbox.MapBoxUtils;
79
import org.gvsig.tools.observer.Observable;
80

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

    
92
    public static final String PERSISTENCE_DEFINITION_NAME = "LayoutControl";
93

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

    
123
    private String currentTool;
124
    private boolean m_bCancelDrawing = false;
125
    private final Rectangle reSel = null;
126
    private boolean isReSel = true;
127
    private FLayoutZooms layoutZooms;
128
//        private LayoutPanel layoutPanel;
129

    
130
    private static final Cursor transparentCursor = Toolkit.getDefaultToolkit()
131
        .createCustomCursor(
132
            Toolkit.getDefaultToolkit().createImage(
133
                new MemoryImageSource(16, 16, new int[16 * 16], 0, 16)),
134
            new Point(0, 0), "invisiblecursor");
135

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

    
156
        LayoutPanListenerImpl lpl = new LayoutPanListenerImpl(layoutPanel);
157
        addLayoutTool("layoutpan", new LayoutMoveBehavior(lpl));
158

    
159
        LayoutZoomInListenerImpl lzil = new LayoutZoomInListenerImpl(layoutPanel);
160
        addLayoutTool("layoutzoomin", new LayoutZoomBehavior(lzil));
161

    
162
        LayoutZoomOutListenerImpl lzol = new LayoutZoomOutListenerImpl(layoutPanel);
163
        addLayoutTool("layoutzoomout", new LayoutZoomBehavior(lzol));
164

    
165
        LayoutAddViewListenerImpl lavl = new LayoutAddViewListenerImpl(layoutPanel);
166
        addLayoutTool("layoutaddview", new LayoutRectangleByTwoPointsBehavior(lavl));
167

    
168
        LayoutAddOverViewListenerImpl laovl =
169
            new LayoutAddOverViewListenerImpl(layoutPanel);
170
        addLayoutTool("layoutaddoverview", new LayoutRectangleByTwoPointsBehavior(laovl));
171

    
172
        LayoutAddPictureListenerImpl lapl =
173
            new LayoutAddPictureListenerImpl(layoutPanel);
174
        addLayoutTool("layoutaddpicture", new LayoutRectangleByTwoPointsBehavior(lapl));
175

    
176
        LayoutAddNorthListenerImpl lanorthl =
177
            new LayoutAddNorthListenerImpl(layoutPanel);
178
        addLayoutTool("layoutaddnorth", new LayoutRectangleByTwoPointsBehavior(lanorthl));
179

    
180
        LayoutAddScaleListenerImpl lasl =
181
            new LayoutAddScaleListenerImpl(layoutPanel);
182
        addLayoutTool("layoutaddscale", new LayoutRectangleByTwoPointsBehavior(lasl));
183

    
184
        LayoutAddLegendListenerImpl lall =
185
            new LayoutAddLegendListenerImpl(layoutPanel);
186
        addLayoutTool("layoutaddlegend", new LayoutRectangleByTwoPointsBehavior(lall));
187

    
188
        LayoutAddTextListenerImpl latl = new LayoutAddTextListenerImpl(layoutPanel);
189
        addLayoutTool("layoutaddtext", new LayoutRectangleByTwoPointsBehavior(latl));
190

    
191
        LayoutAddBoxListenerImpl labl = new LayoutAddBoxListenerImpl(layoutPanel);
192
        addLayoutTool("layoutaddbox", new LayoutRectangleByTwoPointsBehavior(labl));
193

    
194
        LayoutAddPointListenerImpl lapointl =
195
            new LayoutAddPointListenerImpl(layoutPanel);
196
        addLayoutTool("layoutaddpoint", new LayoutPointBehavior(lapointl));
197

    
198
        LayoutAddLineListenerImpl lalinel =
199
            new LayoutAddLineListenerImpl(layoutPanel);
200
        addLayoutTool("layoutaddline", new LayoutPointBehavior(lalinel));
201

    
202
        LayoutAddPolygonListenerImpl lapolygonl =
203
            new LayoutAddPolygonListenerImpl(layoutPanel);
204
        addLayoutTool("layoutaddpolygon", new LayoutPointBehavior(lapolygonl));
205

    
206
        LayoutAddPolylineListenerImpl lapolylinel =
207
            new LayoutAddPolylineListenerImpl(layoutPanel);
208
        addLayoutTool("layoutaddpolyline", new LayoutPointBehavior(lapolylinel));
209

    
210
        LayoutAddCircleListenerImpl lacirclel =
211
            new LayoutAddCircleListenerImpl(layoutPanel);
212
        addLayoutTool("layoutaddcircle", new LayoutPointBehavior(lacirclel));
213

    
214
        LayoutAddRectangleListenerImpl larectanglel =
215
            new LayoutAddRectangleListenerImpl(layoutPanel);
216
        addLayoutTool("layoutaddrectangle", new LayoutPointBehavior(
217
            larectanglel));
218

    
219
        LayoutViewPanListenerImpl lvpl = new LayoutViewPanListenerImpl(layoutPanel);
220
        addLayoutTool("layoutviewpan", new LayoutViewMoveBehavior(lvpl));
221

    
222
        LayoutViewZoomInListenerImpl lvzil =
223
            new LayoutViewZoomInListenerImpl(layoutPanel);
224
        addLayoutTool("layoutviewzoomin", new LayoutViewZoomBehavior(lvzil));
225

    
226
        LayoutViewZoomOutListenerImpl lvzol =
227
            new LayoutViewZoomOutListenerImpl(layoutPanel);
228
        addLayoutTool("layoutviewzoomout", new LayoutViewZoomBehavior(lvzol));
229

    
230
        LayoutSelectListenerImpl lselectl =
231
            new LayoutSelectListenerImpl(layoutPanel);
232
        addLayoutTool("layoutselect", new LayoutSelectBehavior(lselectl));
233

    
234
        LayoutEditGraphicsListenerImpl leditl =
235
            new LayoutEditGraphicsListenerImpl(layoutPanel);
236
        addLayoutTool("layoutedit", new LayoutEditBehavior(leditl));
237
        
238
        MapBoxUtils.addLayoutTool(layoutPanel, this);
239
    }
240

    
241
    @Override
242
    public String getCurrentTool() {
243
        return currentTool;
244
    }
245

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

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

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

    
269
        Rectangle rClip = g.getClipBounds();
270

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

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

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

    
288
            Graphics gimag = img.getGraphics();
289
            Graphics gimgRuler = imgRuler.getGraphics();
290
            clipVisibleRect((Graphics2D) gimag);
291

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

    
298
            g.setClip(rClip);
299
            layoutDraw.drawRectangle((Graphics2D) g);
300

    
301
            g.drawImage(img, 0, 0, this);
302
            g.setClip(rClip);
303

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

    
309
            break;
310

    
311
        case ACTUALIZADO:
312
            layoutDraw.drawRectangle((Graphics2D) g);
313

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

    
321
            g.setClip(rClip);
322
            drawCursor(g);
323
        }
324
    }
325

    
326
    private void setStatus(int s) {
327
        status = s;
328
    }
329

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

    
342
    @Override
343
    public BufferedImage getImgRuler() {
344
        return imgRuler;
345
    }
346

    
347
    @Override
348
    public void fullRect() {
349
        Rectangle2D r = new Rectangle2D.Double(origin.x, origin.y, getWidth(),
350
            getHeight());
351

    
352
        if (layoutContext.getAttributes().isLandscape()) {
353
            r =
354
                layoutContext.getAttributes().getRectangleLandscape(r,
355
                    getWidth(), getHeight());
356
        } else {
357
            r =
358
                layoutContext.getAttributes().getRectanglePortrait(r,
359
                    getWidth(), getHeight());
360
        }
361
        setRect(r);
362
        refresh();
363
    }
364

    
365
    @Override
366
    public Rectangle2D.Double getRect() {
367
            return (Rectangle2D.Double) rect.clone();
368
    }
369

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

    
385
    @Override
386
    public BufferedImage getImage() {
387
        return img;
388
    }
389

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

    
404
    @Override
405
    public void setMapCursor(Image image) {
406
        imageCursor = image;
407
    }
408

    
409
    @Override
410
    public void setTool(String toolName) {
411
        LayoutBehavior layoutTool =
412
            (LayoutBehavior) namesLayoutTools.get(toolName);
413
        currentLayoutTool = layoutTool;
414
        currentLayoutTool.setLayoutControl(this);
415
        currentTool = toolName;
416
        this.setMapCursor(layoutTool.getImageCursor());
417

    
418
        if (getCurrentLayoutTool().getListener() instanceof ILayoutGraphicListener) {
419
            geometryAdapter =
420
                ((ILayoutGraphicListener) getCurrentLayoutTool().getListener())
421
                    .createGeometryAdapter();
422
        }
423

    
424
        if (getCurrentTool().equals("layoutedit")) {
425
            startEdit();
426
        } else {
427
            stopEdit();
428
        }
429
    }
430

    
431
    @Override
432
        public void setDefaultTool() {
433
        PluginsLocator.getMainFrame().setSelectedTool("selection-select-by-rectangle-layout");
434
        setTool("layoutselect");
435
        }
436

    
437
    @Override
438
    public void startEdit() {
439
        IFFrame[] fframes = layoutContext.getFFrames();
440

    
441
        for (IFFrame frame : fframes) {
442
            if (frame instanceof IFFrameEditableVertex) {
443
                if (frame.getSelected() != IFFrame.NOSELECT) {
444
                    ((IFFrameEditableVertex) frame).startEditing();
445
                } else {
446
                    ((IFFrameEditableVertex) frame).stopEditing();
447
                }
448
            }
449
        }
450

    
451
        refresh();
452
    }
453

    
454
    @Override
455
    public void stopEdit() {
456
        boolean refresh = false;
457
        IFFrame[] fframes = layoutContext.getFFrames();
458

    
459
        for (IFFrame frame : fframes) {
460
            if (frame instanceof IFFrameEditableVertex) {
461
                if (((IFFrameEditableVertex) frame).isEditing()) {
462
                    ((IFFrameEditableVertex) frame).stopEditing();
463
                    refresh = true;
464
                }
465
            }
466
        }
467

    
468
        if (refresh) {
469
            refresh();
470
        }
471
    }
472

    
473
    @Override
474
    public Point getRectOrigin() {
475
        return rectOrigin;
476
    }
477

    
478
    @Override
479
    public FLayoutDraw getLayoutDraw() {
480
        return layoutDraw;
481
    }
482

    
483
    @Override
484
    public LayoutBehavior getCurrentLayoutTool() {
485
        return currentLayoutTool;
486
    }
487

    
488
    @Override
489
    public Point getFirstPoint() {
490
        return m_FirstPoint;
491
    }
492

    
493
    @Override
494
    public Point getPointAnt() {
495
        return m_PointAnt;
496
    }
497

    
498
    @Override
499
    public Point getLastPoint() {
500
        return m_LastPoint;
501
    }
502

    
503
    @Override
504
    public void setFirstPoint() {
505
        m_FirstPoint = position;
506
    }
507

    
508
    @Override
509
    public void setPointAnt() {
510
        m_PointAnt = position;
511
    }
512

    
513
    @Override
514
    public void setLastPoint() {
515
        m_LastPoint = position;
516
    }
517

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

    
531
    @Override
532
    public Point getPosition() {
533
        return position;
534
    }
535

    
536
    @Override
537
    public AffineTransform getAT() {
538
        return layoutContext.getAT();
539
    }
540

    
541
    @Override
542
    public GeometryAdapter getGeometryAdapter() {
543
        return geometryAdapter;
544
    }
545

    
546
    @Override
547
    public void delLastPoint() {
548
        getGeometryAdapter().delLastPoint();
549
    }
550

    
551
    @Override
552
    public int addGeometryAdapterPoint() {
553
        return getGeometryAdapter().addPoint(
554
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
555
    }
556

    
557
    @Override
558
    public void setGeometryAdapterPoinPosition() {
559
        getGeometryAdapter().pointPosition(
560
            FLayoutUtilities.toSheetPoint(getPosition(), getAT()));
561
    }
562

    
563
    @Override
564
    public void clearMouseImage() {
565
        setCursor(transparentCursor);
566
    }
567

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

    
613
    @Override
614
    public synchronized boolean isDrawingCancelled() {
615
        return m_bCancelDrawing;
616
    }
617

    
618
    @Override
619
    public synchronized void setCancelDrawing(boolean b) {
620
        m_bCancelDrawing = b;
621

    
622
        for (int i = 0; i < layoutContext.getFFrames().length; i++) {
623
            IFFrame fframe = layoutContext.getFFrame(i);
624

    
625
            if (fframe instanceof IFFrameUseFMap
626
                && (((IFFrameUseFMap) fframe).getMapContext() != null)) {
627
                // //TODO((FFrameView)
628
                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
629
            }
630
        }
631
    }
632

    
633
    @Override
634
    public Rectangle getReSel() {
635
        return reSel;
636
    }
637

    
638
    @Override
639
    public boolean isReSel() {
640
        return isReSel;
641
    }
642

    
643
    @Override
644
    public void setIsReSel(boolean b) {
645
        isReSel = b;
646
    }
647

    
648
    @Override
649
    public void viewFull() throws ReadException {
650
        IFFrame[] fframes = layoutContext.getSelectedFFrames();
651

    
652
        for (IFFrame fframe1 : fframes) {
653
            if (fframe1 instanceof IFFrameUseFMap) {
654
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframe1;
655
                if (fframe.getMapContext() != null) {
656
                    fframe.fullExtent();
657
                }
658
                fframe.refresh();
659
            }
660
        }
661

    
662
        refresh();
663
    }
664

    
665
    @Override
666
    public FLayoutZooms getLayoutZooms() {
667
        return layoutZooms;
668
    }
669

    
670
    @Override
671
    public FLayoutFunctions getLayoutFunctions() {
672
        return layoutFunctions;
673
    }
674

    
675
    @Override
676
    public LayoutContext getLayoutContext() {
677
        return layoutContext;
678
    }
679

    
680
    @Override
681
    public void setGeometryAdapter(GeometryAdapter adapter) {
682
        geometryAdapter = adapter;
683
    }
684

    
685
    @Override
686
    public JComponent getComponent() {
687
        return this;
688
    }
689

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