Statistics
| Revision:

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

History | View | Annotate | Download (22.9 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.layers.LayerEvent;
66
import com.iver.cit.gvsig.fmap.operations.Cancellable;
67
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
68
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior;
69
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
70
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport;
71
import com.iver.utiles.exceptionHandling.ExceptionListener;
72

    
73

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

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

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

    
118
                //Clase usada para cancelar el dibujado
119
                canceldraw = new CancelDraw();
120

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

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

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

    
154
                mapContext = model;
155

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

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

    
165
                mapContext.addAtomicEventListener(mapContextListener);
166

    
167
                status = DESACTUALIZADO;
168
        }
169

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

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

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

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

    
208
        public void addMapTool(String name, Behavior[] tools){
209
                CompoundBehavior tool = new CompoundBehavior(tools);
210
                addMapTool(name, tool);
211
        }
212
        
213
        /**
214
         * DOCUMENT ME!
215
         *
216
         * @param toolName DOCUMENT ME!
217
         */
218
        public void setTool(String toolName) {
219
                Behavior mapTool = (Behavior) namesMapTools.get(toolName);
220
                currentMapTool = mapTool;
221
                currentTool = toolName;
222
                this.setCursor(mapTool.getCursor());
223
        }
224

    
225
        /**
226
         * Devuelve el nombre de la herramienta seleccionada.
227
         *
228
         * @return nombre.
229
         */
230
        public String getTool() {
231
                return currentTool;
232
        }
233

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

    
246
                /* while (!isCancelled) {
247
                        if (!drawer.isAlive()) {
248
                            // Si hemos llegado aqu? con un thread vivo, seguramente
249
                            // no estamos actualizados.
250

251
                                break;
252
                        }
253
                    
254
                }
255
                canceldraw.setCancel(false);
256
                isCancelled = false;
257
        drawerAlive = false; */
258
        }
259
    
260
    private boolean adaptToImageSize()
261
    {
262
        if ((image == null) || (vp.getImageWidth() != this.getWidth()) || (vp.getImageHeight() != this.getHeight()))
263
        {
264
            image = new BufferedImage(this.getWidth(), this.getHeight(),
265
                    BufferedImage.TYPE_INT_ARGB);
266
            vp.setImageSize(new Dimension(getWidth(), getHeight()));
267
            System.out.println("MapControl resized");
268
            // image = null;
269
            vp.setImageSize(new Dimension(getWidth(), getHeight()));
270
            getMapContext().getViewPort().setScale();
271
            
272
            
273
            Graphics gTemp = image.createGraphics();
274
            Color theBackColor = vp.getBackColor();
275
            if (theBackColor == null)
276
                gTemp.setColor(Color.WHITE);
277
            else
278
                gTemp.setColor(theBackColor);
279
            
280
            gTemp.fillRect(0,0,getWidth(), getHeight());
281
            gTemp.dispose();
282
            status = DESACTUALIZADO;
283
            // g.drawImage(image,0,0,null);
284
            return true;
285
        }
286
        return false;
287
    }
288

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

    
303
                        /*
304
                         * Si hay un behaviour y la imagen es distinta de null se delega el dibujado
305
                         * en dicho behaviour
306
                         */
307
            if (image != null)
308
            {
309
                if (currentMapTool != null)
310
                    currentMapTool.paintComponent(g);
311
                else
312
                    g.drawImage(image,0,0,null);
313
                        
314
                                // System.out.println("Pinto ACTUALIZADO");
315
                        }
316
                } else if ((status == DESACTUALIZADO) 
317
                || (status == ONLY_GRAPHICS)) {
318
                        // LWS System.out.println("DESACTUALIZADO: Obteniendo la imagen de la cartograf?a");
319
                        /* if (isOpaque())
320
                        {
321
                            if (image==null)
322
                            {
323
                                g.setColor(vp.getBackColor());
324
                                g.fillRect(0,0,getWidth(), getHeight());                        
325
                            } 
326
                            // else g.drawImage(image,0,0,null);
327
                        } */
328
            // cancelDrawing();
329
                        //Se crea la imagen con el color de fonde deseado
330
                        /* if (image == null)
331
                        {
332
                                image = new BufferedImage(this.getWidth(), this.getHeight(),
333
                                                BufferedImage.TYPE_INT_ARGB);
334
                                vp.setImageSize(new Dimension(getWidth(), getHeight()));
335
                                Graphics gTemp = image.createGraphics();
336
                            Color theBackColor = vp.getBackColor();
337
                            if (theBackColor == null)
338
                                gTemp.setColor(Color.WHITE);
339
                            else
340
                                gTemp.setColor(theBackColor);
341
                                
342
                                gTemp.fillRect(0,0,getWidth(), getHeight());
343
                                gTemp.dispose();
344
                                // g.drawImage(image,0,0,null);
345
                                System.out.println("Imagen con null en DESACTUALIZADO. Width = " + this.getWidth());
346
                        } */
347
            // else
348
            // {
349
            
350
            
351
            // if (image != null)
352
            //  {
353
                g.drawImage(image,0,0,null);
354
                
355
                drawer2.put(new PaintingRequest());
356
                timer.start();
357
            /* }
358
            else
359
                return; */
360
            // }
361
            
362
            /* if (drawerAlive == false)
363
            {
364
                drawer = new Drawer(image, canceldraw);
365
                drawer.start();
366
                        //Se lanza el tread de dibujado                
367
            } */
368
                        
369
                        // status = ACTUALIZADO;
370
                }
371
        }
372

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

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

    
412
        /**
413
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
414
         */
415
        public void componentHidden(ComponentEvent e) {
416
        }
417

    
418
        /**
419
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
420
         */
421
        public void componentMoved(ComponentEvent e) {
422
        }
423

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

    
440
        /**
441
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
442
         */
443
        public void componentShown(ComponentEvent e) {
444
        }
445

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

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

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

    
475
    
476
    private class PaintingRequest
477
    {
478
        
479
        public PaintingRequest()
480
        {
481
        }
482
        
483
        public void paint()
484
        {
485
            try 
486
            {      
487
                canceldraw.setCancel(false);
488
                /* if (image == null)
489
                {
490
                    image = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(),
491
                            BufferedImage.TYPE_INT_ARGB);
492
                    Graphics gTemp = image.createGraphics();
493
                    Color theBackColor = vp.getBackColor();
494
                    if (theBackColor == null)
495
                        gTemp.setColor(Color.WHITE);
496
                    else
497
                        gTemp.setColor(theBackColor);
498
                    
499
                    gTemp.fillRect(0,0,getWidth(), getHeight());
500
                    gTemp.dispose();
501
                    // g.drawImage(image,0,0,null);
502
                    System.out.println("Imagen con null en DESACTUALIZADO. Width = " + this.getWidth());
503
                } */
504
                Graphics2D g = image.createGraphics();
505
                
506
                ViewPort viewPort = mapContext.getViewPort();
507
                
508
                if (status == DESACTUALIZADO)
509
                {
510
                    Color theBackColor = viewPort.getBackColor();
511
                    if (theBackColor == null)
512
                        g.setColor(Color.WHITE);
513
                    else
514
                        g.setColor(theBackColor);
515
                    g.fillRect(0, 0, viewPort.getImageWidth(), viewPort.getImageHeight());
516
                    status = ACTUALIZADO;
517
                    mapContext.draw(image, g, canceldraw, mapContext.getScaleView());
518
                    
519
                }
520
                else if (status == ONLY_GRAPHICS)
521
                {
522
                    status = ACTUALIZADO;   
523
                    mapContext.drawGraphics(image, g, canceldraw,mapContext.getScaleView());
524
                 
525
                }
526
                
527
                
528
                // status = FAST_PAINT;
529
                drawerAlive = false;
530
                timer.stop();
531
                repaint();
532
                
533
                
534
            } catch (Throwable e) {
535
                timer.stop();
536
                isCancelled = true;
537
                e.printStackTrace();
538
                throwException(e);
539
            } finally {
540
            }
541
            
542
        }
543
        
544
    }
545
    
546
    /**
547
     * @author fjp
548
     * 
549
     * Basasdo en el patr?n WorkerThread
550
     *
551
     */
552
    public class Drawer2
553
    {
554
        // Una mini cola de 2. No acumulamos peticiones de dibujado
555
        // dibujamos solo lo ?ltimo que nos han pedido.
556
        private PaintingRequest paintingRequest;
557
        private PaintingRequest waitingRequest;
558
        
559
        private boolean waiting;
560
        private boolean shutdown;
561
        
562
        public void setShutdown(boolean isShutdown)
563
        {
564
            shutdown = isShutdown;
565
        }
566
        
567
        public Drawer2() 
568
        {
569
            paintingRequest = null;
570
            waitingRequest = null;
571
            waiting = false;
572
            shutdown = false;
573
            new Thread(new Worker()).start();
574
        }
575
        
576
        public void put(PaintingRequest newPaintRequest)
577
        {
578
            waitingRequest = newPaintRequest;
579
            if (waiting)
580
            {
581
                synchronized (this) {
582
                    notifyAll();
583
                }
584
            }
585
        }
586
        
587
        public PaintingRequest take()
588
        {
589
            if (waitingRequest == null)
590
            {
591
                synchronized (this) {
592
                    waiting = true;
593
                    try {
594
                        wait();
595
                    }
596
                    catch (InterruptedException ie)
597
                    {
598
                        waiting = false;
599
                    }
600
                }
601
            }
602
            paintingRequest = waitingRequest;
603
            waitingRequest = null;
604
            return paintingRequest;
605
        }
606
        
607
        
608
        private class Worker implements Runnable
609
        {
610
            public void run()
611
            {
612
                while (!shutdown)
613
                {
614
                    PaintingRequest p = take();
615
                    System.out.println("Pintando");
616
                    if (image != null)
617
                        p.paint();
618
                    else
619
                        status = DESACTUALIZADO;
620
                }
621
            }
622
        }
623
    }
624
    
625
        /**
626
         * Clase utilizada para dibujar las capas.
627
         *
628
         * @author Vicente Caballero Navarro
629
         */
630
        public class Drawer extends Thread {
631
                //private Graphics g;
632
                private BufferedImage image = null;
633
                private CancelDraw cancel;
634
                //private boolean threadCancel = false;
635

    
636
                /**
637
                 * Crea un nuevo Drawer.
638
                 *
639
                 */
640
                public Drawer(BufferedImage image, CancelDraw cancel)
641
        {
642
                        this.image = image;
643
                        this.cancel = cancel;
644
            drawerAlive = true;
645
                }
646

    
647
                /**
648
                 * @see java.lang.Runnable#run()
649
                 */
650
                public void run() {
651
                        try {
652
                                // synchronized (Drawer.class) {
653
                                    Graphics2D g = image.createGraphics();
654
                    
655
                                    ViewPort viewPort = mapContext.getViewPort();
656
                    if (status == DESACTUALIZADO)
657
                    {
658
                                        Color theBackColor = viewPort.getBackColor();
659
                                        if (theBackColor == null)
660
                                            g.setColor(Color.WHITE);
661
                                        else
662
                                            g.setColor(theBackColor);
663
                                            g.fillRect(0, 0, viewPort.getImageWidth(), viewPort.getImageHeight());
664
                        status = ACTUALIZADO;
665
                        mapContext.draw(image, g, cancel,mapContext.getScaleView());
666
                    }
667
                    else if (status == ONLY_GRAPHICS)
668
                    {
669
                        status = ACTUALIZADO;
670
                        mapContext.drawGraphics(image, g, cancel,mapContext.getScaleView());
671
                    }
672
                    
673
                                        timer.stop();
674
                    // status = FAST_PAINT;
675
                    drawerAlive = false;
676
                                        repaint();
677
                    
678
                    
679
                                    
680
                                // }
681
                        } catch (Throwable e) {
682
                            timer.stop();
683
                                isCancelled = true;
684
                e.printStackTrace();
685
                                throwException(e);
686
                        } finally {
687
                        }
688
                }
689
        }
690

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

    
699
                /**
700
                 * Crea un nuevo CancelDraw.
701
                 */
702
                public CancelDraw() {
703
                }
704

    
705
                /**
706
                 * Insertar si se debe cancelar el dibujado.
707
                 *
708
                 * @param b true si se debe cancelar el dibujado.
709
                 */
710
                public void setCancel(boolean b) {
711
                        cancel = b;
712
                }
713

    
714
                /**
715
                 * @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
716
                 */
717
                public boolean isCanceled() {
718
                        return cancel;
719
                }
720
        }
721

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

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

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

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

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

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

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

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

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

    
831
                        for (int i = 0; i < layerEvents.length; i++) {
832
                                if (layerEvents[i].getProperty().equals("visible")) {
833
                                        redraw = true;
834
                                }
835
                        }
836

    
837
                        if (e.getColorEvents().length > 0) {
838
                                redraw = true;
839
                        }
840

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

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

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

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

    
857
                        if (redraw) {
858
                System.out.println("MapContextListener redraw");
859
                                MapControl.this.drawMap(true);
860
                        }
861
                }
862
        }
863
        public ViewPort getViewPort() {
864
                return vp;
865
        }
866
        
867
        /**
868
         * Returns a HashMap with the tools that have been registered 
869
         * in the Mapcontrol.
870
         */
871
        public HashMap getNamesMapTools() {
872
                return namesMapTools;
873
        }
874

    
875
}