svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / PointManager.java @ 5697
History | View | Annotate | Download (31.3 KB)
1 |
package org.gvsig.georeferencing.utils; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.geom.Point2D; |
5 |
import java.awt.geom.Rectangle2D; |
6 |
|
7 |
import javax.swing.JDesktopPane; |
8 |
import javax.swing.JInternalFrame; |
9 |
import javax.swing.JLayeredPane; |
10 |
import javax.swing.JOptionPane; |
11 |
import javax.xml.transform.TransformerException; |
12 |
|
13 |
import org.gvsig.georeferencing.GeoOperations; |
14 |
import org.gvsig.georeferencing.GeoreferencingToolsModule; |
15 |
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog; |
16 |
import org.gvsig.georeferencing.gui.listeners.GeoRasterFrameListener; |
17 |
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener; |
18 |
import org.gvsig.georeferencing.gui.panels.AdjustGeorefPanel; |
19 |
import org.gvsig.georeferencing.gui.panels.OptionsPanel; |
20 |
import org.gvsig.georeferencing.gui.panels.ZoomControlPanel; |
21 |
import org.gvsig.georeferencing.gui.pointsTable.ButtonsExportImportPanel; |
22 |
import org.gvsig.georeferencing.gui.pointsTable.TableControlerPanel; |
23 |
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel; |
24 |
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel.PointTable; |
25 |
import org.gvsig.georeferencing.gui.selectPoints.DataPointPanel; |
26 |
import org.gvsig.georeferencing.gui.selectPoints.ErrorPointPanel; |
27 |
import org.gvsig.georeferencing.gui.selectPoints.SelectPointsPanel; |
28 |
|
29 |
import com.iver.andami.PluginServices; |
30 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
31 |
import com.iver.cit.gvsig.fmap.ViewPort; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
34 |
import com.iver.cit.gvsig.fmap.layers.GeoPoint; |
35 |
import com.iver.cit.gvsig.fmap.layers.IGeoUi; |
36 |
import com.iver.cit.gvsig.gui.View; |
37 |
|
38 |
/**
|
39 |
* Gestor de puntos. Contiene metodos para a?adir. borrar, seleccionar,..
|
40 |
* puntos coordinando la capa de puntos y la visualizaci?n del interfaz
|
41 |
* gr?fico.
|
42 |
*
|
43 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
44 |
*
|
45 |
*/
|
46 |
public class PointManager{ |
47 |
|
48 |
//**********************Vars**********************************
|
49 |
private GeoreferencingDialog dialog = null; |
50 |
|
51 |
private SelectPointsPanel selectPointsPanel = null; |
52 |
private ErrorPointPanel errorPointPanel = null; |
53 |
private DataPointPanel dataPointPanel = null; |
54 |
private TableControlerPanel tableControlerPanel1 = null; |
55 |
|
56 |
private TablePointsPanel tablePointsPanel = null; |
57 |
private TableControlerPanel tableControlerPanel2 = null; |
58 |
private ButtonsExportImportPanel buttonsExportImportPanel = null; |
59 |
|
60 |
private OptionsPanel optionsPanel = null; |
61 |
private ZoomControlPanel zoomControlPanelLeft = null; |
62 |
private ZoomControlPanel zoomControlPanelRight = null; |
63 |
|
64 |
private FLyrPoints lyrPoints = null; |
65 |
private double currentMapX = 0D; |
66 |
private double currentMapY = 0D; |
67 |
private double currentPixelX = 0D; |
68 |
private double currentPixelY = 0D; |
69 |
private boolean disableAllControls = false; |
70 |
//**********************End Vars******************************
|
71 |
|
72 |
//**********************Methods*******************************
|
73 |
/**
|
74 |
* Constructor
|
75 |
*/
|
76 |
public PointManager(GeoreferencingDialog dialog, FLyrPoints flyrPoints){
|
77 |
this.dialog = dialog;
|
78 |
this.selectPointsPanel = dialog.getSelectPointsPanel();
|
79 |
this.errorPointPanel = dialog.getSelectPointsPanel().getErrorPointPanel();
|
80 |
this.dataPointPanel = dialog.getSelectPointsPanel().getDataPointPanel();
|
81 |
this.tableControlerPanel1 = dialog.getSelectPointsPanel().getTableControlerPanel();
|
82 |
this.tablePointsPanel = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel();
|
83 |
this.tableControlerPanel2 = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel();
|
84 |
this.buttonsExportImportPanel = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getPButtonsExportImportPanel();
|
85 |
this.optionsPanel = dialog.getConectorPanel().getAdjustGeorefPanel().getOptionsPanel();
|
86 |
this.zoomControlPanelLeft = dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft();
|
87 |
this.zoomControlPanelRight = dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight();
|
88 |
this.lyrPoints = flyrPoints;
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* Crea un nuevo punto vacio en la capa y lo a?ade al interfaz gr?fico para
|
93 |
* que puedan ser introducidas las coordenadas por el usuario
|
94 |
*/
|
95 |
public void newEmptyPoint(){ |
96 |
try{
|
97 |
//Antes de a?adir un nuevo pto compruba que los textField del anterior no est?n vacios
|
98 |
if(tableControlerPanel1.getItemCount() > 0) |
99 |
selectPointsPanel.checkInfoPointText(); |
100 |
|
101 |
//A?ade un punto vacio a la capa
|
102 |
lyrPoints.addPoint(null, null); |
103 |
|
104 |
//A?ade un punto al control de tabla y checkea la activaci?n de los botones
|
105 |
tableControlerPanel1.addPointToTable(lyrPoints.getCountPoints()); |
106 |
|
107 |
//Guardamos el ?ltimo punto seleccionado por si hay que recuperarlo
|
108 |
selectPointsPanel.setLastIndexSelection(lyrPoints.getCountPoints() - 1);
|
109 |
|
110 |
//resetea los controles de (del, delall, selectFromView y miniimagenes)
|
111 |
dialog.resetControls(true);
|
112 |
|
113 |
//Desactivamos los controles de las miniimagenes para que no capture los
|
114 |
//eventos hasta que no se hayan introducido los puntos
|
115 |
dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(false);
|
116 |
dialog.getConectorPanel().getAdjustGeorefPanel().setLZoomRight("1:");
|
117 |
dialog.getConectorPanel().getAdjustGeorefPanel().setLZoomLeft("1:");
|
118 |
|
119 |
}catch(NoSuchFieldException exc){ |
120 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
121 |
PluginServices.getText(this, "coordenadas_vacias")); |
122 |
} |
123 |
} |
124 |
|
125 |
/**
|
126 |
* A partir de nuevas coordenadas actualiza la vista, minimagen, capa de puntos el
|
127 |
* dialogo y la tabla.
|
128 |
*
|
129 |
*/
|
130 |
public void updateData(int nPunto, Point2D pixel, Point2D map, IGeoUi geoUI, View view){ |
131 |
dialog = (GeoreferencingDialog)geoUI; |
132 |
if(dialog == null) |
133 |
return;
|
134 |
if(pixel == null && map == null) |
135 |
return;
|
136 |
|
137 |
//Actualizamos los textBox
|
138 |
if(pixel != null) |
139 |
dialog.setPixelText(GeoUtils.tailDecimals(pixel.getX(), 2), GeoUtils.tailDecimals(pixel.getY(), 2)); |
140 |
//dialog.getSelectPointsPanel().lastTx = String.valueOf(pixel.getX());
|
141 |
//dialog.getSelectPointsPanel().lastTy = String.valueOf(pixel.getY());
|
142 |
|
143 |
if(map != null) |
144 |
dialog.setMapCoordText(map.getX(), map.getY()); |
145 |
//dialog.getSelectPointsPanel().lastLong = String.valueOf(map.getX());
|
146 |
//dialog.getSelectPointsPanel().lastLat = String.valueOf(map.getY());
|
147 |
|
148 |
|
149 |
//El Checkbox de activaci?n
|
150 |
GeoPoint gp = ((GeoPoint)lyrPoints.getPoint(nPunto - 1));
|
151 |
if(gp != null){ |
152 |
dataPointPanel.getCbActive().setSelected(gp.active); |
153 |
dialog.setEnabled(gp.active); |
154 |
} |
155 |
|
156 |
//Actualizamos la tabla
|
157 |
|
158 |
while(dialog.getTableRowCount() < nPunto)
|
159 |
dialog.addTableNew(); |
160 |
dialog.setTableValueAt(String.valueOf(nPunto), nPunto - 1, 0); |
161 |
|
162 |
if(pixel != null){ |
163 |
dialog.setTableValueAt(GeoUtils.tailDecimals(String.valueOf(pixel.getX()), 5), nPunto - 1, 1); |
164 |
dialog.setTableValueAt(GeoUtils.tailDecimals(String.valueOf(pixel.getY()), 5), nPunto - 1, 2); |
165 |
} |
166 |
if(map != null){ |
167 |
dialog.setTableValueAt(GeoUtils.tailDecimals(String.valueOf(map.getX()), 5), nPunto - 1, 3); |
168 |
dialog.setTableValueAt(GeoUtils.tailDecimals(String.valueOf(map.getY()), 5), nPunto - 1, 4); |
169 |
} |
170 |
|
171 |
//Actualizamos la capa de puntos
|
172 |
if(pixel != null || map != null) |
173 |
lyrPoints.updatePoint(pixel, map, nPunto - 1);
|
174 |
|
175 |
//Actualizamos la miniimagen
|
176 |
if(view != null){ |
177 |
ViewPort viewPort = view.getMapControl().getMapContext().getViewPort(); |
178 |
|
179 |
if(pixel != null){ |
180 |
dialog.getZoomControlLeft().setCenterPoint(lyrPoints.getLyrGeoRaster().img2World(pixel)); |
181 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setViewPort(viewPort, lyrPoints.getPoint(nPunto - 1).zoomLeft);
|
182 |
//Si est? extendido hacemos un draw corriente sino es q est? plegado y tocar? asignar el extent de la miniimagen
|
183 |
if(dialog.isEnlarge())
|
184 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
185 |
|
186 |
lyrPoints.setMiniExtent(nPunto - 1,
|
187 |
lyrPoints.getLyrGeoRaster().img2World(pixel), |
188 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().getCanvas().initViewPort(viewPort, lyrPoints.getLyrGeoRaster().img2World(pixel), null, 1), |
189 |
false);
|
190 |
} |
191 |
|
192 |
if(map != null){ |
193 |
dialog.getZoomControlRight().setCenterPoint(map); |
194 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setViewPort(viewPort, lyrPoints.getPoint(nPunto - 1).zoomRight);
|
195 |
//Si est? extendido hacemos un draw corriente sino es q est? plegado y tocar? asignar el extent de la miniimagen
|
196 |
if(dialog.isEnlarge())
|
197 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw(); |
198 |
|
199 |
lyrPoints.setMiniExtent(nPunto - 1,
|
200 |
map, |
201 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().getCanvas().initViewPort(viewPort, map, null, 1), |
202 |
true);
|
203 |
} |
204 |
|
205 |
//Actualizamos la vista
|
206 |
view.getMapControl().getMapContext().invalidate(); |
207 |
} |
208 |
|
209 |
//Calculamos los errores
|
210 |
try{
|
211 |
if(pixel != null || map != null) |
212 |
setErrors(nPunto - 1);
|
213 |
}catch(ArrayIndexOutOfBoundsException ex){ |
214 |
//Esta excepci?n ocurre despues de introducir el primer punto ya que map es null
|
215 |
//En este caso no hacemos nada y no se calcula el error
|
216 |
} |
217 |
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Al actualizar un punto debemos recalcular los errores RMS y Total para ello tenemos que
|
222 |
* pedir la transformaci?n de toda la lista de puntos. Esta funci?n calcula esta lista
|
223 |
* transformada y la asigna a un array en la capa de puntos. Esta funci?n tiene en cuenta
|
224 |
* que un punto puede estar inactivo.
|
225 |
*/
|
226 |
private void transformPointList(){ |
227 |
try{
|
228 |
GeoOperations go = new GeoOperations(lyrPoints);
|
229 |
Point2D[] pointList = new Point2D[lyrPoints.getCountActivePoints()]; |
230 |
int pActive = 0; |
231 |
for(int i=0; i< lyrPoints.getCountPoints(); i++){ |
232 |
if(lyrPoints.getPoint(i).active){
|
233 |
pointList[pActive] = lyrPoints.getPoint(i).pixelPoint; |
234 |
pActive ++; |
235 |
} |
236 |
} |
237 |
|
238 |
Point2D[] transformActivePointList = go.transformPoints(pointList); |
239 |
Point2D[] transformPointList = new Point2D[lyrPoints.getCountPoints()]; |
240 |
|
241 |
pActive = 0;
|
242 |
for(int i=0; i< lyrPoints.getCountPoints(); i++){ |
243 |
if(lyrPoints.getPoint(i).active){
|
244 |
transformPointList[i] = transformActivePointList[pActive]; |
245 |
pActive ++; |
246 |
}else
|
247 |
transformPointList[i] = null;
|
248 |
} |
249 |
|
250 |
lyrPoints.setTransformPointList(transformPointList); |
251 |
}catch(NullPointerException e){ |
252 |
//Si ocurre esta excepci?n es que se est? intentando incluir un punto que se acaba de crear
|
253 |
//y por lo tanto no tiene el valor asignado todavia por lo que es mejor no hacer nada
|
254 |
//y seguir con el proceso
|
255 |
} |
256 |
} |
257 |
|
258 |
/**
|
259 |
* Busca el punto en la capa FLyrPoint que corresponde con la posicion pos
|
260 |
* y carga la informaci?n de este en el panel de informaci?n pasado por par?metro.
|
261 |
* @param pos Posici?n del punto
|
262 |
* @param panel donde se carga la informaci?n
|
263 |
*/
|
264 |
public void selectPoint(int pos, GeoreferencingDialog dialog){ |
265 |
GeoPoint pto = null;
|
266 |
try{
|
267 |
pto = lyrPoints.getPoint(pos); |
268 |
if(pto == null) |
269 |
return;
|
270 |
}catch(ArrayIndexOutOfBoundsException exc){ |
271 |
//Todavia no hay puntos por lo que no hacemos nada
|
272 |
return;
|
273 |
} |
274 |
|
275 |
//Actualizamos el valor del combo
|
276 |
try{
|
277 |
tableControlerPanel1.getCPoint().setSelectedIndex(pos); |
278 |
}catch(IllegalArgumentException ex){} |
279 |
try{
|
280 |
tableControlerPanel2.getCPoint().setSelectedIndex(pos); |
281 |
}catch(IllegalArgumentException ex){} |
282 |
|
283 |
DataPointPanel dpp = dialog.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel(); |
284 |
|
285 |
//Llenamos los JTextField con los valores del punto
|
286 |
if(pto.pixelPoint != null){ |
287 |
dpp.getTX().setText(GeoUtils.tailDecimals(pto.pixelPoint.getX(), 2)+""); |
288 |
dpp.getTY().setText(GeoUtils.tailDecimals(pto.pixelPoint.getY(), 2)+""); |
289 |
} |
290 |
if(pto.mapPoint != null){ |
291 |
dpp.getLatitud().setText(GeoUtils.tailDecimals(String.valueOf(pto.mapPoint.getY()), 5)); |
292 |
dpp.getLongitud().setText(GeoUtils.tailDecimals(String.valueOf(pto.mapPoint.getX()), 5)); |
293 |
} |
294 |
|
295 |
//El Checkbox de activaci?n
|
296 |
dataPointPanel.getCbActive().setSelected(pto.active); |
297 |
dialog.setEnabled(pto.active); |
298 |
|
299 |
//Seleccionamos la fila de la tabla
|
300 |
PointTable table = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getJTable(); |
301 |
try{
|
302 |
table.getTable().setRowSelectionInterval(pos, pos); |
303 |
}catch(IllegalArgumentException exc){ |
304 |
System.err.println("Intervalo erroneo "+pos); |
305 |
} |
306 |
|
307 |
//Cargamos las mini imagenes
|
308 |
dialog.getZoomControlLeft().setCenterPoint(lyrPoints.getCenterPoint(pos, false));
|
309 |
|
310 |
try{
|
311 |
ViewPort vpL = GeoUtils.calcZoom(lyrPoints.getMiniExtent(pos, false), lyrPoints.getZoomLeft(pos));
|
312 |
dialog.getZoomControlLeft().setNewViewPort(vpL); |
313 |
dialog.getZoomControlLeft().draw(); |
314 |
}catch(NullPointerException ex){ |
315 |
//Todavia no hay un viewPort por lo que dar? una excepci?n.
|
316 |
} |
317 |
|
318 |
dialog.getZoomControlRight().setCenterPoint(lyrPoints.getCenterPoint(pos, true));
|
319 |
try{
|
320 |
ViewPort vpR = GeoUtils.calcZoom(lyrPoints.getMiniExtent(pos, true), lyrPoints.getZoomRight(pos));
|
321 |
dialog.getZoomControlRight().setNewViewPort(vpR); |
322 |
dialog.getZoomControlRight().draw(); |
323 |
}catch(NullPointerException ex){ |
324 |
//Todavia no hay un viewPort por lo que dar? una excepci?n
|
325 |
} |
326 |
|
327 |
//Consultamos si hay que centrar la vista sobre el punto seleccionado
|
328 |
|
329 |
if(dialog.isCenterPoint()){
|
330 |
try{
|
331 |
centerView(lyrPoints.getCenterPoint(pos, false));
|
332 |
}catch(NullPointerException ex){ |
333 |
//Excepci?n cuando se cargan los puntos desde fichero. No hacemos nada
|
334 |
} |
335 |
} |
336 |
|
337 |
//Calculamos los errores
|
338 |
if(pto.pixelPoint != null && pto.mapPoint != null) |
339 |
setErrors(pos); |
340 |
} |
341 |
|
342 |
/**
|
343 |
* Obtiene los errores en una matriz de Nx3 en la que cada fila es un punto y la
|
344 |
* columna 0 es el error en X, la columna 1 es el error en Y y la columna 2 es el error RMS.
|
345 |
* @return matriz de errores
|
346 |
*/
|
347 |
public double[][] getErrors(){ |
348 |
|
349 |
transformPointList(); |
350 |
|
351 |
//Al actualizar un punto debemos recalcular los errores RMS y Total para ello tenemos que
|
352 |
//pedir la transformaci?n de toda la lista de puntos
|
353 |
try{
|
354 |
GeoOperations go = new GeoOperations(lyrPoints);
|
355 |
Point2D[] pointList = new Point2D[lyrPoints.length()]; |
356 |
for(int i=0; i< lyrPoints.length(); i++) |
357 |
pointList[i] = lyrPoints.getPoint(i).pixelPoint; |
358 |
|
359 |
Point2D[] transformPointList = go.transformPoints(pointList); |
360 |
lyrPoints.setTransformPointList(transformPointList); |
361 |
}catch(NullPointerException e){ |
362 |
//Si ocurre esta excepci?n es que se est? intentando incluir un punto que se acaba de crear
|
363 |
//y por lo tanto no tiene el valor asignado todavia por lo que es mejor no hacer nada
|
364 |
//y seguir con el proceso
|
365 |
} |
366 |
|
367 |
double[][] err = new double[lyrPoints.getCountPoints()][3]; |
368 |
for(int i = 0; i<lyrPoints.getCountPoints(); i++){ |
369 |
err[i][0] = lyrPoints.calcDoubleResX(i);
|
370 |
err[i][1] = lyrPoints.calcDoubleResY(i);
|
371 |
err[i][2] = lyrPoints.calcDoubleRMS(i);
|
372 |
} |
373 |
return err;
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* Calcula los errores y los asigna al dialogo y tabla. Hay que tener en cuenta que
|
378 |
* hay que tener en la capa de puntos la lista de puntos transformados
|
379 |
* @param pos
|
380 |
*/
|
381 |
public void setErrors(int pos){ |
382 |
|
383 |
if(lyrPoints != null){ |
384 |
transformPointList(); |
385 |
|
386 |
//Calculamos los errores
|
387 |
double d = lyrPoints.calcDoubleRMS(pos);
|
388 |
//System.out.println("-->RMS:"+d);
|
389 |
dialog.setRMS(String.valueOf(GeoUtils.tailDecimals(d, 5))); |
390 |
try{
|
391 |
dialog.setTableValueAt(String.valueOf(GeoUtils.tailDecimals(d, 5)), pos, 7); |
392 |
}catch(ArrayIndexOutOfBoundsException e){ |
393 |
//No asigna el valor a la tabla
|
394 |
} |
395 |
|
396 |
d = lyrPoints.calcDoubleResX(pos); |
397 |
//System.out.println("-->ResX:"+d);
|
398 |
dialog.setResX(String.valueOf(GeoUtils.tailDecimals(d, 5))); |
399 |
try{
|
400 |
dialog.setTableValueAt(String.valueOf(GeoUtils.tailDecimals(d, 5)), pos, 5); |
401 |
}catch(ArrayIndexOutOfBoundsException e){ |
402 |
//No asigna el valor a la tabla
|
403 |
} |
404 |
|
405 |
d = lyrPoints.calcDoubleResY(pos); |
406 |
//System.out.println("-->ResY:"+d);
|
407 |
dialog.setResY(String.valueOf(GeoUtils.tailDecimals(d, 5))); |
408 |
try{
|
409 |
dialog.setTableValueAt(String.valueOf(GeoUtils.tailDecimals(d, 5)), pos, 6); |
410 |
}catch(ArrayIndexOutOfBoundsException e){ |
411 |
//No asigna el valor a la tabla
|
412 |
} |
413 |
|
414 |
d = lyrPoints.calcDoubleTotal(); |
415 |
//System.out.println("-->Total:"+d);
|
416 |
dialog.setTotal(String.valueOf(GeoUtils.tailDecimals(d, 5))); |
417 |
} |
418 |
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* Elimina el punto seleccionado de la lista de puntos. Obtiene el punto seleccionado
|
423 |
* del combobox del tableControler
|
424 |
*/
|
425 |
public void deletePoint(){ |
426 |
int op = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), |
427 |
PluginServices.getText(this, "eliminar_punto")); |
428 |
if(op == JOptionPane.OK_OPTION){ |
429 |
if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos |
430 |
clearVisualList(); |
431 |
else{
|
432 |
int posSelect = tableControlerPanel1.getSelectedIndex();
|
433 |
if(posSelect == -1) |
434 |
return;
|
435 |
deleteVisualPoint(posSelect); |
436 |
|
437 |
if(posSelect == 0){ |
438 |
selectPointsPanel.setLastIndexSelection(posSelect); |
439 |
}else{
|
440 |
selectPointsPanel.setLastIndexSelection(posSelect - 1);
|
441 |
} |
442 |
} |
443 |
} |
444 |
} |
445 |
|
446 |
/**
|
447 |
* Elimina todos los puntos de la capa y resetea el dialogo
|
448 |
*/
|
449 |
public void deleteAllPoints(){ |
450 |
int op = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), |
451 |
PluginServices.getText(this, "eliminar_todos_puntos")); |
452 |
if(op == JOptionPane.OK_OPTION){ |
453 |
clearVisualList(); |
454 |
} |
455 |
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* Elimina un punto de la lista pasado por par?metro y lo elimina del panel
|
460 |
* @param pos Posici?n del punto
|
461 |
* @param grd Panel a limpiar
|
462 |
*/
|
463 |
private void deleteVisualPoint(int pos){ |
464 |
lyrPoints.remove(pos); |
465 |
|
466 |
//Actualiza los controles de tabla y selector
|
467 |
tableControlerPanel1.setNItems(lyrPoints.length()); |
468 |
tableControlerPanel2.setNItems(lyrPoints.length()); |
469 |
|
470 |
//Elimina la fila de la tabla y renumera los puntos
|
471 |
try{
|
472 |
dialog.removeTableValueAt(pos); |
473 |
|
474 |
for(int i=0;i<lyrPoints.length();i++) |
475 |
dialog.setTableValueAt(String.valueOf(i + 1), i, 0); |
476 |
}catch(ArrayIndexOutOfBoundsException exc){ |
477 |
//Si intentamos eliminar una fila que no existe no hacemos nada, simplemente no la eliminamos
|
478 |
} |
479 |
|
480 |
//Carga los puntos
|
481 |
if(pos == 0){ |
482 |
dialog.getSelectPointsPanel().getTableControlerPanel().setSelectedIndex(pos); |
483 |
selectPoint(pos, dialog); |
484 |
}else{
|
485 |
dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().setSelectedIndex(pos - 1);
|
486 |
selectPoint(pos - 1, dialog);
|
487 |
} |
488 |
|
489 |
//Controlamos las flechas del control de puntos
|
490 |
tableControlerPanel1.checkArrows(); |
491 |
tableControlerPanel2.checkArrows(); |
492 |
|
493 |
//Redibujamos la vista
|
494 |
View theView = null; |
495 |
try{
|
496 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
497 |
theView.getMapControl().getMapContext().invalidate(); |
498 |
}catch(ClassCastException exc){ |
499 |
return;
|
500 |
} |
501 |
} |
502 |
|
503 |
/**
|
504 |
* Desplaza la vista centrando esta sobre el punto pasado como par?metro
|
505 |
* @param center Punto sobre el que se centra la vista
|
506 |
*/
|
507 |
private void centerView(Point2D center){ |
508 |
//Obtenemos la vista
|
509 |
View theView = null; |
510 |
try{
|
511 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
512 |
}catch(ClassCastException exc){ |
513 |
} |
514 |
|
515 |
//Calculamos el desplazamiento del extext viejo a partir de la diferencia de centros
|
516 |
Rectangle2D oldExtent = theView.getMapControl().getMapContext().getViewPort().getExtent();
|
517 |
double oldCenterX = oldExtent.getMinX() + (oldExtent.getWidth() / 2); |
518 |
double oldCenterY = oldExtent.getMaxY() - (oldExtent.getHeight() / 2); |
519 |
double difX = oldCenterX - center.getX();
|
520 |
double difY = oldCenterY - center.getY();
|
521 |
|
522 |
double minX = oldExtent.getMinX() - difX;
|
523 |
double minY = oldExtent.getMinY() - difY;
|
524 |
|
525 |
//Asignamos a la vista el nuevo extent
|
526 |
Rectangle2D newExtent = new Rectangle2D.Double(minX, minY, oldExtent.getWidth(), oldExtent.getHeight()); |
527 |
theView.getMapControl().getMapContext().getViewPort().setExtent(newExtent); |
528 |
} |
529 |
|
530 |
/**
|
531 |
* Limpia la lista de puntos .
|
532 |
*/
|
533 |
public void clearVisualList(){ |
534 |
AdjustGeorefPanel agp = dialog.getConectorPanel().getAdjustGeorefPanel(); |
535 |
|
536 |
//Limpiamos la lista de puntos
|
537 |
lyrPoints.clear(); |
538 |
//Limpiamos los controles del Selector de puntos
|
539 |
selectPointsPanel.resetControls(false);
|
540 |
selectPointsPanel.getTableControlerPanel().resetControls(); |
541 |
|
542 |
//Limpiamos la tabla y sus controles
|
543 |
tablePointsPanel.clearTable(); |
544 |
tablePointsPanel.getTableControlerPanel().resetControls(); |
545 |
|
546 |
//Limpiamos las miniimagenes bloqueamos los controles
|
547 |
agp.getZoomLeft().clear(); |
548 |
agp.getZoomRight().clear(); |
549 |
dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(false);
|
550 |
|
551 |
//Actualizamos la vista
|
552 |
View theView = null; |
553 |
try{
|
554 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
555 |
theView.getMapControl().getMapContext().invalidate(); |
556 |
}catch(ClassCastException exc){ |
557 |
return;
|
558 |
} |
559 |
|
560 |
} |
561 |
|
562 |
/**
|
563 |
* Realiza las acciones necesarias cuando se ha seleccionado el primer punto de la georreferenciaci?n.
|
564 |
* Este primer punto corresponde a las coordenadas en pixeles de la imagen. Los par?metros ya vienen
|
565 |
* validados por quien llama.
|
566 |
* @param tx Coordenada X en formato cadena
|
567 |
* @param ty Coordenada Y en formato cadena
|
568 |
* @throws TransformerException Es lanzada si el punto se encuentra fuera del marco de la imagen
|
569 |
*/
|
570 |
public void selectFirstPoint(String tx, String ty){ |
571 |
//Obtenemos el punto seleccionado en coordenadas de la vista
|
572 |
double x = Double.valueOf(tx).doubleValue(); |
573 |
double y = Double.valueOf(ty).doubleValue(); |
574 |
Point2D pixel = new Point2D.Double(); |
575 |
pixel.setLocation(x, y); |
576 |
selectFirstPoint(pixel); |
577 |
} |
578 |
|
579 |
/**
|
580 |
* Realiza las acciones necesarias cuando se ha seleccionado el primer punto de la georreferenciaci?n.
|
581 |
* Este primer punto corresponde a las coordenadas en pixeles de la imagen. Los par?metros ya vienen
|
582 |
* validados por quien llama.
|
583 |
* @param pixel Coordenada X, Y del punto
|
584 |
* @throws TransformerException Es lanzada si el punto se encuentra fuera del marco de la imagen
|
585 |
*/
|
586 |
public void selectFirstPoint(Point2D pixel){ |
587 |
restoreControlsValue(); |
588 |
|
589 |
View theView = null; |
590 |
try{
|
591 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
592 |
}catch(ClassCastException exc){ |
593 |
return;
|
594 |
} |
595 |
|
596 |
//Obtenemos del dialogo el n? de pto seleccionado y lo actualizamos en la capa de ptos
|
597 |
int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
598 |
updateData(n, pixel, null, dialog, theView);
|
599 |
dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(false);
|
600 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setEnabled(true);
|
601 |
|
602 |
disableAllControls(); |
603 |
|
604 |
//Consultamos si ha de desactivarse la capa a georreferenciar despu?s del primer punto
|
605 |
//y si es true la desactivamos
|
606 |
if(dialog.isOffLayer())
|
607 |
lyrPoints.getLyrGeoRaster().setVisible(false);
|
608 |
|
609 |
//Consultamos si ha de desactivarse la capa de puntos despues del primer punto y si es
|
610 |
//true la desactivamos.
|
611 |
if(dialog.isOffPoints())
|
612 |
lyrPoints.setHideViewOnly(false);
|
613 |
|
614 |
GeorefPointSelectorListener.firstPoint = false;
|
615 |
} |
616 |
|
617 |
/**
|
618 |
* Realiza las acciones necesarias cuando se ha seleccionado el segundo punto de la georreferenciaci?n.
|
619 |
* Este segundo punto corresponde a las coordenadas en coordenadas del mundo. Los par?metros ya vienen
|
620 |
* validados por quien llama.
|
621 |
* @param tx Coordenada X en formato cadena
|
622 |
* @param ty Coordenada Y en formato cadena
|
623 |
* @throws TransformerException Es lanzada si el punto se encuentra fuera del marco de la imagen
|
624 |
*/
|
625 |
public void selectSecondPoint(String tx, String ty){ |
626 |
//Obtenemos el punto seleccionado en coordenadas de la vista
|
627 |
double x = Double.valueOf(tx).doubleValue(); |
628 |
double y = Double.valueOf(ty).doubleValue(); |
629 |
Point2D map = new Point2D.Double(); |
630 |
map.setLocation(x, y); |
631 |
selectSecondPoint(map); |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Realiza las acciones necesarias cuando se ha seleccionado el primer punto de la georreferenciaci?n.
|
636 |
* Este primer punto corresponde a las coordenadas en pixeles de la imagen. Los par?metros ya vienen
|
637 |
* validados por quien llama.
|
638 |
* @param pixel Coordenada X, Y del punto
|
639 |
* @throws TransformerException Es lanzada si el punto se encuentra fuera del marco de la imagen
|
640 |
*/
|
641 |
public void selectSecondPoint(Point2D map){ |
642 |
View theView = null; |
643 |
try{
|
644 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
645 |
}catch(ClassCastException exc){ |
646 |
return;
|
647 |
} |
648 |
|
649 |
//Deseleccionamos la herramienta de marcado de puntos
|
650 |
theView.getMapControl().setTool(dialog.getLyrPoints().getLastTool()); |
651 |
|
652 |
//Volvemos a dejar los controles con su valor habitual
|
653 |
dialog.getPointManager().restoreControlsValue(); |
654 |
|
655 |
//Obtenemos del dialogo el n? de pto seleccionado y lo actualizamos en la capa de ptos
|
656 |
int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
657 |
updateData(n, null, map, dialog, theView);
|
658 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
659 |
dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(true);
|
660 |
setErrors(n - 1);
|
661 |
|
662 |
//Consultamos si ha de desactivarse la capa a georreferenciar despu?s del primer punto
|
663 |
//y si es true la volvemos a activar despu?s del segundo punto
|
664 |
if(dialog.isOffLayer())
|
665 |
lyrPoints.getLyrGeoRaster().setVisible(true);
|
666 |
|
667 |
//Consultamos si ha de desactivarse la capa de puntos despues del primer punto y si es
|
668 |
//true la activamos despu?s del segundo punto.
|
669 |
if(dialog.isOffPoints())
|
670 |
lyrPoints.setHideViewOnly(true);
|
671 |
|
672 |
GeorefPointSelectorListener.firstPoint = true;
|
673 |
} |
674 |
|
675 |
/**
|
676 |
* Obtiene la ventana flotante sobre la que ir? el dialogo (GeoreferencingDialog).
|
677 |
* @param obj
|
678 |
* @return JInternalFrame
|
679 |
*/
|
680 |
public static JInternalFrame getInternalFrame(Object obj){ |
681 |
JInternalFrame panel = new JInternalFrame(); |
682 |
panel.addInternalFrameListener(new GeoRasterFrameListener());
|
683 |
panel.setClosable(true);
|
684 |
panel.setResizable(false);
|
685 |
panel.setTitle(PluginServices.getText(obj,"georreferenciar"));
|
686 |
return panel;
|
687 |
} |
688 |
|
689 |
|
690 |
public static GeoreferencingDialog initWindow(FLyrGeoRaster lyrGeoRaster, boolean show, Object obj){ |
691 |
GeoreferencingDialog geoDialog = null;
|
692 |
|
693 |
JInternalFrame panel = PointManager.getInternalFrame(obj);
|
694 |
geoDialog = new GeoreferencingDialog(panel, lyrGeoRaster);
|
695 |
lyrGeoRaster.getStackZoom().setInitExtent(lyrGeoRaster.getAssignExtent(), true);
|
696 |
lyrGeoRaster.getFLyrPoints().saveState(); |
697 |
lyrGeoRaster.setGeoDialog(geoDialog); |
698 |
panel.setSize(geoDialog.getWidth() + 12, geoDialog.getHeight() + 10); |
699 |
panel.getContentPane().add(geoDialog); |
700 |
|
701 |
MDIFrame mainFrame = (MDIFrame) PluginServices.getMainFrame(); |
702 |
|
703 |
JDesktopPane desk = new JDesktopPane(); |
704 |
desk.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
705 |
|
706 |
JLayeredPane lyrPane = mainFrame.getLayeredPane();
|
707 |
lyrPane.add(panel, JDesktopPane.PALETTE_LAYER);
|
708 |
lyrPane.add(desk, JDesktopPane.OUTLINE_DRAG_MODE);
|
709 |
if(show)
|
710 |
panel.show(); |
711 |
|
712 |
return geoDialog;
|
713 |
} |
714 |
|
715 |
/**
|
716 |
* Esta funci?n deshabilita todos los controles y guarda sus valores
|
717 |
* de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
|
718 |
* se vuelvan a quedar como estaba
|
719 |
*/
|
720 |
public void disableAllControls(){ |
721 |
if(!disableAllControls){
|
722 |
disableAllControls = true;
|
723 |
//Salvamos los estados y desactivamos controles
|
724 |
tableControlerPanel1.disableAllControls(); |
725 |
tablePointsPanel.disableAllControls(); |
726 |
tableControlerPanel2.disableAllControls(); |
727 |
dialog.disableAllControls(); |
728 |
dataPointPanel.getCbActive().setEnabled(false);
|
729 |
selectPointsPanel.getBExtended().setEnabled(false);
|
730 |
dialog.getFrame().setClosable(false);
|
731 |
|
732 |
//Desactivamos las herramientas de georreferenciaci?n
|
733 |
GeoreferencingToolsModule.setEnabled(false);
|
734 |
dialog.getConectorPanel().getDataPointsTabPanel().getTbPoints().setEnabled(false);
|
735 |
} |
736 |
} |
737 |
|
738 |
/**
|
739 |
* Esta funci?n deja los controles como estaban al ejecutar la funci?n
|
740 |
* disableAllControls
|
741 |
*/
|
742 |
public void restoreControlsValue(){ |
743 |
if(disableAllControls){
|
744 |
disableAllControls = false;
|
745 |
//Activamos controles
|
746 |
tableControlerPanel1.restoreControlsValue(); |
747 |
tablePointsPanel.restoreControlsValue(); |
748 |
tableControlerPanel2.restoreControlsValue(); |
749 |
dialog.restoreControlsValue(); |
750 |
dataPointPanel.getCbActive().setEnabled(true);
|
751 |
selectPointsPanel.getBExtended().setEnabled(true);
|
752 |
dialog.getFrame().setClosable(true);
|
753 |
|
754 |
//Activamos las herramientas de georreferenciaci?n
|
755 |
GeoreferencingToolsModule.setEnabled(true);
|
756 |
dialog.getConectorPanel().getDataPointsTabPanel().getTbPoints().setEnabled(true);
|
757 |
} |
758 |
} |
759 |
//**********************End Methods***************************
|
760 |
|
761 |
//**********************Getters & Setters*********************
|
762 |
public FLyrPoints getFlyrPoints() {
|
763 |
return lyrPoints;
|
764 |
} |
765 |
|
766 |
public void setFlyrPoints(FLyrPoints flyrPoints) { |
767 |
this.lyrPoints = flyrPoints;
|
768 |
} |
769 |
|
770 |
public GeoreferencingDialog getDialog() {
|
771 |
return dialog;
|
772 |
} |
773 |
|
774 |
/**
|
775 |
* Salva en 2 variables de instancia el valor actual en coordenadas del
|
776 |
* mundo del punto seleccionado. Esto es util para su posterior restauraci?n.
|
777 |
*/
|
778 |
public void setCurrentWC() { |
779 |
int posSelect = 0; |
780 |
try{
|
781 |
if(tableControlerPanel1 != null) |
782 |
posSelect = tableControlerPanel1.getSelectedIndex(); |
783 |
if(lyrPoints != null){ |
784 |
this.currentMapX = lyrPoints.getPoint(posSelect).mapPoint.getX();
|
785 |
this.currentMapY = lyrPoints.getPoint(posSelect).mapPoint.getY();
|
786 |
} |
787 |
}catch(NullPointerException exc){ |
788 |
//Si tableControler o la capa de puntos son null no salvamos el punto
|
789 |
} |
790 |
} |
791 |
|
792 |
/**
|
793 |
* Asigna nuevos valores al texto de la latitud y longitud.
|
794 |
* @param x Longitud
|
795 |
* @param y Latitud
|
796 |
*/
|
797 |
public void setTempWC(double x, double y){ |
798 |
dataPointPanel.getLongitud().setText(GeoUtils.tailDecimals(String.valueOf(x), 5) + ""); |
799 |
dataPointPanel.getLatitud().setText(GeoUtils.tailDecimals(String.valueOf(y), 5) + ""); |
800 |
} |
801 |
|
802 |
/**
|
803 |
* Restaura el ?ltimo valor seleccionado por el usuario de la latitud
|
804 |
* y longitud.
|
805 |
*/
|
806 |
public void replaceWC(){ |
807 |
dataPointPanel.getLongitud().setText(GeoUtils.tailDecimals(String.valueOf(currentMapX), 5) + ""); |
808 |
dataPointPanel.getLatitud().setText(GeoUtils.tailDecimals(String.valueOf(currentMapY), 5) + ""); |
809 |
} |
810 |
|
811 |
/**
|
812 |
* Salva en 2 variables de instancia el valor actual en coordenadas del
|
813 |
* mundo del punto seleccionado. Esto es util para su posterior restauraci?n.
|
814 |
*/
|
815 |
public void setCurrentPixelCoord() { |
816 |
int posSelect = 0; |
817 |
try{
|
818 |
if(tableControlerPanel1 != null) |
819 |
posSelect = tableControlerPanel1.getSelectedIndex(); |
820 |
if(lyrPoints != null){ |
821 |
this.currentPixelX = lyrPoints.getPoint(posSelect).pixelPoint.getX();
|
822 |
this.currentPixelY = lyrPoints.getPoint(posSelect).pixelPoint.getY();
|
823 |
} |
824 |
}catch(NullPointerException exc){ |
825 |
//Si tableControler o la capa de puntos son null no salvamos el punto
|
826 |
} |
827 |
} |
828 |
|
829 |
/**
|
830 |
* Asigna nuevos valores al texto de la latitud y longitud.
|
831 |
* @param x Longitud
|
832 |
* @param y Latitud
|
833 |
*/
|
834 |
public void setTempPixelCoord(double x, double y){ |
835 |
dataPointPanel.getTX().setText(GeoUtils.tailDecimals(String.valueOf(x), 2) + ""); |
836 |
dataPointPanel.getTY().setText(GeoUtils.tailDecimals(String.valueOf(y), 2) + ""); |
837 |
} |
838 |
|
839 |
/**
|
840 |
* Restaura el ?ltimo valor seleccionado por el usuario de la latitud
|
841 |
* y longitud.
|
842 |
*/
|
843 |
public void replacePixelCoord(){ |
844 |
dataPointPanel.getTX().setText(GeoUtils.tailDecimals(currentPixelX, 2) + ""); |
845 |
dataPointPanel.getTY().setText(GeoUtils.tailDecimals(currentPixelY, 2) + ""); |
846 |
} |
847 |
|
848 |
/**
|
849 |
* Consulta si se han desactivado los controles salvando sus valores
|
850 |
* @return true si se han desactivado los controles salvando previamente
|
851 |
* sus valores y false si est?n en estado normal.
|
852 |
*/
|
853 |
public boolean isDisableAllControls() { |
854 |
return disableAllControls;
|
855 |
} |
856 |
//**********************End Getters & Setters*****************
|
857 |
} |