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 @ 1752
History | View | Annotate | Download (14.7 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.gui.beans.table.exceptions.NotInitializeException; |
26 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
27 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
28 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
29 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
30 |
import org.gvsig.raster.georeferencing.swing.impl.view.BaseViewPanel; |
31 |
import org.gvsig.raster.georeferencing.swing.impl.view.ViewPanelImpl; |
32 |
import org.gvsig.raster.georeferencing.swing.model.GCPList; |
33 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
34 |
import org.gvsig.raster.georeferencing.swing.view.IViewRequestManager; |
35 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
36 |
import org.gvsig.raster.georeferencing.swing.view.ToolListener; |
37 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
38 |
|
39 |
/**
|
40 |
* Gestor para operaciones con las vistas y zooms
|
41 |
*
|
42 |
* 04/02/2008
|
43 |
* @author Nacho Brodin nachobrodin@gmail.com
|
44 |
*/
|
45 |
public class SynchronizationViewImpl implements SynchronizedViews { |
46 |
//Dialogos
|
47 |
private GeoreferencingView viewRaster = null; |
48 |
private GeoreferencingView viewMap = null; |
49 |
private GeoreferencingView zoomMap = null; |
50 |
private GeoreferencingView zoomRaster = null; |
51 |
|
52 |
//Gestores de peticiones
|
53 |
private IViewRequestManager viewRasterRequestManager = null; |
54 |
private IViewRequestManager viewMapRequestManager = null; |
55 |
private IViewRequestManager zoomRasterRequestManager = null; |
56 |
private IViewRequestManager zoomMapRequestManager = null; |
57 |
|
58 |
private GCPList gpList = null; |
59 |
private GCPSynchronizationImpl gcpSync = null; |
60 |
private GeorefControlPanel controlPanel = null; |
61 |
|
62 |
public SynchronizationViewImpl(GCPList gpList, ToolListener listener) {
|
63 |
this.gpList = gpList;
|
64 |
gcpSync = new GCPSynchronizationImpl(gpList, listener);
|
65 |
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Asigna las vistas
|
70 |
* @param vRaster
|
71 |
* @param vMap
|
72 |
* @param zRaster
|
73 |
* @param zMap
|
74 |
*/
|
75 |
public void setViews( |
76 |
GeoreferencingView vMap, |
77 |
GeoreferencingView vRaster, |
78 |
GeoreferencingView zMap, |
79 |
GeoreferencingView zRaster, |
80 |
PagedTable table) { |
81 |
viewRaster = vRaster; |
82 |
viewMap = vMap; |
83 |
zoomMap = zMap; |
84 |
zoomRaster = zRaster; |
85 |
gcpSync.setViews(vMap, vRaster, zMap, zRaster, table); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Asigna los gestores de peticiones.
|
90 |
* @param vRaster
|
91 |
* @param vMap
|
92 |
* @param zRaster
|
93 |
* @param zMap
|
94 |
*/
|
95 |
public void setRequestsManager( |
96 |
IViewRequestManager vMap, |
97 |
IViewRequestManager vRaster, |
98 |
IViewRequestManager zMap, |
99 |
IViewRequestManager zRaster) { |
100 |
viewRasterRequestManager = vRaster; |
101 |
viewMapRequestManager= vMap; |
102 |
zoomRasterRequestManager = zRaster; |
103 |
zoomMapRequestManager = zMap; |
104 |
gcpSync.setRequestsManager(vRaster, vMap, zRaster, zMap); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Disables all tools in all views
|
109 |
* @param enable
|
110 |
*/
|
111 |
public void disableAllTools() { |
112 |
if(zoomMap != null) |
113 |
((BaseViewPanel)zoomMap).disableAllTools(); |
114 |
if(zoomRaster != null) |
115 |
((BaseViewPanel)zoomRaster).disableAllTools(); |
116 |
if(viewRaster != null) |
117 |
((BaseViewPanel)viewRaster).disableAllTools(); |
118 |
if(viewMap != null) |
119 |
((BaseViewPanel)viewMap).disableAllTools(); |
120 |
setActiveLayerPoints(false);
|
121 |
controlPanel.getDragPointButton().setSelected(false);
|
122 |
controlPanel.getMovePointButton().setSelected(false);
|
123 |
} |
124 |
|
125 |
public void disableTool(int tool) { |
126 |
if(tool == GeoreferencingSwingLibrary.MOVE_POINT_TOOL)
|
127 |
tool = GeoreferencingSwingLibrary.SELECT_POINT_TOOL; |
128 |
if(zoomMap != null) |
129 |
((BaseViewPanel)zoomMap).disableTool(tool); |
130 |
if(zoomRaster != null) |
131 |
((BaseViewPanel)zoomRaster).disableTool(tool); |
132 |
if(viewRaster != null) |
133 |
((BaseViewPanel)viewRaster).disableTool(tool); |
134 |
if(viewMap != null) |
135 |
((BaseViewPanel)viewMap).disableTool(tool); |
136 |
if(tool == GeoreferencingSwingLibrary.DRAG_POINT_TOOL) {
|
137 |
controlPanel.getDragPointButton().setSelected(false);
|
138 |
setActiveLayerPoints(false);
|
139 |
} |
140 |
if(tool == GeoreferencingSwingLibrary.SELECT_POINT_TOOL) {
|
141 |
controlPanel.getMovePointButton().setSelected(false);
|
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Asigna el panel con la tabla
|
147 |
* @param tablePanel
|
148 |
*/
|
149 |
public void setGeoPointList(GCPList gpList) { |
150 |
this.gpList = gpList;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Desactiva la tool activa de las vistas
|
155 |
* @param active
|
156 |
*/
|
157 |
public void sleepActiveTools() { |
158 |
if(zoomMap != null) |
159 |
((BaseViewPanel)zoomMap).getControl().sleepTools(); |
160 |
if(zoomRaster != null) |
161 |
((BaseViewPanel)zoomRaster).getControl().sleepTools(); |
162 |
if(viewRaster != null) |
163 |
((BaseViewPanel)viewRaster).getControl().sleepTools(); |
164 |
if(viewMap != null) |
165 |
((BaseViewPanel)viewMap).getControl().sleepTools(); |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Activa la tool activa de las vistas
|
170 |
* @param active
|
171 |
*/
|
172 |
public void awakeActiveTools() { |
173 |
if(zoomMap != null) |
174 |
((BaseViewPanel)zoomMap).getControl().awakeTools(); |
175 |
if(zoomRaster != null) |
176 |
((BaseViewPanel)zoomRaster).getControl().awakeTools(); |
177 |
if(viewRaster != null) |
178 |
((BaseViewPanel)viewRaster).getControl().awakeTools(); |
179 |
if(viewMap != null) |
180 |
((BaseViewPanel)viewMap).getControl().awakeTools(); |
181 |
} |
182 |
|
183 |
public void enableTool(int tool) { |
184 |
if(tool == GeoreferencingSwingLibrary.MOVE_POINT_TOOL)
|
185 |
tool = GeoreferencingSwingLibrary.SELECT_POINT_TOOL; |
186 |
if(zoomMap != null) |
187 |
((BaseViewPanel)zoomMap).enableTool(tool); |
188 |
if(zoomRaster != null) |
189 |
((BaseViewPanel)zoomRaster).enableTool(tool); |
190 |
if(viewRaster != null) |
191 |
((BaseViewPanel)viewRaster).enableTool(tool); |
192 |
if(viewMap != null) |
193 |
((BaseViewPanel)viewMap).enableTool(tool); |
194 |
if(tool == GeoreferencingSwingLibrary.DRAG_POINT_TOOL) {
|
195 |
controlPanel.getDragPointButton().setSelected(true);
|
196 |
setActiveLayerPoints(true);
|
197 |
} |
198 |
if(tool == GeoreferencingSwingLibrary.SELECT_POINT_TOOL) {
|
199 |
controlPanel.getMovePointButton().setSelected(true);
|
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Selecciona o deselecciona la tool de selecci?n de punto para cada vista
|
205 |
* @param true para activar y false para desactivar
|
206 |
*/
|
207 |
/*public void selectPointTool(boolean select) {
|
208 |
if(zoomMap != null)
|
209 |
((BaseZoomView)zoomMap).getControl().selectTool(SelectCoordOnViewTool.class, select);
|
210 |
if(zoomRaster != null)
|
211 |
((BaseZoomView)zoomRaster).getControl().selectTool(SelectCoordOnViewTool.class, select);
|
212 |
if(viewRaster != null)
|
213 |
((BaseZoomView)viewRaster).getControl().selectTool(SelectCoordOnViewTool.class, select);
|
214 |
if(viewMap != null)
|
215 |
((BaseZoomView)viewMap).getControl().selectTool(SelectCoordOnViewTool.class, select);
|
216 |
}*/
|
217 |
|
218 |
/**
|
219 |
* Asigna el color de los gr?ficos.
|
220 |
* @param c
|
221 |
*/
|
222 |
public void setGraphicsColor(Color c) { |
223 |
if(viewRaster != null && viewRaster instanceof ViewPanelImpl) { |
224 |
viewRaster.getCanvas().setTextColor(c); |
225 |
((ViewPanelImpl)viewRaster).getZoomCursorGraphicLayer().setColor(c); |
226 |
} |
227 |
if(viewMap != null && viewRaster instanceof ViewPanelImpl) { |
228 |
viewMap.getCanvas().setTextColor(c); |
229 |
((ViewPanelImpl)viewMap).getZoomCursorGraphicLayer().setColor(c); |
230 |
} |
231 |
if(zoomRaster != null) |
232 |
zoomRaster.getCanvas().setTextColor(c); |
233 |
if(zoomMap != null) |
234 |
zoomMap.getCanvas().setTextColor(c); |
235 |
} |
236 |
|
237 |
/**
|
238 |
* Asigna el color de los gr?ficos.
|
239 |
* @param c
|
240 |
*/
|
241 |
public void setBackgroundColor(Color c) { |
242 |
if(viewMapRequestManager != null) |
243 |
viewMapRequestManager.setBackGroundColor(c); |
244 |
if(viewRasterRequestManager != null) |
245 |
viewRasterRequestManager.setBackGroundColor(c); |
246 |
if(zoomMapRequestManager != null) |
247 |
zoomMapRequestManager.setBackGroundColor(c); |
248 |
if(zoomRasterRequestManager != null) |
249 |
zoomRasterRequestManager.setBackGroundColor(c); |
250 |
try {
|
251 |
if(viewRaster != null) { |
252 |
viewRaster.getCanvas().setBackgroundColor(c); |
253 |
viewRaster.getCanvas().setForceRequest(true);
|
254 |
((BaseViewPanel)viewRaster).getControl().getExtensionRequest().request(viewRaster.getCanvas().getExtent()); |
255 |
} |
256 |
if(viewMap != null) { |
257 |
viewMap.getCanvas().setBackgroundColor(c); |
258 |
viewMap.getCanvas().setForceRequest(true);
|
259 |
((BaseViewPanel)viewMap).getControl().getExtensionRequest().request(viewMap.getCanvas().getExtent()); |
260 |
} |
261 |
if(zoomRaster != null) { |
262 |
zoomRaster.getCanvas().setBackgroundColor(c); |
263 |
zoomRaster.getCanvas().setForceRequest(true);
|
264 |
((BaseViewPanel)zoomRaster).getControl().getExtensionRequest().request(zoomRaster.getCanvas().getExtent()); |
265 |
} |
266 |
if(zoomMap != null) { |
267 |
zoomMap.getCanvas().setBackgroundColor(c); |
268 |
zoomMap.getCanvas().setForceRequest(true);
|
269 |
((BaseViewPanel)zoomMap).getControl().getExtensionRequest().request(zoomMap.getCanvas().getExtent()); |
270 |
} |
271 |
} catch (InvalidRequestException e) {
|
272 |
} |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Centra las vistas sobre el punto pasado por par?metro
|
277 |
* @param n N?mero de punto sobre el que se centrar? la visualizaci?n
|
278 |
*/
|
279 |
public void centerToPoint(int n) { |
280 |
if(gpList.size() <= 0) { |
281 |
GeoreferencingSwingImplLibrary.messageBoxError("no_selected_point", null); |
282 |
return;
|
283 |
} |
284 |
|
285 |
GeoPoint gp = gpList.getGeoPoint(n); |
286 |
double xMap = gp.getMapPoint().getX();
|
287 |
double yMap = gp.getMapPoint().getY();
|
288 |
double xRaster = gp.getPixelPoint().getX();
|
289 |
double yRaster = gp.getPixelPoint().getY();
|
290 |
|
291 |
if(viewRaster != null && viewRaster instanceof ViewPanelImpl) |
292 |
((ViewPanelImpl)viewRaster).setCenter(new Point2D.Double(xRaster, yRaster)); |
293 |
if(zoomRaster != null) |
294 |
((BaseViewPanel)zoomRaster).getControl().setCenter(new Point2D.Double(xRaster, yRaster)); |
295 |
if(viewMap != null && viewMap instanceof ViewPanelImpl) |
296 |
((ViewPanelImpl)viewMap).setCenter(new Point2D.Double(xMap, yMap)); |
297 |
if(zoomMap != null) |
298 |
((BaseViewPanel)zoomMap).getControl().setCenter(new Point2D.Double(xMap, yMap)); |
299 |
} |
300 |
|
301 |
/**
|
302 |
* Obtiene la vista con el mapa de referencia
|
303 |
* @return ViewDialog
|
304 |
*/
|
305 |
public GeoreferencingView getViewMap() {
|
306 |
return viewMap;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Obtiene la vista con el raster a georreferenciar
|
311 |
* @return ViewDialog
|
312 |
*/
|
313 |
public GeoreferencingView getViewRaster() {
|
314 |
return viewRaster;
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* Obtiene la vista con el zoom del mapa de referencia
|
319 |
* @return ZoomMapDialog
|
320 |
*/
|
321 |
public GeoreferencingView getZoomMap() {
|
322 |
return zoomMap;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Obtiene la vista con el zoom del raster a georreferenciar
|
327 |
* @return ZoomRasterDialog
|
328 |
*/
|
329 |
public GeoreferencingView getZoomRaster() {
|
330 |
return zoomRaster;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* Obtiene el gestor de la vista con la cartograf?a de referencia
|
335 |
* @return ViewMapRequestManager
|
336 |
*/
|
337 |
public IViewRequestManager getViewMapRequestManager() {
|
338 |
return viewMapRequestManager;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Obtiene el gestor de la vista con el raster a georreferenciar
|
343 |
* @return ViewRasterRequestManager
|
344 |
*/
|
345 |
public IViewRequestManager getViewRasterRequestManager() {
|
346 |
return viewRasterRequestManager;
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Obtiene el gestor de la vista zoom con la cartograf?a de referencia
|
351 |
* @return ViewMapRequestManager
|
352 |
*/
|
353 |
public IViewRequestManager getZoomMapRequestManager() {
|
354 |
return zoomMapRequestManager;
|
355 |
} |
356 |
|
357 |
/**
|
358 |
* Obtiene el gestor de la vista zoom con el raster
|
359 |
* @return ViewRasterRequestManager
|
360 |
*/
|
361 |
public IViewRequestManager getZoomRasterRequestManager() {
|
362 |
return zoomRasterRequestManager;
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* Activa o desactiva la capa de puntos
|
367 |
* @param active
|
368 |
*/
|
369 |
public void setActiveLayerZoomCursor(boolean active) { |
370 |
gcpSync.setActiveLayerZoomCursor(active); |
371 |
} |
372 |
|
373 |
/**
|
374 |
* Activa y desactiva los n?meros de punto de las capas gr?ficas
|
375 |
* @param active
|
376 |
*/
|
377 |
public void setActiveNumberPoint(boolean active) { |
378 |
gcpSync.setActiveNumberPoint(active); |
379 |
} |
380 |
|
381 |
/**
|
382 |
* Activa o desactiva la capa de puntos
|
383 |
* @param active
|
384 |
*/
|
385 |
public void setActiveLayerPoints(boolean active) { |
386 |
gcpSync.setActiveLayerPoints(active); |
387 |
} |
388 |
|
389 |
/**
|
390 |
* Recalcula las coordenadas de dibujado de los puntos de control
|
391 |
* y redibuja estos en todas las vistas
|
392 |
*/
|
393 |
public void redrawPoints() { |
394 |
gcpSync.redrawPoints(); |
395 |
} |
396 |
|
397 |
public void removePoint(int position) { |
398 |
gcpSync.removePoint(position); |
399 |
} |
400 |
|
401 |
public void removeAllPoints() { |
402 |
gcpSync.removeAllPoints(); |
403 |
} |
404 |
|
405 |
/**
|
406 |
* Asigna la numeraci?n a los puntos de control. Tanto a la tabla como
|
407 |
* a los GeoPuntos
|
408 |
* @throws NotInitializeException
|
409 |
*/
|
410 |
public void calcPointsNumeration() { |
411 |
gcpSync.calcPointsNumeration(); |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Obtiene un punto (GeoPoint) a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
416 |
* punto puede no coincidir con su posici?n en el array.
|
417 |
* @return GeoPoint
|
418 |
*/
|
419 |
public GeoPoint getPointByNumber(int number) { |
420 |
return gcpSync.getPointByNumber(number);
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* Obtiene la posici?n de un punto a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
425 |
* punto puede no coincidir con su posici?n en el array.
|
426 |
* @return entero con la posici?n o -1 si no existe
|
427 |
*/
|
428 |
public int getPointPositionByNumber(int number) { |
429 |
return gcpSync.getPointPositionByNumber(number);
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* Activa o desactiva la visualizaci?n de un punto.
|
434 |
* @param active true para activarlo y false para desactivarlo
|
435 |
* @param position Posici?n del punto
|
436 |
*/
|
437 |
public void setVisiblePoint(boolean visible, int position) { |
438 |
gcpSync.setVisiblePoint(visible, position); |
439 |
} |
440 |
|
441 |
/**
|
442 |
* Asigna las coordenadas del mundo real y raster al punto indicado en el par?metro.
|
443 |
* @param point Punto a asignar las nuevas coordenadas
|
444 |
* @param xMap Coordenada real en X
|
445 |
* @param yMap Coordenada real en Y
|
446 |
* @param xRaster Coordenada pixel en X
|
447 |
* @param yRaster Coordenada pixel en Y
|
448 |
*/
|
449 |
public void setCoordinates(int point, double xMap, double yMap, double xRaster, double yRaster) { |
450 |
gcpSync.setCoordinates(point, xMap, yMap, xRaster, yRaster); |
451 |
} |
452 |
|
453 |
/**
|
454 |
* A?ade un punto a las capas gr?ficas
|
455 |
* @param map Coordenadas del mapa del punto
|
456 |
* @param raster Coordenadas pixel del punto
|
457 |
* @return identificador del punto a?adido
|
458 |
*/
|
459 |
public long addPoint(Point2D map, Point2D raster) { |
460 |
return gcpSync.addPoint(map, raster);
|
461 |
} |
462 |
|
463 |
public void setControlPanel(GeorefControlPanel control) { |
464 |
this.controlPanel = control;
|
465 |
} |
466 |
} |