Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / panels / ZoomControlPanel.java @ 4745

History | View | Annotate | Download (27.7 KB)

1
package com.iver.cit.gvsig.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 com.iver.andami.PluginServices;
29
import com.iver.cit.gvsig.fmap.DriverException;
30
import com.iver.cit.gvsig.fmap.MapControl;
31
import com.iver.cit.gvsig.fmap.ViewPort;
32
import com.iver.cit.gvsig.fmap.layers.FLayers;
33
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
34
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
35
import com.iver.cit.gvsig.fmap.operations.Cancellable;
36
import com.iver.cit.gvsig.gui.View;
37
import com.iver.cit.gvsig.gui.dialogs.GeoreferencingDialog;
38

    
39
/**
40
 * Panel que contiene los controles de zoom de la vista para 
41
 * afinar en la georreferenciaci?n.
42
 * 
43
 * @author Nacho Brodin (brodin_ign@gva.es)
44
 *
45
 */
46
public class ZoomControlPanel extends JPanel implements ActionListener{
47
        
48
        //**********************Vars**********************************
49
        private JPanel                                         pImage = null;
50
        private JPanel                                         pControls = null;
51
        private JButton                                 bZoomMas = null;
52
        private JButton                                 bZoomMenos = null;
53
        private int                                         sX = 140, sY = 140; 
54
        private CanvasZone                                 canvas = null;
55
        private ViewPort                                 viewPort = null;
56
    public FLyrPoints                                 lyrPoints = null;
57
    public FLyrGeoRaster                         lyrGeoRaster = null;
58
    public GeoreferencingDialog         dialog = null;
59
    private boolean                                 rightControl = false;
60
        //**********************End Vars******************************
61
    
62
        //**********************Methods*******************************
63
        /**
64
         * This is the default constructor
65
         */
66
        public ZoomControlPanel(boolean rightControl, GeoreferencingDialog dialog) {
67
                super();
68
                this.rightControl = rightControl;
69
                this.dialog = dialog;
70
                initialize(rightControl);
71
        }
72

    
73
        /**
74
         * This method initializes this
75
         * 
76
         * @return void
77
         */
78
        private void initialize(boolean rightControl) {
79
                
80
        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
81
        if(rightControl)
82
                gridBagConstraints1.gridx = 1;
83
        else
84
                gridBagConstraints1.gridx = 0;
85
        gridBagConstraints1.gridy = 0;
86
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
87
        if(rightControl)
88
                gridBagConstraints.gridx = 0;
89
        else
90
                gridBagConstraints.gridx = 1;
91
        gridBagConstraints.gridy = 0;
92
        this.setLayout(new GridBagLayout());
93
        this.setPreferredSize(new java.awt.Dimension(175,142));
94
        this.setSize(new java.awt.Dimension(175,142));
95
        this.setLocation(new java.awt.Point(0,0));
96
        this.add(getPImage(), gridBagConstraints);
97
        this.add(getPControls(), gridBagConstraints1);
98
        //Desactivamos el control en la inicializaci?n
99
        this.setEnabled(false);
100
        }
101

    
102
        /**
103
         * Carga las capas de puntos y de raster georreferenciado
104
         *
105
         */
106
        public void loadLayer() throws InstantiationException{
107
                //Cargamos las capas
108
                this.lyrGeoRaster = dialog.getLyrGeoRaster();
109
                this.lyrPoints = dialog.getLyrPoints();
110
                
111
                if(lyrGeoRaster == null || lyrPoints == null)
112
                        throw new InstantiationException("No se ha podido instanciar la capa de puntos o georreferenciada");
113
                
114
        }
115
                
116
        /**
117
         *Llama a la funci?n de pintado del canvas con los par?metros que tenga en ese momento
118
         */
119
        public void draw(){
120
                if(!getDialog().isEnlarge())
121
                        getCanvas().loadBuffer();
122
                getCanvas().repaint();
123
        }
124
                
125
        /**
126
         * Manejo de los controles zoom m?s y zoom menos
127
         */
128
        public void actionPerformed(ActionEvent e) {
129
                if(e.getSource() == bZoomMas){
130
                        canvas.calcZoom(0.6);
131
                        canvas.repaint();
132
                }
133
                
134
                if(e.getSource() == bZoomMenos){
135
                        canvas.calcZoom(1.8);
136
                        canvas.repaint();
137
                }
138
                
139
        }
140
            
141
    /**
142
     *Limpia el canvas
143
     */
144
    public void clear(){
145
            canvas.setCleanCanvas(true);
146
            canvas.repaint();
147
    }
148
        //**********************End Methods***************************
149
    
150
    //**********************Setters & Getters*********************
151
    /**
152
         * @param viewPort The viewPort to set.
153
         */
154
        public void setViewPort(ViewPort viewPort) {
155
                this.viewPort = viewPort;
156
                getCanvas().setViewPort(this.viewPort);
157
        }
158
        
159
        /**
160
         * This method initializes jPanel        
161
         *         
162
         * @return javax.swing.JPanel        
163
         */
164
        private JPanel getPImage() {
165
                if (pImage == null) {
166
                        pImage = new JPanel();
167
                        BorderLayout borderLayout = new BorderLayout();
168
                        pImage.setLayout(borderLayout);
169
                        pImage.setPreferredSize(new java.awt.Dimension(140,140));
170
                        pImage.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
171
                        pImage.add(getCanvas(), BorderLayout.CENTER);
172
                }
173
                return pImage;
174
        }
175

    
176
        /**
177
         * This method initilizes canvas
178
         * @return        CanvasZone
179
         */
180
        public CanvasZone getCanvas(){
181
                if(canvas == null){
182
                        canvas = new CanvasZone(sX, sY, this);
183
                        canvas.setVisible(false);
184
                        canvas.addMouseListener(canvas);
185
                        canvas.addMouseMotionListener(canvas);
186
                }
187
                return canvas;
188
        }
189
        
190
        /**
191
         * This method initializes jPanel1        
192
         *         
193
         * @return javax.swing.JPanel        
194
         */
195
        private JPanel getPControls() {
196
                if (pControls == null) {
197
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
198
                        gridBagConstraints3.gridx = 0;
199
                        gridBagConstraints3.insets = new java.awt.Insets(5,0,0,0);
200
                        gridBagConstraints3.gridy = 1;
201
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
202
                        gridBagConstraints2.gridx = 0;
203
                        gridBagConstraints2.gridy = 0;
204
                        pControls = new JPanel();
205
                        pControls.setLayout(new GridBagLayout());
206
                        pControls.setPreferredSize(new java.awt.Dimension(33,140));
207
                        pControls.add(getBZoomMas(), gridBagConstraints2);
208
                        pControls.add(getBZoomMenos(), gridBagConstraints3);
209
                }
210
                return pControls;
211
        }
212

    
213
        /**
214
         * This method initializes jButton        
215
         *         
216
         * @return javax.swing.JButton        
217
         */
218
        private JButton getBZoomMas() {
219
                if (bZoomMas == null) {
220
                        bZoomMas = new JButton();
221
                        bZoomMas.setPreferredSize(new java.awt.Dimension(25,25));
222
                        bZoomMas.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/panels/images/aumentar.png")));
223
                        bZoomMas.addActionListener(this);
224
                }
225
                return bZoomMas;
226
        }
227

    
228
        /**
229
         * This method initializes jButton        
230
         *         
231
         * @return javax.swing.JButton        
232
         */
233
        private JButton getBZoomMenos() {
234
                if (bZoomMenos == null) {
235
                        bZoomMenos = new JButton();
236
                        bZoomMenos.setPreferredSize(new java.awt.Dimension(25,25));
237
                        bZoomMenos.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/panels/images/disminuir.png")));
238
                        bZoomMenos.addActionListener(this);
239
                }
240
                return bZoomMenos;
241
        }
242
        
243
        /**
244
         * Obtiene true si se trata de un control con los botones de zoom
245
         * a la derecha y false si los tiene a la izquierda.
246
         * @return Returns the rightControl.
247
         */
248
        public boolean isRightControl() {
249
                return rightControl;
250
        }
251
        
252
        /**
253
         * Obtiene la capa de imagen georreferenciada.
254
         * @return Returns the lyrGeoRaster.
255
         */
256
        public FLyrGeoRaster getLyrGeoRaster() {
257
                return lyrGeoRaster;
258
        }
259

    
260
        /**
261
         * Obtiene la capa de puntos.
262
         * @return Returns the lyrPoints.
263
         */
264
        public FLyrPoints getLyrPoints() {
265
                try{
266
                if(lyrPoints == null)
267
                        this.loadLayer();
268
                }catch(InstantiationException e){
269
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
270
                                        PluginServices.getText(this, "error_capa_puntos"));
271
                }
272
                return lyrPoints;
273
        }
274
        
275
        /**
276
         * @return Returns the dialog.
277
         */
278
        public GeoreferencingDialog getDialog() {
279
                try{
280
                        if(dialog == null)
281
                                this.loadLayer();
282
                }catch(InstantiationException e){
283
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
284
                                        PluginServices.getText(this, "error_capa_puntos"));
285
                }
286
                return dialog;
287
        }        
288
        
289
    /**
290
     * Asigna el viewPort recalculado
291
     * @param vp ViewPort
292
     */
293
    public void setNewViewPort(ViewPort vp){
294
            canvas.setNewViewPort(vp);
295
    }
296
    
297
        /**
298
         * Asigna al canvas la propiedad de visibilidad a verdadero o falso.
299
         * @param visible true para mostrar el canvas y false para ocultarlo
300
         */
301
        public void setVisible(boolean visible){
302
                canvas.setVisible(visible);
303
                canvas.repaint();
304
        }
305
        
306
        /**
307
         * Asigna el punto sobre el que se centrar? el zoom de la minimagen
308
         * @param pto
309
         */
310
        public void setCenterPoint(Point2D pto){
311
                getCanvas().setCenterPoint(pto);
312
        }
313
        
314
        /**
315
         * Recupera el n?mero de punto que se est? tratando
316
         * @param n
317
         */
318
        public int getNumberPoint(){
319
                try{
320
                        if(getDialog().getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 0)
321
                                return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1;
322
                        else
323
                                return Integer.valueOf(getDialog().getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue() - 1;
324
                }catch(NullPointerException exc){
325
                        return -1;
326
                }
327
        }
328
        
329
        /**
330
     * Activa o desactiva este panel y todos los que lo componen
331
     * @param enabled variable booleana para la activaci?n y/o desactivaci?n
332
     */
333
    public void setEnabled(boolean enabled){
334
            this.getBZoomMas().setEnabled(enabled);
335
            this.getBZoomMenos().setEnabled(enabled);
336
            this.getCanvas().setEnableEvent(enabled);
337
    }
338
        
339
        //**********************End Setters & Getters*****************
340
        /**
341
         * Control que representa la zona de dibujado de la ventana. Este se encarga de
342
         * repintar el contenido sobre el Graphics2D a partir del viewPort que se le pase
343
         * @author Nacho Brodin (brodin_ign@gva.es)
344
         */
345
        public class CanvasZone extends JPanel implements MouseListener, MouseMotionListener{
346
                
347
                //**********************Params********************************
348
                /**
349
                 * Zoom inicial de la miniimagen
350
                 */
351
                private int                                 initZoom = 20;
352
                //**********************End Params****************************
353
                
354
                //**********************Vars**********************************
355
                private ZoomControlPanel         zoomControl = null;
356
            private int                                 ancho;
357
            private int                                 alto;
358
            private FLayers                         flayers = null;
359
            private ViewPort                         newViewPort = null;
360
            private Point2D                         centerPoint = null;
361
            private Image                                 dobleBuffer = null;
362
            private BufferedImage                 imgTmp = null;
363
            private Graphics                         dbGraphics = null;
364
            private boolean                         cleanCanvas = false;
365
            /**
366
             * Cuando el control est? desactivado necesitamos controlar con esta variable que
367
             * aunque se pinche sobre el canvas no se capture el evento 
368
             */            
369
            private boolean                                enableEvent = true;
370
            /**
371
             * Puntos inicial y final para el desplazamiento del punto de control
372
             */
373
            private Point2D ptoIni = null, ptoFin = null;
374
            private Point2D movDragged = null, initCrux = null;
375
            private final Image redCursor = new ImageIcon(this.getClass().getResource(
376
                                                                                                "images/CircleCursor.png")).getImage();
377
            private final Image blueCursor = new ImageIcon(this.getClass().getResource(
378
                                                                                                "images/RectangleCursor.png")).getImage();
379
                //**********************End Vars******************************
380
            
381
            //**********************Methods*******************************
382
            /**
383
             * 
384
             */
385
            public CanvasZone( int anc,int alt, ZoomControlPanel zc) {
386
                    zoomControl = zc;
387
                ancho = anc;
388
                alto = alt;
389
              
390
                this.setSize(ancho, alto);            
391
                this.setBackground(Color.WHITE);
392
                
393
                imgTmp = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB);
394
                dobleBuffer = new BufferedImage(this.ancho, this.alto, BufferedImage.TYPE_INT_ARGB);
395
                dbGraphics = dobleBuffer.getGraphics();
396
            }
397
                        
398
            /**
399
             * Calcula el zoom dependiendo del factor de escala pasado por
400
             * par?metro.
401
             */
402
            public void calcZoom(double factor){
403
                    Rectangle2D.Double r = new Rectangle2D.Double();
404
                        double nuevoX = centerPoint.getX() -
405
                                ((newViewPort.getExtent().getWidth() * factor) / 2.0);
406
                        double nuevoY = centerPoint.getY() -
407
                                ((newViewPort.getExtent().getHeight() * factor) / 2.0);
408
                        r.x = nuevoX;
409
                        r.y = nuevoY;
410
                        r.width = newViewPort.getExtent().getWidth() * factor;
411
                        r.height = newViewPort.getExtent().getHeight() * factor;
412
                        newViewPort.setExtent(r);
413
                        newViewPort.setScale();
414
                }
415
        
416
            
417
            /**
418
             *Calculamos el viewPort para el zoom de la minimagen
419
             */
420
            public ViewPort initViewPort(ViewPort vp, Point2D center, ViewPort vpDest){
421
                    if(center != null){
422
                                                        
423
                        //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
424
                                double relacionPixelWcWidth =  ((vp.getExtent().getMaxX() - vp.getExtent().getMinX()) / initZoom) / ancho;
425
                                double relacionPixelWcHeight = ((vp.getExtent().getMaxY() - vp.getExtent().getMinY()) / initZoom) / alto;
426
                                
427
                                double wcOriginX = center.getX() - ((vp.getImageWidth() * relacionPixelWcWidth) / 2);
428
                                double wcOriginY = center.getY() - ((vp.getImageHeight() * relacionPixelWcHeight) / 2);
429
                                
430
                                double wcDstMinX = wcOriginX; 
431
                                double wcDstMinY = wcOriginY; 
432
                                double wcDstMaxX = wcDstMinX + (vp.getImageWidth()*relacionPixelWcWidth);
433
                                double wcDstMaxY = wcDstMinY + (vp.getImageHeight()*relacionPixelWcHeight);
434
                                
435
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
436
                                double wcDstHeight = wcDstMaxY - wcDstMinY;
437
                                                                
438
                        Rectangle2D ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
439
                        
440
                        if(vpDest == null){
441
                                    newViewPort = vp.cloneViewPort();
442
                                newViewPort.setExtent(ext);
443
                                newViewPort.setImageSize(new java.awt.Dimension(ancho, alto));        
444
                                newViewPort.setScale();
445
                                return newViewPort;
446
                            }else{
447
                                    vpDest.setExtent(ext);
448
                                    vpDest.setScale();
449
                                    return vpDest;
450
                            }
451
                            
452
                    }
453
                    return null;
454
            }
455
            
456
            /**
457
             * Dibuja sobre el graphics de la mini imagen la imagen
458
             * definida en el newViewPort.
459
             */
460
            public void loadBuffer(){                    
461
                    Graphics2D gTmp = (Graphics2D)imgTmp.getGraphics();
462
                    
463
                    
464
                    dbGraphics.setColor( Color.WHITE );
465
                    dbGraphics.fillRect( 0,0,ancho,alto );
466
                    gTmp.setColor( Color.WHITE );
467
                        gTmp.fillRect( 0,0,ancho,alto );
468
                        
469
                    try{                            
470
                             if(newViewPort != null){
471
                                       if(zoomControl.getNumberPoint() != -1){//Salvamos el miniextent si hay puntos en la lista
472
                                        if(!zoomControl.isRightControl())
473
                                                zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), 
474
                                                                                                                                centerPoint,
475
                                                                                                                                        newViewPort, 
476
                                                                                                                                        true);
477
                                        else
478
                                                zoomControl.getLyrPoints().setMiniExtent(zoomControl.getNumberPoint(), 
479
                                                                                                                                        centerPoint,
480
                                                                                                                                        newViewPort, 
481
                                                                                                                                        false);
482
                                }                                                
483
                                       //Si no tenemos las capas las cargamos
484
                                       if(flayers == null){
485
                                               View  theView = null;
486
                                    try{
487
                                            theView = (View)PluginServices.getMDIManager().getActiveView();
488
                                    }catch(ClassCastException exc){
489
                                            return;
490
                                    }
491
                                         flayers = theView.getMapControl().getMapContext().getLayers();
492
                                }
493
                                        
494
                                /*Dibujamos sobre las miniimagenes
495
                                       Forzamos un draw de las capas para dibujar la vista sobre el control de las miniimagenes.
496
                                       Como la capa gr?fica est? en FMap esta no aparece en el dibujado de FLayers por los que 
497
                                       forzaremos el pintado tambi?n de la capa de puntos sobre nuestro control*/
498
                                       
499
                                if(zoomControl.getDialog().isEnlarge()){
500
                                        if(zoomControl.getNumberPoint() != -1){
501
                                                       flayers.draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() {
502
                                                               public boolean isCanceled() {
503
                                                                        return false;
504
                                                                }
505
                                                       },flayers.getFMap().getScaleView());
506
                                                       zoomControl.getLyrPoints().draw(null, (Graphics2D) dbGraphics, newViewPort,new Cancellable() {
507
                                                               public boolean isCanceled() {
508
                                                                        return false;
509
                                                                }
510
                                                       },flayers.getFMap().getScaleView());
511
                                        }
512
                                }
513
                                        
514
                                flayers.draw(null, gTmp, newViewPort,new Cancellable() {
515
                                        public boolean isCanceled() {
516
                                                        return false;
517
                                                }
518
                                },flayers.getFMap().getScaleView());
519
                                    zoomControl.getLyrPoints().draw(null, gTmp, newViewPort,new Cancellable() {
520
                                               public boolean isCanceled() {
521
                                                        return false;
522
                                                }
523
                                       },flayers.getFMap().getScaleView());
524
                              
525
                               }
526
                     }catch (DriverException e) {
527
                                e.printStackTrace();
528
                     }
529
            }
530
            
531
            /**
532
             * 
533
             */
534
            public void update(Graphics g){
535
                    this.paint(g);
536
            }
537
            
538
            /**
539
             * Dibuja sobre el Graphics2D pasado el viewPort solicitado a
540
             * la lista de capas.
541
             * @param g
542
             */
543
            public void paint( Graphics g ) {
544
                    if(!cleanCanvas){
545
                            loadBuffer();
546
                            g.drawImage(dobleBuffer, 0, 0, null);
547
                    }else{
548
                            g.setColor( Color.WHITE );
549
                            g.fillRect( 0,0,ancho,alto );
550
                            cleanCanvas = false;
551
                    }
552
            }
553
                        
554
            /**
555
             * Desplaza el extent al nuevo centro 
556
             * @param pto
557
             */
558
            public void shiftExtent(Point2D pto){
559
                    this.setCenterPoint(pto);
560
                    this.calcZoom(1);
561
            }
562
            
563
                /* (non-Javadoc)
564
                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
565
                 */
566
                public void mouseClicked(MouseEvent ev) {
567
                        
568
                }
569
                
570
                /**
571
                 * Cuando el rat?n entra dentro del control fijamos el valor de las coordenadas
572
                 * que tiene el punto seleccionado. De esta forma cuando salga del control podr?
573
                 * volver a restaurarlo en caso de que no haya sido cambiado.
574
                 */
575
                public void mouseEntered(MouseEvent arg0) {
576
                        if(isEnableEvent()){
577
                                if(!zoomControl.rightControl)
578
                                        zoomControl.getDialog().getPointManager().setCurrentWC();
579
                                else
580
                                        zoomControl.getDialog().getPointManager().setCurrentPixelCoord();
581
                        }
582
                }
583
                
584
                /**
585
                 * Al sacar el rat?n de la zona de dibujado de la miniimagen restauramos los valores
586
                 * de los JTextField. 
587
                 * 
588
                 * Se actualizaran los correspondientes a las coordenadas del mundo real 
589
                 * en el caso de que el control tenga botones a la izquierda.
590
                 * 
591
                 * Se actualizaran los correspondientes a las coordenadas en pixels cuando se trata del control con
592
                 * botones a la derecha.
593
                 */
594
                public void mouseExited(MouseEvent arg0) {
595
                        if(isEnableEvent()){
596
                                if(!zoomControl.rightControl)
597
                                        zoomControl.getDialog().getPointManager().replaceWC();
598
                                else
599
                                        zoomControl.getDialog().getPointManager().replacePixelCoord();
600
                        }
601
                }
602
                
603
                /**
604
                 * Controla la actualizaci?n del valor de un punto en los JTextDialog. Cuando se mueve sobre
605
                 * el panel con controles a la izquierda actualizamos las coordenadas del mapa. Cuando se mueve sobre
606
                 * el panel con controles a la derecha actualizamos las coordenadas de la imagen.  
607
                 */
608
                public void mouseMoved(MouseEvent arg0) {
609
                        if(isEnableEvent()){
610
                                double newWCPointX = this.newViewPort.getExtent().getMinX() + ((arg0.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth());
611
                                int ptoSelectY = (int)(this.getHeight() - arg0.getY());
612
                                double newWCPointY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight());
613
                                if(!zoomControl.rightControl){
614
                                        System.out.println("--->"+newWCPointX+" "+newWCPointY);
615
                                        zoomControl.getDialog().getPointManager().setTempWC(newWCPointX, newWCPointY);
616
                                }else{
617
                                        Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
618
                                        if(pixelImg != null)
619
                                                zoomControl.getDialog().getPointManager().setTempPixelCoord(pixelImg.getX(), pixelImg.getY());
620
                                        else 
621
                                                //Si pixelImg es null es que nos hemos salido de la imagen por lo que reponemos los valores originales hasta que vuelva a entrar.
622
                                                zoomControl.getDialog().getPointManager().replacePixelCoord();        
623
                                        
624
                                }
625
                        }
626
                }
627
                
628
                /**
629
                 * Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
630
                 *
631
                 */
632
                public void mousePressed(MouseEvent ev) {
633
                        this.movDragged = ptoIni = ev.getPoint();
634
                        try{
635
                                if(zoomControl.isRightControl())
636
                                        setCursor(Toolkit.getDefaultToolkit().createCustomCursor(redCursor, new Point(16, 16), ""));
637
                                else
638
                                        setCursor(Toolkit.getDefaultToolkit().createCustomCursor(blueCursor, new Point(16, 16), ""));
639
                                
640
                                zoomControl.loadLayer();
641
                                initCrux = new Point2D.Double();
642
                                initCrux.setLocation(this.getWidth() / 2, this.getHeight() / 2);
643
                                repaint();
644
                        }catch(InstantiationException e){
645
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
646
                                                PluginServices.getText(this, "error_capa_puntos"));
647
                        }
648
                }
649

    
650
                /* (non-Javadoc)
651
                 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
652
                 */
653
                public void mouseReleased(MouseEvent ev) {
654
                        View  theView = null;
655
                        try{
656
                                theView = (View) PluginServices.getMDIManager().getActiveView();
657
                        }catch(ClassCastException exc){
658
                                return;
659
                        }
660
                        ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
661
                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
662
                        
663
                        ptoFin = ev.getPoint();
664

    
665
                        double destX = newViewPort.getExtent().getMinX() + ((ptoFin.getX() * (centerPoint.getX() - newViewPort.getExtent().getMinX())) / ptoIni.getX());
666
                        double destY = newViewPort.getExtent().getMinY() + (((this.getHeight() - ptoFin.getY()) * (centerPoint.getY() - newViewPort.getExtent().getMinY())) / (this.getHeight() - ptoIni.getY()));
667
                                        
668
                        int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
669

    
670
                        FLyrPoints lp = zoomControl.getLyrPoints();//(FLyrPoints)lyr;
671
                                 
672
                if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen
673
                        Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(destX, destY);
674
                                         
675
                        if(pixelImg == null){
676
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
677
                                                                     PluginServices.getText(this, "fuera_de_extent"));
678
                                     return;
679
                             }
680
                        zoomControl.getDialog().getPointManager().updateData(        nPoint,
681
                                                                                                                                         pixelImg,
682
                                                                                                                                         null, 
683
                                                                                                                                         zoomControl.getDialog(),
684
                                                                                                                                         null);
685

    
686
                        //Actualizamos la otra miniimagen
687
                        shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg));
688
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
689
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
690
                        zoomControl.getDialog().getPointManager().setCurrentPixelCoord();
691
                }else{ //Control de actualizaci?n de coordenadas del mundo
692
                                Point2D mapPoint = new Point2D.Double();
693
                                mapPoint.setLocation(destX, destY);
694
                                zoomControl.getDialog().getPointManager().updateData(        nPoint,
695
                                                                                                                                                        null, 
696
                                                                                                                                                        mapPoint,
697
                                                                                                                                                        zoomControl.getDialog(),
698
                                                                                                                                                        null);
699
                                          
700
                                //Actualizamos la otra miniimagen
701
                                shiftExtent(mapPoint);
702
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
703
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
704
                                zoomControl.getDialog().getPointManager().setCurrentWC();
705
                 }
706
                        repaint();
707
                        theView.getMapControl().getMapContext().invalidate();
708
                }
709
                
710
                /**
711
                 * Al pulsar el rat?n sobre la minimagen permitimos que se pueda desplazar la cruz
712
                 */
713
                /*public void mousePressed(MouseEvent ev) {
714
                
715
                }
716
                
717
                public void mouseReleased(MouseEvent ev) {
718
                        if(!isEnableEvent())
719
                                return ;
720
                        
721
                        View  theView = null;
722
                        try{
723
                                theView = (View) PluginServices.getMDIManager().getActiveView();
724
                        }catch(ClassCastException exc){
725
                                return;
726
                        }
727
                        Point2D ptoFin = ev.getPoint();
728
                        
729
                        int nPoint = Integer.valueOf(zoomControl.getDialog().getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
730
                        
731
                        double newWCPointX = this.newViewPort.getExtent().getMinX() + ((ptoFin.getX() * this.newViewPort.getExtent().getWidth()) / this.getWidth());
732
                        int ptoSelectY = (int)(this.getHeight() - ptoFin.getY());
733
                        double newWCPointY = this.newViewPort.getExtent().getMinY() + ((ptoSelectY * this.newViewPort.getExtent().getHeight()) / this.getHeight());
734
                                                
735
                if(zoomControl.isRightControl()){ //Control de actualizaci?n de pixel de imagen
736
                        Point2D pixelImg = zoomControl.getLyrGeoRaster().world2Img(newWCPointX, newWCPointY);
737
                                         
738
                        if(pixelImg == null){
739
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
740
                                                                     PluginServices.getText(this, "fuera_de_extent"));
741
                                     return;
742
                             }
743
                        zoomControl.getLyrPoints().getPointManager().updateData(nPoint,
744
                                                                                                                                         pixelImg, 
745
                                                                                                                                         null, 
746
                                                                                                                                         zoomControl.getDialog(),
747
                                                                                                                                         null);
748
                                         
749
                        //Actualizamos la otra miniimagen
750
                        shiftExtent(zoomControl.getLyrGeoRaster().img2World(pixelImg));
751
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
752
                        zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
753
                }else{ //Control de actualizaci?n de coordenadas del mundo
754
                                Point2D mapPoint = new Point2D.Double();
755
                                mapPoint.setLocation(newWCPointX, newWCPointY);
756
                                zoomControl.getLyrPoints().getPointManager().updateData(nPoint,
757
                                                                                                                                                        null, 
758
                                                                                                                                                        mapPoint, 
759
                                                                                                                                                        zoomControl.getDialog(),
760
                                                                                                                                                        null);        
761
                                          
762
                                //Actualizamos la otra miniimagen
763
                                shiftExtent(mapPoint);
764
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
765
                                zoomControl.getDialog().getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
766
                                zoomControl.getDialog().getPointManager().setCurrentWC();
767
                 }
768
                        repaint();
769
                        theView.getMapControl().getMapContext().invalidate();
770
                }*/
771
                
772
                /* (non-Javadoc)
773
                 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
774
                 */
775
                public void mouseDragged(MouseEvent ev) {
776
                        this.mouseMoved(ev);
777
                }
778
            //**********************End Methods***************************
779

    
780
                //**********************Setters & Getters*********************
781
                /**
782
                 * @param cleanCanvas The cleanCanvas to set.
783
                 */
784
                public void setCleanCanvas(boolean cleanCanvas) {
785
                        this.cleanCanvas = cleanCanvas;
786
                }
787
                
788
                 /**
789
             * Asigna el punto donde se centrar? la vista de la minimagen
790
             * @param pto Punto central.
791
             */
792
            public void setCenterPoint(Point2D pto){
793
                    this.centerPoint = pto;
794
            }
795
            
796
            /**
797
             * Asigna el viewPort
798
             * @param vp ViewPort
799
             */
800
            public void setViewPort(ViewPort vp){
801
                    this.initViewPort(vp, this.centerPoint, null);
802
            }
803

    
804
            /**
805
             * Asigna el viewPort recalculado
806
             * @param vp ViewPort
807
             */
808
            public void setNewViewPort(ViewPort vp){
809
                    this.newViewPort = vp;
810
            }
811
            
812
            /**
813
             * Obtiene el valor del desactivador de eventos sobre el canvas.
814
             * @return
815
             */
816
            public boolean isEnableEvent() {
817
                        return enableEvent;
818
                }
819

    
820
            /**
821
             * Asigna el desactivador de eventos sobre el canvas
822
             * @param enableEvent
823
             */
824
                public void setEnableEvent(boolean enableEvent) {
825
                        this.enableEvent = enableEvent;
826
                }
827
                //**********************End Setters & Getters*****************
828
                
829
        }
830
 }