Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / panels / ZoomControlPanel.java @ 5556

History | View | Annotate | Download (29.8 KB)

1
package org.gvsig.georeferencing.gui.panels;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Cursor;
7
import java.awt.Graphics;
8
import java.awt.Graphics2D;
9
import java.awt.GridBagConstraints;
10
import java.awt.GridBagLayout;
11
import java.awt.Image;
12
import java.awt.Point;
13
import java.awt.Toolkit;
14
import java.awt.event.ActionEvent;
15
import java.awt.event.ActionListener;
16
import java.awt.event.MouseEvent;
17
import java.awt.event.MouseListener;
18
import java.awt.event.MouseMotionListener;
19
import java.awt.geom.Point2D;
20
import java.awt.geom.Rectangle2D;
21
import java.awt.image.BufferedImage;
22

    
23
import javax.swing.ImageIcon;
24
import javax.swing.JButton;
25
import javax.swing.JOptionPane;
26
import javax.swing.JPanel;
27

    
28
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
29
import org.gvsig.georeferencing.utils.MathUtils;
30

    
31
import com.iver.andami.PluginServices;
32
import com.iver.cit.gvsig.fmap.DriverException;
33
import com.iver.cit.gvsig.fmap.ViewPort;
34
import com.iver.cit.gvsig.fmap.layers.FLayer;
35
import com.iver.cit.gvsig.fmap.layers.FLayers;
36
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
37
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
38
import com.iver.cit.gvsig.gui.View;
39
import com.iver.utiles.swing.threads.Cancellable;
40

    
41
/**
42
 * Panel que contiene los controles de zoom de la vista para 
43
 * afinar en la georreferenciaci?n.
44
 * 
45
 * @author Nacho Brodin (brodin_ign@gva.es)
46
 *
47
 */
48
public class ZoomControlPanel extends JPanel implements ActionListener{
49
        
50
        //**********************Vars**********************************
51
        private JPanel                                         pImage = null;
52
        private JPanel                                         pControls = null;
53
        private JButton                                 bZoomMas = null;
54
        private JButton                                 bZoomMenos = null;
55
        private int                                         sX = 140, sY = 140; 
56
        private CanvasZone                                 canvas = null;
57
        private ViewPort                                 viewPort = null;
58
    public FLyrPoints                                 lyrPoints = null;
59
    public FLyrGeoRaster                         lyrGeoRaster = null;
60
    public GeoreferencingDialog         dialog = null;
61
    private boolean                                 rightControl = false;
62
    /**
63
         * Estado de los botones cuando se ejecuta disableAllControls
64
         */
65
        private boolean[]                                 buttonsState = new boolean[2];
66
        /**
67
         * DisableAllControls ha sido ejecutada si est? a true esta variabled
68
         */
69
        private boolean                                 disableAllControls = false;
70
        /**
71
         * Factor multiplicador cuando hacemos zoom mas
72
         */
73
        private double                                        zoomMas = 0.6;
74
        /**
75
         * Factor multiplicador cuando hacemos zoom menos
76
         */
77
        private double                                        zoomMenos = 1.8;
78
        //**********************End Vars******************************
79
    
80
        //**********************Methods*******************************
81
        /**
82
         * This is the default constructor
83
         */
84
        public ZoomControlPanel(boolean rightControl, GeoreferencingDialog dialog) {
85
                super();
86
                this.rightControl = rightControl;
87
                this.dialog = dialog;
88
                initialize(rightControl);
89
        }
90

    
91
        /**
92
         * This method initializes this
93
         * 
94
         * @return void
95
         */
96
        private void initialize(boolean rightControl) {
97
                
98
        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
99
        if(rightControl)
100
                gridBagConstraints1.gridx = 1;
101
        else
102
                gridBagConstraints1.gridx = 0;
103
        gridBagConstraints1.gridy = 0;
104
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
105
        if(rightControl)
106
                gridBagConstraints.gridx = 0;
107
        else
108
                gridBagConstraints.gridx = 1;
109
        gridBagConstraints.gridy = 0;
110
        this.setLayout(new GridBagLayout());
111
        this.setPreferredSize(new java.awt.Dimension(175,142));
112
        this.setSize(new java.awt.Dimension(175,142));
113
        this.setLocation(new java.awt.Point(0,0));
114
        this.add(getPImage(), gridBagConstraints);
115
        this.add(getPControls(), gridBagConstraints1);
116
        //Desactivamos el control en la inicializaci?n
117
        this.setEnabled(false);
118
        }
119

    
120
        /**
121
         * Carga las capas de puntos y de raster georreferenciado
122
         *
123
         */
124
        public void loadLayer() throws InstantiationException{
125
                //Cargamos las capas
126
                this.lyrGeoRaster = dialog.getLyrGeoRaster();
127
                this.lyrPoints = dialog.getLyrPoints();
128
                
129
                if(lyrGeoRaster == null || lyrPoints == null)
130
                        throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada");
131
                
132
        }
133
                
134
        /**
135
         *Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
136
         */
137
        public void draw(){
138
                if(!getDialog().isEnlarge())
139
                        getCanvas().loadBuffer();
140
                canvas.draw = true;
141
                getCanvas().repaint();
142
        }
143
                
144
        /**
145
         * Manejo de los controles zoom m?s y zoom menos
146
         */
147
        public void actionPerformed(ActionEvent e) {
148
                double zoom = zoomMas;
149
                
150
                if(e.getSource() == bZoomMas)
151
                        canvas.calcZoom(zoomMas);
152
                
153
                if(e.getSource() == bZoomMenos){
154
                        canvas.calcZoom(zoomMenos);
155
                        zoom = zoomMenos;
156
                }
157
            
158
                canvas.draw = true;
159
                canvas.repaint();
160
                if(isRightControl())
161
                        lyrPoints.getPoint(dialog.getSelectedPoint()).zoomLeft *= zoom;
162
                else
163
                        lyrPoints.getPoint(dialog.getSelectedPoint()).zoomRight *= zoom;
164
                
165
                lyrPoints.showPoints();
166
        }
167
            
168
    /**
169
     *Limpia el canvas
170
     */
171
    public void clear(){
172
            canvas.setCleanCanvas(true);
173
            canvas.repaint();
174
    }
175
    
176
    /**
177
         * Esta funci?n deshabilita todos los controles y guarda sus valores
178
         * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
179
         * se vuelvan a quedar como estaba
180
         */
181
        public void disableAllControls(){
182
                if(!disableAllControls){
183
                        disableAllControls = true;
184
                        
185
                        //Salvamos los estados
186
                        buttonsState[0] = getBZoomMas().isEnabled();
187
                        buttonsState[1] = getBZoomMenos().isEnabled();
188
                        
189
                        //Desactivamos controles
190
                        getBZoomMas().setEnabled(false);
191
                        getBZoomMenos().setEnabled(false);
192
                }
193
        }
194
        
195
        /**
196
         * Esta funci?n deja los controles como estaban al ejecutar la funci?n 
197
         * disableAllControls
198
         */
199
        public void restoreControlsValue(){
200
                if(disableAllControls){
201
                        disableAllControls = false;
202
                        getBZoomMas().setEnabled(buttonsState[0]);
203
                        getBZoomMenos().setEnabled(buttonsState[1]);
204
                }
205
        }
206
        //**********************End Methods***************************
207
    
208
    //**********************Setters & Getters*********************
209
    /**
210
         * @param viewPort The viewPort to set.
211
         */
212
        public void setViewPort(ViewPort viewPort, double zoom) {
213
                this.viewPort = viewPort;
214
                getCanvas().setViewPort(this.viewPort, zoom);
215
        }
216
        
217
        /**
218
         * This method initializes jPanel        
219
         *         
220
         * @return javax.swing.JPanel        
221
         */
222
        private JPanel getPImage() {
223
                if (pImage == null) {
224
                        pImage = new JPanel();
225
                        BorderLayout borderLayout = new BorderLayout();
226
                        pImage.setLayout(borderLayout);
227
                        pImage.setPreferredSize(new java.awt.Dimension(140,140));
228
                        pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
229
                        pImage.add(getCanvas(), BorderLayout.CENTER);
230
                }
231
                return pImage;
232
        }
233

    
234
        /**
235
         * This method initilizes canvas
236
         * @return        CanvasZone
237
         */
238
        public CanvasZone getCanvas(){
239
                if(canvas == null){
240
                        canvas = new CanvasZone(sX, sY, this);
241
                        canvas.setVisible(false);
242
                        canvas.addMouseListener(canvas);
243
                        canvas.addMouseMotionListener(canvas);
244
                }
245
                return canvas;
246
        }
247
        
248
        /**
249
         * This method initializes jPanel1        
250
         *         
251
         * @return javax.swing.JPanel        
252
         */
253
        private JPanel getPControls() {
254
                if (pControls == null) {
255
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
256
                        gridBagConstraints3.gridx = 0;
257
                        gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0);
258
                        gridBagConstraints3.gridy = 1;
259
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
260
                        gridBagConstraints2.gridx = 0;
261
                        gridBagConstraints2.gridy = 0;
262
                        pControls = new JPanel();
263
                        pControls.setLayout(new GridBagLayout());
264
                        pControls.setPreferredSize(new java.awt.Dimension(33,140));
265
                        pControls.add(getBZoomMas(), gridBagConstraints2);
266
                        pControls.add(getBZoomMenos(), gridBagConstraints3);
267
                }
268
                return pControls;
269
        }
270

    
271
        /**
272
         * This method initializes jButton        
273
         *         
274
         * @return javax.swing.JButton        
275
         */
276
        public JButton getBZoomMas() {
277
                if (bZoomMas == null) {
278
                        bZoomMas = new JButton();
279
                        bZoomMas.setPreferredSize(new java.awt.Dimension(25,25));
280
                        bZoomMas.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/aumentar.png")));
281
                        bZoomMas.addActionListener(this);
282
                }
283
                return bZoomMas;
284
        }
285

    
286
        /**
287
         * This method initializes jButton        
288
         *         
289
         * @return javax.swing.JButton        
290
         */
291
        public JButton getBZoomMenos() {
292
                if (bZoomMenos == null) {
293
                        bZoomMenos = new JButton();
294
                        bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25));
295
                        bZoomMenos.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/disminuir.png")));
296
                        bZoomMenos.addActionListener(this);
297
                }
298
                return bZoomMenos;
299
        }
300
        
301
        /**
302
         * Obtiene true si se trata de un control con los botones de zoom
303
         * a la derecha y false si los tiene a la izquierda.
304
         * @return Returns the rightControl.
305
         */
306
        public boolean isRightControl() {
307
                return rightControl;
308
        }
309
        
310
        /**
311
         * Obtiene la capa de imagen georreferenciada.
312
         * @return Returns the lyrGeoRaster.
313
         */
314
        public FLyrGeoRaster getLyrGeoRaster() {
315
                return lyrGeoRaster;
316
        }
317

    
318
        /**
319
         * Obtiene la capa de puntos.
320
         * @return Returns the lyrPoints.
321
         */
322
        public FLyrPoints getLyrPoints() {
323
                try{
324
                if(lyrPoints == null)
325
                        this.loadLayer();
326
                }catch(InstantiationException e){
327
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
328
                                        PluginServices.getText(this, "error_capa_puntos"));
329
                }
330
                return lyrPoints;
331
        }
332
        
333
        /**
334
         * @return Returns the dialog.
335
         */
336
        public GeoreferencingDialog getDialog() {
337
                try{
338
                        if(dialog == null)
339
                                this.loadLayer();
340
                }catch(InstantiationException e){
341
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
342
                                        PluginServices.getText(this, "error_capa_puntos"));
343
                }
344
                return dialog;
345
        }        
346
        
347
    /**
348
     * Asigna el viewPort recalculado
349
     * @param vp ViewPort
350
     */
351
    public void setNewViewPort(ViewPort vp){
352
            canvas.setNewViewPort(vp);
353
    }
354
    
355
    /**
356
     * Obtiene el viewPort recalculado
357
     * @return vp ViewPort
358
     */
359
    public ViewPort getNewViewPort(){
360
            return canvas.getNewViewPort();
361
    }
362
    
363
        /**
364
         * Asigna al canvas la propiedad de visibilidad a verdadero o falso.
365
         * @param visible true para mostrar el canvas y false para ocultarlo
366
         */
367
        public void setVisible(boolean visible){
368
                canvas.setVisible(visible);
369
                canvas.draw = true;
370
                canvas.repaint();
371
        }
372
        
373
        /**
374
         * Asigna el punto sobre el que se centrar? el zoom de la minimagen
375
         * @param pto
376
         */
377
        public void setCenterPoint(Point2D pto){
378
                getCanvas().setCenterPoint(pto);
379
        }
380
        
381
        /**
382
         * Recupera el n?mero de punto que se est? tratando
383
         * @param n
384
         */
385
        public int getNumberPoint(){
386
                try{
387
                        if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0)
388
                                return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1;
389
                        else
390
                                return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1;
391
                }catch(NullPointerException exc){
392
                        return -1;
393
                }
394
        }
395
        
396
        /**
397
     * Activa o desactiva este panel y todos los que lo componen
398
     * @param enabled variable booleana para la activaci?n y/o desactivaci?n
399
     */
400
    public void setEnabled(boolean enabled){
401
            this.getBZoomMas().setEnabled(enabled);
402
            this.getBZoomMenos().setEnabled(enabled);
403
            this.getCanvas().setEnableEvent(enabled);
404
    }
405
        
406
    /**
407
     * Obtiene el modificador de escala aplicado a zoom m?s
408
     * @return
409
     */
410
    public double getZoomMas() {
411
                return zoomMas;
412
        }
413

    
414
    /**
415
     * Obtiene el modificador de escala aplicado a zoom m?s
416
     * @return
417
     */
418
    public double getZoomMenos() {
419
                return zoomMenos;
420
        }
421
    
422
        //**********************End Setters & Getters*****************
423
        /**
424
         * Control que representa la zona de dibujado de la ventana. Este se encarga de
425
         * repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
426
         * @author Nacho Brodin (brodin_ign@gva.es)
427
         */
428
        public class CanvasZone extends JPanel implements MouseListener, MouseMotionListener{
429
                
430
                //**********************Params********************************
431
                /**
432
                 * Zoom inicial de la miniimagen
433
                 */
434
                private int                                 initZoom = 20;
435
                //**********************End Params****************************
436
                
437
                //**********************Vars**********************************
438
                private ZoomControlPanel         zoomControl = null;
439
            private int                                 ancho;
440
            private int                                 alto;
441
            private FLayers                         flayers = null;
442
            private ViewPort                         newViewPort = null;
443
            private Point2D                         centerPoint = null;
444
            private Image                                 dobleBuffer = null;
445
            private BufferedImage                 imgTmp = null;
446
            private Graphics                         dbGraphics = null;
447
            private boolean                         cleanCanvas = false;
448
            /**
449
             * Cuando el control est? desactivado necesitamos controlar con esta variable que
450
             * aunque se pinche sobre el canvas no se capture el evento 
451
             */            
452
            private boolean                                enableEvent = true;
453
            /**
454
             * Puntos inicial y final para el desplazamiento del punto de control
455
             */
456
            private Point2D                         ptoIni = null, ptoFin = null;
457
            private Point2D                         movDragged = null, initCrux = null;
458
            private boolean                         dragged = false;
459
            private final Image                 redCursor = new ImageIcon(getClass().getClassLoader().getResource(
460
                                                                                                "images/icoRed.png")).getImage();
461
            private final Image                 blueCursor = new ImageIcon(getClass().getClassLoader().getResource(
462
                                                                                                "images/icoBlue.png")).getImage();
463
            /**
464
             * Esta variable se usa para informar cuando debe recargarse el buffer de las miniimagenes. Si siempre
465
             * est? a true no para de llamar al draw de FLyers para que pinte sobre el minicanvas.
466
             */
467
            public boolean                                draw = true;
468
            public boolean                                drawPoint = true;
469
            
470
                //**********************End Vars******************************
471
            
472
            //**********************Classes*******************************
473
            class CancellableClass implements Cancellable{
474
                    private boolean cancel = false;
475
                       public void setCanceled(boolean canceled) {
476
                               this.cancel = canceled;
477
                       }
478
                       
479
                        public boolean isCanceled() {
480
                                return this.cancel;
481
                        }
482
               }
483
            //**********************End Classes***************************
484
            
485
            //**********************Methods*******************************
486
            /**
487
             * 
488
             */
489
            public CanvasZone( int anc,int alt, ZoomControlPanel zc) {
490
                    zoomControl = zc;
491
                ancho = anc;
492
                alto = alt;
493
              
494
                this.setSize(ancho, alto);            
495
                this.setBackground(Color.WHITE);
496
                
497
                imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB);
498
                dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB);
499
                dbGraphics = dobleBuffer.getGraphics();
500
            }
501
                        
502
            /**
503
             * Calcula el zoom dependiendo del factor de escala pasado por
504
             * par?metro.
505
             */
506
            public void calcZoom(double factor){
507
                    Rectangle2D.Double r = new Rectangle2D.Double();
508
                        double nuevoX = centerPoint.getX() -
509
                                ((newViewPort.getExtent().getWidth() * factor) / 2.0);
510
                        double nuevoY = centerPoint.getY() -
511
                                ((newViewPort.getExtent().getHeight() * factor) / 2.0);
512
                        r.x = nuevoX;
513
                        r.y = nuevoY;
514
                        r.width = newViewPort.getExtent().getWidth() * factor;
515
                        r.height = newViewPort.getExtent().getHeight() * factor;
516
                        newViewPort.setExtent(r);
517
                        newViewPort.setScale();
518
                }
519
        
520
            /**
521
             * Calculamos el viewPort para el zoom de la minimagen
522
             * @param vp                ViewPort inicial
523
             * @param center        Centro del ViewPort a calcular.
524
             * @param vpDest        ViewPort de destino. Si este es null se crear? un nuevo ViewPort sino se asignar?n los cambios a este.
525
             * @return
526
             */
527
            public ViewPort initViewPort(ViewPort vp, Point2D center, ViewPort vpDest, double zoom){
528
                    if(center != null){                            
529
                        //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
530
                                double relacionPixelWcWidth =  ((vp.getExtent().getMaxX() - vp.getExtent().getMinX()) / initZoom) / ancho;
531
                                double relacionPixelWcHeight = ((vp.getExtent().getMaxY() - vp.getExtent().getMinY()) / initZoom) / alto;
532
                                
533
                                double wcOriginX = center.getX() - ((vp.getImageWidth() * relacionPixelWcWidth) / 2);
534
                                double wcOriginY = center.getY() - ((vp.getImageHeight() * relacionPixelWcHeight) / 2);
535
                                
536
                                double wcDstMinX = wcOriginX; 
537
                                double wcDstMinY = wcOriginY; 
538
                                double wcDstMaxX = wcDstMinX + (vp.getImageWidth()*relacionPixelWcWidth);
539
                                double wcDstMaxY = wcDstMinY + (vp.getImageHeight()*relacionPixelWcHeight);
540
                                
541
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
542
                                double wcDstHeight = wcDstMaxY - wcDstMinY;
543
                                                                
544
                        Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
545
                        
546
                        if(vpDest == null){
547
                                    newViewPort = vp.cloneViewPort();
548
                                newViewPort.setExtent(ext);
549
                                newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));        
550
                                newViewPort.setScale();
551
                                if(zoom != 1 && zoom != 0)
552
                                        newViewPort = MathUtils.calcZoom(newViewPort, zoom);
553
                                return newViewPort;
554
                            }else{
555
                                    vpDest.setExtent(ext);
556
                                    vpDest.setScale();
557
                                    if(zoom != 1 && zoom != 0)
558
                                        vpDest = MathUtils.calcZoom(vpDest, zoom);
559
                                    return vpDest;
560
                            }
561
                            
562
                    }
563
                    return null;
564
            }
565
            
566
            /**
567
             * Dibuja sobre el graphics de la mini imagen la imagen
568
             * definida en el newViewPort.
569
             */
570
            public void loadBuffer(){                    
571
                    Graphics2D gTmp = (Graphics2D)imgTmp.getGraphics();
572
                    
573
                    dbGraphics.setColor( Color.WHITE );
574
                    dbGraphics.fillRect( 0,0,ancho,alto );
575
                    gTmp.setColor( Color.WHITE );
576
                        gTmp.fillRect( 0,0,ancho,alto );
577
                        
578
                    try{                            
579
                             if(newViewPort != null){                        
580
                                       //Si no tenemos las capas las cargamos
581
                                       if(flayers == null){
582
                                               View  theView = null;
583
                                    try{
584
                                            theView = (View)PluginServices.getMDIManager().getActiveView();
585
                                    }catch(ClassCastException exc){
586
                                            return;
587
                                    }
588
                                         flayers = theView.getMapControl().getMapContext().getLayers();
589
                                }
590
                                        
591
                                /*Dibujamos sobre las miniimagenes
592
                                       Forzamos un draw de las capas para dibujar la vista sobre el control de las miniimagenes.
593
                                       Como la capa gr?fica est? en FMap esta no aparece en el dibujado de FLayers por los que 
594
                                       forzaremos el pintado tambi?n de la capa de puntos sobre nuestro control*/
595
                                                                      
596
                                       Cancellable cancellable = new CancellableClass();
597
                                if(zoomControl.getDialog().isEnlarge()){
598
                                        if(zoomControl.getNumberPoint() != -1){
599
                                                       draw(null, (Graphics2D) dbGraphics, newViewPort,cancellable ,flayers.getFMap().getScaleView());
600
                                                       if(zoomControl.isRightControl())
601
                                                               zoomControl.getLyrPoints().drawPixelCrux((Graphics2D) dbGraphics, newViewPort, cancellable);
602
                                                       else
603
                                                               zoomControl.getLyrPoints().drawMapCrux((Graphics2D) dbGraphics, newViewPort, cancellable);
604
                                        }
605
                                }
606
                                        
607
                                draw(null, gTmp, newViewPort, cancellable, flayers.getFMap().getScaleView());
608
                                    if(zoomControl.isRightControl())
609
                                            zoomControl.getLyrPoints().drawPixelCrux(gTmp, newViewPort, cancellable);
610
                                    else
611
                                               zoomControl.getLyrPoints().drawMapCrux(gTmp, newViewPort, cancellable);
612
                                       
613
                               
614
                               }
615
                     }catch (DriverException e) {
616
                                e.printStackTrace();
617
                     }
618
            }
619
            
620
            /**
621
             * Esta funci?n es una copia de la de Flyers modificada para para dibujar sobre las miniimagenes. En
622
             * la miniimagen con los controles a la derecha solo dibujar? el raster a georreferenciar. En la miniimagen
623
             * con los controles a la izquierda dibujar? la cartograf?a de base.
624
             * @param image 
625
             * @param g
626
             * @param viewPort
627
             * @param cancel
628
             * @param scale
629
             * @throws DriverException
630
             */
631
            public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
632
                            Cancellable cancel,double scale) throws DriverException {                    
633
                    for(int i=0;i<flayers.getLayersCount();i++){
634
                            if (cancel.isCanceled())
635
                                    break; 
636
                            FLayer lyr = flayers.getLayer(i);
637
                            
638
                                    try{
639
                                            if(zoomControl.isRightControl()){
640
                                                    if(lyr instanceof FLyrGeoRaster)
641
                                                            lyr.draw(image, g, viewPort, cancel,scale);
642
                                            }else{
643
                                                    if (lyr.isVisible()){
644
                                                            if(!(lyr instanceof FLyrGeoRaster))
645
                                                                    lyr.draw(image, g, viewPort, cancel,scale);
646
                                                    }
647
                                            }
648
                                            
649
                                    } catch (DriverException e){
650
                                    }
651
                    }
652
            }
653
            
654
            /**
655
             * 
656
             */
657
            public void update(Graphics g){
658
                    draw = true;
659
                    this.paint(g);
660
            }
661
            
662
            /**
663
             * Dibuja sobre el Graphics2D pasado el viewPort solicitado a
664
             * la lista de capas.
665
             * @param g
666
             */
667
            public void paint( Graphics g ) {
668
                    if(!cleanCanvas){
669
                            if(draw){
670
                                    loadBuffer();
671
                                    draw = false;
672
                            }
673
                            g.drawImage(dobleBuffer, 0, 0, null);
674
                            this.invalidate();
675
                            AdjustGeorefPanel p = zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel();
676
                            try{
677
                                    if(!this.zoomControl.isRightControl())
678
                                            p.setLZoomLeft("1:"+((int)newViewPort.getScale()));
679
                                    else
680
                                            p.setLZoomRight("1:"+((int)newViewPort.getScale()));
681
                            }catch(NullPointerException exc){
682
                                    //No ponemos la escala
683
                            }
684
                    }else{
685
                            dbGraphics.setColor( Color.WHITE );
686
                            dbGraphics.fillRect( 0,0,ancho,alto );
687
                            g.setColor( Color.WHITE );
688
                            g.fillRect( 0,0,ancho,alto );
689
                            cleanCanvas = false;
690
                    }
691
            }
692
                        
693
            /**
694
             * Desplaza el extent al nuevo centro 
695
             * @param pto
696
             */
697
            public void shiftExtent(Point2D pto){
698
                    this.setCenterPoint(pto);
699
                    this.calcZoom(1);
700
            }
701
            
702
                /* (non-Javadoc)
703
                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
704
                 */
705
                public void mouseClicked(MouseEvent ev) {
706
                        
707
                }
708
                
709
                /**
710
                 * Cuando el rat?n entra dentro del control fijamos el valor de las coordenadas
711
                 * que tiene el punto seleccionado. De esta forma cuando salga del control podr?
712
                 * volver a restaurarlo en caso de que no haya sido cambiado.
713
                 */
714
                public void mouseEntered(MouseEvent arg0) {
715
                        if(isEnableEvent()){
716
                                if(!zoomControl.rightControl)
717
                                        zoomControl.getDialog().getPointManager().setCurrentWC();
718
                                else
719
                                        zoomControl.getDialog().getPointManager().setCurrentPixelCoord();
720
                        }
721
                }
722
                
723
                /**
724
                 * Al sacar el rat?n de la zona de dibujado de la miniimagen restauramos los valores
725
                 * de los JTextField. 
726
                 * 
727
                 * Se actualizaran los correspondientes a las coordenadas del mundo real 
728
                 * en el caso de que el control tenga botones a la izquierda.
729
                 * 
730
                 * Se actualizaran los correspondientes a las coordenadas en pixels cuando se trata del control con
731
                 * botones a la derecha.
732
                 */
733
                public void mouseExited(MouseEvent arg0) {
734
                        if(isEnableEvent()){
735
                                if(!zoomControl.rightControl)
736
                                        zoomControl.getDialog().getPointManager().replaceWC();
737
                                else
738
                                        zoomControl.getDialog().getPointManager().replacePixelCoord();
739
                        }
740
                }
741
                
742
                /**
743
                 * Controla la actualizaci?n del valor de un punto en los JTextDialog. Cuando se mueve sobre
744
                 * el panel con controles a la izquierda actualizamos las coordenadas del mapa. Cuando se mueve sobre
745
                 * el panel con controles a la derecha actualizamos las coordenadas de la imagen.  
746
                 */
747
                public void mouseMoved(MouseEvent arg0) {
748
                        if(        isEnableEvent() && 
749
                                zoomControl.getLyrPoints() != null &&
750
                                zoomControl.getLyrPoints().getCountPoints() > 0 &&
751
                                this.newViewPort != null &&
752
                                this.newViewPort.getExtent() != null){
753
                                
754
                                double newWCPointX = this.newViewPort.getExtent().getMinX() + ((arg0.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth());
755
                                int ptoSelectY = (int)(this.getHeight() - arg0.getY());
756
                                double newWCPointY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight());
757
                                if(!zoomControl.rightControl){
758
                                        zoomControl.getDialog().getPointManager().setTempWC(newWCPointX, newWCPointY);
759
                                }else{
760
                                        Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
761
                                        if(pixelImg != null)
762
                                                zoomControl.getDialog().getPointManager().setTempPixelCoord(pixelImg.getX(), pixelImg.getY());
763
                                        else 
764
                                                //Si pixelImg es null es que nos hemos salido de la imagen por lo que reponemos los valores originales hasta que vuelva a entrar.
765
                                                zoomControl.getDialog().getPointManager().replacePixelCoord();        
766
                                        
767
                                }
768
                        }
769
                }
770
                
771
                /**
772
                 * Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
773
                 *
774
                 */
775
                public void mousePressed(MouseEvent ev) {
776
                        int cte = 10;
777
                        if( (ev.getX() > ((getWidth() >> 1) - cte)) && (ev.getX() < ((getWidth() >> 1) + cte)) &&
778
                                (ev.getY() > ((getHeight() >> 1) - cte)) && (ev.getY() < ((getHeight() >> 1) + cte))){
779
                                this.dragged = true;
780
                                this.movDragged = ptoIni = ev.getPoint();
781
                                try{
782
                                        if(zoomControl.isRightControl())
783
                                                setCursor(Toolkit.getDefaultToolkit().createCustomCursor(redCursor, new Point(16, 16), ""));
784
                                        else
785
                                                setCursor(Toolkit.getDefaultToolkit().createCustomCursor(blueCursor, new Point(16, 16), ""));
786
                                        
787
                                        zoomControl.loadLayer();
788
                                        initCrux = new Point2D.Double();
789
                                        initCrux.setLocation(this.getWidth() / 2, this.getHeight() / 2);
790
                                    draw = true;
791
                                        repaint();
792
                                }catch(InstantiationException e){
793
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
794
                                                        PluginServices.getText(this, "error_capa_puntos"));
795
                                }
796
                        }
797
                }
798

    
799
                /* (non-Javadoc)
800
                 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
801
                 */
802
                public void mouseReleased(MouseEvent ev) {
803
                        if(!dragged)
804
                                return;
805
                        dragged = false;
806
                        View  theView = null;
807
                        try{
808
                                theView = (View) PluginServices.getMDIManager().getActiveView();
809
                        }catch(ClassCastException exc){
810
                                return;
811
                        }
812
                        ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
813
                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
814
                        
815
                        ptoFin = ev.getPoint();
816

    
817
                        Point2D point = newViewPort.toMapPoint(ev.getX(), ev.getY());                        
818
                        int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
819

    
820
                        FLyrPoints lp = zoomControl.getLyrPoints();//(FLyrPoints)lyr;
821
                                 
822
                if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen
823
                        Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(point);
824
                        //Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
825
                        
826
                        if(pixelImg == null){
827
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
828
                                                                     PluginServices.getText(this, "fuera_de_extent"));
829
                                     return;
830
                             }
831
                        zoomControl.getDialog().getPointManager().updateData(        nPoint,
832
                                                                                                                                         pixelImg,
833
                                                                                                                                         null, 
834
                                                                                                                                         zoomControl.getDialog(),
835
                                                                                                                                         null);
836

    
837
                        //Actualizamos la otra miniimagen
838
                        shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg));
839
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
840
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
841
                        zoomControl.getDialog().getPointManager().setCurrentPixelCoord();
842
                }else{ //Control de actualizaci?n de coordenadas del mundo
843
                                Point2D mapPoint = new Point2D.Double();
844
                                mapPoint.setLocation(point);
845
                                zoomControl.getDialog().getPointManager().updateData(        nPoint,
846
                                                                                                                                                        null, 
847
                                                                                                                                                        mapPoint,
848
                                                                                                                                                        zoomControl.getDialog(),
849
                                                                                                                                                        null);
850
                                          
851
                                //Actualizamos la otra miniimagen
852
                                shiftExtent(mapPoint);
853
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
854
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
855
                                zoomControl.getDialog().getPointManager().setCurrentWC();
856
                 }
857
                    draw = true;
858
                        repaint();
859
                        theView.getMapControl().getMapContext().invalidate();
860
                }
861
                
862
                /* (non-Javadoc)
863
                 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
864
                 */
865
                public void mouseDragged(MouseEvent ev) {
866
                        this.mouseMoved(ev);
867
                }
868
            //**********************End Methods***************************
869

    
870
                //**********************Setters & Getters*********************
871
                /**
872
                 * @param cleanCanvas The cleanCanvas to set.
873
                 */
874
                public void setCleanCanvas(boolean cleanCanvas) {
875
                        this.cleanCanvas = cleanCanvas;
876
                }
877
                
878
                 /**
879
             * Asigna el punto donde se centrar? la vista de la minimagen
880
             * @param pto Punto central.
881
             */
882
            public void setCenterPoint(Point2D pto){
883
                    this.centerPoint = pto;
884
            }
885
            
886
            /**
887
             * Asigna el viewPort
888
             * @param vp ViewPort
889
             */
890
            public void setViewPort(ViewPort vp, double zoom){
891
                    this.initViewPort(vp, this.centerPoint, null, zoom);
892
            }
893

    
894
            /**
895
             * Asigna el viewPort recalculado
896
             * @param vp ViewPort
897
             */
898
            public void setNewViewPort(ViewPort vp){
899
                    this.newViewPort = vp;
900
            }
901
            
902
            /**
903
             * Obtiene el viewPort recalculado
904
             * @return vp ViewPort
905
             */
906
            public ViewPort getNewViewPort(){
907
                    return this.newViewPort;
908
            }
909
            
910
            /**
911
             * Obtiene el valor del desactivador de eventos sobre el canvas.
912
             * @return
913
             */
914
            public boolean isEnableEvent() {
915
                        return enableEvent;
916
                }
917

    
918
            /**
919
             * Asigna el desactivador de eventos sobre el canvas
920
             * @param enableEvent
921
             */
922
                public void setEnableEvent(boolean enableEvent) {
923
                        this.enableEvent = enableEvent;
924
                }
925
                
926
                //**********************End Setters & Getters*****************
927
                
928
        }
929
 }