gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.app / org.gvsig.raster.georeferencing.app.georeferencingclient / src / main / java / org / gvsig / raster / georeferencing / app / georeferencingclient / listener / ApplicationControlsListener.java @ 1730
History | View | Annotate | Download (17.4 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.georeferencing.app.georeferencingclient.listener; |
23 |
|
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
29 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
30 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
31 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
32 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
33 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
34 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
35 |
import org.gvsig.i18n.Messages; |
36 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.GeoPointsPersistence; |
37 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.Georeferencing; |
38 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.TableWrapper; |
39 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkLocator; |
40 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkManager; |
41 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
42 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
43 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanelListener; |
44 |
import org.gvsig.raster.georeferencing.swing.impl.option.GeorefOptionsDialog; |
45 |
import org.gvsig.raster.georeferencing.swing.model.GeoreferencingOptionsDataModel; |
46 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
47 |
import org.gvsig.raster.swing.pagedtable.PagedTableEvent; |
48 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
49 |
|
50 |
/**
|
51 |
* Listener para los botones de control de la aplicaci?n de georreferenciaci?n.
|
52 |
* F?sicamente est?n en el panel de la tabla de puntos de control.
|
53 |
*
|
54 |
* 25/01/2008
|
55 |
* @author Nacho Brodin nachobrodin@gmail.com
|
56 |
*/
|
57 |
public class ApplicationControlsListener implements GeorefControlPanelListener { |
58 |
private TableWrapper tableWrapper = null; |
59 |
private Georeferencing appMain = null; |
60 |
private GeorefControlPanel controlPanel = null; |
61 |
private GeorefOptionsDialog optionsDialog = null; |
62 |
private GeoreferencingFrameworkManager fManager = null; |
63 |
private GeoPointsPersistence persistence = null; |
64 |
|
65 |
/**
|
66 |
* Flag que estar? a true despu?s de crear un nuevo punto de control. Volver? a false
|
67 |
* cuando se ejecute el evento de inserci?n de fila en una tabla. Esto es necesario para
|
68 |
* que no se centre el punto sobre la vista despu?s de insertar un nuevo punto. Ya que las
|
69 |
* vistas se van a la posici?n (0,0)
|
70 |
*/
|
71 |
private boolean newPointCreated = false; |
72 |
|
73 |
/**
|
74 |
* Constructor. Asigna el panel con los controles
|
75 |
* @param tablePanel
|
76 |
*/
|
77 |
public ApplicationControlsListener(TableWrapper tableWrapper, Georeferencing appMain) {
|
78 |
this.tableWrapper = tableWrapper;
|
79 |
this.appMain = appMain;
|
80 |
this.controlPanel = appMain.getGeorefControlPanel();
|
81 |
this.controlPanel.setListener(this); |
82 |
this.fManager = GeoreferencingFrameworkLocator.getManager();
|
83 |
this.persistence = new GeoPointsPersistence(); |
84 |
} |
85 |
|
86 |
private SynchronizedViews getSyncViews() {
|
87 |
return appMain.getSyncViews();
|
88 |
} |
89 |
|
90 |
private GeoreferencingOptionsDataModel getDataModel() {
|
91 |
return appMain.getDataModel();
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Eventos de los botones del cuadro de tabla y selecci?n de fila de tabla
|
96 |
*/
|
97 |
public void actionPerformed(ActionEvent e) { |
98 |
if(!Georeferencing.enableTableEvent)
|
99 |
return;
|
100 |
|
101 |
Georeferencing.enableTableEvent = false;
|
102 |
try {
|
103 |
//-------------------------------------
|
104 |
//Finalizaci?n de la georreferenciaci?n
|
105 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bEndGeoref)
|
106 |
endGeoref(); |
107 |
|
108 |
//-----------------------------------------
|
109 |
//Centrar la vista en el punto seleccionado
|
110 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bCenterView) {
|
111 |
getSyncViews().centerToPoint(tableWrapper.getTable().getSelectedRows()[0]);
|
112 |
} |
113 |
|
114 |
//---------------------------------
|
115 |
//Selecci?n de una fila de la tabla
|
116 |
if(e.getActionCommand().equals("SELECT_ROW")) { |
117 |
if(getDataModel().isCenterView() && !newPointCreated)
|
118 |
getSyncViews().centerToPoint(e.getID()); |
119 |
newPointCreated = false;
|
120 |
} |
121 |
|
122 |
//----------------------------------------------------------
|
123 |
//Seleccion de opciones. Se asignan las propiedades al abrir
|
124 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bOptions) {
|
125 |
if(optionsDialog == null) |
126 |
optionsDialog = new GeorefOptionsDialog(Georeferencing.DEFAULT_DEGREE, this); |
127 |
optionsDialog.setDegree(getDataModel().getDegree()); |
128 |
optionsDialog.setAlgorithm(getDataModel().getAlgorithm()); |
129 |
optionsDialog.setBackGroundColor(getDataModel().getBackgroundColor()); |
130 |
optionsDialog.setTextColor(getDataModel().getTextColor()); |
131 |
optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getAddErrorsCSVCheck().setSelected(getDataModel().isAddErrorsCSV());
|
132 |
optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getCenterViewCheck().setSelected(getDataModel().isCenterView());
|
133 |
optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getShowNumberCheck().setSelected(getDataModel().isShowNumber());
|
134 |
optionsDialog.setThresholdError(getDataModel().getThreshold()); |
135 |
optionsDialog.setInterpolationMethod(getDataModel().getInterpolationMethod()); |
136 |
optionsDialog.setOutFile(getDataModel().getOutFile()); |
137 |
optionsDialog.setXCellSize(getDataModel().getXCellSize()); |
138 |
optionsDialog.setYCellSize(getDataModel().getYCellSize()); |
139 |
fManager.showWindow(optionsDialog, 410, 440, Messages.getText("georeferencing")); |
140 |
} |
141 |
|
142 |
//------------------------------
|
143 |
//Mover el punto de control seleccionado
|
144 |
if(e.getSource() == appMain.getGeorefControlPanel().getMovePointButton()) {
|
145 |
if(appMain.getGeorefControlPanel().getMovePointButton().isSelected()) {
|
146 |
if(getSyncViews() != null) { |
147 |
getSyncViews().disableAllTools(); |
148 |
} |
149 |
getSyncViews().enableTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL); |
150 |
} else {
|
151 |
getSyncViews().disableTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL); |
152 |
} |
153 |
} |
154 |
|
155 |
//------------------------------
|
156 |
//Arrastrar y seleccionar un punto de control sobre la vista
|
157 |
if(e.getSource() == appMain.getGeorefControlPanel().getDragPointButton()) {
|
158 |
if(appMain.getGeorefControlPanel().getDragPointButton().isSelected()) {
|
159 |
if(getSyncViews() != null) { |
160 |
getSyncViews().disableAllTools(); |
161 |
} |
162 |
getSyncViews().enableTool(GeoreferencingSwingLibrary.DRAG_POINT_TOOL); |
163 |
} else {
|
164 |
getSyncViews().disableTool(GeoreferencingSwingLibrary.DRAG_POINT_TOOL); |
165 |
} |
166 |
} |
167 |
|
168 |
//-------
|
169 |
//Testear
|
170 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bTest) {
|
171 |
try {
|
172 |
appMain.getProcessActions().addTestRasterLayer( |
173 |
getDataModel().getDataStore(), |
174 |
getDataModel().getAlgorithm(), |
175 |
getDataModel().getInterpolationMethod(), |
176 |
getDataModel().getDegree(), |
177 |
getDataModel().getOutFile(), |
178 |
getDataModel().getXCellSize(), |
179 |
getDataModel().getYCellSize(), |
180 |
tableWrapper.getGeoTransformDataResult()); |
181 |
} catch (LoadLayerException e1) {
|
182 |
RasterToolsUtil.messageBoxError("error_loading_layer", tableWrapper.getTable(), e1);
|
183 |
} |
184 |
} |
185 |
|
186 |
//------------
|
187 |
//Fin del Test
|
188 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bEndTest) {
|
189 |
if(appMain != null && appMain.getProcessActions().getLastTestLayer() != null) { |
190 |
appMain.getProcessActions().getLastTestLayer().setRemoveRasterFlag(false);
|
191 |
appMain.getProcessActions().removeTestRasterLayer(); |
192 |
} |
193 |
} |
194 |
|
195 |
//------------
|
196 |
//Salvar a CSV
|
197 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bSaveToAscii) {
|
198 |
persistence.exportToCSV(getDataModel().getGCPList(), getDataModel().isAddErrorsCSV()); |
199 |
} |
200 |
|
201 |
//----------------
|
202 |
//Cargar desde CSV
|
203 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bLoadFromAscii) {
|
204 |
persistence.importFromCSV(getSyncViews(), tableWrapper); |
205 |
} |
206 |
|
207 |
//------------
|
208 |
//Salvar a RMF
|
209 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bSaveToXml) {
|
210 |
persistence.saveToRMF(getDataModel().getGCPList(), getDataModel().getDataStore()); |
211 |
} |
212 |
|
213 |
//----------------
|
214 |
//Cargar desde RMF
|
215 |
if(controlPanel.getButtonIDPressed(e.getSource()) == GeorefControlPanel.bLoadFromXml) {
|
216 |
persistence.loadFromRMF(getDataModel().getDataStore(), getSyncViews(), tableWrapper); |
217 |
} |
218 |
|
219 |
} finally {
|
220 |
Georeferencing.enableTableEvent = true;
|
221 |
} |
222 |
} |
223 |
|
224 |
/**
|
225 |
* Acciones de finalizaci?n de georreferenciaci?n. La secuencia de acciones es:
|
226 |
* <UL>
|
227 |
* <LI>Preguntar si est? seguro de finalizar.</LI>
|
228 |
* <LI>Preguntar si se desea salvar la transformaci?n (Solo en caso de ser af?n).</LI>
|
229 |
* <LI>Preguntar si se desea cargar el resultado en la vista (Solo en caso de ser con mapa de referencia).</LI>
|
230 |
* </UL>
|
231 |
*/
|
232 |
private void endGeoref() { |
233 |
if(RasterToolsUtil.messageBoxYesOrNot("ask_end_georef", null)) { |
234 |
boolean saveTransform = false; |
235 |
if(getDataModel().getAlgorithm() == Georeferencing.AFFINE) {
|
236 |
if(RasterToolsUtil.messageBoxYesOrNot("ask_save_transformation", null)) |
237 |
saveTransform = true;
|
238 |
else {
|
239 |
appMain.getProcessActions().removeTestRasterLayer(); |
240 |
fManager.closeAllWindows(); |
241 |
return;
|
242 |
} |
243 |
} |
244 |
|
245 |
if(getDataModel().getType() == Georeferencing.WITH_MAP) {
|
246 |
if(appMain.getProcessActions().getLastTestLayer() != null) |
247 |
appMain.getProcessActions().getLastTestLayer().setRemoveRasterFlag(false);
|
248 |
|
249 |
if(RasterToolsUtil.messageBoxYesOrNot("ask_load_view", null)) { |
250 |
FLayers lyrs = appMain.getMapCtrl().getMapContext().getLayers(); |
251 |
if(lyrs != null) { |
252 |
try {
|
253 |
if(appMain.getProcessActions().getLastTestLayer() != null){ |
254 |
lyrs.removeLayer(appMain.getProcessActions().getLastTestLayer()); |
255 |
PluginServices.getMainFrame().enableControls(); |
256 |
} |
257 |
} catch(NullPointerException ex){ |
258 |
//No hay raster para eliminar
|
259 |
} |
260 |
} |
261 |
|
262 |
//Cargar en la vista
|
263 |
if(getDataModel().getAlgorithm() == Georeferencing.AFFINE) {
|
264 |
try {
|
265 |
appMain.getProcessActions().addTestRasterLayer( |
266 |
getDataModel().getDataStore(), |
267 |
getDataModel().getAlgorithm(), |
268 |
getDataModel().getInterpolationMethod(), |
269 |
getDataModel().getDegree(), |
270 |
getDataModel().getOutFile(), |
271 |
getDataModel().getXCellSize(), |
272 |
getDataModel().getYCellSize(), |
273 |
tableWrapper.getGeoTransformDataResult()); |
274 |
} catch (LoadLayerException e) {
|
275 |
RasterToolsUtil.messageBoxError("error_loading_layer", null, e); |
276 |
} |
277 |
} |
278 |
if(getDataModel().getAlgorithm() == Georeferencing.POLYNOMIAL) {
|
279 |
if(appMain.getProcessActions().getLastTestLayer() != null && lyrs != null) { |
280 |
appMain.getMapCtrl().getMapContext().getLayers().addLayer(appMain.getProcessActions().getLastTestLayer()); |
281 |
} else {
|
282 |
RasterToolsUtil.messageBoxInfo("raster_not_created", null); |
283 |
return;
|
284 |
} |
285 |
} |
286 |
} else {
|
287 |
appMain.getProcessActions().removeTestRasterLayer(); |
288 |
} |
289 |
} |
290 |
|
291 |
if (saveTransform) {
|
292 |
// Salvar transformaci?n
|
293 |
if (appMain.getProcessActions().getLastTestLayer() == null) { |
294 |
RasterToolsUtil.messageBoxInfo("raster_not_created", null); |
295 |
return;
|
296 |
} |
297 |
|
298 |
RasterDataStore store = appMain.getProcessActions().getLastTestLayer().getDataStore(); |
299 |
try {
|
300 |
store.saveGeoreferencingToRmf(); |
301 |
} catch (RmfSerializerException e) {
|
302 |
RasterToolsUtil.messageBoxError("error_salvando_rmf", null, e); |
303 |
} |
304 |
} |
305 |
|
306 |
fManager.closeAllWindows(); |
307 |
} |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Evento de modificaci?n de la tabla de puntos de control. El a?adir, borrar
|
312 |
* o mover puntos dentro de la tabla hace que estos se creen, borren o muevan en
|
313 |
* la lista de GeoPoints.
|
314 |
*/
|
315 |
public void tableChanged(PagedTableEvent e) { |
316 |
if(!Georeferencing.enableTableEvent)
|
317 |
return;
|
318 |
Georeferencing.enableTableEvent = false;
|
319 |
|
320 |
try {
|
321 |
//-----------------------------------
|
322 |
//Inserci?n de nueva fila en la tabla
|
323 |
if(e.getEvent() == PagedTableEvent.EVENT_ADD_ENTRY) {
|
324 |
long id = getSyncViews().addPoint(new Point2D.Double(0, 0), new Point2D.Double(0, 0)); |
325 |
tableWrapper.initializeRow(e.getRows()[0], id);
|
326 |
getSyncViews().calcPointsNumeration(); |
327 |
|
328 |
//Activamos la herramienta de mover punto en la vista
|
329 |
getSyncViews().enableTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL); |
330 |
|
331 |
newPointCreated = true;
|
332 |
} |
333 |
|
334 |
//-----------------------------
|
335 |
//Eliminado de fila de la tabla
|
336 |
if(e.getEvent() == PagedTableEvent.EVENT_REMOVE_ENTRY) {
|
337 |
for (int i = 0; i >= e.getRows().length; i--) |
338 |
appMain.getSyncViews().removePoint(e.getRows()[i]); |
339 |
getSyncViews().calcPointsNumeration(); |
340 |
tableWrapper.updateErrors(); |
341 |
} |
342 |
|
343 |
//-----------------------------
|
344 |
//Eliminado todas las filas
|
345 |
if(e.getEvent() == PagedTableEvent.EVENT_REMOVE_ALL) {
|
346 |
getSyncViews().removeAllPoints(); |
347 |
} |
348 |
|
349 |
//-------------------------------------
|
350 |
//Actualizaci?n de una fila de la tabla
|
351 |
if(e.getEvent() == PagedTableEvent.EVENT_MODIFY_ENTRY) {
|
352 |
getSyncViews().calcPointsNumeration(); |
353 |
//Revisamos el flag de activo de cada punto poniendo el valor que pone en la entrada de la tabla
|
354 |
for (int i = 0; i < tableWrapper.getTable().getRowCount(); i++) { |
355 |
boolean active = ((Boolean) tableWrapper.getTable().getValueAt(i, 0)).booleanValue(); |
356 |
int position = appMain.getSyncViews().getPointPositionByNumber(i);
|
357 |
if (position < 0) |
358 |
return;
|
359 |
GeoPoint pt = getDataModel().getGCPList().getGeoPoint(position); |
360 |
pt.setActive(active); |
361 |
getSyncViews().setVisiblePoint(active, position); |
362 |
|
363 |
//Para la funcionalidad de cambio de coordenadas desde la tabla: reasignamos el valor
|
364 |
//de las coordenadas por si han cambiado estas
|
365 |
double[] values = tableWrapper.getCoordinates(i); |
366 |
|
367 |
getSyncViews().setCoordinates(position, values[0], values[1], values[2], values[3]); |
368 |
} |
369 |
tableWrapper.updateErrors(); |
370 |
} |
371 |
|
372 |
if(e.getEvent() == PagedTableEvent.EVENT_SELECTED_ROWS) {
|
373 |
if(getDataModel().isCenterView())
|
374 |
getSyncViews().centerToPoint(tableWrapper.getTable().getSelectedRows()[0]);
|
375 |
getDataModel().getGCPList().setSelectedPoint(tableWrapper.getTable().getSelectedRows()[0]);
|
376 |
} |
377 |
|
378 |
} finally {
|
379 |
Georeferencing.enableTableEvent = true;
|
380 |
} |
381 |
} |
382 |
|
383 |
/**
|
384 |
* Eventos de los botones del cuadro de opciones
|
385 |
*/
|
386 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
387 |
Georeferencing.enableTableEvent = false;
|
388 |
|
389 |
try {
|
390 |
//---------------------------------------------------
|
391 |
//Bot?n de Aplicar y Aceptar en el cuadro de opciones
|
392 |
if (e.getButton() == ButtonsPanel.BUTTON_APPLY || e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
393 |
if(optionsDialog != null) { |
394 |
|
395 |
//Asignamos las propiedades seleccionadas
|
396 |
getDataModel().setAlgorithm(optionsDialog.getAlgorithm()); |
397 |
getDataModel().setBackGroundColor(optionsDialog.getBackGroundColor()); |
398 |
getDataModel().setTextColor(optionsDialog.getTextColor()); |
399 |
getDataModel().setAddErrorsCSV(optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getAddErrorsCSVCheck().isSelected());
|
400 |
getDataModel().setCenterView(optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getCenterViewCheck().isSelected());
|
401 |
getDataModel().setShowNumber(optionsDialog.getOptionsPanel(this).getCheckOptionsPanel().getShowNumberCheck().isSelected());
|
402 |
getDataModel().setInterpolationMethod(optionsDialog.getInterpolationMethod()); |
403 |
getDataModel().setOutFile(optionsDialog.getOptionsPanel(this).getOutFileSelectionPanel().getOutFile());
|
404 |
|
405 |
//Recalculamos los errores si ha cambiado el grado
|
406 |
if(optionsDialog.getDegree() != getDataModel().getDegree()) {
|
407 |
getDataModel().setDegree(optionsDialog.getDegree()); |
408 |
tableWrapper.updateErrors(); |
409 |
} |
410 |
|
411 |
try {
|
412 |
getDataModel().setThreshold(optionsDialog.getThresholdError()); |
413 |
getDataModel().setXCellSize(optionsDialog.getOptionsPanel(this).getCellSizePanel().getXCellSizeValue());
|
414 |
getDataModel().setYCellSize(optionsDialog.getOptionsPanel(this).getCellSizePanel().getYCellSizeValue());
|
415 |
} catch(NumberFormatException exc) { |
416 |
RasterToolsUtil.messageBoxError("error_numeric_format", null, exc); |
417 |
} |
418 |
|
419 |
getSyncViews().setGraphicsColor(getDataModel().getTextColor()); |
420 |
getSyncViews().setBackgroundColor(getDataModel().getBackgroundColor()); |
421 |
getSyncViews().setActiveNumberPoint(getDataModel().isShowNumber()); |
422 |
|
423 |
} |
424 |
} |
425 |
|
426 |
//--------------------------------------------------
|
427 |
// Bot?n de Cerrar y Aceptar en el cuadro de opciones
|
428 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL || e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
429 |
if(optionsDialog != null) { |
430 |
fManager.closeWindow(optionsDialog); |
431 |
} |
432 |
} |
433 |
|
434 |
} finally {
|
435 |
Georeferencing.enableTableEvent = true;
|
436 |
} |
437 |
} |
438 |
} |