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