1 |
|
/**
|
2 |
|
* gvSIG. Desktop Geographic Information System.
|
3 |
|
*
|
4 |
|
* Copyright (C) 2007-2012 gvSIG Association.
|
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 |
|
* For any additional information, do not hesitate to contact us
|
22 |
|
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
|
*/
|
24 |
|
package org.gvsig.raster.georeferencing.swing.impl.table;
|
25 |
|
|
26 |
|
import java.awt.BorderLayout;
|
27 |
|
import java.awt.Color;
|
28 |
|
import java.awt.Component;
|
29 |
|
import java.awt.Dimension;
|
30 |
|
import java.awt.GridBagConstraints;
|
31 |
|
import java.awt.GridBagLayout;
|
32 |
|
import java.awt.event.ComponentEvent;
|
33 |
|
import java.awt.event.ComponentListener;
|
34 |
|
import java.awt.geom.Point2D;
|
35 |
|
import java.util.ArrayList;
|
36 |
|
import java.util.HashMap;
|
37 |
|
import java.util.List;
|
38 |
|
|
39 |
|
import javax.swing.BorderFactory;
|
40 |
|
import javax.swing.ImageIcon;
|
41 |
|
import javax.swing.JButton;
|
42 |
|
import javax.swing.JPanel;
|
43 |
|
import javax.swing.JTable;
|
44 |
|
import javax.swing.JToggleButton;
|
45 |
|
import javax.swing.table.DefaultTableCellRenderer;
|
46 |
|
import javax.swing.table.DefaultTableModel;
|
47 |
|
import javax.swing.table.TableColumn;
|
48 |
|
|
49 |
|
import org.gvsig.andami.IconThemeHelper;
|
50 |
|
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint;
|
51 |
|
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList;
|
52 |
|
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
|
53 |
|
import org.gvsig.gui.beans.datainput.DataInputContainer;
|
54 |
|
import org.gvsig.gui.beans.table.TableContainer;
|
55 |
|
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
|
56 |
|
import org.gvsig.gui.beans.table.models.GCPModel;
|
57 |
|
import org.gvsig.i18n.Messages;
|
58 |
|
import org.gvsig.raster.georeferencing.GeoreferencingLibrary;
|
59 |
|
import org.gvsig.raster.georeferencing.Geotransformation;
|
60 |
|
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary;
|
61 |
|
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary;
|
62 |
|
import org.gvsig.raster.georeferencing.swing.table.GCPTable;
|
63 |
|
import org.gvsig.raster.georeferencing.swing.table.TableControlListener;
|
64 |
|
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
|
65 |
|
import org.gvsig.raster.tools.algorithm.base.process.ProcessException;
|
66 |
|
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
|
67 |
|
|
68 |
|
/**
|
69 |
|
* Panel que contiene la tabla de puntos de control
|
70 |
|
*
|
71 |
|
* 22/12/2007
|
72 |
|
* @author Nacho Brodin (nachobrodin@gmail.com)
|
73 |
|
*/
|
74 |
|
public class GCPTablePanelImpl extends JPanel implements GCPTable, ComponentListener {
|
75 |
|
private static final long serialVersionUID = 1L;
|
76 |
|
private String[] columnNames = {"-",
|
77 |
|
Messages.getText("num"),
|
78 |
|
Messages.getText("worldx"),
|
79 |
|
Messages.getText("worldy"),
|
80 |
|
Messages.getText("imagex"),
|
81 |
|
Messages.getText("imagey"),
|
82 |
|
"Error X", "Error Y", "RMS", "-"};
|
83 |
|
private int[] columnWidths = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//{25, 25, 90, 90, 90, 90, 50, 50, 50, 0};
|
84 |
|
private TableContainer table = null;
|
85 |
|
|
86 |
|
private JPanel buttonsPanel = null;
|
87 |
|
private TableControlListener buttonsListener = null;
|
88 |
|
private JButton bSaveToXml = null;
|
89 |
|
private JButton bLoadFromXml = null;
|
90 |
|
private JButton bSaveToAscii = null;
|
91 |
|
private JButton bLoadFromAscii = null;
|
92 |
|
private JButton bOptions = null;
|
93 |
|
private JButton bTest = null;
|
94 |
|
private JButton bEndTest = null;
|
95 |
|
private JButton bEndGeoref = null;
|
96 |
|
private JButton bCenterView = null;
|
97 |
|
private JToggleButton bAddPoint = null;
|
98 |
|
private DataInputContainer error = null;
|
99 |
|
|
100 |
|
private RasterProcess process = null;
|
101 |
|
private GeoPointList pointList = null;
|
102 |
|
private int selectedDegree = GeoreferencingSwingLibrary.UNDEFINED;
|
103 |
|
private double threshold = 0;
|
104 |
|
private String pathToImagesForTest = "/src/main/resources/images/";
|
105 |
|
|
106 |
|
/**
|
107 |
|
* Constructor.
|
108 |
|
* Crea la composici?n de controles de zoom.
|
109 |
|
*/
|
110 |
|
public GCPTablePanelImpl(int degree, double threshold) {
|
111 |
|
this.selectedDegree = degree;
|
112 |
|
this.threshold = threshold;
|
113 |
|
}
|
114 |
|
|
115 |
|
/**
|
116 |
|
* Asigna el listener para los botones
|
117 |
|
* @param listener
|
118 |
|
*/
|
119 |
|
public void setTableListener(TableControlListener listener) {
|
120 |
|
this.buttonsListener = listener;
|
121 |
|
try {
|
122 |
|
process = RasterBaseAlgorithmLibrary.getManager().createRasterTask(GeoreferencingLibrary.PROCESS_LABEL);
|
123 |
|
} catch (ProcessException e1) {
|
124 |
|
GeoreferencingSwingImplLibrary.messageBoxError("error_creating_algorithm", null);
|
125 |
|
return;
|
126 |
|
}
|
127 |
|
this.addComponentListener(this);
|
128 |
|
try {
|
129 |
|
init();
|
130 |
|
} catch (NotInitializeException e) {
|
131 |
|
GeoreferencingSwingImplLibrary.messageBoxError(Messages.getText("table_not_initialize"), this, null);
|
132 |
|
}
|
133 |
|
}
|
134 |
|
|
135 |
|
public JPanel getComponent() {
|
136 |
|
return this;
|
137 |
|
}
|
138 |
|
|
139 |
|
/**
|
140 |
|
* Inicializaci?n de los componentes gr?ficos
|
141 |
|
*/
|
142 |
|
private void init() throws NotInitializeException {
|
143 |
|
setLayout(new GridBagLayout());
|
144 |
|
//setPreferredSize(new java.awt.Dimension(0, h));
|
145 |
|
|
146 |
|
GridBagConstraints gb = new GridBagConstraints();
|
147 |
|
gb.insets = new java.awt.Insets(0, 0, 0, 0);
|
148 |
|
gb.fill = GridBagConstraints.BOTH;
|
149 |
|
gb.gridx = 0;
|
150 |
|
gb.weightx = 1D;
|
151 |
|
gb.weighty = 1D;
|
152 |
|
add(getTable(), gb);
|
153 |
|
|
154 |
|
gb.fill = GridBagConstraints.VERTICAL;
|
155 |
|
gb.weightx = 0;
|
156 |
|
gb.weighty = 1;
|
157 |
|
gb.gridx = 1;
|
158 |
|
JPanel p = new JPanel();
|
159 |
|
p.add(getButtonsPanel(), BorderLayout.NORTH);
|
160 |
|
p.add(new JPanel(), BorderLayout.CENTER);
|
161 |
|
add(p, gb);
|
162 |
|
}
|
163 |
|
|
164 |
|
/**
|
165 |
|
* Obtiene la tabla de puntos de control
|
166 |
|
* @return TableContainer
|
167 |
|
*/
|
168 |
|
public TableContainer getTable() throws NotInitializeException {
|
169 |
|
if(table == null) {
|
170 |
|
ArrayList<TableControlListener> listeners = new ArrayList<TableControlListener>();
|
171 |
|
listeners.add(buttonsListener);
|
172 |
|
table = new TableContainer(columnNames, columnWidths, listeners);
|
173 |
|
table.setModel("GCPModel");
|
174 |
|
table.initialize();
|
175 |
|
table.setControlVisible(true);
|
176 |
|
table.setMoveRowsButtonsVisible(true);
|
177 |
|
table.setEditable(true);
|
178 |
|
table.getTable().getJTable().getColumnModel().getColumn(columnNames.length - 1).setMinWidth(0);
|
179 |
|
table.getTable().getJTable().getColumnModel().getColumn(columnNames.length - 1).setMaxWidth(0);
|
180 |
|
table.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(26);
|
181 |
|
table.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(26);
|
182 |
|
table.getTable().getJTable().getColumnModel().getColumn(1).setMinWidth(26);
|
183 |
|
table.getTable().getJTable().getColumnModel().getColumn(1).setMaxWidth(26);
|
184 |
|
table.getModel().addTableModelListener(buttonsListener);
|
185 |
|
}
|
186 |
|
return table;
|
187 |
|
}
|
188 |
|
|
189 |
|
/**
|
190 |
|
* Obtiene el panel de botones
|
191 |
|
* @return JPanel
|
192 |
|
*/
|
193 |
|
public JPanel getButtonsPanel() {
|
194 |
|
if(buttonsPanel == null) {
|
195 |
|
buttonsPanel = new JPanel();
|
196 |
|
buttonsPanel.setLayout(new GridBagLayout());
|
197 |
|
buttonsPanel.setPreferredSize(new Dimension(130, 130));
|
198 |
|
buttonsPanel.setBorder(BorderFactory.createLineBorder(Color.red));
|
199 |
|
|
200 |
|
GridBagConstraints gb = new GridBagConstraints();
|
201 |
|
gb.insets = new java.awt.Insets(0, 0, 1, 1);
|
202 |
|
gb.gridy = 0;
|
203 |
|
gb.gridx = 0;
|
204 |
|
buttonsPanel.add(getSaveToXMLButton(), gb);
|
205 |
|
|
206 |
|
gb.gridy = 0;
|
207 |
|
gb.gridx = 1;
|
208 |
|
buttonsPanel.add(getLoadFromXMLButton(), gb);
|
209 |
|
|
210 |
|
gb.gridy = 0;
|
211 |
|
gb.gridx = 2;
|
212 |
|
buttonsPanel.add(getExporToCSVButton(), gb);
|
213 |
|
|
214 |
|
gb.gridy = 0;
|
215 |
|
gb.gridx = 3;
|
216 |
|
buttonsPanel.add(getLoadFromCSVButton(), gb);
|
217 |
|
|
218 |
|
gb.gridy = 1;
|
219 |
|
gb.gridx = 0;
|
220 |
|
buttonsPanel.add(getOptionsButton(), gb);
|
221 |
|
|
222 |
|
gb.gridy = 1;
|
223 |
|
gb.gridx = 1;
|
224 |
|
buttonsPanel.add(getCenterButton(), gb);
|
225 |
|
|
226 |
|
gb.gridy = 1;
|
227 |
|
gb.gridx = 2;
|
228 |
|
buttonsPanel.add(getToolSelectPointButton(), gb);
|
229 |
|
|
230 |
|
gb.gridy = 1;
|
231 |
|
gb.gridx = 3;
|
232 |
|
buttonsPanel.add(getEndGeorefButton(), gb);
|
233 |
|
|
234 |
|
gb.gridy = 2;
|
235 |
|
gb.gridx = 0;
|
236 |
|
buttonsPanel.add(getTestButton(), gb);
|
237 |
|
|
238 |
|
gb.gridy = 2;
|
239 |
|
gb.gridx = 1;
|
240 |
|
buttonsPanel.add(getEndTestButton(), gb);
|
241 |
|
|
242 |
|
gb.gridy = 3;
|
243 |
|
gb.gridx = 0;
|
244 |
|
gb.gridwidth = 4;
|
245 |
|
buttonsPanel.add(getError(), gb);
|
246 |
|
}
|
247 |
|
return buttonsPanel;
|
248 |
|
}
|
249 |
|
|
250 |
|
/**
|
251 |
|
* Obtiene el objeto con el error total
|
252 |
|
* @return
|
253 |
|
*/
|
254 |
|
public DataInputContainer getError() {
|
255 |
|
if(error == null) {
|
256 |
|
error = new DataInputContainer();
|
257 |
|
error.setLabelText("RMS");
|
258 |
|
error.setPreferredSize(new Dimension(85, 35));
|
259 |
|
}
|
260 |
|
return error;
|
261 |
|
}
|
262 |
|
|
263 |
|
/**
|
264 |
|
* Obtiene el bot?n de finalizar georreferenciaci?n. Si no existe se crea.
|
265 |
|
* @return JButton
|
266 |
|
*/
|
267 |
|
public JButton getEndGeorefButton() {
|
268 |
|
if(bEndGeoref == null) {
|
269 |
|
bEndGeoref = new JButton();
|
270 |
|
bEndGeoref.setPreferredSize(new Dimension(22, 22));
|
271 |
|
bEndGeoref.setIcon(loadIcon("exit-icon"));
|
272 |
|
bEndGeoref.setToolTipText(Messages.getText("end_georef"));
|
273 |
|
bEndGeoref.addActionListener(buttonsListener);
|
274 |
|
}
|
275 |
|
return bEndGeoref;
|
276 |
|
}
|
277 |
|
|
278 |
|
/**
|
279 |
|
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
280 |
|
* @return JButton
|
281 |
|
*/
|
282 |
|
public JButton getTestButton() {
|
283 |
|
if(bTest == null) {
|
284 |
|
bTest = new JButton();
|
285 |
|
bTest.setPreferredSize(new Dimension(22, 22));
|
286 |
|
bTest.setToolTipText(Messages.getText("test_georef"));
|
287 |
|
bTest.addActionListener(buttonsListener);
|
288 |
|
bTest.setIcon(loadIcon("process-icon"));
|
289 |
|
}
|
290 |
|
return bTest;
|
291 |
|
}
|
292 |
|
|
293 |
|
/**
|
294 |
|
* Obtiene el bot?n de terminar el test de georreferenciaci?n. Si no existe se crea.
|
295 |
|
* @return JButton
|
296 |
|
*/
|
297 |
|
public JButton getEndTestButton() {
|
298 |
|
if(bEndTest == null) {
|
299 |
|
bEndTest = new JButton();
|
300 |
|
bEndTest.setPreferredSize(new Dimension(22, 22));
|
301 |
|
bEndTest.setToolTipText(Messages.getText("end_test_georef"));
|
302 |
|
bEndTest.addActionListener(buttonsListener);
|
303 |
|
bEndTest.setIcon(loadIcon("endprocess-icon"));
|
304 |
|
}
|
305 |
|
return bEndTest;
|
306 |
|
}
|
307 |
|
|
308 |
|
/**
|
309 |
|
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
310 |
|
* @return JButton
|
311 |
|
*/
|
312 |
|
public JButton getLoadFromCSVButton() {
|
313 |
|
if(bLoadFromAscii == null) {
|
314 |
|
bLoadFromAscii = new JButton();
|
315 |
|
bLoadFromAscii.setPreferredSize(new Dimension(22, 22));
|
316 |
|
bLoadFromAscii.setToolTipText(Messages.getText("load_from_ascii"));
|
317 |
|
bLoadFromAscii.addActionListener(buttonsListener);
|
318 |
|
bLoadFromAscii.setIcon(loadIcon("importfromcsv-icon"));
|
319 |
|
}
|
320 |
|
return bLoadFromAscii;
|
321 |
|
}
|
322 |
|
|
323 |
|
/**
|
324 |
|
* Obtiene el bot?n de exportar a Ascii. Si no existe se crea.
|
325 |
|
* @return JButton
|
326 |
|
*/
|
327 |
|
public JButton getExporToCSVButton() {
|
328 |
|
if(bSaveToAscii == null) {
|
329 |
|
bSaveToAscii = new JButton();
|
330 |
|
bSaveToAscii.setPreferredSize(new Dimension(22, 22));
|
331 |
|
bSaveToAscii.setToolTipText(Messages.getText("save_to_ascii"));
|
332 |
|
bSaveToAscii.addActionListener(buttonsListener);
|
333 |
|
bSaveToAscii.setIcon(loadIcon("exporttocsv-icon"));
|
334 |
|
}
|
335 |
|
return bSaveToAscii;
|
336 |
|
}
|
337 |
|
|
338 |
|
/**
|
339 |
|
* Obtiene el bot?n de cargar desde XML. Si no existe se crea.
|
340 |
|
* @return JButton
|
341 |
|
*/
|
342 |
|
public JButton getLoadFromXMLButton() {
|
343 |
|
if(bLoadFromXml == null) {
|
344 |
|
bLoadFromXml = new JButton();
|
345 |
|
bLoadFromXml.setPreferredSize(new Dimension(22, 22));
|
346 |
|
bLoadFromXml.setToolTipText(Messages.getText("load_from_xml"));
|
347 |
|
bLoadFromXml.addActionListener(buttonsListener);
|
348 |
|
bLoadFromXml.setIcon(loadIcon("tfwload-icon"));
|
349 |
|
}
|
350 |
|
return bLoadFromXml;
|
351 |
|
}
|
352 |
|
|
353 |
|
private ImageIcon loadIcon(String iconName) {
|
354 |
|
ImageIcon icon = null;
|
355 |
|
try {
|
356 |
|
icon = IconThemeHelper.getImageIcon(iconName);
|
357 |
|
} catch(NullPointerException e) {}
|
358 |
|
if(icon == null)
|
359 |
|
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png", "");
|
360 |
|
if(icon == null)
|
361 |
|
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", "");
|
362 |
|
return icon;
|
363 |
|
}
|
364 |
|
|
365 |
|
/**
|
366 |
|
* Obtiene el bot?n de salvar a XML. Si no existe se crea.
|
367 |
|
* @return JButton
|
368 |
|
*/
|
369 |
|
public JButton getSaveToXMLButton() {
|
370 |
|
if(bSaveToXml == null) {
|
371 |
|
bSaveToXml = new JButton();
|
372 |
|
bSaveToXml.setPreferredSize(new Dimension(22, 22));
|
373 |
|
bSaveToXml.setToolTipText(Messages.getText("save_gcp_to_xml"));
|
374 |
|
bSaveToXml.addActionListener(buttonsListener);
|
375 |
|
bSaveToXml.setIcon(loadIcon("save-icon"));
|
376 |
|
}
|
377 |
|
return bSaveToXml;
|
378 |
|
}
|
379 |
|
|
380 |
|
/**
|
381 |
|
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
382 |
|
* @return JButton
|
383 |
|
*/
|
384 |
|
public JButton getOptionsButton() {
|
385 |
|
if(bOptions == null) {
|
386 |
|
bOptions = new JButton();
|
387 |
|
bOptions.setPreferredSize(new Dimension(22, 22));
|
388 |
|
bOptions.setToolTipText(Messages.getText("options"));
|
389 |
|
bOptions.addActionListener(buttonsListener);
|
390 |
|
bOptions.setIcon(loadIcon("options-icon"));
|
391 |
|
}
|
392 |
|
return bOptions;
|
393 |
|
}
|
394 |
|
|
395 |
|
/**
|
396 |
|
* Obtiene el bot?n de asignar el punto de control seleccionado en la tabla sobre
|
397 |
|
* una posici?n de la vista. Si no existe se crea.
|
398 |
|
* @return JButton
|
399 |
|
*/
|
400 |
|
public JToggleButton getToolSelectPointButton() {
|
401 |
|
if(bAddPoint == null) {
|
402 |
|
bAddPoint = new JToggleButton();
|
403 |
|
bAddPoint.setPreferredSize(new Dimension(22, 22));
|
404 |
|
bAddPoint.setToolTipText(Messages.getText("move-point"));
|
405 |
|
bAddPoint.addActionListener(buttonsListener);
|
406 |
|
bAddPoint.setIcon(loadIcon("add-icon"));
|
407 |
|
}
|
408 |
|
return bAddPoint;
|
409 |
|
}
|
410 |
|
|
411 |
|
/**
|
412 |
|
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
413 |
|
* @return JButton
|
414 |
|
*/
|
415 |
|
public JButton getCenterButton() {
|
416 |
|
if(bCenterView == null) {
|
417 |
|
bCenterView = new JButton();
|
418 |
|
bCenterView.setPreferredSize(new Dimension(22, 22));
|
419 |
|
bCenterView.setToolTipText(Messages.getText("center_view"));
|
420 |
|
bCenterView.addActionListener(buttonsListener);
|
421 |
|
bCenterView.setIcon(loadIcon("centerpoint-icon"));
|
422 |
|
}
|
423 |
|
return bCenterView;
|
424 |
|
}
|
425 |
|
|
426 |
|
public void componentHidden(ComponentEvent e) {
|
427 |
|
}
|
428 |
|
|
429 |
|
public void componentMoved(ComponentEvent e) {
|
430 |
|
}
|
431 |
|
|
432 |
|
public void componentShown(ComponentEvent e) {
|
433 |
|
}
|
434 |
|
|
435 |
|
/**
|
436 |
|
* Cuando la tabla tiene un tama?o mayor de 800 pixeles de ancho se muestran las
|
437 |
|
* columnas de error en X e Y que cuando est? minimizada no aparecen.
|
438 |
|
*/
|
439 |
|
public void componentResized(ComponentEvent e) {
|
440 |
|
try {
|
441 |
|
Dimension dim = ((GCPTablePanelImpl)e.getSource()).getSize();
|
442 |
|
if(dim.getWidth() <= 800) {
|
443 |
|
TableColumn col = getTable().getTable().getJTable().getColumnModel().getColumn(6);
|
444 |
|
col.setMinWidth(0);
|
445 |
|
col.setMaxWidth(0);
|
446 |
|
col = getTable().getTable().getJTable().getColumnModel().getColumn(7);
|
447 |
|
col.setMinWidth(0);
|
448 |
|
col.setMaxWidth(0);
|
449 |
|
} else {
|
450 |
|
TableColumn col = getTable().getTable().getJTable().getColumnModel().getColumn(6);
|
451 |
|
col.setMaxWidth(110);
|
452 |
|
col.setMinWidth(110);
|
453 |
|
col = getTable().getTable().getJTable().getColumnModel().getColumn(7);
|
454 |
|
col.setMaxWidth(110);
|
455 |
|
col.setMinWidth(110);
|
456 |
|
}
|
457 |
|
getTable().getTable().invalidate();
|
458 |
|
} catch (NotInitializeException ex) {
|
459 |
|
return;
|
460 |
|
}
|
461 |
|
}
|
462 |
|
|
463 |
|
//****************************************************
|
464 |
|
//Acceso a los datos de la tabla
|
465 |
|
|
466 |
|
/**
|
467 |
|
* Obtiene las coordenadas de una fila
|
468 |
|
* @param row Fila de la que se quieren obtener las coordenadas
|
469 |
|
* @return Array con 4 valores coordenadas real X, coordenada real Y, coordenadas raster X y coordenada raste Y
|
470 |
|
*/
|
471 |
|
public double[] getCoordinates(int row) {
|
472 |
|
double xMap = 0, yMap = 0, xRaster = 0, yRaster = 0;
|
473 |
|
boolean numberFormatException = false;
|
474 |
|
try {
|
475 |
|
Object value = getTable().getModel().getValueAt(row, 2);
|
476 |
|
try {
|
477 |
|
if(value instanceof Double)
|
478 |
|
xMap = ((Double)value).doubleValue();
|
479 |
|
else if(value instanceof String)
|
480 |
|
xMap = Double.valueOf(((String)value)).doubleValue();
|
481 |
|
} catch (NumberFormatException ex1) {
|
482 |
|
numberFormatException = true;
|
483 |
|
}
|
484 |
|
|
485 |
|
value = getTable().getModel().getValueAt(row, 3);
|
486 |
|
try {
|
487 |
|
if(value instanceof Double)
|
488 |
|
yMap = ((Double)value).doubleValue();
|
489 |
|
else if(value instanceof String)
|
490 |
|
yMap = Double.valueOf(((String)value)).doubleValue();
|
491 |
|
} catch (NumberFormatException ex1) {
|
492 |
|
numberFormatException = true;
|
493 |
|
}
|
494 |
|
|
495 |
|
try {
|
496 |
|
value = getTable().getModel().getValueAt(row, 4);
|
497 |
|
if(value instanceof Double)
|
498 |
|
xRaster = ((Double)value).doubleValue();
|
499 |
|
else if(value instanceof String)
|
500 |
|
xRaster = Double.valueOf(((String)value)).doubleValue();
|
501 |
|
} catch (NumberFormatException ex1) {
|
502 |
|
numberFormatException = true;
|
503 |
|
}
|
504 |
|
|
505 |
|
try {
|
506 |
|
value = getTable().getModel().getValueAt(row, 5);
|
507 |
|
if(value instanceof Double)
|
508 |
|
yRaster = ((Double)value).doubleValue();
|
509 |
|
else if(value instanceof String)
|
510 |
|
yRaster = Double.valueOf(((String)value)).doubleValue();
|
511 |
|
} catch (NumberFormatException ex1) {
|
512 |
|
numberFormatException = true;
|
513 |
|
}
|
514 |
|
|
515 |
|
//Esto es necesario porque aunque se produzca una excepci?n en la lectura
|
516 |
|
//de un valor deben leerse los dem?s campos antes de terminar.
|
517 |
|
if(numberFormatException) {
|
518 |
|
GeoreferencingSwingImplLibrary.messageBoxError("value_not_valid", table, null);
|
519 |
|
try {
|
520 |
|
getTable().getModel().setValueAt(new String(xMap + ""), row, 2);
|
521 |
|
getTable().getModel().setValueAt(new String(yMap + ""), row, 3);
|
522 |
|
getTable().getModel().setValueAt(new String(xRaster + ""), row, 4);
|
523 |
|
getTable().getModel().setValueAt(new String(yRaster + ""), row, 5);
|
524 |
|
} catch (NotInitializeException e) {
|
525 |
|
//Si est? inicializada sino habr?a entrado en la excepci?n de nivel mayor
|
526 |
|
}
|
527 |
|
}
|
528 |
|
|
529 |
|
//return new double[]{xMap, yMap, xRaster, yRaster};
|
530 |
|
} catch (NotInitializeException ex) {
|
531 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", table, null);
|
532 |
|
}
|
533 |
|
return new double[]{xMap, yMap, xRaster, yRaster};
|
534 |
|
}
|
535 |
|
|
536 |
|
/**
|
537 |
|
*
|
538 |
|
* @param row
|
539 |
|
* @return
|
540 |
|
*/
|
541 |
|
public boolean getChecked(int row) {
|
542 |
|
try {
|
543 |
|
Object value = getTable().getModel().getValueAt(row, 0);
|
544 |
|
if(value != null && value instanceof Boolean)
|
545 |
|
return ((Boolean)value).booleanValue();
|
546 |
|
}catch (NotInitializeException ex) {
|
547 |
|
GeoreferencingSwingImplLibrary.messageBoxYesOrNot("table_not_initialize", table);
|
548 |
|
}
|
549 |
|
return false;
|
550 |
|
}
|
551 |
|
|
552 |
|
/**
|
553 |
|
* A?ade una fila de datos al final de la tabla
|
554 |
|
* @param checked
|
555 |
|
* @param mX
|
556 |
|
* @param mY
|
557 |
|
* @param pX
|
558 |
|
* @param pY
|
559 |
|
* @param z
|
560 |
|
* @param eX
|
561 |
|
* @param eY
|
562 |
|
* @param rms
|
563 |
|
*/
|
564 |
|
public void addRow(boolean checked, Point2D map, Point2D pixel, double z, double eX, double eY, double rms, long id) {
|
565 |
|
try {
|
566 |
|
int rowCount = getTable().getRowCount();
|
567 |
|
DefaultTableModel model = getTable().getModel();
|
568 |
|
if(model instanceof GCPModel) {
|
569 |
|
Object[] rowData = ((GCPModel)model).getNewLine();
|
570 |
|
rowData[0] = new Boolean(checked);
|
571 |
|
rowData[1] = rowCount + "";
|
572 |
|
rowData[2] = map.getX() + "";
|
573 |
|
rowData[3] = map.getY() + "";
|
574 |
|
rowData[4] = pixel.getX() + "";
|
575 |
|
rowData[5] = pixel.getY() + "";
|
576 |
|
rowData[rowData.length - 1] = new Long(id);
|
577 |
|
getTable().addRow(rowData);
|
578 |
|
}
|
579 |
|
} catch (NotInitializeException e) {
|
580 |
|
GeoreferencingSwingImplLibrary.messageBoxYesOrNot("table_not_initialize", table);
|
581 |
|
}
|
582 |
|
}
|
583 |
|
|
584 |
|
/**
|
585 |
|
* Elimina todos los puntos de la tabla
|
586 |
|
*/
|
587 |
|
public void removeAllPoints() {
|
588 |
|
try {
|
589 |
|
getTable().removeAllRows();
|
590 |
|
} catch (NotInitializeException e) {
|
591 |
|
GeoreferencingSwingImplLibrary.messageBoxYesOrNot("table_not_initialize", table);
|
592 |
|
}
|
593 |
|
}
|
594 |
|
|
595 |
|
/**
|
596 |
|
* Asigna una valor a una celda de la tabla
|
597 |
|
* @param value Valor a asignar
|
598 |
|
* @param row Fila
|
599 |
|
* @param col Columna
|
600 |
|
*/
|
601 |
|
public void setValueAt(Object value, int row, int col) {
|
602 |
|
try {
|
603 |
|
getTable().setValueAt(value, row, col);
|
604 |
|
} catch (NotInitializeException e) {
|
605 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
606 |
|
}
|
607 |
|
}
|
608 |
|
|
609 |
|
/**
|
610 |
|
* Asigna un valor al punto en coordenadas raster de la tabla. Es recomendable gastar este y no
|
611 |
|
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
612 |
|
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
613 |
|
* @param valueX Valor en X
|
614 |
|
* @param valueY Valor en Y
|
615 |
|
* @param row Fila a actualizar
|
616 |
|
* @param col Columna a actualizar
|
617 |
|
*/
|
618 |
|
public void updateRasterPoint(Object valueX, Object valueY, int row) {
|
619 |
|
try {
|
620 |
|
getTable().setValueAt(valueX, row, 4);
|
621 |
|
getTable().setValueAt(valueY, row, 5);
|
622 |
|
updateErrors();
|
623 |
|
} catch (NotInitializeException e) {
|
624 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
625 |
|
}
|
626 |
|
}
|
627 |
|
|
628 |
|
/**
|
629 |
|
* Asigna un valor al punto en coordenadas del mundo de la tabla. Es recomendable gastar este y no
|
630 |
|
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
631 |
|
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
632 |
|
* @param valueX Valor en X
|
633 |
|
* @param valueY Valor en Y
|
634 |
|
* @param row Fila a actualizar
|
635 |
|
* @param col Columna a actualizar
|
636 |
|
*/
|
637 |
|
public void updateMapPoint(Object valueX, Object valueY, int row) {
|
638 |
|
try {
|
639 |
|
getTable().setValueAt(valueX, row, 2);
|
640 |
|
getTable().setValueAt(valueY, row, 3);
|
641 |
|
updateErrors();
|
642 |
|
} catch (NotInitializeException e) {
|
643 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
644 |
|
}
|
645 |
|
}
|
646 |
|
|
647 |
|
/**
|
648 |
|
* Asigna un valor al punto de la tabla. Es recomendable gastar este y no
|
649 |
|
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
650 |
|
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
651 |
|
* @param mapX Valor en X en coordenadas del mundo
|
652 |
|
* @param mapY Valor en Y en coordenadas del mundo
|
653 |
|
* @param pixelX Valor en X en coordenadas del raster
|
654 |
|
* @param pixelY Valor en Y en coordenadas del raster
|
655 |
|
* @param row Fila a actualizar
|
656 |
|
* @param col Columna a actualizar
|
657 |
|
*/
|
658 |
|
public void updatePoint(Object mapX, Object mapY, Object pixelX, Object pixelY, int row) {
|
659 |
|
try {
|
660 |
|
getTable().setValueAt(mapX, row, 2);
|
661 |
|
getTable().setValueAt(mapY, row, 3);
|
662 |
|
getTable().setValueAt(pixelX, row, 4);
|
663 |
|
getTable().setValueAt(pixelY, row, 5);
|
664 |
|
updateErrors();
|
665 |
|
} catch (NotInitializeException e) {
|
666 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
667 |
|
}
|
668 |
|
}
|
669 |
|
|
670 |
|
/**
|
671 |
|
* Actualiza los errores de toda la tabla. Esta funci?n debe ser llamada cuando ha
|
672 |
|
* habido alg?n cambio en los valores de los puntos.
|
673 |
|
* @throws NotInitializeException
|
674 |
|
*/
|
675 |
|
@SuppressWarnings("unchecked")
|
676 |
|
public void updateErrors() {
|
677 |
|
if(pointList == null)
|
678 |
|
return;
|
679 |
|
process.addParam("gpcs", pointList);
|
680 |
|
process.addParam("orden", new Integer(selectedDegree));
|
681 |
|
try {
|
682 |
|
process.execute();
|
683 |
|
} catch(RuntimeException e) {
|
684 |
|
//Matriz singular
|
685 |
|
return;
|
686 |
|
} catch (ProcessInterruptedException e) {
|
687 |
|
} catch (ProcessException e) {
|
688 |
|
}
|
689 |
|
HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
|
690 |
|
Geotransformation result = (Geotransformation)map.get("RESULT");
|
691 |
|
if(result == null)
|
692 |
|
return;
|
693 |
|
|
694 |
|
//Actualizamos los errores de toda la tabla
|
695 |
|
try {
|
696 |
|
ColorColumnRenderer cr = new ColorColumnRenderer();
|
697 |
|
for (int i = 0; i < pointList.size(); i++) {
|
698 |
|
GeoPoint point = pointList.get(i);
|
699 |
|
getTable().setValueAt(new Double(point.getErrorX()), point.getNumber(), 6);
|
700 |
|
getTable().setValueAt(new Double(point.getErrorY()), point.getNumber(), 7);
|
701 |
|
getTable().setValueAt(new Double(point.getRms()), point.getNumber(), 8);
|
702 |
|
if (point.getRms() > threshold)
|
703 |
|
cr.addRowToColor1(point.getNumber());
|
704 |
|
else
|
705 |
|
cr.addRowToColor2(point.getNumber());
|
706 |
|
}
|
707 |
|
getTable().getTable().getJTable().getColumnModel().getColumn(8).setCellRenderer(cr);
|
708 |
|
getError().setValue(result.getRmsTotal() + "");
|
709 |
|
} catch (NotInitializeException e) {
|
710 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
711 |
|
}
|
712 |
|
}
|
713 |
|
|
714 |
|
/**
|
715 |
|
* Obtiene el resultado de aplicar el algoritmo de transformaci?n
|
716 |
|
* @return
|
717 |
|
*/
|
718 |
|
@SuppressWarnings("unchecked")
|
719 |
|
public Geotransformation getGeoTransformDataResult() {
|
720 |
|
if(process != null) {
|
721 |
|
HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
|
722 |
|
return (Geotransformation)map.get("RESULT");
|
723 |
|
}
|
724 |
|
return null;
|
725 |
|
}
|
726 |
|
|
727 |
|
/**
|
728 |
|
* Obtiene una valor de una celda de la tabla
|
729 |
|
* @param row Fila
|
730 |
|
* @param col Columna
|
731 |
|
* @return Valor obtenido
|
732 |
|
*/
|
733 |
|
public Object getValueAt(int row, int col) {
|
734 |
|
try {
|
735 |
|
return getTable().getModel().getValueAt(row, col);
|
736 |
|
} catch (NotInitializeException e) {
|
737 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
738 |
|
}
|
739 |
|
return null;
|
740 |
|
}
|
741 |
|
|
742 |
|
/**
|
743 |
|
* Obtiene el n?mero de filas de la tabla
|
744 |
|
* @return Entero que representa el n?mero de filas de la tabla
|
745 |
|
*/
|
746 |
|
public int getRowCount() {
|
747 |
|
try {
|
748 |
|
return getTable().getRowCount();
|
749 |
|
} catch (NotInitializeException e) {
|
750 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
751 |
|
}
|
752 |
|
return 0;
|
753 |
|
}
|
754 |
|
|
755 |
|
/**
|
756 |
|
* Obtiene el n?mero de columnas de la tabla
|
757 |
|
* @return Entero que representa el n?mero de columnas de la tabla
|
758 |
|
*/
|
759 |
|
public int getColumnCount() {
|
760 |
|
try {
|
761 |
|
return getTable().getModel().getColumnCount();
|
762 |
|
} catch (NotInitializeException e) {
|
763 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
764 |
|
}
|
765 |
|
return 0;
|
766 |
|
}
|
767 |
|
|
768 |
|
/**
|
769 |
|
* Inicializa una fila de la tabla con los valores a 0, el n?mero de punto
|
770 |
|
* y el identificador. Esto es util para la inserci?n de un nuevo punto antes
|
771 |
|
* de introducir sus coordenadas.
|
772 |
|
* @param row Fila a inicializar
|
773 |
|
* @param id Identificador
|
774 |
|
*/
|
775 |
|
public void initializeRow(int row, long id) {
|
776 |
|
try {
|
777 |
|
getTable().setValueAt(new Integer(row), row, 1);
|
778 |
|
for (int i = 2; i <= 9; i++)
|
779 |
|
getTable().setValueAt(new Double(0), row, i);
|
780 |
|
getTable().setValueAt(new Long(id), row, getColumnCount() - 1);
|
781 |
|
} catch (NotInitializeException e) {
|
782 |
|
GeoreferencingSwingImplLibrary.messageBoxError("table_not_initialize", this, e);
|
783 |
|
}
|
784 |
|
}
|
785 |
|
|
786 |
|
|
787 |
|
/**
|
788 |
|
* Renderer para cambiar el color a la columna de la tabla
|
789 |
|
* 06/02/2008
|
790 |
|
* @author Nacho Brodin nachobrodin@gmail.com
|
791 |
|
*/
|
792 |
|
public class ColorColumnRenderer extends DefaultTableCellRenderer {
|
793 |
|
private static final long serialVersionUID = 1L;
|
794 |
|
private Color back = Color.red;
|
795 |
|
private Color fore = Color.white;
|
796 |
|
private Color back2 = Color.white;
|
797 |
|
private Color fore2 = Color.black;
|
798 |
|
private List<Integer> color1 = null;
|
799 |
|
private List<Integer> color2 = null;
|
800 |
|
|
801 |
|
public ColorColumnRenderer() {
|
802 |
|
super();
|
803 |
|
color1 = new ArrayList<Integer>();
|
804 |
|
color2 = new ArrayList<Integer>();
|
805 |
|
}
|
806 |
|
|
807 |
|
/**
|
808 |
|
* A?ade una fila al tipo de color 1
|
809 |
|
* @param row
|
810 |
|
*/
|
811 |
|
public void addRowToColor1(int row) {
|
812 |
|
color1.add(new Integer(row));
|
813 |
|
}
|
814 |
|
|
815 |
|
/**
|
816 |
|
* A?ade una fila al tipo de color 2
|
817 |
|
* @param row
|
818 |
|
*/
|
819 |
|
public void addRowToColor2(int row) {
|
820 |
|
color2.add(new Integer(row));
|
821 |
|
}
|
822 |
|
|
823 |
|
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected,
|
824 |
|
boolean hasFocus, int row, int column) {
|
825 |
|
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
826 |
|
for (int i = 0; i < color1.size(); i++) {
|
827 |
|
if(((Integer)color1.get(i)).intValue() == row) {
|
828 |
|
cell.setBackground(back);
|
829 |
|
cell.setForeground(fore);
|
830 |
|
}
|
831 |
|
}
|
832 |
|
for (int i = 0; i < color2.size(); i++) {
|
833 |
|
if(((Integer)color2.get(i)).intValue() == row) {
|
834 |
|
cell.setBackground(back2);
|
835 |
|
cell.setForeground(fore2);
|
836 |
|
}
|
837 |
|
}
|
838 |
|
return cell;
|
839 |
|
}
|
840 |
|
}
|
841 |
|
}
|
842 |
|
|