Statistics
| Revision:

gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.swing / org.gvsig.raster.georeferencing.swing.impl / src / main / java / org / gvsig / raster / georeferencing / swing / impl / view / synchronize / SynchronizationViewImpl.java @ 1712

History | View | Annotate | Download (12.3 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.raster.georeferencing.swing.impl.view.synchronize;
20

    
21
import java.awt.Color;
22
import java.awt.geom.Point2D;
23

    
24
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint;
25
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList;
26
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
27
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException;
28
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary;
29
import org.gvsig.raster.georeferencing.swing.impl.tool.SelectPointTool;
30
import org.gvsig.raster.georeferencing.swing.impl.view.BaseZoomView;
31
import org.gvsig.raster.georeferencing.swing.impl.view.ViewPanelImpl;
32
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView;
33
import org.gvsig.raster.georeferencing.swing.view.IViewRequestManager;
34
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews;
35

    
36
/**
37
 * Gestor para operaciones con las vistas y zooms
38
 * 
39
 * 04/02/2008
40
 * @author Nacho Brodin nachobrodin@gmail.com
41
 */
42
public class SynchronizationViewImpl implements SynchronizedViews {
43
        //Dialogos
44
        private GeoreferencingView                viewRaster                     = null;
45
        private GeoreferencingView                viewMap                        = null;
46
        private GeoreferencingView                zoomMap                        = null;
47
        private GeoreferencingView                zoomRaster                     = null;
48
        
49
        //Gestores de peticiones
50
        private IViewRequestManager               viewRasterRequestManager       = null;
51
        private IViewRequestManager               viewMapRequestManager          = null;
52
        private IViewRequestManager               zoomRasterRequestManager       = null;
53
        private IViewRequestManager               zoomMapRequestManager          = null;
54
        
55
        private GeoPointList                      gpList                         = null;
56
        private GCPSynchronizationImpl            gcpSync                        = null;
57
        
58
        public SynchronizationViewImpl(GeoPointList gpList) {
59
                this.gpList = gpList;
60
        }
61
        
62
        public void setGCPSync(GCPSynchronizationImpl gcpSync) {
63
                this.gcpSync = gcpSync;
64
        }
65
        
66
        /**
67
         * Asigna las vistas
68
         * @param vRaster
69
         * @param vMap
70
         * @param zRaster
71
         * @param zMap
72
         */
73
        public void setViews(
74
                        GeoreferencingView vRaster, 
75
                        GeoreferencingView vMap, 
76
                        GeoreferencingView zRaster, 
77
                        GeoreferencingView zMap) {
78
                viewRaster = vRaster;
79
                viewMap = vMap;
80
                zoomMap = zMap;
81
                zoomRaster = zRaster;
82
        }
83

    
84
        /**
85
         * Asigna los gestores de peticiones.
86
         * @param vRaster
87
         * @param vMap
88
         * @param zRaster
89
         * @param zMap
90
         */
91
        public void setRequestsManager(
92
                        IViewRequestManager vRaster, 
93
                        IViewRequestManager vMap, 
94
                        IViewRequestManager zRaster, 
95
                        IViewRequestManager zMap) {
96
                viewRasterRequestManager = vRaster;
97
                viewMapRequestManager= vMap;
98
                zoomRasterRequestManager = zRaster;
99
                zoomMapRequestManager = zMap;
100
        }
101
        
102
        /**
103
         * Asigna el panel con la tabla
104
         * @param tablePanel
105
         */
106
        public void setGeoPointList(GeoPointList gpList) {
107
                this.gpList = gpList;
108
        }
109
        
110
        /**
111
         * Desactiva la tool activa de las vistas
112
         * @param active
113
         */
114
        public void sleepActiveTools() {
115
                if(zoomMap != null) 
116
                        ((BaseZoomView)zoomMap).getControl().sleepTools();
117
                if(zoomRaster != null) 
118
                        ((BaseZoomView)zoomRaster).getControl().sleepTools();
119
                if(viewRaster != null)
120
                        ((BaseZoomView)viewRaster).getControl().sleepTools();
121
                if(viewMap != null)
122
                        ((BaseZoomView)viewMap).getControl().sleepTools();
123
        }
124
        
125
        /**
126
         * Activa la tool activa de las vistas
127
         * @param active
128
         */
129
        public void awakeActiveTools() {
130
                if(zoomMap != null) 
131
                        ((BaseZoomView)zoomMap).getControl().awakeTools();
132
                if(zoomRaster != null) 
133
                        ((BaseZoomView)zoomRaster).getControl().awakeTools();
134
                if(viewRaster != null)
135
                        ((BaseZoomView)viewRaster).getControl().awakeTools();
136
                if(viewMap != null)
137
                        ((BaseZoomView)viewMap).getControl().awakeTools();
138
        }
139
        
140
        /**
141
         * Selecciona o deselecciona la tool de selecci?n de punto para cada vista
142
         * @param true para activar y false para desactivar
143
         */
144
        public void selectPointTool(boolean select) {
145
                if(zoomMap != null)
146
                        ((BaseZoomView)zoomMap).getControl().selectTool(SelectPointTool.class, select);
147
                if(zoomRaster != null)
148
                        ((BaseZoomView)zoomRaster).getControl().selectTool(SelectPointTool.class, select);
149
                if(viewRaster != null)
150
                        ((BaseZoomView)viewRaster).getControl().selectTool(SelectPointTool.class, select);
151
                if(viewMap != null)
152
                        ((BaseZoomView)viewMap).getControl().selectTool(SelectPointTool.class, select);
153
        }
154
        
155
        /**
156
         * Asigna el color de los gr?ficos.
157
         * @param c
158
         */
159
        public void setGraphicsColor(Color c) {
160
                if(viewRaster != null && viewRaster instanceof ViewPanelImpl) {
161
                        viewRaster.getCanvas().setTextColor(c);
162
                        ((ViewPanelImpl)viewRaster).getZoomCursorGraphicLayer().setColor(c);
163
                }
164
                if(viewMap != null && viewRaster instanceof ViewPanelImpl) {
165
                        viewMap.getCanvas().setTextColor(c);
166
                        ((ViewPanelImpl)viewMap).getZoomCursorGraphicLayer().setColor(c);
167
                }
168
                if(zoomRaster != null) 
169
                        zoomRaster.getCanvas().setTextColor(c);
170
                if(zoomMap != null) 
171
                        zoomMap.getCanvas().setTextColor(c);
172
        }
173
        
174
        /**
175
         * Asigna el color de los gr?ficos.
176
         * @param c
177
         */
178
        public void setBackgroundColor(Color c) {
179
                if(viewMapRequestManager != null)
180
                        viewMapRequestManager.setBackGroundColor(c);
181
                if(viewRasterRequestManager != null)
182
                        viewRasterRequestManager.setBackGroundColor(c);
183
                if(zoomMapRequestManager != null)
184
                        zoomMapRequestManager.setBackGroundColor(c);
185
                if(zoomRasterRequestManager != null)
186
                        zoomRasterRequestManager.setBackGroundColor(c);
187
                try {
188
                        if(viewRaster != null) {
189
                                viewRaster.getCanvas().setBackgroundColor(c);
190
                                viewRaster.getCanvas().setForceRequest(true);
191
                                ((BaseZoomView)viewRaster).getControl().getExtensionRequest().request(viewRaster.getCanvas().getExtent());
192
                        }
193
                        if(viewMap != null) {
194
                                viewMap.getCanvas().setBackgroundColor(c);
195
                                viewMap.getCanvas().setForceRequest(true);
196
                                ((BaseZoomView)viewMap).getControl().getExtensionRequest().request(viewMap.getCanvas().getExtent());
197
                        }
198
                        if(zoomRaster != null) { 
199
                                zoomRaster.getCanvas().setBackgroundColor(c);
200
                                zoomRaster.getCanvas().setForceRequest(true);
201
                                ((BaseZoomView)zoomRaster).getControl().getExtensionRequest().request(zoomRaster.getCanvas().getExtent());
202
                        }
203
                        if(zoomMap != null) { 
204
                                zoomMap.getCanvas().setBackgroundColor(c);
205
                                zoomMap.getCanvas().setForceRequest(true);
206
                                ((BaseZoomView)zoomMap).getControl().getExtensionRequest().request(zoomMap.getCanvas().getExtent());
207
                        }
208
                } catch (InvalidRequestException e) {
209
                }
210
        }
211
        
212
        /**
213
         * Centra las vistas sobre el punto pasado por par?metro
214
         * @param n N?mero de punto sobre el que se centrar? la visualizaci?n
215
         */
216
        public void centerToPoint(int n) {
217
                if(gpList.size() <= 0) {
218
                        GeoreferencingSwingImplLibrary.messageBoxError("no_selected_point", null);
219
                        return;
220
                }
221

    
222
                GeoPoint gp = gpList.get(n);
223
                double xMap = gp.getMapPoint().getX();
224
                double yMap = gp.getMapPoint().getY();
225
                double xRaster = gp.getPixelPoint().getX();
226
                double yRaster = gp.getPixelPoint().getY();
227

    
228
                if(viewRaster != null && viewMap instanceof ViewPanelImpl) 
229
                        ((ViewPanelImpl)viewRaster).setCenter(new Point2D.Double(xRaster, yRaster));
230
                if(zoomRaster != null) 
231
                        ((BaseZoomView)zoomRaster).getControl().setCenter(new Point2D.Double(xRaster, yRaster));
232
                if(viewMap != null && viewMap instanceof ViewPanelImpl) 
233
                        ((ViewPanelImpl)viewMap).setCenter(new Point2D.Double(xMap, yMap));
234
                if(zoomMap != null) 
235
                        ((BaseZoomView)zoomMap).getControl().setCenter(new Point2D.Double(xMap, yMap));
236
        }
237

    
238
        /**
239
         * Obtiene la vista con el mapa de referencia
240
         * @return ViewDialog
241
         */
242
        public GeoreferencingView getViewMap() {
243
                return viewMap;
244
        }
245

    
246
        /**
247
         * Obtiene la vista con el raster a georreferenciar
248
         * @return ViewDialog
249
         */
250
        public GeoreferencingView getViewRaster() {
251
                return viewRaster;
252
        }
253

    
254
        /**
255
         * Obtiene la vista con el zoom del mapa de referencia
256
         * @return ZoomMapDialog
257
         */
258
        public GeoreferencingView getZoomMap() {
259
                return zoomMap;
260
        }
261

    
262
        /**
263
         * Obtiene la vista con el zoom del raster a georreferenciar
264
         * @return ZoomRasterDialog
265
         */
266
        public GeoreferencingView getZoomRaster() {
267
                return zoomRaster;
268
        }
269

    
270
        /**
271
         * Obtiene el gestor de la vista con la cartograf?a de referencia
272
         * @return ViewMapRequestManager
273
         */
274
        public IViewRequestManager getViewMapRequestManager() {
275
                return viewMapRequestManager;
276
        }
277

    
278
        /**
279
         * Obtiene el gestor de la vista con el raster a georreferenciar
280
         * @return ViewRasterRequestManager
281
         */
282
        public IViewRequestManager getViewRasterRequestManager() {
283
                return viewRasterRequestManager;
284
        }
285

    
286
        /**
287
         * Obtiene el gestor de la vista zoom con la cartograf?a de referencia
288
         * @return ViewMapRequestManager
289
         */
290
        public IViewRequestManager getZoomMapRequestManager() {
291
                return zoomMapRequestManager;
292
        }
293

    
294
        /**
295
         * Obtiene el gestor de la vista zoom con el raster
296
         * @return ViewRasterRequestManager
297
         */
298
        public IViewRequestManager getZoomRasterRequestManager() {
299
                return zoomRasterRequestManager;
300
        }
301
        
302
        /**
303
         * Activa o desactiva la capa de puntos
304
         * @param active
305
         */
306
        public void setActiveLayerZoomCursor(boolean active) {
307
                gcpSync.setActiveLayerZoomCursor(active);
308
        }
309
        
310
        /**
311
         * Activa y desactiva los n?meros de punto de las capas gr?ficas
312
         * @param active
313
         */
314
        public void setActiveNumberPoint(boolean active) {
315
                gcpSync.setActiveNumberPoint(active);
316
        }
317
        
318
        /**
319
         * Activa o desactiva la capa de puntos
320
         * @param active
321
         */
322
        public void setActiveLayerPoints(boolean active) {
323
                gcpSync.setActiveLayerPoints(active);
324
        }
325
        
326
        /**
327
         * Recalcula las coordenadas de dibujado de los puntos de control
328
         * y redibuja estos en todas las vistas
329
         */
330
        public void redrawPoints() {
331
                gcpSync.redrawPoints();
332
        }
333
        
334
        /**
335
         * Elimina un punto de la lista a partir de su posici?n
336
         * @param position
337
         */
338
        public void removePoint(int position) {
339
                gcpSync.removePoint(position);
340
        }
341
        
342
        /**
343
         * Asigna la numeraci?n a los puntos de control. Tanto a la tabla como
344
         * a los GeoPuntos
345
         * @throws NotInitializeException
346
         */
347
        public void calcPointsNumeration() throws NotInitializeException {
348
                gcpSync.calcPointsNumeration();
349
        }
350
        
351
        /**
352
         * Obtiene un punto (GeoPoint) a partir de su n?mero. Hay que tener en cuenta que el n?mero de
353
         * punto puede no coincidir con su posici?n en el array.
354
         * @return GeoPoint
355
         */
356
        public GeoPoint getPointByNumber(int number) {
357
                return gcpSync.getPointByNumber(number);
358
        }
359
        
360
        /**
361
         * Obtiene la posici?n de un punto a partir de su n?mero. Hay que tener en cuenta que el n?mero de
362
         * punto puede no coincidir con su posici?n en el array.
363
         * @return entero con la posici?n o -1 si no existe
364
         */
365
        public int getPointPositionByNumber(int number) {
366
                return gcpSync.getPointPositionByNumber(number);
367
        }
368
        
369
        /**
370
         * Activa o desactiva la visualizaci?n de un punto.
371
         * @param active true para activarlo y false para desactivarlo
372
         * @param position Posici?n del punto
373
         */
374
        public void setVisiblePoint(boolean visible, int position) {
375
                gcpSync.setVisiblePoint(visible, position);
376
        }
377
        
378
        /**
379
         * Asigna las coordenadas del mundo real y raster al punto indicado en el par?metro. 
380
         * @param point Punto a asignar las nuevas coordenadas
381
         * @param xMap Coordenada real en X
382
         * @param yMap Coordenada real en Y
383
         * @param xRaster Coordenada pixel en X
384
         * @param yRaster Coordenada pixel en Y
385
         */
386
        public void setCoordinates(int point, double xMap, double yMap, double xRaster, double yRaster) {
387
                gcpSync.setCoordinates(point, xMap, yMap, xRaster, yRaster);
388
        }
389
        
390
        /**
391
         * A?ade un punto a las capas gr?ficas
392
         * @param map Coordenadas del mapa del punto
393
         * @param raster Coordenadas pixel del punto
394
         * @return identificador del punto a?adido
395
         */
396
        public long addPoint(Point2D map, Point2D raster) {
397
                return gcpSync.addPoint(map, raster);
398
        }
399
}