Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / MapControl.java @ 4619

History | View | Annotate | Download (22.7 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap;
42

    
43
import java.awt.Color;
44
import java.awt.Dimension;
45
import java.awt.Graphics;
46
import java.awt.Graphics2D;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.awt.event.ComponentEvent;
50
import java.awt.event.ComponentListener;
51
import java.awt.event.MouseEvent;
52
import java.awt.event.MouseListener;
53
import java.awt.event.MouseMotionListener;
54
import java.awt.event.MouseWheelEvent;
55
import java.awt.event.MouseWheelListener;
56
import java.awt.image.BufferedImage;
57
import java.util.HashMap;
58

    
59
import javax.swing.JComponent;
60
import javax.swing.Timer;
61

    
62
import org.cresques.cts.IProjection;
63
import org.cresques.cts.ProjectionPool;
64

    
65
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener;
66
import com.iver.cit.gvsig.fmap.layers.LayerEvent;
67
import com.iver.cit.gvsig.fmap.operations.Cancellable;
68
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
69
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior;
70
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
71
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport;
72
import com.iver.utiles.exceptionHandling.ExceptionListener;
73

    
74

    
75
/**
76
 * MapControl.
77
 *
78
 * @author Fernando Gonz?lez Cort?s
79
 */
80
public class MapControl extends JComponent implements ComponentListener,CommandListener {
81
        /** Cuando la vista est? actualizada. */
82
        public static final int ACTUALIZADO = 0;
83

    
84
        /** Cuando la vista est? desactualizada. */
85
        public static final int DESACTUALIZADO = 1;
86
    public static final int ONLY_GRAPHICS = 2;
87
    // public static final int FAST_PAINT = 3;
88
        //private static Logger logger = Logger.getLogger(MapControl.class.getName());
89
        private FMap mapContext = null;
90
    //private boolean drawerAlive = false;
91
        private HashMap namesMapTools = new HashMap();
92
        private Behavior currentMapTool = null;
93
        private int status = DESACTUALIZADO;
94
        private BufferedImage image = null;
95
        private String currentTool;
96
        private CancelDraw canceldraw;
97
        //private boolean isCancelled = true;
98
        private Timer timer;
99
        protected ViewPort vp;
100
        //private Drawer drawer;
101
    private Drawer2 drawer2;
102
    // private boolean firstDraw = true;
103
        private MapToolListener mapToolListener = new MapToolListener();
104
        private MapContextListener mapContextListener = new MapContextListener();
105
        private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport();
106

    
107
        /**
108
     * We need this to avoid not wanted refresh. REMEMBER TO SET TO TRUE!!
109
     */
110
    // private boolean paintEnabled = false;
111

    
112
        /**
113
         * Crea un nuevo NewMapControl.
114
         */
115
        public MapControl() {
116
                setDoubleBuffered(false);
117
                setOpaque(true);
118
                status = DESACTUALIZADO;
119

    
120
                //Clase usada para cancelar el dibujado
121
                canceldraw = new CancelDraw();
122

    
123
                //Modelo de datos y ventana del mismo
124
                // TODO: Cuando creamos un mapControl, deber?amos asignar
125
                // la projecci?n por defecto con la que vayamos a trabajar.
126
                // 23030 es el c?digo EPSG del UTM30 elipsoide ED50
127
                vp = new ViewPort(ProjectionPool.get("EPSG:23030"));
128
                setMapContext(new FMap(vp));
129

    
130
                //eventos
131
                this.addComponentListener(this);
132
                this.addMouseListener(mapToolListener);
133
                this.addMouseMotionListener(mapToolListener);
134
                this.addMouseWheelListener(mapToolListener);
135

    
136
        this.drawer2 = new Drawer2();
137
                //Timer para mostrar el redibujado mientras se dibuja
138
                timer = new Timer(300,
139
                                new ActionListener() {
140
                                        public void actionPerformed(ActionEvent e) {
141
                                                MapControl.this.repaint();
142
                                        }
143
                                });
144
        }
145

    
146
        /**
147
         * Inserta el modelo.
148
         *
149
         * @param model FMap.
150
         */
151
        public void setMapContext(FMap model) {
152
                if (mapContext != null) {
153
                        mapContext.removeAtomicEventListener(mapContextListener);
154
                }
155

    
156
                mapContext = model;
157

    
158
                if (mapContext.getViewPort() == null) {
159
                        mapContext.setViewPort(vp);
160
                } else {
161
                        vp = mapContext.getViewPort();
162

    
163
                        // vp.setImageSize(new Dimension(getWidth(), getHeight()));
164
                        //System.err.println("Viewport en setMapContext:" + vp);
165
                }
166

    
167
                mapContext.addAtomicEventListener(mapContextListener);
168

    
169
                status = DESACTUALIZADO;
170
        }
171

    
172
        /**
173
         * Devuelve la proyecci?n.
174
         *
175
         * @return Proyecci?n.
176
         */
177
        public IProjection getProjection() {
178
                return getMapContext().getProjection();
179
        }
180

    
181
        /**
182
         * Inserta una proyecci?n.
183
         *
184
         * @param proj Proyecci?n.
185
         */
186
        public void setProjection(IProjection proj) {
187
                getMapContext().setProjection(proj);
188
        }
189

    
190
        /**
191
         * Devuelve el modelo.
192
         *
193
         * @return FMap.
194
         */
195
        public FMap getMapContext() {
196
                return mapContext;
197
        }
198

    
199
        /**
200
         * Registra una herramienta (tool).
201
         *
202
         * @param name Nombre de la herramienta.
203
         * @param tool Herramienta.
204
         */
205
        public void addMapTool(String name, Behavior tool) {
206
                namesMapTools.put(name, tool);
207
                tool.setMapControl(this);
208
        }
209

    
210
        public void addMapTool(String name, Behavior[] tools){
211
                CompoundBehavior tool = new CompoundBehavior(tools);
212
                addMapTool(name, tool);
213
        }
214

    
215
        /**
216
         * DOCUMENT ME!
217
         *
218
         * @param toolName DOCUMENT ME!
219
         */
220
        public void setTool(String toolName) {
221
                Behavior mapTool = (Behavior) namesMapTools.get(toolName);
222
                currentMapTool = mapTool;
223
                currentTool = toolName;
224
                this.setCursor(mapTool.getCursor());
225
        }
226
        public Behavior getCurrentMapTool(){
227
                return currentMapTool;
228
        }
229
        /**
230
         * Devuelve el nombre de la herramienta seleccionada.
231
         *
232
         * @return nombre.
233
         */
234
        public String getTool() {
235
                return currentTool;
236
        }
237

    
238
        /**
239
         * Cancela el dibujado. Se espera a que la cancelaci?n surta efecto
240
         */
241
        public void cancelDrawing() {
242
                /* if (drawer != null) {
243
                        if (!drawer.isAlive()) {
244
                                return;
245
                        }
246
                }
247
                */
248
                canceldraw.setCancel(true);
249

    
250
                /* while (!isCancelled) {
251
                        if (!drawer.isAlive()) {
252
                            // Si hemos llegado aqu? con un thread vivo, seguramente
253
                            // no estamos actualizados.
254

255
                                break;
256
                        }
257

258
                }
259
                canceldraw.setCancel(false);
260
                isCancelled = false;
261
        drawerAlive = false; */
262
        }
263

    
264
    private boolean adaptToImageSize()
265
    {
266
        if ((image == null) || (vp.getImageWidth() != this.getWidth()) || (vp.getImageHeight() != this.getHeight()))
267
        {
268
            image = new BufferedImage(this.getWidth(), this.getHeight(),
269
                    BufferedImage.TYPE_INT_ARGB);
270
            vp.setImageSize(new Dimension(getWidth(), getHeight()));
271
            getMapContext().getViewPort().setScale();
272

    
273

    
274
            Graphics gTemp = image.createGraphics();
275
            Color theBackColor = vp.getBackColor();
276
            if (theBackColor == null)
277
                gTemp.setColor(Color.WHITE);
278
            else
279
                gTemp.setColor(theBackColor);
280

    
281
            gTemp.fillRect(0,0,getWidth(), getHeight());
282
            gTemp.dispose();
283
            status = DESACTUALIZADO;
284
            // g.drawImage(image,0,0,null);
285
            return true;
286
        }
287
        return false;
288
    }
289

    
290
        /**
291
         * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
292
         */
293
        protected void paintComponent(Graphics g) {
294
        adaptToImageSize();
295
        /* if (status == FAST_PAINT) {
296
            System.out.println("FAST_PAINT");
297
            g.drawImage(image,0,0,null);
298
            status = ACTUALIZADO;
299
            return;
300
        } */
301
        // System.out.println("PINTANDO MAPCONTROL" + this);
302
                if (status == ACTUALIZADO) {
303
                        // LWS logger.debug("Dibujando la imagen obtenida");
304

    
305
                        /*
306
                         * Si hay un behaviour y la imagen es distinta de null se delega el dibujado
307
                         * en dicho behaviour
308
                         */
309
            if (image != null)
310
            {
311
                if (currentMapTool != null)
312
                    currentMapTool.paintComponent(g);
313
                else
314
                    g.drawImage(image,0,0,null);
315

    
316
                                // System.out.println("Pinto ACTUALIZADO");
317
                        }
318
                } else if ((status == DESACTUALIZADO)
319
                || (status == ONLY_GRAPHICS)) {
320
                        // LWS System.out.println("DESACTUALIZADO: Obteniendo la imagen de la cartograf?a");
321
                        /* if (isOpaque())
322
                        {
323
                            if (image==null)
324
                            {
325
                                g.setColor(vp.getBackColor());
326
                                g.fillRect(0,0,getWidth(), getHeight());
327
                            }
328
                            // else g.drawImage(image,0,0,null);
329
                        } */
330
            // cancelDrawing();
331
                        //Se crea la imagen con el color de fonde deseado
332
                        /* if (image == null)
333
                        {
334
                                image = new BufferedImage(this.getWidth(), this.getHeight(),
335
                                                BufferedImage.TYPE_INT_ARGB);
336
                                vp.setImageSize(new Dimension(getWidth(), getHeight()));
337
                                Graphics gTemp = image.createGraphics();
338
                            Color theBackColor = vp.getBackColor();
339
                            if (theBackColor == null)
340
                                gTemp.setColor(Color.WHITE);
341
                            else
342
                                gTemp.setColor(theBackColor);
343

344
                                gTemp.fillRect(0,0,getWidth(), getHeight());
345
                                gTemp.dispose();
346
                                // g.drawImage(image,0,0,null);
347
                                System.out.println("Imagen con null en DESACTUALIZADO. Width = " + this.getWidth());
348
                        } */
349
            // else
350
            // {
351

    
352

    
353
            // if (image != null)
354
            //  {
355
                g.drawImage(image,0,0,null);
356

    
357
                drawer2.put(new PaintingRequest());
358
                timer.start();
359
            /* }
360
            else
361
                return; */
362
            // }
363

    
364
            /* if (drawerAlive == false)
365
            {
366
                drawer = new Drawer(image, canceldraw);
367
                drawer.start();
368
                        //Se lanza el tread de dibujado
369
            } */
370

    
371
                        // status = ACTUALIZADO;
372
                }
373
        }
374

    
375
        /**
376
         * Devuelve la imagen de la vista.
377
         *
378
         * @return imagen.
379
         */
380
        public BufferedImage getImage() {
381
                return image;
382
        }
383

    
384
        /**
385
         * Marca el mapa para que en el pr?ximo redibujado se acceda a la
386
         * cartograf?a para reobtener la imagen
387
         * @param doClear Solo deber?a ser true cuando se llama desde pan
388
         */
389
        public void drawMap(boolean doClear) {
390
                cancelDrawing();
391
                System.out.println("drawMap con doClear=" + doClear);
392
        status = DESACTUALIZADO;
393
                if (doClear)
394
        {
395
            // image = null; // Se usa para el PAN
396
            if (image != null)
397
            {
398
                Graphics2D g = image.createGraphics();
399
                Color theBackColor = vp.getBackColor();
400
                if (theBackColor == null)
401
                    g.setColor(Color.WHITE);
402
                else
403
                    g.setColor(theBackColor);
404
                g.fillRect(0, 0, vp.getImageWidth(), vp.getImageHeight());
405
                g.dispose();
406
            }
407
        }
408
                repaint();
409
        }
410
    public void drawGraphics() {
411
        status = ONLY_GRAPHICS;
412
        repaint();
413
    }
414

    
415
        /**
416
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
417
         */
418
        public void componentHidden(ComponentEvent e) {
419
        }
420

    
421
        /**
422
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
423
         */
424
        public void componentMoved(ComponentEvent e) {
425
        }
426

    
427
        /**
428
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
429
         */
430
        public void componentResized(ComponentEvent e) {
431
                /* image = new BufferedImage(this.getWidth(), this.getHeight(),
432
                                BufferedImage.TYPE_INT_ARGB);
433
                Graphics gTemp = image.createGraphics();
434
                gTemp.setColor(vp.getBackColor());
435
                gTemp.fillRect(0,0,getWidth(), getHeight());
436
        System.out.println("MapControl resized");
437
            // image = null;
438
            vp.setImageSize(new Dimension(getWidth(), getHeight()));
439
                getMapContext().getViewPort().setScale(); */
440
                // drawMap(true);
441
        }
442

    
443
        /**
444
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
445
         */
446
        public void componentShown(ComponentEvent e) {
447
        }
448

    
449
        /**
450
         * A?ade un listener de tipo ExceptionListener.
451
         *
452
         * @param o ExceptionListener.
453
         */
454
        public void addExceptionListener(ExceptionListener o) {
455
                exceptionHandlingSupport.addExceptionListener(o);
456
        }
457

    
458
        /**
459
         * Borra la ExceptioListener que se pasa como par?metro.
460
         *
461
         * @param o ExceptionListener.
462
         *
463
         * @return True si se borra correctamente.
464
         */
465
        public boolean removeExceptionListener(ExceptionListener o) {
466
                return exceptionHandlingSupport.removeExceptionListener(o);
467
        }
468

    
469
        /**
470
         * Lanza una Excepci?n.
471
         *
472
         * @param t Excepci?n.
473
         */
474
        private void throwException(Throwable t) {
475
                exceptionHandlingSupport.throwException(t);
476
        }
477

    
478

    
479
    private class PaintingRequest
480
    {
481

    
482
        public PaintingRequest()
483
        {
484
        }
485

    
486
        public void paint()
487
        {
488
            try
489
            {
490
                    canceldraw.setCancel(false);
491
                /* if (image == null)
492
                {
493
                    image = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(),
494
                            BufferedImage.TYPE_INT_ARGB);
495
                    Graphics gTemp = image.createGraphics();
496
                    Color theBackColor = vp.getBackColor();
497
                    if (theBackColor == null)
498
                        gTemp.setColor(Color.WHITE);
499
                    else
500
                        gTemp.setColor(theBackColor);
501

502
                    gTemp.fillRect(0,0,getWidth(), getHeight());
503
                    gTemp.dispose();
504
                    // g.drawImage(image,0,0,null);
505
                    System.out.println("Imagen con null en DESACTUALIZADO. Width = " + this.getWidth());
506
                } */
507
                Graphics2D g = image.createGraphics();
508

    
509
                ViewPort viewPort = mapContext.getViewPort();
510

    
511
                if (status == DESACTUALIZADO)
512
                {
513
                    Color theBackColor = viewPort.getBackColor();
514
                    if (theBackColor == null)
515
                        g.setColor(Color.WHITE);
516
                    else
517
                        g.setColor(theBackColor);
518
                    g.fillRect(0, 0, viewPort.getImageWidth(), viewPort.getImageHeight());
519
                    status = ACTUALIZADO;
520
                    mapContext.draw(image, g, canceldraw, mapContext.getScaleView());
521

    
522
                }
523
                else if (status == ONLY_GRAPHICS)
524
                {
525
                    status = ACTUALIZADO;
526
                    mapContext.drawGraphics(image, g, canceldraw,mapContext.getScaleView());
527

    
528
                }
529

    
530

    
531
                // status = FAST_PAINT;
532
              //  drawerAlive = false;
533
                timer.stop();
534
                repaint();
535

    
536

    
537
            } catch (Throwable e) {
538
                timer.stop();
539
              //  isCancelled = true;
540
                e.printStackTrace();
541
                throwException(e);
542
            } finally {
543
            }
544

    
545
        }
546

    
547
    }
548

    
549
    /**
550
     * @author fjp
551
     *
552
     * Basasdo en el patr?n WorkerThread
553
     *
554
     */
555
    public class Drawer2
556
    {
557
        // Una mini cola de 2. No acumulamos peticiones de dibujado
558
        // dibujamos solo lo ?ltimo que nos han pedido.
559
        private PaintingRequest paintingRequest;
560
        private PaintingRequest waitingRequest;
561

    
562
        private boolean waiting;
563
        private boolean shutdown;
564

    
565
        public void setShutdown(boolean isShutdown)
566
        {
567
            shutdown = isShutdown;
568
        }
569

    
570
        public Drawer2()
571
        {
572
            paintingRequest = null;
573
            waitingRequest = null;
574
            waiting = false;
575
            shutdown = false;
576
            new Thread(new Worker()).start();
577
        }
578

    
579
        public void put(PaintingRequest newPaintRequest)
580
        {
581
            waitingRequest = newPaintRequest;
582
            if (waiting)
583
            {
584
                synchronized (this) {
585
                    notifyAll();
586
                }
587
            }
588
        }
589

    
590
        public PaintingRequest take()
591
        {
592
            if (waitingRequest == null)
593
            {
594
                synchronized (this) {
595
                    waiting = true;
596
                    try {
597
                        wait();
598
                    }
599
                    catch (InterruptedException ie)
600
                    {
601
                        waiting = false;
602
                    }
603
                }
604
            }
605
            paintingRequest = waitingRequest;
606
            waitingRequest = null;
607
            return paintingRequest;
608
        }
609

    
610

    
611
        private class Worker implements Runnable
612
        {
613
            public void run()
614
            {
615
                while (!shutdown)
616
                {
617
                    PaintingRequest p = take();
618
                    System.out.println("Pintando");
619
                    if (image != null){
620
                            cancelDrawing();
621
                        p.paint();
622
                    } else
623
                        status = DESACTUALIZADO;
624
                }
625
            }
626
        }
627
    }
628

    
629
        /**
630
         * Clase utilizada para dibujar las capas.
631
         *
632
         * @author Vicente Caballero Navarro
633
         */
634
        public class Drawer extends Thread {
635
                //private Graphics g;
636
                private BufferedImage image = null;
637
                private CancelDraw cancel;
638
                //private boolean threadCancel = false;
639

    
640
                /**
641
                 * Crea un nuevo Drawer.
642
                 *
643
                 */
644
                public Drawer(BufferedImage image, CancelDraw cancel)
645
        {
646
                        this.image = image;
647
                        this.cancel = cancel;
648
         //   drawerAlive = true;
649
                }
650

    
651
                /**
652
                 * @see java.lang.Runnable#run()
653
                 */
654
                public void run() {
655
                        try {
656
                                // synchronized (Drawer.class) {
657
                                    Graphics2D g = image.createGraphics();
658

    
659
                                    ViewPort viewPort = mapContext.getViewPort();
660
                    if (status == DESACTUALIZADO)
661
                    {
662
                                        Color theBackColor = viewPort.getBackColor();
663
                                        if (theBackColor == null)
664
                                            g.setColor(Color.WHITE);
665
                                        else
666
                                            g.setColor(theBackColor);
667
                                            g.fillRect(0, 0, viewPort.getImageWidth(), viewPort.getImageHeight());
668
                        status = ACTUALIZADO;
669
                        mapContext.draw(image, g, cancel,mapContext.getScaleView());
670
                    }
671
                    else if (status == ONLY_GRAPHICS)
672
                    {
673
                        status = ACTUALIZADO;
674
                        mapContext.drawGraphics(image, g, cancel,mapContext.getScaleView());
675
                    }
676

    
677
                                        timer.stop();
678
                    // status = FAST_PAINT;
679
                  //  drawerAlive = false;
680
                                        repaint();
681

    
682

    
683

    
684
                                // }
685
                        } catch (Throwable e) {
686
                            timer.stop();
687
                                //isCancelled = true;
688
                e.printStackTrace();
689
                                throwException(e);
690
                        } finally {
691
                        }
692
                }
693
        }
694

    
695
        /**
696
         * Clase para cancelar el dibujado.
697
         *
698
         * @author Fernando Gonz?lez Cort?s
699
         */
700
        public class CancelDraw implements Cancellable {
701
                private boolean cancel = false;
702

    
703
                /**
704
                 * Crea un nuevo CancelDraw.
705
                 */
706
                public CancelDraw() {
707
                }
708

    
709
                /**
710
                 * Insertar si se debe cancelar el dibujado.
711
                 *
712
                 * @param b true si se debe cancelar el dibujado.
713
                 */
714
                public void setCancel(boolean b) {
715
                        cancel = b;
716
                }
717

    
718
                /**
719
                 * @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
720
                 */
721
                public boolean isCanceled() {
722
                        return cancel;
723
                }
724
        }
725

    
726
        /**
727
         * Listener del MapTool.
728
         *
729
         * @author Fernando Gonz?lez Cort?s
730
         */
731
        public class MapToolListener implements MouseListener, MouseWheelListener,
732
                MouseMotionListener {
733
                /**
734
                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
735
                 */
736
                public void mouseClicked(MouseEvent e) {
737
                        try {
738
                                currentMapTool.mouseClicked(e);
739
                        } catch (BehaviorException t) {
740
                                throwException(t);
741
                        }
742
                }
743

    
744
                /**
745
                 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
746
                 */
747
                public void mouseEntered(MouseEvent e) {
748
                        try {
749
                                currentMapTool.mouseEntered(e);
750
                        } catch (BehaviorException t) {
751
                                throwException(t);
752
                        }
753
                }
754

    
755
                /**
756
                 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
757
                 */
758
                public void mouseExited(MouseEvent e) {
759
                        try {
760
                                currentMapTool.mouseExited(e);
761
                        } catch (BehaviorException t) {
762
                                throwException(t);
763
                        }
764
                }
765

    
766
                /**
767
                 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
768
                 */
769
                public void mousePressed(MouseEvent e) {
770
                        try {
771
                                currentMapTool.mousePressed(e);
772
                        } catch (BehaviorException t) {
773
                                throwException(t);
774
                        }
775
                }
776

    
777
                /**
778
                 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
779
                 */
780
                public void mouseReleased(MouseEvent e) {
781
                        try {
782
                                currentMapTool.mouseReleased(e);
783
                        } catch (BehaviorException t) {
784
                                throwException(t);
785
                        }
786
                }
787

    
788
                /**
789
                 * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
790
                 */
791
                public void mouseWheelMoved(MouseWheelEvent e) {
792
                        try {
793
                                currentMapTool.mouseWheelMoved(e);
794
                        } catch (BehaviorException t) {
795
                                throwException(t);
796
                        }
797
                }
798

    
799
                /**
800
                 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
801
                 */
802
                public void mouseDragged(MouseEvent e) {
803
                        try {
804
                                currentMapTool.mouseDragged(e);
805
                        } catch (BehaviorException t) {
806
                                throwException(t);
807
                        }
808
                }
809

    
810
                /**
811
                 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
812
                 */
813
                public void mouseMoved(MouseEvent e) {
814
                        try {
815
                                currentMapTool.mouseMoved(e);
816
                        } catch (BehaviorException t) {
817
                                throwException(t);
818
                        }
819
                }
820
        }
821

    
822
        /**
823
         * Listener sobre el MapContext.
824
         *
825
         * @author Fernando Gonz?lez Cort?s
826
         */
827
        public class MapContextListener implements AtomicEventListener {
828
                /**
829
                 * @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
830
                 */
831
                public void atomicEvent(AtomicEvent e) {
832
                        boolean redraw = false;
833
                        LayerEvent[] layerEvents = e.getLayerEvents();
834

    
835
                        for (int i = 0; i < layerEvents.length; i++) {
836
                                if (layerEvents[i].getProperty().equals("visible")) {
837
                                        redraw = true;
838
                                }
839
                        }
840

    
841
                        if (e.getColorEvents().length > 0) {
842
                                redraw = true;
843
                        }
844

    
845
                        if (e.getExtentEvents().length > 0) {
846
                                redraw = true;
847
                        }
848

    
849
                        if (e.getLayerCollectionEvents().length > 0) {
850
                                redraw = true;
851
                        }
852

    
853
                        if (e.getLegendEvents().length > 0) {
854
                                redraw = true;
855
                        }
856

    
857
                        if (e.getSelectionEvents().length > 0) {
858
                                redraw = true;
859
                        }
860

    
861
                        if (redraw) {
862
                System.out.println("MapContextListener redraw");
863
                                MapControl.this.drawMap(false);
864
                        }
865
                }
866
        }
867
        public ViewPort getViewPort() {
868
                return vp;
869
        }
870

    
871
        /**
872
         * Returns a HashMap with the tools that have been registered
873
         * in the Mapcontrol.
874
         */
875
        public HashMap getNamesMapTools() {
876
                return namesMapTools;
877
        }
878

    
879
        public void commandRepaint() {
880
                drawMap(false);
881
        }
882

    
883
        public void commandRefresh() {
884
                // TODO Auto-generated method stub
885
        }
886
}