Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / main / Georeferencing.java @ 18530

History | View | Annotate | Download (25 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.georeferencing.main;
20

    
21
import java.awt.geom.AffineTransform;
22
import java.awt.geom.Point2D;
23
import java.awt.geom.Rectangle2D;
24
import java.util.ArrayList;
25

    
26
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
27
import org.gvsig.georeferencing.ui.launcher.GeorefLauncherDialog;
28
import org.gvsig.georeferencing.ui.table.GCPTablePanel;
29
import org.gvsig.georeferencing.ui.zoom.InvalidRequestException;
30
import org.gvsig.georeferencing.ui.zoom.ViewEvent;
31
import org.gvsig.georeferencing.ui.zoom.ViewListener;
32
import org.gvsig.georeferencing.ui.zoom.ViewMapRequestManager;
33
import org.gvsig.georeferencing.ui.zoom.ViewRasterRequestManager;
34
import org.gvsig.georeferencing.ui.zoom.layers.GCPsGraphicLayer;
35
import org.gvsig.georeferencing.ui.zoom.layers.GPGraphic;
36
import org.gvsig.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer;
37
import org.gvsig.georeferencing.ui.zoom.tools.PanTool;
38
import org.gvsig.georeferencing.ui.zoom.tools.SelectPointTool;
39
import org.gvsig.georeferencing.ui.zoom.tools.ToolEvent;
40
import org.gvsig.georeferencing.ui.zoom.tools.ToolListener;
41
import org.gvsig.georeferencing.ui.zoom.tools.ZoomRectangleTool;
42
import org.gvsig.georeferencing.view.ViewDialog;
43
import org.gvsig.georeferencing.view.ZoomMapDialog;
44
import org.gvsig.georeferencing.view.ZoomRasterDialog;
45
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
46
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
47
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
48
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
49
import org.gvsig.raster.datastruct.GeoPoint;
50
import org.gvsig.raster.util.RasterToolsUtil;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.andami.ui.mdiFrame.MDIFrame;
54
import com.iver.andami.ui.mdiManager.IWindow;
55
import com.iver.cit.gvsig.ProjectExtension;
56
import com.iver.cit.gvsig.fmap.MapControl;
57
import com.iver.cit.gvsig.project.Project;
58
import com.iver.cit.gvsig.project.documents.view.ProjectView;
59
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
60
import com.iver.cit.gvsig.project.documents.view.gui.IView;
61

    
62
/**
63
 * Clase principal para la georreferenciaci?n. Se encarga de la inicializaci?n
64
 * de la funcionalidad. Las acciones a realizar son:
65
 * <UL>
66
 * <LI>Lanzamiento del dialogo de inicializaci?n.</LI>
67
 * <LI>Carga de la capa raster a georreferenciar.</LI>
68
 * <LI>Creaci?n de las ventanas si no han sido creadas previamente.</LI>
69
 * <LI>Asignaci?n de tama?os y posiciones a las ventanas.</LI>
70
 * </UL>
71
 * 26/12/2007
72
 * @author Nacho Brodin (nachobrodin@gmail.com)
73
 */
74
public class Georeferencing implements ButtonsPanelListener, ToolListener, ViewListener {
75
        public static final int               UNDEFINED                      = -1;
76
        //Algoritmo
77
        public static final int               POLYNOMIAL                     = 0;
78
        public static final int               AFFINE                         = 1;
79
        
80
        //Tipo de georreferenciacion
81
        public static final int               WITH_MAP                       = 0;
82
        public static final int               WITHOUT_MAP                    = 1;
83
        
84
        public static int                     DEFAULT_DEGREE                 = 3;
85
        
86
        private FLyrRasterSE                  lyrToGeoref                    = null;
87
        private String                        selectedView                   = null;
88
                
89
        private static final int              smallWindowsHeight             = 100;
90
        private static final double           smallWindowsWidthPercent       = 0.5;
91
        
92
        //Dialogos
93
        private GeorefLauncherDialog          initDialog                     = null;
94
        private ViewDialog                    viewRaster                     = null;
95
        private ViewDialog                    viewMap                        = null;
96
        private ZoomMapDialog                 zoomMap                        = null;
97
        private ZoomRasterDialog              zoomRaster                     = null;
98
        
99
        //Gestores de peticiones
100
        private ViewRasterRequestManager      viewRasterRequestManager       = null;
101
        private ViewMapRequestManager         viewMapRequestManager          = null;
102
        private ViewRasterRequestManager      zoomRasterRequestManager       = null;
103
        private ViewMapRequestManager         zoomMapRequestManager          = null;
104
                
105
        //Herramientas de selecci?n
106
        private SelectPointTool               viewRasterSelectPointTool      = null;
107
        private SelectPointTool               viewMapSelectPointTool         = null;
108
        private SelectPointTool               zoomRasterSelectPointTool      = null;
109
        private SelectPointTool               zoomMapSelectPointTool         = null;
110

    
111
        private GCPTablePanel                 table                          = null;
112
        private ApplicationControlsListener   buttonsListener                = null;
113
        private GeorefOptions                 options                        = null;
114
        
115
        private LayersPointManager            layersPointManager             = null;
116
        private ViewsManager                  viewsManager                   = null;
117
                
118
        public void initialize() {
119
                getLayerPointManager();        
120
                getViewsManager();
121
                launcher();
122
        }
123
        
124
        /**
125
         * Obtiene el gestor para capas de puntos de la aplicaci?n,
126
         * @return LayersPointManager
127
         */
128
        public LayersPointManager getLayerPointManager() {
129
                if(layersPointManager == null)
130
                        layersPointManager = new LayersPointManager(this);
131
                return layersPointManager;
132
        }
133
        
134
        /**
135
         * Obtiene el gestor para las vistas de la aplicaci?n,
136
         * @return ViewsManager
137
         */
138
        public ViewsManager getViewsManager() {
139
                if(viewsManager == null)
140
                        viewsManager = new ViewsManager();
141
                return viewsManager;
142
        }
143
        
144
        /**
145
         * Obtiene la clase con las opciones de georreferenciaci?n
146
         * @return
147
         */
148
        public GeorefOptions getOptions() {
149
                if(options == null)
150
                        options = new GeorefOptions();
151
                return options;
152
        }
153
        
154
        /**
155
         * Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
156
         * de ventanas con cartograf?a de referencia.
157
         */
158
        private void initWindowsWithoutMap() {
159
                MDIFrame p = (MDIFrame)PluginServices.getMainFrame();
160
                int totalWidth = p.getWidth(); 
161
                int wViews = totalWidth;
162
                int hViews = p.getHeight() - 178 - smallWindowsHeight;
163
                int posYViews = p.getHeight() - 138 - smallWindowsHeight;
164
                int smallWindowsWidth = (int)(totalWidth * 0.25);
165
                int tableWidth = (int)(totalWidth * 0.75);
166
                
167
                //Si hay ventanas de georreferenciaci?n abiertas las cerramos
168
                closeAllWindows();
169
                
170
                //Inicializaci?n de la tabla
171
                table = new GCPTablePanel(0, posYViews, tableWidth, smallWindowsHeight);
172
                buttonsListener = new ApplicationControlsListener(table, this);
173
                table.initialize(buttonsListener);
174
                                
175
                //Inicializaci?n de la ventana con la vista raster
176
                viewRaster = new ViewDialog(0, 0, wViews, hViews, this);
177
                viewRaster.setViewListener(this);
178
                viewRaster.setMinxMaxyUL(false);
179
                viewRaster.setShowInfo(true);
180
                viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, lyrToGeoref);
181
                viewRaster.setExtensionRequest(viewRasterRequestManager);
182
                viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), this);
183
                                
184
                //Inicializaci?n de la ventana del zoom de la vista raster
185
                zoomRaster = new ZoomRasterDialog(tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
186
                zoomRaster.setMinxMaxyUL(false);
187
                zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, lyrToGeoref);
188
                zoomRaster.setExtensionRequest(zoomRasterRequestManager);
189
                zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), this);
190
                        
191
                //A?adimos las ventanas a gvSIG
192
                PluginServices.getMDIManager().addWindow(viewRaster);
193
                PluginServices.getMDIManager().addWindow(table);
194
                PluginServices.getMDIManager().addWindow(zoomRaster);
195
        
196
                layersPointManager.setViews(viewRaster, null, zoomRaster, null);
197
                layersPointManager.setTools(viewRasterSelectPointTool, null, zoomRasterSelectPointTool, null);
198
                layersPointManager.registerPointToolListener();
199
                
200
                viewsManager.setViews(viewRaster, null, zoomRaster, null);
201
                viewsManager.setRequestsManager(viewRasterRequestManager, null, zoomRasterRequestManager, null);
202
                viewsManager.setTablePanel(table);
203
                
204
                try {
205
                        viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / 3, zoomRaster.getCanvasHeight() / 3);
206
                        viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2);
207
                        
208
                        //Inicializamos la vista de raster
209
                        viewRasterRequestManager.initRequest(lyrToGeoref.getFullExtent());
210
                                                
211
                        //Inicializamos el zoom de raster
212
                        Rectangle2D ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
213
                        zoomRasterRequestManager.initRequest(lyrToGeoref.getFullExtent());
214
                        zoomRasterRequestManager.request(ext);
215
                        
216
                        layersPointManager.createGCPPIxelLayer(viewRaster, viewRasterRequestManager, zoomRasterRequestManager);
217
                        
218
                } catch (InvalidRequestException e1) {
219
                        RasterToolsUtil.messageBoxError("error_setview_preview", this, e1);
220
                        closeAllWindows();
221
                }catch (Exception e1) {
222
                        RasterToolsUtil.messageBoxError("error_setview_preview", this, e1);
223
                        closeAllWindows();
224
                }
225
        }
226
        
227
        /**
228
         * Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
229
         * de ventanas con cartograf?a de referencia.
230
         */
231
        private void initWindowsWithMap() {
232
                MDIFrame p = (MDIFrame)PluginServices.getMainFrame();
233
                int wViews = p.getWidth() >> 1;
234
                int hViews = p.getHeight() - 178 - smallWindowsHeight;
235
                int posYViews = p.getHeight() - 138 - smallWindowsHeight;
236
                int smallWindowsWidth = (int)(p.getWidth() * (smallWindowsWidthPercent * 0.5));
237
                int tableWidth = (int)(p.getWidth() * (1 - smallWindowsWidthPercent));
238
                
239
                //Si hay ventanas de georreferenciaci?n abiertas las cerramos
240
                closeAllWindows();
241
                
242
                MapControl mapControl = null;
243
                IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
244
                for (int i = 0; i < windowList.length; i++) {
245
                        if(windowList[i] instanceof IView && windowList[i].getWindowInfo().getTitle().endsWith(": " + selectedView)) 
246
                                mapControl = ((IView)windowList[i]).getMapControl();
247
                }
248
                
249
                if(mapControl == null) {
250
                        RasterToolsUtil.messageBoxError("error_lookingfor_view", this);
251
                        return;
252
                }
253
                
254
                //Inicializamos el control de tabla
255
                table = new GCPTablePanel(smallWindowsWidth, posYViews, tableWidth, smallWindowsHeight);
256
                buttonsListener = new ApplicationControlsListener(table, this);
257
                table.initialize(buttonsListener);
258
                                
259
                //Inicializaci?n de la ventana con la vista mapa
260
                viewMap = new ViewDialog(0, 0, wViews, hViews, this);
261
                viewMap.setViewListener(this);
262
                viewMap.setShowInfo(true);
263
                viewMapRequestManager = new ViewMapRequestManager(viewMap, mapControl);
264
                viewMap.setExtensionRequest(viewMapRequestManager);
265
                viewMapSelectPointTool = new SelectPointTool(viewMap.getCanvas(), this);
266
                
267
                //Inicializaci?n de la ventana con la vista raster
268
                viewRaster = new ViewDialog(wViews, 0, wViews, hViews, this);
269
                viewRaster.setViewListener(this);
270
                viewRaster.setMinxMaxyUL(false);
271
                viewRaster.setShowInfo(true);
272
                viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, lyrToGeoref);
273
                viewRaster.setExtensionRequest(viewRasterRequestManager);
274
                viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), this);
275
                
276
                //Inicializaci?n de la ventana del zoom de la vista raster
277
                zoomRaster = new ZoomRasterDialog(smallWindowsWidth + tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
278
                zoomRaster.setMinxMaxyUL(false);
279
                zoomRaster.setShowInfo(true);
280
                zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, lyrToGeoref);
281
                zoomRaster.setExtensionRequest(zoomRasterRequestManager);
282
                zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), this);
283
                
284
                //Inicializaci?n de la ventana del zoom de la vista de referencia
285
                zoomMap = new ZoomMapDialog(0, posYViews, smallWindowsWidth, smallWindowsHeight);
286
                zoomMap.setShowInfo(true);
287
                zoomMapRequestManager = new ViewMapRequestManager(zoomMap, mapControl);
288
                zoomMap.setExtensionRequest(zoomMapRequestManager);
289
                zoomMapSelectPointTool = new SelectPointTool(zoomMap.getCanvas(), this);
290
                                        
291
                //A?adimos las ventanas a gvSIG
292
                PluginServices.getMDIManager().addWindow(viewRaster);
293
                PluginServices.getMDIManager().addWindow(viewMap);
294
                PluginServices.getMDIManager().addWindow(table);
295
                PluginServices.getMDIManager().addWindow(zoomMap);
296
                PluginServices.getMDIManager().addWindow(zoomRaster);
297
                
298
                layersPointManager.setViews(viewRaster, viewMap, zoomRaster, zoomMap);
299
                layersPointManager.setTools(viewRasterSelectPointTool, viewMapSelectPointTool, zoomRasterSelectPointTool, zoomMapSelectPointTool);
300
                layersPointManager.registerPointToolListener();
301
                
302
                viewsManager.setViews(viewRaster, viewMap, zoomRaster, zoomMap);
303
                viewsManager.setRequestsManager(viewRasterRequestManager, viewMapRequestManager, zoomRasterRequestManager, zoomMapRequestManager);
304
                viewsManager.setTablePanel(table);
305
                
306
                try {
307
                        viewMap.setCursorSize(zoomMap.getCanvasWidth() / 3, zoomMap.getCanvasHeight() / 3);
308
                        viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / 3, zoomRaster.getCanvasHeight() / 3);
309
                        viewMap.setCursorPosition(viewMap.getCanvasWidth() / 2, viewMap.getCanvasHeight() / 2);
310
                        viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2);
311
                        
312
                        if(mapControl.getMapContext().getLayers().getFullExtent() == null)
313
                                RasterToolsUtil.messageBoxError("error_setview_preview", this);
314
                        
315
                        //Inicializamos la vista de mapa
316
                        viewMapRequestManager.initRequest(mapControl.getMapContext().getLayers().getFullExtent());
317
                        
318
                        //Inicializamos la vista de raster
319
                        viewRasterRequestManager.initRequest(lyrToGeoref.getFullExtent());
320
                        
321
                        //Inicializamos el zoom de mapa
322
                        Rectangle2D ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
323
                        zoomMapRequestManager.initRequest(ext);
324
                        
325
                        //Inicializamos el zoom de raster
326
                        ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
327
                        zoomRasterRequestManager.initRequest(lyrToGeoref.getFullExtent());
328
                        zoomRasterRequestManager.request(ext);
329
                        
330
                        layersPointManager.createGCPPIxelLayer(viewRaster, viewRasterRequestManager, zoomRasterRequestManager);
331
                        layersPointManager.createGCPMapLayer(viewMap, viewMapRequestManager, zoomMapRequestManager);
332
                        
333
                } catch (InvalidRequestException e1) {
334
                        RasterToolsUtil.messageBoxError("error_setview_preview", this, e1);
335
                        closeAllWindows();
336
                }catch (Exception e1) {
337
                        RasterToolsUtil.messageBoxError("error_setview_preview", this, e1);
338
                        closeAllWindows();
339
                }
340
        }
341
        
342
        /**
343
         * Cierra todas las ventanas de georreferenciaci?n
344
         */
345
        public void closeAllWindows() {
346
                if(zoomMap != null)
347
                        PluginServices.getMDIManager().closeWindow(zoomMap);
348
                if(zoomRaster != null)
349
                        PluginServices.getMDIManager().closeWindow(zoomRaster);
350
                if(viewRaster != null)
351
                        PluginServices.getMDIManager().closeWindow(viewRaster);
352
                if(viewMap != null)
353
                        PluginServices.getMDIManager().closeWindow(viewMap);
354
                if(table != null)
355
                        PluginServices.getMDIManager().closeWindow(table);
356
        }
357
        
358
        /**
359
         * Lanzador del cuadro de inicializaci?n de propiedades de georreferenciaci?n.
360
         */
361
        private void launcher() {
362
                Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
363
                ArrayList docs = p.getDocumentsByType(ProjectViewFactory.registerName);
364
                String[] viewList = new String[docs.size()];
365
                for (int i = 0; i < docs.size(); i++) 
366
                        viewList[i] = (((ProjectView)docs.get(i)).getName());
367
                initDialog = new GeorefLauncherDialog(viewList, DEFAULT_DEGREE, this);
368
                PluginServices.getMDIManager().addWindow(initDialog);
369
        }
370
        
371
        /**
372
         * Captura de eventos de los botones Aceptar y Cancelar del cuadro
373
         * inicial con las propiedades de georreferenciaci?n.
374
         */
375
        public void actionButtonPressed(ButtonsPanelEvent e) {
376
                // Bot?n de Aceptar
377
                if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
378
                        if(initDialog != null) {
379
                                selectedView = initDialog.getSelectedView();
380
                                lyrToGeoref = initDialog.getLayer();
381
                                getOptions().setAlgorithm(initDialog.getAlgorithm());
382
                                getOptions().setDegree(initDialog.getDegree());
383
                                //Inicializamos la matriz de transformaci?n en la imagen que vamos a georreferenciar para
384
                                //que nos de coordenadas pixel
385
                                if(lyrToGeoref == null) 
386
                                        RasterToolsUtil.messageBoxError("layer_not_loaded", this);
387
                                else {
388
                                        lyrToGeoref.setAffineTransform(new AffineTransform(1, 0, 0, 1, 0, 0));
389
                                        PluginServices.getMDIManager().closeWindow(initDialog);
390
                                        if(initDialog.getType() == Georeferencing.WITH_MAP)
391
                                                initWindowsWithMap();
392
                                        if(initDialog.getType() == Georeferencing.WITHOUT_MAP)
393
                                                initWindowsWithoutMap();
394
                                }
395
                        }
396
                }
397
                // Bot?n de Cerrar
398
                if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
399
                        if(initDialog != null)
400
                                PluginServices.getMDIManager().closeWindow(initDialog);
401
                }
402
        }
403

    
404
        /**
405
         * Controla los eventos de finalizaci?n de la capa con el 
406
         * cursor gr?fico que controla el ?rea de la miniimagen asociada y
407
         * la terminaci?n de la operaci?n de mover punto
408
         */
409
        public void endAction(ToolEvent ev) {
410
                //Operaci?n de zoom
411
                if(ev.getSource() instanceof ZoomCursorGraphicLayer) {
412
                        try {        
413
                                Rectangle2D ext = null;
414
                                if(viewRaster != null) {
415
                                        ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
416
                                        zoomRasterRequestManager.request(ext);
417
                                }
418
                                if(viewMap != null) {
419
                                        ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
420
                                        zoomMapRequestManager.request(ext);
421
                                }
422
                        } catch (InvalidRequestException e1) {
423
                                RasterToolsUtil.messageBoxError("error_setview_preview", this);
424
                        }
425
                }
426
                
427
                //Mover punto
428
                if(ev.getSource() instanceof GCPsGraphicLayer) {
429
                        buttonsListener.setEnableTableEvent(false);
430
                        //Se redibujan, se obtienen las coordenadas del punto y se actualiza la tabla
431
                        if(layersPointManager != null)
432
                                layersPointManager.redrawPoints();
433
                        GPGraphic gPoint = ((GCPsGraphicLayer)ev.getSource()).getLastPoint();
434
                        Point2D pRaster = gPoint.getGeoPoint().pixelPoint;
435
                        Point2D pMap = gPoint.getGeoPoint().mapPoint;
436
                        try {
437
                                table.getTable().setValueAt(new Double(pMap.getX()), gPoint.getGeoPoint().number, 2);
438
                                table.getTable().setValueAt(new Double(pMap.getY()), gPoint.getGeoPoint().number, 3);
439
                                table.getTable().setValueAt(new Double(pRaster.getX()), gPoint.getGeoPoint().number, 4);
440
                                table.getTable().setValueAt(new Double(pRaster.getY()), gPoint.getGeoPoint().number, 5);
441
                                table.getTable().getTable().getJTable().setRowSelectionInterval(gPoint.getGeoPoint().number, gPoint.getGeoPoint().number);
442
                        } catch (NotInitializeException e) {
443
                                RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
444
                        } catch (ArrayIndexOutOfBoundsException e) {
445
                                RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
446
                        }
447
                        if(getOptions().isCenterView())
448
                                viewsManager.centerToPoint(gPoint.getGeoPoint().number);
449
                        buttonsListener.setEnableTableEvent(true);
450
                }
451
                
452
                //Selecci?n de punto
453
                if(ev.getSource() instanceof SelectPointTool) {
454
                        try {
455
                                //Se obtiene el punto seleccionado, se actualiza la tabla y se redibujan
456
                                int nPoint = table.getTable().getSelectedRow();
457
                                GeoPoint gp = layersPointManager.getPointByNumber(nPoint);
458
                                
459
                                if(ev.getSource() == viewRasterSelectPointTool || ev.getSource() == zoomRasterSelectPointTool) {
460
                                        Point2D[] p = (Point2D[])((SelectPointTool)ev.getSource()).getResult();
461
                                        table.getTable().setValueAt(new Double(p[1].getX()), nPoint, 4);
462
                                        table.getTable().setValueAt(new Double(p[1].getY()), nPoint, 5);
463
                                        if(gp != null) {
464
                                                gp.pixelPoint = p[1];
465
                                                layersPointManager.redrawPoints();
466
                                        }
467
                                }
468
                                if(ev.getSource() == viewMapSelectPointTool || ev.getSource() == zoomMapSelectPointTool) {
469
                                        Point2D[] p = (Point2D[])((SelectPointTool)ev.getSource()).getResult();
470
                                        table.getTable().setValueAt(new Double(p[1].getX()), nPoint, 2);
471
                                        table.getTable().setValueAt(new Double(p[1].getY()), nPoint, 3);
472
                                        if(gp != null) {
473
                                                gp.mapPoint = p[1];
474
                                                layersPointManager.redrawPoints();
475
                                        }
476
                                }
477
                                if(getOptions().isCenterView())
478
                                        viewsManager.centerToPoint(nPoint);
479
                        } catch (NotInitializeException e) {
480
                                RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
481
                        } catch (ArrayIndexOutOfBoundsException e) {
482
                                RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
483
                        }
484
                }
485
        }
486
        
487
        /**
488
         *  <P>
489
         *  Controla las prioridades de eventos sobre la vista en las herramientas y capas de selecci?n.
490
         *  Esto es necesario para que no se mezclen eventos entre capas.
491
         *  <P></P>
492
         *  Prioridades:
493
         *  </P>
494
         *  <UL>
495
         *  <LI>Capa de ZoomCursorGraphicLayer</LI>
496
         *  <LI>Capa de GCPsGraphicLayer</LI>
497
         *  <LI>Tool de selecci?n de zoom rectangulo</LI>
498
         *  <LI>Tool de selecci?n de puntos</LI>
499
         *  </UL>
500
         */
501
        public void onTool(ToolEvent ev) {
502
                //Operaci?n de cursor de zoom 
503
                if(ev.getSource() instanceof ZoomCursorGraphicLayer) {
504
                        layersPointManager.setActiveLayerPoints(false);
505
                        viewsManager.sleepActiveTools();
506
                        return;
507
                }
508
                
509
                //Mover punto
510
                if(ev.getSource() instanceof GCPsGraphicLayer) {
511
                        layersPointManager.setActiveLayerZoomCursor(false);
512
                        viewsManager.sleepActiveTools();
513
                        return;
514
                }
515
                
516
                //Selecci?n de punto
517
                if(ev.getSource() instanceof SelectPointTool) {
518
                        if(viewMap != null) {
519
                                viewMap.getControl().selectTool(ZoomRectangleTool.class, false);
520
                                viewMap.getControl().selectTool(PanTool.class, false);
521
                                viewMap.getControl().getBSelectZoomArea().setSelected(false);
522
                                viewMap.getControl().getBMove().setSelected(false);
523
                        }
524
                        if(viewRaster != null) { 
525
                                viewRaster.getControl().selectTool(ZoomRectangleTool.class, false);
526
                                viewMap.getControl().selectTool(PanTool.class, false);
527
                                viewRaster.getControl().getBSelectZoomArea().setSelected(false);
528
                                viewRaster.getControl().getBMove().setSelected(false);
529
                        }
530
                }
531
                
532
                //Selecci?n de zoom ventana
533
                if(ev.getSource() instanceof ZoomRectangleTool) {
534
                        if(viewMap != null) {
535
                                viewMap.getControl().selectTool(SelectPointTool.class, false);
536
                                viewMap.getControl().selectTool(PanTool.class, false);
537
                                viewMap.getControl().getBMove().setSelected(false);
538
                        }
539
                        if(viewRaster != null) { 
540
                                viewRaster.getControl().selectTool(SelectPointTool.class, false);
541
                                viewRaster.getControl().selectTool(PanTool.class, false);
542
                                viewRaster.getControl().getBMove().setSelected(false);
543
                        }
544
                        table.getToolSelectPointButton().setSelected(false);
545
                }
546
                
547
                //Selecci?n de desplazamiento
548
                if(ev.getSource() instanceof PanTool) {
549
                        if(viewMap != null) {
550
                                viewMap.getControl().selectTool(SelectPointTool.class, false);
551
                                viewMap.getControl().selectTool(ZoomRectangleTool.class, false);
552
                                viewMap.getControl().getBSelectZoomArea().setSelected(false);
553
                        }
554
                        if(viewRaster != null) { 
555
                                viewRaster.getControl().selectTool(SelectPointTool.class, false);
556
                                viewRaster.getControl().selectTool(ZoomRectangleTool.class, false);
557
                                viewRaster.getControl().getBSelectZoomArea().setSelected(false);
558
                        }
559
                        table.getToolSelectPointButton().setSelected(false);
560
                }
561
        }
562
        
563
        /**
564
         *  
565
         */
566
        public void offTool(ToolEvent ev) {
567
                //Operaci?n de zoom
568
                if(ev.getSource() instanceof ZoomCursorGraphicLayer) {
569
                        layersPointManager.setActiveLayerPoints(true);
570
                        viewsManager.awakeActiveTools();
571
                        return;
572
                }
573
                
574
                //Mover punto
575
                if(ev.getSource() instanceof GCPsGraphicLayer) {
576
                        layersPointManager.setActiveLayerZoomCursor(true);
577
                        viewsManager.awakeActiveTools();
578
                        return;
579
                }
580
                
581
                //Selecci?n de punto
582
                /*if(ev.getSource() instanceof SelectPointTool) {
583
                }
584
                //Selecci?n de zoom ventana
585
                if(ev.getSource() instanceof ZoomRectangleTool) {
586
                }*/
587
        }
588
        
589
        //*******************************************************
590
        //Eventos sobre las vistas
591
        
592
        
593
        public void addingTool(ViewEvent ev) {
594
        }
595

    
596
        public void endDraw(ViewEvent ev) {
597
        }
598

    
599
        public void startDraw(ViewEvent ev) {
600
        }
601

    
602
        /**
603
         * Cuando cambia el zoom de alguna vista hay que recalcular la posici?n
604
         * del cursor de zoom
605
         */
606
        public void zoomViewChanged(ViewEvent ev) {
607
                Rectangle2D ext = null;
608
                try {
609
                        if(viewRaster != null && zoomRaster != null && zoomRasterRequestManager != null) {
610
                                ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
611
                                zoomRasterRequestManager.request(ext);
612
                        }
613
                        if(viewMap != null && zoomMap != null && zoomMapRequestManager != null) {
614
                                ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
615
                                zoomMapRequestManager.request(ext);
616
                        }
617
                }catch(InvalidRequestException ex) {
618
                        RasterToolsUtil.messageBoxError("error_set_view", table, ex);
619
                }
620
        }
621
        
622
        /**
623
         * Obtiene la capa a georreferenciar
624
         * @return FLyrRasterSE
625
         */
626
        public FLyrRasterSE getLayer() {
627
                return lyrToGeoref;
628
        }
629
                
630
}