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 / SynchronizedViewsImpl.java @ 1711
History | View | Annotate | Download (15.8 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.geom.Point2D; |
22 |
import java.util.ArrayList; |
23 |
import java.util.List; |
24 |
|
25 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
26 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
27 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
28 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GCPsGraphicLayer; |
29 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GPGraphic; |
30 |
import org.gvsig.raster.georeferencing.swing.impl.tool.PanTool; |
31 |
import org.gvsig.raster.georeferencing.swing.impl.tool.SelectPointTool; |
32 |
import org.gvsig.raster.georeferencing.swing.impl.tool.ZoomRectangleTool; |
33 |
import org.gvsig.raster.georeferencing.swing.impl.view.ViewPanelImpl; |
34 |
import org.gvsig.raster.georeferencing.swing.impl.view.ZoomPanelImpl; |
35 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
36 |
import org.gvsig.raster.georeferencing.swing.view.IGraphicLayer; |
37 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
38 |
import org.gvsig.raster.georeferencing.swing.view.ToolListener; |
39 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
40 |
|
41 |
/**
|
42 |
* Clase para realizar operaciones y mantener la sincronizaci?n entre las
|
43 |
* capas de puntos de las dos vistas y las dos ventanas de zoom.
|
44 |
*
|
45 |
* 04/02/2008
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class SynchronizedViewsImpl implements SynchronizedViews { |
49 |
private ToolListener toolListener = null; |
50 |
//Vistas
|
51 |
private ViewPanelImpl viewRaster = null; |
52 |
private ViewPanelImpl viewMap = null; |
53 |
private ZoomPanelImpl zoomMap = null; |
54 |
private ZoomPanelImpl zoomRaster = null; |
55 |
|
56 |
//Capas de puntos
|
57 |
private GCPsGraphicLayer viewRasterGCPs = null; |
58 |
private GCPsGraphicLayer viewMapGCPs = null; |
59 |
private GCPsGraphicLayer viewRasterGCPsZoom = null; |
60 |
private GCPsGraphicLayer viewMapGCPsZoom = null; |
61 |
|
62 |
//Herramientas de selecci?n
|
63 |
private SelectPointTool viewRasterSelectPointTool = null; |
64 |
private SelectPointTool viewMapSelectPointTool = null; |
65 |
private SelectPointTool zoomRasterSelectPointTool = null; |
66 |
private SelectPointTool zoomMapSelectPointTool = null; |
67 |
private PagedTable table = null; |
68 |
|
69 |
public SynchronizedViewsImpl(ToolListener listener) {
|
70 |
this.toolListener = listener;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Asigna las vistas
|
75 |
* @param vRaster
|
76 |
* @param vMap
|
77 |
* @param zRaster
|
78 |
* @param zMap
|
79 |
*/
|
80 |
public void setViews( |
81 |
GeoreferencingView vRaster, |
82 |
GeoreferencingView vMap, |
83 |
GeoreferencingView zRaster, |
84 |
GeoreferencingView zMap, |
85 |
PagedTable table) { |
86 |
this.table = table;
|
87 |
viewRaster = (ViewPanelImpl)vRaster; |
88 |
viewMap = (ViewPanelImpl)vMap; |
89 |
zoomMap = (ZoomPanelImpl)zMap; |
90 |
zoomRaster = (ZoomPanelImpl)zRaster; |
91 |
if(zoomRaster != null) |
92 |
zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), toolListener);
|
93 |
if(zoomMap != null) |
94 |
zoomMapSelectPointTool = new SelectPointTool(zoomMap.getCanvas(), toolListener);
|
95 |
if(viewRaster != null) |
96 |
viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), toolListener);
|
97 |
if(viewMap != null) |
98 |
viewMapSelectPointTool = new SelectPointTool(viewMap.getCanvas(), toolListener);
|
99 |
createGCPLayers(); |
100 |
registerPointToolListener(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Asigna las capas de puntos
|
105 |
* @param vRaster
|
106 |
* @param vMap
|
107 |
* @param zRaster
|
108 |
* @param zMap
|
109 |
*/
|
110 |
public void setLayerPoints( |
111 |
IGraphicLayer vRaster, |
112 |
IGraphicLayer vMap, |
113 |
IGraphicLayer zRaster, |
114 |
IGraphicLayer zMap) { |
115 |
viewRasterGCPs = (GCPsGraphicLayer)vRaster; |
116 |
viewMapGCPs = (GCPsGraphicLayer)vMap; |
117 |
viewRasterGCPsZoom = (GCPsGraphicLayer)zRaster; |
118 |
viewMapGCPsZoom = (GCPsGraphicLayer)zMap; |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Activa o desactiva la capa de puntos
|
123 |
* @param active
|
124 |
*/
|
125 |
public void setActiveLayerZoomCursor(boolean active) { |
126 |
if(viewRaster != null && viewRaster.getZoomCursorGraphicLayer() != null) |
127 |
viewRaster.getZoomCursorGraphicLayer().setActive(active); |
128 |
if(viewMap != null && viewMap.getZoomCursorGraphicLayer() != null) |
129 |
viewMap.getZoomCursorGraphicLayer().setActive(active); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Recalcula las coordenadas de dibujado de los puntos de control
|
134 |
* y redibuja estos en todas las vistas
|
135 |
*/
|
136 |
public void redrawPoints() { |
137 |
if(viewMapGCPs != null) |
138 |
viewMapGCPs.recalcMapDrawCoordinates(); |
139 |
if(viewRasterGCPs != null) |
140 |
viewRasterGCPs.recalcPixelDrawCoordinates(); |
141 |
if(viewMapGCPsZoom != null) |
142 |
viewMapGCPsZoom.recalcMapDrawCoordinates(); |
143 |
if(viewRasterGCPsZoom != null) |
144 |
viewRasterGCPsZoom.recalcPixelDrawCoordinates(); |
145 |
repaint(); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Redibuja el canvas de todas las vistas
|
150 |
*/
|
151 |
private void repaint() { |
152 |
if(viewRaster != null) |
153 |
viewRaster.getCanvas().repaint(); |
154 |
if(viewMap != null) |
155 |
viewMap.getCanvas().repaint(); |
156 |
if(zoomMap != null) |
157 |
zoomMap.getCanvas().repaint(); |
158 |
if(zoomRaster != null) |
159 |
zoomRaster.getCanvas().repaint(); |
160 |
} |
161 |
|
162 |
/**
|
163 |
* Registra el listener para la herramienta de selecci?n de puntos de control
|
164 |
*/
|
165 |
public void registerPointToolListener() { |
166 |
if(zoomMap != null) { |
167 |
zoomMapSelectPointTool.setActive(false);
|
168 |
zoomMap.getControl().addTool(zoomMapSelectPointTool); |
169 |
zoomMap.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
170 |
zoomMap.getControl().registerToolListener(PanTool.class, toolListener); |
171 |
} |
172 |
if(zoomRaster != null) { |
173 |
zoomRasterSelectPointTool.setActive(false);
|
174 |
zoomRaster.getControl().addTool(zoomRasterSelectPointTool); |
175 |
zoomRaster.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
176 |
zoomRaster.getControl().registerToolListener(PanTool.class, toolListener); |
177 |
} |
178 |
if(viewRaster != null) { |
179 |
viewRasterSelectPointTool.setActive(false);
|
180 |
viewRaster.getControl().addTool(viewRasterSelectPointTool); |
181 |
viewRaster.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
182 |
viewRaster.getControl().registerToolListener(PanTool.class, toolListener); |
183 |
} |
184 |
if(viewMap != null) { |
185 |
viewMapSelectPointTool.setActive(false);
|
186 |
viewMap.getControl().addTool(viewMapSelectPointTool); |
187 |
viewMap.getControl().registerToolListener(ZoomRectangleTool.class, toolListener); |
188 |
viewMap.getControl().registerToolListener(PanTool.class, toolListener); |
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* A?ade un punto a las capas gr?ficas
|
194 |
* @param map Coordenadas del mapa del punto
|
195 |
* @param raster Coordenadas pixel del punto
|
196 |
* @return identificador del punto a?adido
|
197 |
*/
|
198 |
public long addPoint(Point2D map, Point2D raster) { |
199 |
GeoPoint gp = RasterLocator.getManager().getDataStructFactory().createGeoPoint(raster, map); |
200 |
long id = System.currentTimeMillis(); |
201 |
System.out.println(id);
|
202 |
//Esperamos al menos 5 ms para que la carga de los puntos no sea
|
203 |
//tan r?pida que coincida el id de dos puntos
|
204 |
try {
|
205 |
Thread.sleep(80); |
206 |
} catch (InterruptedException e) { |
207 |
} |
208 |
if(viewRasterGCPs != null) |
209 |
viewRasterGCPs.addPixelGeoPoint(gp, id); |
210 |
if(viewMapGCPs != null) |
211 |
viewMapGCPs.addMapGeoPoint(gp, id); |
212 |
if(viewRasterGCPsZoom != null) |
213 |
viewRasterGCPsZoom.addPixelGeoPoint(gp, id); |
214 |
if(viewMapGCPsZoom != null) |
215 |
viewMapGCPsZoom.addMapGeoPoint(gp, id); |
216 |
return id;
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* Elimina todos los puntos gr?ficos de las capas
|
221 |
*
|
222 |
*/
|
223 |
public void removeAllPoints() { |
224 |
if(viewRasterGCPs != null) |
225 |
viewRasterGCPs.removeAllPoints(); |
226 |
if(viewMapGCPs != null) |
227 |
viewMapGCPs.removeAllPoints(); |
228 |
if(viewRasterGCPsZoom != null) |
229 |
viewRasterGCPsZoom.removeAllPoints(); |
230 |
if(viewMapGCPsZoom != null) |
231 |
viewMapGCPsZoom.removeAllPoints(); |
232 |
} |
233 |
|
234 |
/**
|
235 |
* Asigna las coordenadas del mundo real y raster al punto indicado en el par?metro.
|
236 |
* @param point Punto a asignar las nuevas coordenadas
|
237 |
* @param xMap Coordenada real en X
|
238 |
* @param yMap Coordenada real en Y
|
239 |
* @param xRaster Coordenada pixel en X
|
240 |
* @param yRaster Coordenada pixel en Y
|
241 |
*/
|
242 |
public void setCoordinates(int point, double xMap, double yMap, double xRaster, double yRaster) { |
243 |
setXMapCoordinate(point, xMap); |
244 |
setYMapCoordinate(point, yMap); |
245 |
setXRasterCoordinate(point, xRaster); |
246 |
setYRasterCoordinate(point, yRaster); |
247 |
redrawPoints(); |
248 |
} |
249 |
|
250 |
/**
|
251 |
* Asigna la coordenada del mundo real X
|
252 |
* @param point
|
253 |
* @param xMap
|
254 |
*/
|
255 |
public void setXMapCoordinate(int point, double xMap) { |
256 |
double oldMapY = viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().getY();
|
257 |
viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().setLocation(xMap, oldMapY); |
258 |
} |
259 |
|
260 |
/**
|
261 |
* Asigna la coordenada del mundo real Y
|
262 |
* @param point
|
263 |
* @param yMap
|
264 |
*/
|
265 |
public void setYMapCoordinate(int point, double yMap) { |
266 |
double oldMapX = viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().getX();
|
267 |
viewRasterGCPs.getPoint(point).getGeoPoint().getMapPoint().setLocation(oldMapX, yMap); |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Asigna la coordenada raster X
|
272 |
* @param point
|
273 |
* @param xRaster
|
274 |
*/
|
275 |
public void setXRasterCoordinate(int point, double xRaster) { |
276 |
double oldRasterY = viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().getY();
|
277 |
viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().setLocation(xRaster, oldRasterY); |
278 |
} |
279 |
|
280 |
/**
|
281 |
* Asigna la coordenada raster Y
|
282 |
* @param point
|
283 |
* @param xRaster
|
284 |
*/
|
285 |
public void setYRasterCoordinate(int point, double yRaster) { |
286 |
double oldRasterX = viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().getX();
|
287 |
viewRasterGCPs.getPoint(point).getGeoPoint().getPixelPoint().setLocation(oldRasterX, yRaster); |
288 |
} |
289 |
|
290 |
/**
|
291 |
* Elimina un punto de la lista a partir de su posici?n
|
292 |
* @param position
|
293 |
*/
|
294 |
public void removePoint(int position) { |
295 |
if(viewRasterGCPs != null) |
296 |
viewRasterGCPs.removePixelGeoPoint(position); |
297 |
if(viewMapGCPs != null) |
298 |
viewMapGCPs.removePixelGeoPoint(position); |
299 |
if(viewRasterGCPsZoom != null) |
300 |
viewRasterGCPsZoom.removePixelGeoPoint(position); |
301 |
if(viewMapGCPsZoom != null) |
302 |
viewMapGCPsZoom.removePixelGeoPoint(position); |
303 |
} |
304 |
|
305 |
/**
|
306 |
* Informa de si la tool de selecci?n de puntos est? activa o no
|
307 |
* @return true si est? activa y false si no lo est?
|
308 |
*/
|
309 |
public boolean isSelectPointToolSelected() { |
310 |
if(viewRaster != null) |
311 |
if(viewRaster.getControl().getToolSelected() instanceof SelectPointTool) |
312 |
return true; |
313 |
return false; |
314 |
} |
315 |
|
316 |
/**
|
317 |
* Obtiene la lista de puntos
|
318 |
* @return ArrayList
|
319 |
*/
|
320 |
public List<GPGraphic> getPointList() { |
321 |
if(viewRasterGCPs != null) |
322 |
return viewRasterGCPs.getPointList();
|
323 |
return null; |
324 |
} |
325 |
|
326 |
/**
|
327 |
* Obtiene un array con la lista de puntos
|
328 |
* @return
|
329 |
*/
|
330 |
public List<GeoPoint> getGeoPoints() { |
331 |
List<GPGraphic> pointList = getPointList();
|
332 |
List<GeoPoint> geoPointList = new ArrayList<GeoPoint>(); |
333 |
for (int i = 0; i < pointList.size(); i++) |
334 |
geoPointList.add(((GPGraphic) pointList.get(i)).getGeoPoint()); |
335 |
return geoPointList;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* Activa o desactiva la visualizaci?n de un punto.
|
340 |
* @param active true para activarlo y false para desactivarlo
|
341 |
* @param position Posici?n del punto
|
342 |
*/
|
343 |
public void setVisiblePoint(boolean visible, int position) { |
344 |
if(viewRasterGCPs != null) |
345 |
((GPGraphic)viewRasterGCPs.getPointList().get(position)).setDraw(visible); |
346 |
if(viewMapGCPs != null) |
347 |
((GPGraphic)viewMapGCPs.getPointList().get(position)).setDraw(visible); |
348 |
if(viewRasterGCPsZoom != null) |
349 |
((GPGraphic)viewRasterGCPsZoom.getPointList().get(position)).setDraw(visible); |
350 |
if(viewMapGCPsZoom != null) |
351 |
((GPGraphic)viewMapGCPsZoom.getPointList().get(position)).setDraw(visible); |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Asigna la numeraci?n a los puntos de control. Tanto a la tabla como
|
356 |
* a los GeoPuntos
|
357 |
* @throws NotInitializeException
|
358 |
*/
|
359 |
public void calcPointsNumeration() throws NotInitializeException { |
360 |
List<GPGraphic> pointList = getPointList();
|
361 |
|
362 |
for (int i = 0; i < table.getRowCount(); i++) { |
363 |
table.setValueAt(new Integer(i), i, 1); |
364 |
long id = (long)((Long)table.getValueAt(i, table.getColumnCount() - 1)).longValue(); |
365 |
|
366 |
if(i < pointList.size()) {
|
367 |
for (int j = 0; j < pointList.size(); j++) { |
368 |
GPGraphic gpg = ((GPGraphic)pointList.get(j)); |
369 |
if(id == gpg.getId()) {
|
370 |
((GPGraphic)pointList.get(j)).getGeoPoint().setNumber(i); |
371 |
break;
|
372 |
} |
373 |
} |
374 |
} |
375 |
} |
376 |
redrawPoints(); |
377 |
} |
378 |
|
379 |
public void createGCPLayers() { |
380 |
if(viewRaster != null) { |
381 |
viewRasterGCPs = new GCPsGraphicLayer(GPGraphic.PIXEL, toolListener);
|
382 |
viewRasterGCPs.setCanvas(viewRaster.getCanvas()); |
383 |
viewRaster.addGraphicLayer(viewRasterGCPs); |
384 |
//viewRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPs);
|
385 |
} |
386 |
|
387 |
if(zoomRaster != null) { |
388 |
viewRasterGCPsZoom = new GCPsGraphicLayer(GPGraphic.PIXEL, toolListener);
|
389 |
viewRasterGCPsZoom.setCanvas(zoomRaster.getCanvas()); |
390 |
zoomRaster.addGraphicLayer(viewRasterGCPsZoom); |
391 |
//zoomRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPsZoom);
|
392 |
} |
393 |
|
394 |
if(viewMap != null) { |
395 |
viewMapGCPs = new GCPsGraphicLayer(GPGraphic.MAP, toolListener);
|
396 |
viewMapGCPs.setCanvas(viewMap.getCanvas()); |
397 |
viewMap.addGraphicLayer(viewMapGCPs); |
398 |
//viewMapRequestManager.setGCPsGraphicLayer(viewMapGCPs);
|
399 |
} |
400 |
|
401 |
if(zoomMap != null) { |
402 |
viewMapGCPsZoom = new GCPsGraphicLayer(GPGraphic.MAP, toolListener);
|
403 |
viewMapGCPsZoom.setCanvas(zoomMap.getCanvas()); |
404 |
zoomMap.addGraphicLayer(viewMapGCPsZoom); |
405 |
//zoomMapRequestManager.setGCPsGraphicLayer(viewMapGCPsZoom);
|
406 |
} |
407 |
} |
408 |
|
409 |
/**
|
410 |
* Activa y desactiva los n?meros de punto de las capas gr?ficas
|
411 |
* @param active
|
412 |
*/
|
413 |
public void setActiveNumberPoint(boolean active) { |
414 |
if(viewMapGCPs != null) |
415 |
viewMapGCPs.setShowNumber(active); |
416 |
if(viewRasterGCPs != null) |
417 |
viewRasterGCPs.setShowNumber(active); |
418 |
if(viewMapGCPsZoom != null) |
419 |
viewMapGCPsZoom.setShowNumber(active); |
420 |
if(viewRasterGCPsZoom != null) |
421 |
viewRasterGCPsZoom.setShowNumber(active); |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Activa o desactiva la capa de puntos
|
426 |
* @param active
|
427 |
*/
|
428 |
public void setActiveLayerPoints(boolean active) { |
429 |
if(viewRasterGCPs != null) |
430 |
viewRasterGCPs.setActive(active); |
431 |
if(viewMapGCPs != null) |
432 |
viewMapGCPs.setActive(active); |
433 |
if(viewRasterGCPsZoom != null) |
434 |
viewRasterGCPsZoom.setActive(active); |
435 |
if(viewMapGCPsZoom != null) |
436 |
viewMapGCPsZoom.setActive(active); |
437 |
} |
438 |
|
439 |
/**
|
440 |
* Obtiene un punto (GeoPoint) a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
441 |
* punto puede no coincidir con su posici?n en el array.
|
442 |
* @return GeoPoint
|
443 |
*/
|
444 |
public GeoPoint getPointByNumber(int number) { |
445 |
List<GPGraphic> pointList = getPointList();
|
446 |
for (int i = 0; i < pointList.size(); i++) { |
447 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
448 |
if(p.getNumber() == number)
|
449 |
return p;
|
450 |
} |
451 |
return null; |
452 |
} |
453 |
|
454 |
/**
|
455 |
* Obtiene la posici?n de un punto a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
456 |
* punto puede no coincidir con su posici?n en el array.
|
457 |
* @return entero con la posici?n o -1 si no existe
|
458 |
*/
|
459 |
public int getPointPositionByNumber(int number) { |
460 |
List<GPGraphic> pointList = getPointList();
|
461 |
for (int i = 0; i < pointList.size(); i++) { |
462 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
463 |
if(p.getNumber() == number)
|
464 |
return i;
|
465 |
} |
466 |
return -1; |
467 |
} |
468 |
} |